Mercurial > cortex
view thesis/cortex.org @ 450:432f2c4646cb
sleepig.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Wed, 26 Mar 2014 03:18:57 -0400 |
parents | 09b7c8dd4365 |
children | 0a4362d1f138 |
line wrap: on
line source
1 #+title: =CORTEX=2 #+author: Robert McIntyre3 #+email: rlm@mit.edu4 #+description: Using embodied AI to facilitate Artificial Imagination.5 #+keywords: AI, clojure, embodiment8 * Empathy and Embodiment as problem solving strategies10 By the end of this thesis, you will have seen a novel approach to11 interpreting video using embodiment and empathy. You will have also12 seen one way to efficiently implement empathy for embodied13 creatures. Finally, you will become familiar with =CORTEX=, a system14 for designing and simulating creatures with rich senses, which you15 may choose to use in your own research.17 This is the core vision of my thesis: That one of the important ways18 in which we understand others is by imagining ourselves in their19 position and emphatically feeling experiences relative to our own20 bodies. By understanding events in terms of our own previous21 corporeal experience, we greatly constrain the possibilities of what22 would otherwise be an unwieldy exponential search. This extra23 constraint can be the difference between easily understanding what24 is happening in a video and being completely lost in a sea of25 incomprehensible color and movement.27 ** Recognizing actions in video is extremely difficult29 Consider for example the problem of determining what is happening30 in a video of which this is one frame:32 #+caption: A cat drinking some water. Identifying this action is33 #+caption: beyond the state of the art for computers.34 #+ATTR_LaTeX: :width 7cm35 [[./images/cat-drinking.jpg]]37 It is currently impossible for any computer program to reliably38 label such a video as ``drinking''. And rightly so -- it is a very39 hard problem! What features can you describe in terms of low level40 functions of pixels that can even begin to describe at a high level41 what is happening here?43 Or suppose that you are building a program that recognizes chairs.44 How could you ``see'' the chair in figure \ref{hidden-chair}?46 #+caption: The chair in this image is quite obvious to humans, but I47 #+caption: doubt that any modern computer vision program can find it.48 #+name: hidden-chair49 #+ATTR_LaTeX: :width 10cm50 [[./images/fat-person-sitting-at-desk.jpg]]52 Finally, how is it that you can easily tell the difference between53 how the girls /muscles/ are working in figure \ref{girl}?55 #+caption: The mysterious ``common sense'' appears here as you are able56 #+caption: to discern the difference in how the girl's arm muscles57 #+caption: are activated between the two images.58 #+name: girl59 #+ATTR_LaTeX: :width 7cm60 [[./images/wall-push.png]]62 Each of these examples tells us something about what might be going63 on in our minds as we easily solve these recognition problems.65 The hidden chairs show us that we are strongly triggered by cues66 relating to the position of human bodies, and that we can determine67 the overall physical configuration of a human body even if much of68 that body is occluded.70 The picture of the girl pushing against the wall tells us that we71 have common sense knowledge about the kinetics of our own bodies.72 We know well how our muscles would have to work to maintain us in73 most positions, and we can easily project this self-knowledge to74 imagined positions triggered by images of the human body.76 ** =EMPATH= neatly solves recognition problems78 I propose a system that can express the types of recognition79 problems above in a form amenable to computation. It is split into80 four parts:82 - Free/Guided Play :: The creature moves around and experiences the83 world through its unique perspective. Many otherwise84 complicated actions are easily described in the language of a85 full suite of body-centered, rich senses. For example,86 drinking is the feeling of water sliding down your throat, and87 cooling your insides. It's often accompanied by bringing your88 hand close to your face, or bringing your face close to water.89 Sitting down is the feeling of bending your knees, activating90 your quadriceps, then feeling a surface with your bottom and91 relaxing your legs. These body-centered action descriptions92 can be either learned or hard coded.93 - Posture Imitation :: When trying to interpret a video or image,94 the creature takes a model of itself and aligns it with95 whatever it sees. This alignment can even cross species, as96 when humans try to align themselves with things like ponies,97 dogs, or other humans with a different body type.98 - Empathy :: The alignment triggers associations with99 sensory data from prior experiences. For example, the100 alignment itself easily maps to proprioceptive data. Any101 sounds or obvious skin contact in the video can to a lesser102 extent trigger previous experience. Segments of previous103 experiences are stitched together to form a coherent and104 complete sensory portrait of the scene.105 - Recognition :: With the scene described in terms of first106 person sensory events, the creature can now run its107 action-identification programs on this synthesized sensory108 data, just as it would if it were actually experiencing the109 scene first-hand. If previous experience has been accurately110 retrieved, and if it is analogous enough to the scene, then111 the creature will correctly identify the action in the scene.113 For example, I think humans are able to label the cat video as114 ``drinking'' because they imagine /themselves/ as the cat, and115 imagine putting their face up against a stream of water and116 sticking out their tongue. In that imagined world, they can feel117 the cool water hitting their tongue, and feel the water entering118 their body, and are able to recognize that /feeling/ as drinking.119 So, the label of the action is not really in the pixels of the120 image, but is found clearly in a simulation inspired by those121 pixels. An imaginative system, having been trained on drinking and122 non-drinking examples and learning that the most important123 component of drinking is the feeling of water sliding down one's124 throat, would analyze a video of a cat drinking in the following125 manner:127 1. Create a physical model of the video by putting a ``fuzzy''128 model of its own body in place of the cat. Possibly also create129 a simulation of the stream of water.131 2. Play out this simulated scene and generate imagined sensory132 experience. This will include relevant muscle contractions, a133 close up view of the stream from the cat's perspective, and most134 importantly, the imagined feeling of water entering the135 mouth. The imagined sensory experience can come from a136 simulation of the event, but can also be pattern-matched from137 previous, similar embodied experience.139 3. The action is now easily identified as drinking by the sense of140 taste alone. The other senses (such as the tongue moving in and141 out) help to give plausibility to the simulated action. Note that142 the sense of vision, while critical in creating the simulation,143 is not critical for identifying the action from the simulation.145 For the chair examples, the process is even easier:147 1. Align a model of your body to the person in the image.149 2. Generate proprioceptive sensory data from this alignment.151 3. Use the imagined proprioceptive data as a key to lookup related152 sensory experience associated with that particular proproceptive153 feeling.155 4. Retrieve the feeling of your bottom resting on a surface, your156 knees bent, and your leg muscles relaxed.158 5. This sensory information is consistent with the =sitting?=159 sensory predicate, so you (and the entity in the image) must be160 sitting.162 6. There must be a chair-like object since you are sitting.164 Empathy offers yet another alternative to the age-old AI165 representation question: ``What is a chair?'' --- A chair is the166 feeling of sitting.168 My program, =EMPATH= uses this empathic problem solving technique169 to interpret the actions of a simple, worm-like creature.171 #+caption: The worm performs many actions during free play such as172 #+caption: curling, wiggling, and resting.173 #+name: worm-intro174 #+ATTR_LaTeX: :width 15cm175 [[./images/worm-intro-white.png]]177 #+caption: =EMPATH= recognized and classified each of these poses by178 #+caption: inferring the complete sensory experience from179 #+caption: proprioceptive data.180 #+name: worm-recognition-intro181 #+ATTR_LaTeX: :width 15cm182 [[./images/worm-poses.png]]184 One powerful advantage of empathic problem solving is that it185 factors the action recognition problem into two easier problems. To186 use empathy, you need an /aligner/, which takes the video and a187 model of your body, and aligns the model with the video. Then, you188 need a /recognizer/, which uses the aligned model to interpret the189 action. The power in this method lies in the fact that you describe190 all actions form a body-centered viewpoint. You are less tied to191 the particulars of any visual representation of the actions. If you192 teach the system what ``running'' is, and you have a good enough193 aligner, the system will from then on be able to recognize running194 from any point of view, even strange points of view like above or195 underneath the runner. This is in contrast to action recognition196 schemes that try to identify actions using a non-embodied approach.197 If these systems learn about running as viewed from the side, they198 will not automatically be able to recognize running from any other199 viewpoint.201 Another powerful advantage is that using the language of multiple202 body-centered rich senses to describe body-centerd actions offers a203 massive boost in descriptive capability. Consider how difficult it204 would be to compose a set of HOG filters to describe the action of205 a simple worm-creature ``curling'' so that its head touches its206 tail, and then behold the simplicity of describing thus action in a207 language designed for the task (listing \ref{grand-circle-intro}):209 #+caption: Body-centerd actions are best expressed in a body-centered210 #+caption: language. This code detects when the worm has curled into a211 #+caption: full circle. Imagine how you would replicate this functionality212 #+caption: using low-level pixel features such as HOG filters!213 #+name: grand-circle-intro214 #+begin_listing clojure215 #+begin_src clojure216 (defn grand-circle?217 "Does the worm form a majestic circle (one end touching the other)?"218 [experiences]219 (and (curled? experiences)220 (let [worm-touch (:touch (peek experiences))221 tail-touch (worm-touch 0)222 head-touch (worm-touch 4)]223 (and (< 0.55 (contact worm-segment-bottom-tip tail-touch))224 (< 0.55 (contact worm-segment-top-tip head-touch))))))225 #+end_src226 #+end_listing229 ** =CORTEX= is a toolkit for building sensate creatures231 I built =CORTEX= to be a general AI research platform for doing232 experiments involving multiple rich senses and a wide variety and233 number of creatures. I intend it to be useful as a library for many234 more projects than just this one. =CORTEX= was necessary to meet a235 need among AI researchers at CSAIL and beyond, which is that people236 often will invent neat ideas that are best expressed in the237 language of creatures and senses, but in order to explore those238 ideas they must first build a platform in which they can create239 simulated creatures with rich senses! There are many ideas that240 would be simple to execute (such as =EMPATH=), but attached to them241 is the multi-month effort to make a good creature simulator. Often,242 that initial investment of time proves to be too much, and the243 project must make do with a lesser environment.245 =CORTEX= is well suited as an environment for embodied AI research246 for three reasons:248 - You can create new creatures using Blender, a popular 3D modeling249 program. Each sense can be specified using special blender nodes250 with biologically inspired paramaters. You need not write any251 code to create a creature, and can use a wide library of252 pre-existing blender models as a base for your own creatures.254 - =CORTEX= implements a wide variety of senses, including touch,255 proprioception, vision, hearing, and muscle tension. Complicated256 senses like touch, and vision involve multiple sensory elements257 embedded in a 2D surface. You have complete control over the258 distribution of these sensor elements through the use of simple259 png image files. In particular, =CORTEX= implements more260 comprehensive hearing than any other creature simulation system261 available.263 - =CORTEX= supports any number of creatures and any number of264 senses. Time in =CORTEX= dialates so that the simulated creatures265 always precieve a perfectly smooth flow of time, regardless of266 the actual computational load.268 =CORTEX= is built on top of =jMonkeyEngine3=, which is a video game269 engine designed to create cross-platform 3D desktop games. =CORTEX=270 is mainly written in clojure, a dialect of =LISP= that runs on the271 java virtual machine (JVM). The API for creating and simulating272 creatures and senses is entirely expressed in clojure, though many273 senses are implemented at the layer of jMonkeyEngine or below. For274 example, for the sense of hearing I use a layer of clojure code on275 top of a layer of java JNI bindings that drive a layer of =C++=276 code which implements a modified version of =OpenAL= to support277 multiple listeners. =CORTEX= is the only simulation environment278 that I know of that can support multiple entities that can each279 hear the world from their own perspective. Other senses also280 require a small layer of Java code. =CORTEX= also uses =bullet=, a281 physics simulator written in =C=.283 #+caption: Here is the worm from above modeled in Blender, a free284 #+caption: 3D-modeling program. Senses and joints are described285 #+caption: using special nodes in Blender.286 #+name: worm-recognition-intro287 #+ATTR_LaTeX: :width 12cm288 [[./images/blender-worm.png]]290 Here are some thing I anticipate that =CORTEX= might be used for:292 - exploring new ideas about sensory integration293 - distributed communication among swarm creatures294 - self-learning using free exploration,295 - evolutionary algorithms involving creature construction296 - exploration of exoitic senses and effectors that are not possible297 in the real world (such as telekenisis or a semantic sense)298 - imagination using subworlds300 During one test with =CORTEX=, I created 3,000 entities each with301 their own independent senses and ran them all at only 1/80 real302 time. In another test, I created a detailed model of my own hand,303 equipped with a realistic distribution of touch (more sensitive at304 the fingertips), as well as eyes and ears, and it ran at around 1/4305 real time.307 #+BEGIN_LaTeX308 \begin{sidewaysfigure}309 \includegraphics[width=9.5in]{images/full-hand.png}310 \caption{Here is the worm from above modeled in Blender,311 a free 3D-modeling program. Senses and joints are described312 using special nodes in Blender. The senses are displayed on313 the right, and the simulation is displayed on the left. Notice314 that the hand is curling its fingers, that it can see its own315 finger from the eye in its palm, and thta it can feel its own316 thumb touching its palm.}317 \end{sidewaysfigure}318 #+END_LaTeX320 ** Contributions322 I built =CORTEX=, a comprehensive platform for embodied AI323 experiments. =CORTEX= many new features lacking in other systems,324 such as sound. It is easy to create new creatures using Blender, a325 free 3D modeling program.327 I built =EMPATH=, which uses =CORTEX= to identify the actions of a328 worm-like creature using a computational model of empathy.330 * Building =CORTEX=332 ** To explore embodiment, we need a world, body, and senses334 ** Because of Time, simulation is perferable to reality336 ** Video game engines are a great starting point338 ** Bodies are composed of segments connected by joints340 ** Eyes reuse standard video game components342 ** Hearing is hard; =CORTEX= does it right344 ** Touch uses hundreds of hair-like elements346 ** Proprioception is the sense that makes everything ``real''348 ** Muscles are both effectors and sensors350 ** =CORTEX= brings complex creatures to life!352 ** =CORTEX= enables many possiblities for further research354 * Empathy in a simulated worm356 Here I develop a computational model of empathy, using =CORTEX= as a357 base. Empathy in this context is the ability to observe another358 creature and infer what sorts of sensations that creature is359 feeling. My empathy algorithm involves multiple phases. First is360 free-play, where the creature moves around and gains sensory361 experience. From this experience I construct a representation of the362 creature's sensory state space, which I call \Phi-space. Using363 \Phi-space, I construct an efficient function which takes the364 limited data that comes from observing another creature and enriches365 it full compliment of imagined sensory data. I can then use the366 imagined sensory data to recognize what the observed creature is367 doing and feeling, using straightforward embodied action predicates.368 This is all demonstrated with using a simple worm-like creature, and369 recognizing worm-actions based on limited data.371 #+caption: Here is the worm with which we will be working.372 #+caption: It is composed of 5 segments. Each segment has a373 #+caption: pair of extensor and flexor muscles. Each of the374 #+caption: worm's four joints is a hinge joint which allows375 #+caption: 30 degrees of rotation to either side. Each segment376 #+caption: of the worm is touch-capable and has a uniform377 #+caption: distribution of touch sensors on each of its faces.378 #+caption: Each joint has a proprioceptive sense to detect379 #+caption: relative positions. The worm segments are all the380 #+caption: same except for the first one, which has a much381 #+caption: higher weight than the others to allow for easy382 #+caption: manual motor control.383 #+name: basic-worm-view384 #+ATTR_LaTeX: :width 10cm385 [[./images/basic-worm-view.png]]387 #+caption: Program for reading a worm from a blender file and388 #+caption: outfitting it with the senses of proprioception,389 #+caption: touch, and the ability to move, as specified in the390 #+caption: blender file.391 #+name: get-worm392 #+begin_listing clojure393 #+begin_src clojure394 (defn worm []395 (let [model (load-blender-model "Models/worm/worm.blend")]396 {:body (doto model (body!))397 :touch (touch! model)398 :proprioception (proprioception! model)399 :muscles (movement! model)}))400 #+end_src401 #+end_listing403 ** Embodiment factors action recognition into managable parts405 Using empathy, I divide the problem of action recognition into a406 recognition process expressed in the language of a full compliment407 of senses, and an imaganitive process that generates full sensory408 data from partial sensory data. Splitting the action recognition409 problem in this manner greatly reduces the total amount of work to410 recognize actions: The imaganitive process is mostly just matching411 previous experience, and the recognition process gets to use all412 the senses to directly describe any action.414 ** Action recognition is easy with a full gamut of senses416 Embodied representations using multiple senses such as touch,417 proprioception, and muscle tension turns out be be exceedingly418 efficient at describing body-centered actions. It is the ``right419 language for the job''. For example, it takes only around 5 lines420 of LISP code to describe the action of ``curling'' using embodied421 primitives. It takes about 8 lines to describe the seemingly422 complicated action of wiggling.424 The following action predicates each take a stream of sensory425 experience, observe however much of it they desire, and decide426 whether the worm is doing the action they describe. =curled?=427 relies on proprioception, =resting?= relies on touch, =wiggling?=428 relies on a fourier analysis of muscle contraction, and429 =grand-circle?= relies on touch and reuses =curled?= as a gaurd.431 #+caption: Program for detecting whether the worm is curled. This is the432 #+caption: simplest action predicate, because it only uses the last frame433 #+caption: of sensory experience, and only uses proprioceptive data. Even434 #+caption: this simple predicate, however, is automatically frame435 #+caption: independent and ignores vermopomorphic differences such as436 #+caption: worm textures and colors.437 #+name: curled438 #+begin_listing clojure439 #+begin_src clojure440 (defn curled?441 "Is the worm curled up?"442 [experiences]443 (every?444 (fn [[_ _ bend]]445 (> (Math/sin bend) 0.64))446 (:proprioception (peek experiences))))447 #+end_src448 #+end_listing450 #+caption: Program for summarizing the touch information in a patch451 #+caption: of skin.452 #+name: touch-summary453 #+begin_listing clojure454 #+begin_src clojure455 (defn contact456 "Determine how much contact a particular worm segment has with457 other objects. Returns a value between 0 and 1, where 1 is full458 contact and 0 is no contact."459 [touch-region [coords contact :as touch]]460 (-> (zipmap coords contact)461 (select-keys touch-region)462 (vals)463 (#(map first %))464 (average)465 (* 10)466 (- 1)467 (Math/abs)))468 #+end_src469 #+end_listing472 #+caption: Program for detecting whether the worm is at rest. This program473 #+caption: uses a summary of the tactile information from the underbelly474 #+caption: of the worm, and is only true if every segment is touching the475 #+caption: floor. Note that this function contains no references to476 #+caption: proprioction at all.477 #+name: resting478 #+begin_listing clojure479 #+begin_src clojure480 (def worm-segment-bottom (rect-region [8 15] [14 22]))482 (defn resting?483 "Is the worm resting on the ground?"484 [experiences]485 (every?486 (fn [touch-data]487 (< 0.9 (contact worm-segment-bottom touch-data)))488 (:touch (peek experiences))))489 #+end_src490 #+end_listing492 #+caption: Program for detecting whether the worm is curled up into a493 #+caption: full circle. Here the embodied approach begins to shine, as494 #+caption: I am able to both use a previous action predicate (=curled?=)495 #+caption: as well as the direct tactile experience of the head and tail.496 #+name: grand-circle497 #+begin_listing clojure498 #+begin_src clojure499 (def worm-segment-bottom-tip (rect-region [15 15] [22 22]))501 (def worm-segment-top-tip (rect-region [0 15] [7 22]))503 (defn grand-circle?504 "Does the worm form a majestic circle (one end touching the other)?"505 [experiences]506 (and (curled? experiences)507 (let [worm-touch (:touch (peek experiences))508 tail-touch (worm-touch 0)509 head-touch (worm-touch 4)]510 (and (< 0.55 (contact worm-segment-bottom-tip tail-touch))511 (< 0.55 (contact worm-segment-top-tip head-touch))))))512 #+end_src513 #+end_listing516 #+caption: Program for detecting whether the worm has been wiggling for517 #+caption: the last few frames. It uses a fourier analysis of the muscle518 #+caption: contractions of the worm's tail to determine wiggling. This is519 #+caption: signigicant because there is no particular frame that clearly520 #+caption: indicates that the worm is wiggling --- only when multiple frames521 #+caption: are analyzed together is the wiggling revealed. Defining522 #+caption: wiggling this way also gives the worm an opportunity to learn523 #+caption: and recognize ``frustrated wiggling'', where the worm tries to524 #+caption: wiggle but can't. Frustrated wiggling is very visually different525 #+caption: from actual wiggling, but this definition gives it to us for free.526 #+name: wiggling527 #+begin_listing clojure528 #+begin_src clojure529 (defn fft [nums]530 (map531 #(.getReal %)532 (.transform533 (FastFourierTransformer. DftNormalization/STANDARD)534 (double-array nums) TransformType/FORWARD)))536 (def indexed (partial map-indexed vector))538 (defn max-indexed [s]539 (first (sort-by (comp - second) (indexed s))))541 (defn wiggling?542 "Is the worm wiggling?"543 [experiences]544 (let [analysis-interval 0x40]545 (when (> (count experiences) analysis-interval)546 (let [a-flex 3547 a-ex 2548 muscle-activity549 (map :muscle (vector:last-n experiences analysis-interval))550 base-activity551 (map #(- (% a-flex) (% a-ex)) muscle-activity)]552 (= 2553 (first554 (max-indexed555 (map #(Math/abs %)556 (take 20 (fft base-activity))))))))))557 #+end_src558 #+end_listing560 With these action predicates, I can now recognize the actions of561 the worm while it is moving under my control and I have access to562 all the worm's senses.564 #+caption: Use the action predicates defined earlier to report on565 #+caption: what the worm is doing while in simulation.566 #+name: report-worm-activity567 #+begin_listing clojure568 #+begin_src clojure569 (defn debug-experience570 [experiences text]571 (cond572 (grand-circle? experiences) (.setText text "Grand Circle")573 (curled? experiences) (.setText text "Curled")574 (wiggling? experiences) (.setText text "Wiggling")575 (resting? experiences) (.setText text "Resting")))576 #+end_src577 #+end_listing579 #+caption: Using =debug-experience=, the body-centered predicates580 #+caption: work together to classify the behaviour of the worm.581 #+caption: while under manual motor control.582 #+name: basic-worm-view583 #+ATTR_LaTeX: :width 10cm584 [[./images/worm-identify-init.png]]586 These action predicates satisfy the recognition requirement of an587 empathic recognition system. There is a lot of power in the588 simplicity of the action predicates. They describe their actions589 without getting confused in visual details of the worm. Each one is590 frame independent, but more than that, they are each indepent of591 irrelevant visual details of the worm and the environment. They592 will work regardless of whether the worm is a different color or593 hevaily textured, or of the environment has strange lighting.595 The trick now is to make the action predicates work even when the596 sensory data on which they depend is absent. If I can do that, then597 I will have gained much,599 ** \Phi-space describes the worm's experiences601 As a first step towards building empathy, I need to gather all of602 the worm's experiences during free play. I use a simple vector to603 store all the experiences.605 #+caption: Program to gather the worm's experiences into a vector for606 #+caption: further processing. The =motor-control-program= line uses607 #+caption: a motor control script that causes the worm to execute a series608 #+caption: of ``exercices'' that include all the action predicates.609 #+name: generate-phi-space610 #+begin_listing clojure611 #+begin_src clojure612 (defn generate-phi-space []613 (let [experiences (atom [])]614 (run-world615 (apply-map616 worm-world617 (merge618 (worm-world-defaults)619 {:end-frame 700620 :motor-control621 (motor-control-program worm-muscle-labels do-all-the-things)622 :experiences experiences})))623 @experiences))624 #+end_src625 #+end_listing627 Each element of the experience vector exists in the vast space of628 all possible worm-experiences. Most of this vast space is actually629 unreachable due to physical constraints of the worm's body. For630 example, the worm's segments are connected by hinge joints that put631 a practical limit on the worm's degrees of freedom. Also, the worm632 can not be bent into a circle so that its ends are touching and at633 the same time not also experience the sensation of touching itself.635 As the worm moves around during free play and the vector grows636 larger, the vector begins to define a subspace which is all the637 practical experiences the worm can experience during normal638 operation, which I call \Phi-space, short for physical-space. The639 vector defines a path through \Phi-space. This path has interesting640 properties that all derive from embodiment. The proprioceptive641 components are completely smooth, because in order for the worm to642 move from one position to another, it must pass through the643 intermediate positions. The path invariably forms loops as actions644 are repeated. Finally and most importantly, proprioception actually645 gives very strong inference about the other senses. For example,646 when the worm is flat, you can infer that it is touching the ground647 and that its muscles are not active, because if the muscles were648 active, the worm would be moving and would not be perfectly flat.649 In order to stay flat, the worm has to be touching the ground, or650 it would again be moving out of the flat position due to gravity.651 If the worm is positioned in such a way that it interacts with652 itself, then it is very likely to be feeling the same tactile653 feelings as the last time it was in that position, because it has654 the same body as then. If you observe multiple frames of655 proprioceptive data, then you can become increasingly confident656 about the exact activations of the worm's muscles, because it657 generally takes a unique combination of muscle contractions to658 transform the worm's body along a specific path through \Phi-space.660 There is a simple way of taking \Phi-space and the total ordering661 provided by an experience vector and reliably infering the rest of662 the senses.664 ** Empathy is the process of tracing though \Phi-space666 Here is the core of a basic empathy algorithm, starting with an667 experience vector: First, group the experiences into tiered668 proprioceptive bins. I use powers of 10 and 3 bins, and the669 smallest bin has and approximate size of 0.001 radians in all670 proprioceptive dimensions.672 Then, given a sequence of proprioceptive input, generate a set of673 matching experience records for each input.675 Finally, to infer sensory data, select the longest consective chain676 of experiences as determined by the indexes into the experience677 vector.679 This algorithm has three advantages:681 1. It's simple683 3. It's very fast -- both tracing through possibilites and684 retrieving possible interpretations take essentially constant685 time.687 2. It protects from wrong interpretations of transient ambiguous688 proprioceptive data : for example, if the worm is flat for just689 an instant, this flattness will not be interpreted as implying690 that the worm has its muscles relaxed, since the flattness is691 part of a longer chain which includes a distinct pattern of692 muscle activation. A memoryless statistical model such as a693 markov model that operates on individual frames may very well694 make this mistake.696 #+caption: Program to convert an experience vector into a697 #+caption: proprioceptively binned lookup function.698 #+name: bin699 #+begin_listing clojure700 #+begin_src clojure701 (defn bin [digits]702 (fn [angles]703 (->> angles704 (flatten)705 (map (juxt #(Math/sin %) #(Math/cos %)))706 (flatten)707 (mapv #(Math/round (* % (Math/pow 10 (dec digits))))))))709 (defn gen-phi-scan710 "Nearest-neighbors with binning. Only returns a result if711 the propriceptive data is within 10% of a previously recorded712 result in all dimensions."713 [phi-space]714 (let [bin-keys (map bin [3 2 1])715 bin-maps716 (map (fn [bin-key]717 (group-by718 (comp bin-key :proprioception phi-space)719 (range (count phi-space)))) bin-keys)720 lookups (map (fn [bin-key bin-map]721 (fn [proprio] (bin-map (bin-key proprio))))722 bin-keys bin-maps)]723 (fn lookup [proprio-data]724 (set (some #(% proprio-data) lookups)))))725 #+end_src726 #+end_listing729 #+caption: Program to calculate empathy by tracing though \Phi-space730 #+caption: and finding the longest (ie. most coherent) interpretation731 #+caption: of the data.732 #+name: longest-thread733 #+begin_listing clojure734 #+begin_src clojure735 (defn longest-thread736 "Find the longest thread from phi-index-sets. The index sets should737 be ordered from most recent to least recent."738 [phi-index-sets]739 (loop [result '()740 [thread-bases & remaining :as phi-index-sets] phi-index-sets]741 (if (empty? phi-index-sets)742 (vec result)743 (let [threads744 (for [thread-base thread-bases]745 (loop [thread (list thread-base)746 remaining remaining]747 (let [next-index (dec (first thread))]748 (cond (empty? remaining) thread749 (contains? (first remaining) next-index)750 (recur751 (cons next-index thread) (rest remaining))752 :else thread))))753 longest-thread754 (reduce (fn [thread-a thread-b]755 (if (> (count thread-a) (count thread-b))756 thread-a thread-b))757 '(nil)758 threads)]759 (recur (concat longest-thread result)760 (drop (count longest-thread) phi-index-sets))))))761 #+end_src762 #+end_listing765 There is one final piece, which is to replace missing sensory data766 with a best-guess estimate. While I could fill in missing data by767 using a gradient over the closest known sensory data points, averages768 can be misleading. It is certainly possible to create an impossible769 sensory state by averaging two possible sensory states. Therefore, I770 simply replicate the most recent sensory experience to fill in the771 gaps.773 #+caption: Fill in blanks in sensory experience by replicating the most774 #+caption: recent experience.775 #+name: infer-nils776 #+begin_listing clojure777 #+begin_src clojure778 (defn infer-nils779 "Replace nils with the next available non-nil element in the780 sequence, or barring that, 0."781 [s]782 (loop [i (dec (count s))783 v (transient s)]784 (if (zero? i) (persistent! v)785 (if-let [cur (v i)]786 (if (get v (dec i) 0)787 (recur (dec i) v)788 (recur (dec i) (assoc! v (dec i) cur)))789 (recur i (assoc! v i 0))))))790 #+end_src791 #+end_listing794 ** Efficient action recognition with =EMPATH=796 In my exploration with the worm, I can generally infer actions from797 proprioceptive data exactly as well as when I have the complete798 sensory data. To reach this level, I have to train the worm with799 verious exercices for about 1 minute.801 ** Digression: bootstrapping touch using free exploration803 * Contributions808 # An anatomical joke:809 # - Training810 # - Skeletal imitation811 # - Sensory fleshing-out812 # - Classification