view thesis/cortex.org @ 464:8bf4bb02ed05

sleeeeeep.
author Robert McIntyre <rlm@mit.edu>
date Fri, 28 Mar 2014 00:42:42 -0400
parents 6d55ac73bc6f
children e4104ce9105c
line wrap: on
line source
1 #+title: =CORTEX=
2 #+author: Robert McIntyre
3 #+email: rlm@mit.edu
4 #+description: Using embodied AI to facilitate Artificial Imagination.
5 #+keywords: AI, clojure, embodiment
6 #+LaTeX_CLASS_OPTIONS: [nofloat]
8 * Empathy and Embodiment as problem solving strategies
10 By the end of this thesis, you will have seen a novel approach to
11 interpreting video using embodiment and empathy. You will have also
12 seen one way to efficiently implement empathy for embodied
13 creatures. Finally, you will become familiar with =CORTEX=, a system
14 for designing and simulating creatures with rich senses, which you
15 may choose to use in your own research.
17 This is the core vision of my thesis: That one of the important ways
18 in which we understand others is by imagining ourselves in their
19 position and emphatically feeling experiences relative to our own
20 bodies. By understanding events in terms of our own previous
21 corporeal experience, we greatly constrain the possibilities of what
22 would otherwise be an unwieldy exponential search. This extra
23 constraint can be the difference between easily understanding what
24 is happening in a video and being completely lost in a sea of
25 incomprehensible color and movement.
27 ** Recognizing actions in video is extremely difficult
29 Consider for example the problem of determining what is happening
30 in a video of which this is one frame:
32 #+caption: A cat drinking some water. Identifying this action is
33 #+caption: beyond the state of the art for computers.
34 #+ATTR_LaTeX: :width 7cm
35 [[./images/cat-drinking.jpg]]
37 It is currently impossible for any computer program to reliably
38 label such a video as ``drinking''. And rightly so -- it is a very
39 hard problem! What features can you describe in terms of low level
40 functions of pixels that can even begin to describe at a high level
41 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 I
47 #+caption: doubt that any modern computer vision program can find it.
48 #+name: hidden-chair
49 #+ATTR_LaTeX: :width 10cm
50 [[./images/fat-person-sitting-at-desk.jpg]]
52 Finally, how is it that you can easily tell the difference between
53 how the girls /muscles/ are working in figure \ref{girl}?
55 #+caption: The mysterious ``common sense'' appears here as you are able
56 #+caption: to discern the difference in how the girl's arm muscles
57 #+caption: are activated between the two images.
58 #+name: girl
59 #+ATTR_LaTeX: :width 7cm
60 [[./images/wall-push.png]]
62 Each of these examples tells us something about what might be going
63 on in our minds as we easily solve these recognition problems.
65 The hidden chairs show us that we are strongly triggered by cues
66 relating to the position of human bodies, and that we can determine
67 the overall physical configuration of a human body even if much of
68 that body is occluded.
70 The picture of the girl pushing against the wall tells us that we
71 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 in
73 most positions, and we can easily project this self-knowledge to
74 imagined positions triggered by images of the human body.
76 ** =EMPATH= neatly solves recognition problems
78 I propose a system that can express the types of recognition
79 problems above in a form amenable to computation. It is split into
80 four parts:
82 - Free/Guided Play :: The creature moves around and experiences the
83 world through its unique perspective. Many otherwise
84 complicated actions are easily described in the language of a
85 full suite of body-centered, rich senses. For example,
86 drinking is the feeling of water sliding down your throat, and
87 cooling your insides. It's often accompanied by bringing your
88 hand close to your face, or bringing your face close to water.
89 Sitting down is the feeling of bending your knees, activating
90 your quadriceps, then feeling a surface with your bottom and
91 relaxing your legs. These body-centered action descriptions
92 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 with
95 whatever it sees. This alignment can even cross species, as
96 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 with
99 sensory data from prior experiences. For example, the
100 alignment itself easily maps to proprioceptive data. Any
101 sounds or obvious skin contact in the video can to a lesser
102 extent trigger previous experience. Segments of previous
103 experiences are stitched together to form a coherent and
104 complete sensory portrait of the scene.
105 - Recognition :: With the scene described in terms of first
106 person sensory events, the creature can now run its
107 action-identification programs on this synthesized sensory
108 data, just as it would if it were actually experiencing the
109 scene first-hand. If previous experience has been accurately
110 retrieved, and if it is analogous enough to the scene, then
111 the creature will correctly identify the action in the scene.
113 For example, I think humans are able to label the cat video as
114 ``drinking'' because they imagine /themselves/ as the cat, and
115 imagine putting their face up against a stream of water and
116 sticking out their tongue. In that imagined world, they can feel
117 the cool water hitting their tongue, and feel the water entering
118 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 the
120 image, but is found clearly in a simulation inspired by those
121 pixels. An imaginative system, having been trained on drinking and
122 non-drinking examples and learning that the most important
123 component of drinking is the feeling of water sliding down one's
124 throat, would analyze a video of a cat drinking in the following
125 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 create
129 a simulation of the stream of water.
131 2. Play out this simulated scene and generate imagined sensory
132 experience. This will include relevant muscle contractions, a
133 close up view of the stream from the cat's perspective, and most
134 importantly, the imagined feeling of water entering the
135 mouth. The imagined sensory experience can come from a
136 simulation of the event, but can also be pattern-matched from
137 previous, similar embodied experience.
139 3. The action is now easily identified as drinking by the sense of
140 taste alone. The other senses (such as the tongue moving in and
141 out) help to give plausibility to the simulated action. Note that
142 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 related
152 sensory experience associated with that particular proproceptive
153 feeling.
155 4. Retrieve the feeling of your bottom resting on a surface, your
156 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 be
160 sitting.
162 6. There must be a chair-like object since you are sitting.
164 Empathy offers yet another alternative to the age-old AI
165 representation question: ``What is a chair?'' --- A chair is the
166 feeling of sitting.
168 My program, =EMPATH= uses this empathic problem solving technique
169 to interpret the actions of a simple, worm-like creature.
171 #+caption: The worm performs many actions during free play such as
172 #+caption: curling, wiggling, and resting.
173 #+name: worm-intro
174 #+ATTR_LaTeX: :width 15cm
175 [[./images/worm-intro-white.png]]
177 #+caption: =EMPATH= recognized and classified each of these
178 #+caption: poses by inferring the complete sensory experience
179 #+caption: from proprioceptive data.
180 #+name: worm-recognition-intro
181 #+ATTR_LaTeX: :width 15cm
182 [[./images/worm-poses.png]]
184 One powerful advantage of empathic problem solving is that it
185 factors the action recognition problem into two easier problems. To
186 use empathy, you need an /aligner/, which takes the video and a
187 model of your body, and aligns the model with the video. Then, you
188 need a /recognizer/, which uses the aligned model to interpret the
189 action. The power in this method lies in the fact that you describe
190 all actions form a body-centered viewpoint. You are less tied to
191 the particulars of any visual representation of the actions. If you
192 teach the system what ``running'' is, and you have a good enough
193 aligner, the system will from then on be able to recognize running
194 from any point of view, even strange points of view like above or
195 underneath the runner. This is in contrast to action recognition
196 schemes that try to identify actions using a non-embodied approach.
197 If these systems learn about running as viewed from the side, they
198 will not automatically be able to recognize running from any other
199 viewpoint.
201 Another powerful advantage is that using the language of multiple
202 body-centered rich senses to describe body-centerd actions offers a
203 massive boost in descriptive capability. Consider how difficult it
204 would be to compose a set of HOG filters to describe the action of
205 a simple worm-creature ``curling'' so that its head touches its
206 tail, and then behold the simplicity of describing thus action in a
207 language designed for the task (listing \ref{grand-circle-intro}):
209 #+caption: Body-centerd actions are best expressed in a body-centered
210 #+caption: language. This code detects when the worm has curled into a
211 #+caption: full circle. Imagine how you would replicate this functionality
212 #+caption: using low-level pixel features such as HOG filters!
213 #+name: grand-circle-intro
214 #+attr_latex: [htpb]
215 #+begin_listing clojure
216 #+begin_src clojure
217 (defn grand-circle?
218 "Does the worm form a majestic circle (one end touching the other)?"
219 [experiences]
220 (and (curled? experiences)
221 (let [worm-touch (:touch (peek experiences))
222 tail-touch (worm-touch 0)
223 head-touch (worm-touch 4)]
224 (and (< 0.2 (contact worm-segment-bottom-tip tail-touch))
225 (< 0.2 (contact worm-segment-top-tip head-touch))))))
226 #+end_src
227 #+end_listing
230 ** =CORTEX= is a toolkit for building sensate creatures
232 I built =CORTEX= to be a general AI research platform for doing
233 experiments involving multiple rich senses and a wide variety and
234 number of creatures. I intend it to be useful as a library for many
235 more projects than just this thesis. =CORTEX= was necessary to meet
236 a need among AI researchers at CSAIL and beyond, which is that
237 people often will invent neat ideas that are best expressed in the
238 language of creatures and senses, but in order to explore those
239 ideas they must first build a platform in which they can create
240 simulated creatures with rich senses! There are many ideas that
241 would be simple to execute (such as =EMPATH=), but attached to them
242 is the multi-month effort to make a good creature simulator. Often,
243 that initial investment of time proves to be too much, and the
244 project must make do with a lesser environment.
246 =CORTEX= is well suited as an environment for embodied AI research
247 for three reasons:
249 - You can create new creatures using Blender, a popular 3D modeling
250 program. Each sense can be specified using special blender nodes
251 with biologically inspired paramaters. You need not write any
252 code to create a creature, and can use a wide library of
253 pre-existing blender models as a base for your own creatures.
255 - =CORTEX= implements a wide variety of senses, including touch,
256 proprioception, vision, hearing, and muscle tension. Complicated
257 senses like touch, and vision involve multiple sensory elements
258 embedded in a 2D surface. You have complete control over the
259 distribution of these sensor elements through the use of simple
260 png image files. In particular, =CORTEX= implements more
261 comprehensive hearing than any other creature simulation system
262 available.
264 - =CORTEX= supports any number of creatures and any number of
265 senses. Time in =CORTEX= dialates so that the simulated creatures
266 always precieve a perfectly smooth flow of time, regardless of
267 the actual computational load.
269 =CORTEX= is built on top of =jMonkeyEngine3=, which is a video game
270 engine designed to create cross-platform 3D desktop games. =CORTEX=
271 is mainly written in clojure, a dialect of =LISP= that runs on the
272 java virtual machine (JVM). The API for creating and simulating
273 creatures and senses is entirely expressed in clojure, though many
274 senses are implemented at the layer of jMonkeyEngine or below. For
275 example, for the sense of hearing I use a layer of clojure code on
276 top of a layer of java JNI bindings that drive a layer of =C++=
277 code which implements a modified version of =OpenAL= to support
278 multiple listeners. =CORTEX= is the only simulation environment
279 that I know of that can support multiple entities that can each
280 hear the world from their own perspective. Other senses also
281 require a small layer of Java code. =CORTEX= also uses =bullet=, a
282 physics simulator written in =C=.
284 #+caption: Here is the worm from above modeled in Blender, a free
285 #+caption: 3D-modeling program. Senses and joints are described
286 #+caption: using special nodes in Blender.
287 #+name: worm-recognition-intro
288 #+ATTR_LaTeX: :width 12cm
289 [[./images/blender-worm.png]]
291 Here are some thing I anticipate that =CORTEX= might be used for:
293 - exploring new ideas about sensory integration
294 - distributed communication among swarm creatures
295 - self-learning using free exploration,
296 - evolutionary algorithms involving creature construction
297 - exploration of exoitic senses and effectors that are not possible
298 in the real world (such as telekenisis or a semantic sense)
299 - imagination using subworlds
301 During one test with =CORTEX=, I created 3,000 creatures each with
302 their own independent senses and ran them all at only 1/80 real
303 time. In another test, I created a detailed model of my own hand,
304 equipped with a realistic distribution of touch (more sensitive at
305 the fingertips), as well as eyes and ears, and it ran at around 1/4
306 real time.
308 #+BEGIN_LaTeX
309 \begin{sidewaysfigure}
310 \includegraphics[width=9.5in]{images/full-hand.png}
311 \caption{
312 I modeled my own right hand in Blender and rigged it with all the
313 senses that {\tt CORTEX} supports. My simulated hand has a
314 biologically inspired distribution of touch sensors. The senses are
315 displayed on the right, and the simulation is displayed on the
316 left. Notice that my hand is curling its fingers, that it can see
317 its own finger from the eye in its palm, and that it can feel its
318 own thumb touching its palm.}
319 \end{sidewaysfigure}
320 #+END_LaTeX
322 ** Contributions
324 - I built =CORTEX=, a comprehensive platform for embodied AI
325 experiments. =CORTEX= supports many features lacking in other
326 systems, such proper simulation of hearing. It is easy to create
327 new =CORTEX= creatures using Blender, a free 3D modeling program.
329 - I built =EMPATH=, which uses =CORTEX= to identify the actions of
330 a worm-like creature using a computational model of empathy.
332 * Building =CORTEX=
334 I intend for =CORTEX= to be used as a general purpose library for
335 building creatures and outfitting them with senses, so that it will
336 be useful for other researchers who want to test out ideas of their
337 own. To this end, wherver I have had to make archetictural choices
338 about =CORTEX=, I have chosen to give as much freedom to the user as
339 possible, so that =CORTEX= may be used for things I have not
340 forseen.
342 ** Simulation or Reality?
344 The most important archetictural decision of all is the choice to
345 use a computer-simulated environemnt in the first place! The world
346 is a vast and rich place, and for now simulations are a very poor
347 reflection of its complexity. It may be that there is a significant
348 qualatative difference between dealing with senses in the real
349 world and dealing with pale facilimilies of them in a
350 simulation. What are the advantages and disadvantages of a
351 simulation vs. reality?
353 *** Simulation
355 The advantages of virtual reality are that when everything is a
356 simulation, experiments in that simulation are absolutely
357 reproducible. It's also easier to change the character and world
358 to explore new situations and different sensory combinations.
360 If the world is to be simulated on a computer, then not only do
361 you have to worry about whether the character's senses are rich
362 enough to learn from the world, but whether the world itself is
363 rendered with enough detail and realism to give enough working
364 material to the character's senses. To name just a few
365 difficulties facing modern physics simulators: destructibility of
366 the environment, simulation of water/other fluids, large areas,
367 nonrigid bodies, lots of objects, smoke. I don't know of any
368 computer simulation that would allow a character to take a rock
369 and grind it into fine dust, then use that dust to make a clay
370 sculpture, at least not without spending years calculating the
371 interactions of every single small grain of dust. Maybe a
372 simulated world with today's limitations doesn't provide enough
373 richness for real intelligence to evolve.
375 *** Reality
377 The other approach for playing with senses is to hook your
378 software up to real cameras, microphones, robots, etc., and let it
379 loose in the real world. This has the advantage of eliminating
380 concerns about simulating the world at the expense of increasing
381 the complexity of implementing the senses. Instead of just
382 grabbing the current rendered frame for processing, you have to
383 use an actual camera with real lenses and interact with photons to
384 get an image. It is much harder to change the character, which is
385 now partly a physical robot of some sort, since doing so involves
386 changing things around in the real world instead of modifying
387 lines of code. While the real world is very rich and definitely
388 provides enough stimulation for intelligence to develop as
389 evidenced by our own existence, it is also uncontrollable in the
390 sense that a particular situation cannot be recreated perfectly or
391 saved for later use. It is harder to conduct science because it is
392 harder to repeat an experiment. The worst thing about using the
393 real world instead of a simulation is the matter of time. Instead
394 of simulated time you get the constant and unstoppable flow of
395 real time. This severely limits the sorts of software you can use
396 to program the AI because all sense inputs must be handled in real
397 time. Complicated ideas may have to be implemented in hardware or
398 may simply be impossible given the current speed of our
399 processors. Contrast this with a simulation, in which the flow of
400 time in the simulated world can be slowed down to accommodate the
401 limitations of the character's programming. In terms of cost,
402 doing everything in software is far cheaper than building custom
403 real-time hardware. All you need is a laptop and some patience.
405 ** Because of Time, simulation is perferable to reality
407 I envision =CORTEX= being used to support rapid prototyping and
408 iteration of ideas. Even if I could put together a well constructed
409 kit for creating robots, it would still not be enough because of
410 the scourge of real-time processing. Anyone who wants to test their
411 ideas in the real world must always worry about getting their
412 algorithms to run fast enough to process information in real
413 time. The need for real time processing only increases if multiple
414 senses are involved. In the extreme case, even simple algorithms
415 will have to be accelerated by ASIC chips or FPGAs, turning what
416 would otherwise be a few lines of code and a 10x speed penality
417 into a multi-month ordeal. For this reason, =CORTEX= supports
418 /time-dialiation/, which scales back the framerate of the
419 simulation in proportion to the amount of processing each
420 frame. From the perspective of the creatures inside the simulation,
421 time always appears to flow at a constant rate, regardless of how
422 complicated the envorimnent becomes or how many creatures are in
423 the simulation. The cost is that =CORTEX= can sometimes run slower
424 than real time. This can also be an advantage, however ---
425 simulations of very simple creatures in =CORTEX= generally run at
426 40x on my machine!
428 ** Video game engines are a great starting point
430 I did not need to write my own physics simulation code or shader to
431 build =CORTEX=. Doing so would lead to a system that is impossible
432 for anyone but myself to use anyway. Instead, I use a video game
433 engine as a base and modify it to accomodate the additional needs
434 of =CORTEX=. Video game engines are an ideal starting point to
435 build =CORTEX=, because they are not far from being creature
436 building systems themselves.
438 First off, general purpose video game engines come with a physics
439 engine and lighting / sound system. The physics system provides
440 tools that can be co-opted to serve as touch, proprioception, and
441 muscles. Since some games support split screen views, a good video
442 game engine will allow you to efficiently create multiple cameras
443 in the simulated world that can be used as eyes. Video game systems
444 offer integrated asset management for things like textures and
445 creatures models, providing an avenue for defining creatures.
446 Finally, because video game engines support a large number of
447 users, if I don't stray too far from the base system, other
448 researchers can turn to this community for help when doing their
449 research.
451 ** =CORTEX= is based on jMonkeyEngine3
453 While preparing to build =CORTEX= I studied several video game
454 engines to see which would best serve as a base. The top contenders
455 were:
457 - [[http://www.idsoftware.com][Quake II]]/[[http://www.bytonic.de/html/jake2.html][Jake2]] :: The Quake II engine was designed by ID
458 software in 1997. All the source code was released by ID
459 software into the Public Domain several years ago, and as a
460 result it has been ported to many different languages. This
461 engine was famous for its advanced use of realistic shading
462 and had decent and fast physics simulation. The main advantage
463 of the Quake II engine is its simplicity, but I ultimately
464 rejected it because the engine is too tied to the concept of a
465 first-person shooter game. One of the problems I had was that
466 there does not seem to be any easy way to attach multiple
467 cameras to a single character. There are also several physics
468 clipping issues that are corrected in a way that only applies
469 to the main character and do not apply to arbitrary objects.
471 - [[http://source.valvesoftware.com/][Source Engine]] :: The Source Engine evolved from the Quake II
472 and Quake I engines and is used by Valve in the Half-Life
473 series of games. The physics simulation in the Source Engine
474 is quite accurate and probably the best out of all the engines
475 I investigated. There is also an extensive community actively
476 working with the engine. However, applications that use the
477 Source Engine must be written in C++, the code is not open, it
478 only runs on Windows, and the tools that come with the SDK to
479 handle models and textures are complicated and awkward to use.
481 - [[http://jmonkeyengine.com/][jMonkeyEngine3]] :: jMonkeyEngine3 is a new library for creating
482 games in Java. It uses OpenGL to render to the screen and uses
483 screengraphs to avoid drawing things that do not appear on the
484 screen. It has an active community and several games in the
485 pipeline. The engine was not built to serve any particular
486 game but is instead meant to be used for any 3D game.
488 I chose jMonkeyEngine3 because it because it had the most features
489 out of all the free projects I looked at, and because I could then
490 write my code in clojure, an implementation of =LISP= that runs on
491 the JVM.
493 ** Bodies are composed of segments connected by joints
495 For the simple worm-like creatures I will use later on in this
496 thesis, I could define a simple API in =CORTEX= that would allow
497 one to create boxes, spheres, etc., and leave that API as the sole
498 way to create creatures. However, for =CORTEX= to truly be useful
499 for other projects, it needs to have a way to construct complicated
500 creatures. If possible, it would be nice to leverage work that has
501 already been done by the community of 3D modelers, or at least
502 enable people who are talented at moedling but not programming to
503 design =CORTEX= creatures.
505 Therefore, I use Blender, a free 3D modeling program, as the main
506 way to create creatures in =CORTEX=. However, the creatures modeled
507 in Blender must also be simple to simulate in jMonkeyEngine3's game
508 engine, and must also be easy to rig with =CORTEX='s senses.
510 While trying to find a good compromise for body-design, one option
511 I ultimately rejected is to use blender's [[http://wiki.blender.org/index.php/Doc:2.6/Manual/Rigging/Armatures][armature]] system. The idea
512 would have been to define a mesh which describes the creature's
513 entire body. To this you add an skeleton which deforms this
514 mesh. This technique is used extensively to model humans and create
515 realistic animations. It is hard to use for my purposes because it
516 is difficult to update the creature's Physics Collision Mesh in
517 tandem with its Geometric Mesh under the influence of the
518 armature. Without this the creature will not be able to grab things
519 in its environment, and it won't be able to tell where its physical
520 body is by using its eyes. Also, armatures do not specify any
521 rotational limits for a joint, making it hard to model elbows,
522 shoulders, etc.
524 Instead of using the human-like ``deformable bag of bones''
525 approach, I decided to base my body plans on multiple solid objects
526 that are connected by joints, inspired by the robot =EVE= from the
527 movie WALL-E.
529 #+caption: =EVE= from the movie WALL-E. This body plan turns
530 #+caption: out to be much better suited to my purposes than a more
531 #+caption: human-like one.
532 [[./images/Eve.jpg]]
534 =EVE='s body is composed of several rigid components that are held
535 together by invisible joint constraints. This is what I mean by
536 ``eve-like''. The main reason that I use eve-style bodies is for
537 efficiency, and so that there will be correspondence between the
538 AI's vision and the physical presence of its body. Each individual
539 section is simulated by a separate rigid body that corresponds
540 exactly with its visual representation and does not change.
541 Sections are connected by invisible joints that are well supported
542 in jMonkeyEngine3. Bullet, the physics backend for jMonkeyEngine3,
543 can efficiently simulate hundreds of rigid bodies connected by
544 joints. Sections do not have to stay as one piece forever; they can
545 be dynamically replaced with multiple sections to simulate
546 splitting in two. This could be used to simulate retractable claws
547 or =EVE='s hands, which are able to coalesce into one object in the
548 movie.
552 ** Eyes reuse standard video game components
554 ** Hearing is hard; =CORTEX= does it right
556 ** Touch uses hundreds of hair-like elements
558 ** Proprioception is the sense that makes everything ``real''
560 ** Muscles are both effectors and sensors
562 ** =CORTEX= brings complex creatures to life!
564 ** =CORTEX= enables many possiblities for further research
566 * Empathy in a simulated worm
568 Here I develop a computational model of empathy, using =CORTEX= as a
569 base. Empathy in this context is the ability to observe another
570 creature and infer what sorts of sensations that creature is
571 feeling. My empathy algorithm involves multiple phases. First is
572 free-play, where the creature moves around and gains sensory
573 experience. From this experience I construct a representation of the
574 creature's sensory state space, which I call \Phi-space. Using
575 \Phi-space, I construct an efficient function which takes the
576 limited data that comes from observing another creature and enriches
577 it full compliment of imagined sensory data. I can then use the
578 imagined sensory data to recognize what the observed creature is
579 doing and feeling, using straightforward embodied action predicates.
580 This is all demonstrated with using a simple worm-like creature, and
581 recognizing worm-actions based on limited data.
583 #+caption: Here is the worm with which we will be working.
584 #+caption: It is composed of 5 segments. Each segment has a
585 #+caption: pair of extensor and flexor muscles. Each of the
586 #+caption: worm's four joints is a hinge joint which allows
587 #+caption: about 30 degrees of rotation to either side. Each segment
588 #+caption: of the worm is touch-capable and has a uniform
589 #+caption: distribution of touch sensors on each of its faces.
590 #+caption: Each joint has a proprioceptive sense to detect
591 #+caption: relative positions. The worm segments are all the
592 #+caption: same except for the first one, which has a much
593 #+caption: higher weight than the others to allow for easy
594 #+caption: manual motor control.
595 #+name: basic-worm-view
596 #+ATTR_LaTeX: :width 10cm
597 [[./images/basic-worm-view.png]]
599 #+caption: Program for reading a worm from a blender file and
600 #+caption: outfitting it with the senses of proprioception,
601 #+caption: touch, and the ability to move, as specified in the
602 #+caption: blender file.
603 #+name: get-worm
604 #+begin_listing clojure
605 #+begin_src clojure
606 (defn worm []
607 (let [model (load-blender-model "Models/worm/worm.blend")]
608 {:body (doto model (body!))
609 :touch (touch! model)
610 :proprioception (proprioception! model)
611 :muscles (movement! model)}))
612 #+end_src
613 #+end_listing
615 ** Embodiment factors action recognition into managable parts
617 Using empathy, I divide the problem of action recognition into a
618 recognition process expressed in the language of a full compliment
619 of senses, and an imaganitive process that generates full sensory
620 data from partial sensory data. Splitting the action recognition
621 problem in this manner greatly reduces the total amount of work to
622 recognize actions: The imaganitive process is mostly just matching
623 previous experience, and the recognition process gets to use all
624 the senses to directly describe any action.
626 ** Action recognition is easy with a full gamut of senses
628 Embodied representations using multiple senses such as touch,
629 proprioception, and muscle tension turns out be be exceedingly
630 efficient at describing body-centered actions. It is the ``right
631 language for the job''. For example, it takes only around 5 lines
632 of LISP code to describe the action of ``curling'' using embodied
633 primitives. It takes about 10 lines to describe the seemingly
634 complicated action of wiggling.
636 The following action predicates each take a stream of sensory
637 experience, observe however much of it they desire, and decide
638 whether the worm is doing the action they describe. =curled?=
639 relies on proprioception, =resting?= relies on touch, =wiggling?=
640 relies on a fourier analysis of muscle contraction, and
641 =grand-circle?= relies on touch and reuses =curled?= as a gaurd.
643 #+caption: Program for detecting whether the worm is curled. This is the
644 #+caption: simplest action predicate, because it only uses the last frame
645 #+caption: of sensory experience, and only uses proprioceptive data. Even
646 #+caption: this simple predicate, however, is automatically frame
647 #+caption: independent and ignores vermopomorphic differences such as
648 #+caption: worm textures and colors.
649 #+name: curled
650 #+attr_latex: [htpb]
651 #+begin_listing clojure
652 #+begin_src clojure
653 (defn curled?
654 "Is the worm curled up?"
655 [experiences]
656 (every?
657 (fn [[_ _ bend]]
658 (> (Math/sin bend) 0.64))
659 (:proprioception (peek experiences))))
660 #+end_src
661 #+end_listing
663 #+caption: Program for summarizing the touch information in a patch
664 #+caption: of skin.
665 #+name: touch-summary
666 #+attr_latex: [htpb]
668 #+begin_listing clojure
669 #+begin_src clojure
670 (defn contact
671 "Determine how much contact a particular worm segment has with
672 other objects. Returns a value between 0 and 1, where 1 is full
673 contact and 0 is no contact."
674 [touch-region [coords contact :as touch]]
675 (-> (zipmap coords contact)
676 (select-keys touch-region)
677 (vals)
678 (#(map first %))
679 (average)
680 (* 10)
681 (- 1)
682 (Math/abs)))
683 #+end_src
684 #+end_listing
687 #+caption: Program for detecting whether the worm is at rest. This program
688 #+caption: uses a summary of the tactile information from the underbelly
689 #+caption: of the worm, and is only true if every segment is touching the
690 #+caption: floor. Note that this function contains no references to
691 #+caption: proprioction at all.
692 #+name: resting
693 #+attr_latex: [htpb]
694 #+begin_listing clojure
695 #+begin_src clojure
696 (def worm-segment-bottom (rect-region [8 15] [14 22]))
698 (defn resting?
699 "Is the worm resting on the ground?"
700 [experiences]
701 (every?
702 (fn [touch-data]
703 (< 0.9 (contact worm-segment-bottom touch-data)))
704 (:touch (peek experiences))))
705 #+end_src
706 #+end_listing
708 #+caption: Program for detecting whether the worm is curled up into a
709 #+caption: full circle. Here the embodied approach begins to shine, as
710 #+caption: I am able to both use a previous action predicate (=curled?=)
711 #+caption: as well as the direct tactile experience of the head and tail.
712 #+name: grand-circle
713 #+attr_latex: [htpb]
714 #+begin_listing clojure
715 #+begin_src clojure
716 (def worm-segment-bottom-tip (rect-region [15 15] [22 22]))
718 (def worm-segment-top-tip (rect-region [0 15] [7 22]))
720 (defn grand-circle?
721 "Does the worm form a majestic circle (one end touching the other)?"
722 [experiences]
723 (and (curled? experiences)
724 (let [worm-touch (:touch (peek experiences))
725 tail-touch (worm-touch 0)
726 head-touch (worm-touch 4)]
727 (and (< 0.55 (contact worm-segment-bottom-tip tail-touch))
728 (< 0.55 (contact worm-segment-top-tip head-touch))))))
729 #+end_src
730 #+end_listing
733 #+caption: Program for detecting whether the worm has been wiggling for
734 #+caption: the last few frames. It uses a fourier analysis of the muscle
735 #+caption: contractions of the worm's tail to determine wiggling. This is
736 #+caption: signigicant because there is no particular frame that clearly
737 #+caption: indicates that the worm is wiggling --- only when multiple frames
738 #+caption: are analyzed together is the wiggling revealed. Defining
739 #+caption: wiggling this way also gives the worm an opportunity to learn
740 #+caption: and recognize ``frustrated wiggling'', where the worm tries to
741 #+caption: wiggle but can't. Frustrated wiggling is very visually different
742 #+caption: from actual wiggling, but this definition gives it to us for free.
743 #+name: wiggling
744 #+attr_latex: [htpb]
745 #+begin_listing clojure
746 #+begin_src clojure
747 (defn fft [nums]
748 (map
749 #(.getReal %)
750 (.transform
751 (FastFourierTransformer. DftNormalization/STANDARD)
752 (double-array nums) TransformType/FORWARD)))
754 (def indexed (partial map-indexed vector))
756 (defn max-indexed [s]
757 (first (sort-by (comp - second) (indexed s))))
759 (defn wiggling?
760 "Is the worm wiggling?"
761 [experiences]
762 (let [analysis-interval 0x40]
763 (when (> (count experiences) analysis-interval)
764 (let [a-flex 3
765 a-ex 2
766 muscle-activity
767 (map :muscle (vector:last-n experiences analysis-interval))
768 base-activity
769 (map #(- (% a-flex) (% a-ex)) muscle-activity)]
770 (= 2
771 (first
772 (max-indexed
773 (map #(Math/abs %)
774 (take 20 (fft base-activity))))))))))
775 #+end_src
776 #+end_listing
778 With these action predicates, I can now recognize the actions of
779 the worm while it is moving under my control and I have access to
780 all the worm's senses.
782 #+caption: Use the action predicates defined earlier to report on
783 #+caption: what the worm is doing while in simulation.
784 #+name: report-worm-activity
785 #+attr_latex: [htpb]
786 #+begin_listing clojure
787 #+begin_src clojure
788 (defn debug-experience
789 [experiences text]
790 (cond
791 (grand-circle? experiences) (.setText text "Grand Circle")
792 (curled? experiences) (.setText text "Curled")
793 (wiggling? experiences) (.setText text "Wiggling")
794 (resting? experiences) (.setText text "Resting")))
795 #+end_src
796 #+end_listing
798 #+caption: Using =debug-experience=, the body-centered predicates
799 #+caption: work together to classify the behaviour of the worm.
800 #+caption: the predicates are operating with access to the worm's
801 #+caption: full sensory data.
802 #+name: basic-worm-view
803 #+ATTR_LaTeX: :width 10cm
804 [[./images/worm-identify-init.png]]
806 These action predicates satisfy the recognition requirement of an
807 empathic recognition system. There is power in the simplicity of
808 the action predicates. They describe their actions without getting
809 confused in visual details of the worm. Each one is frame
810 independent, but more than that, they are each indepent of
811 irrelevant visual details of the worm and the environment. They
812 will work regardless of whether the worm is a different color or
813 hevaily textured, or if the environment has strange lighting.
815 The trick now is to make the action predicates work even when the
816 sensory data on which they depend is absent. If I can do that, then
817 I will have gained much,
819 ** \Phi-space describes the worm's experiences
821 As a first step towards building empathy, I need to gather all of
822 the worm's experiences during free play. I use a simple vector to
823 store all the experiences.
825 Each element of the experience vector exists in the vast space of
826 all possible worm-experiences. Most of this vast space is actually
827 unreachable due to physical constraints of the worm's body. For
828 example, the worm's segments are connected by hinge joints that put
829 a practical limit on the worm's range of motions without limiting
830 its degrees of freedom. Some groupings of senses are impossible;
831 the worm can not be bent into a circle so that its ends are
832 touching and at the same time not also experience the sensation of
833 touching itself.
835 As the worm moves around during free play and its experience vector
836 grows larger, the vector begins to define a subspace which is all
837 the sensations the worm can practicaly experience during normal
838 operation. I call this subspace \Phi-space, short for
839 physical-space. The experience vector defines a path through
840 \Phi-space. This path has interesting properties that all derive
841 from physical embodiment. The proprioceptive components are
842 completely smooth, because in order for the worm to move from one
843 position to another, it must pass through the intermediate
844 positions. The path invariably forms loops as actions are repeated.
845 Finally and most importantly, proprioception actually gives very
846 strong inference about the other senses. For example, when the worm
847 is flat, you can infer that it is touching the ground and that its
848 muscles are not active, because if the muscles were active, the
849 worm would be moving and would not be perfectly flat. In order to
850 stay flat, the worm has to be touching the ground, or it would
851 again be moving out of the flat position due to gravity. If the
852 worm is positioned in such a way that it interacts with itself,
853 then it is very likely to be feeling the same tactile feelings as
854 the last time it was in that position, because it has the same body
855 as then. If you observe multiple frames of proprioceptive data,
856 then you can become increasingly confident about the exact
857 activations of the worm's muscles, because it generally takes a
858 unique combination of muscle contractions to transform the worm's
859 body along a specific path through \Phi-space.
861 There is a simple way of taking \Phi-space and the total ordering
862 provided by an experience vector and reliably infering the rest of
863 the senses.
865 ** Empathy is the process of tracing though \Phi-space
867 Here is the core of a basic empathy algorithm, starting with an
868 experience vector:
870 First, group the experiences into tiered proprioceptive bins. I use
871 powers of 10 and 3 bins, and the smallest bin has an approximate
872 size of 0.001 radians in all proprioceptive dimensions.
874 Then, given a sequence of proprioceptive input, generate a set of
875 matching experience records for each input, using the tiered
876 proprioceptive bins.
878 Finally, to infer sensory data, select the longest consective chain
879 of experiences. Conecutive experience means that the experiences
880 appear next to each other in the experience vector.
882 This algorithm has three advantages:
884 1. It's simple
886 3. It's very fast -- retrieving possible interpretations takes
887 constant time. Tracing through chains of interpretations takes
888 time proportional to the average number of experiences in a
889 proprioceptive bin. Redundant experiences in \Phi-space can be
890 merged to save computation.
892 2. It protects from wrong interpretations of transient ambiguous
893 proprioceptive data. For example, if the worm is flat for just
894 an instant, this flattness will not be interpreted as implying
895 that the worm has its muscles relaxed, since the flattness is
896 part of a longer chain which includes a distinct pattern of
897 muscle activation. Markov chains or other memoryless statistical
898 models that operate on individual frames may very well make this
899 mistake.
901 #+caption: Program to convert an experience vector into a
902 #+caption: proprioceptively binned lookup function.
903 #+name: bin
904 #+attr_latex: [htpb]
905 #+begin_listing clojure
906 #+begin_src clojure
907 (defn bin [digits]
908 (fn [angles]
909 (->> angles
910 (flatten)
911 (map (juxt #(Math/sin %) #(Math/cos %)))
912 (flatten)
913 (mapv #(Math/round (* % (Math/pow 10 (dec digits))))))))
915 (defn gen-phi-scan
916 "Nearest-neighbors with binning. Only returns a result if
917 the propriceptive data is within 10% of a previously recorded
918 result in all dimensions."
919 [phi-space]
920 (let [bin-keys (map bin [3 2 1])
921 bin-maps
922 (map (fn [bin-key]
923 (group-by
924 (comp bin-key :proprioception phi-space)
925 (range (count phi-space)))) bin-keys)
926 lookups (map (fn [bin-key bin-map]
927 (fn [proprio] (bin-map (bin-key proprio))))
928 bin-keys bin-maps)]
929 (fn lookup [proprio-data]
930 (set (some #(% proprio-data) lookups)))))
931 #+end_src
932 #+end_listing
934 #+caption: =longest-thread= finds the longest path of consecutive
935 #+caption: experiences to explain proprioceptive worm data.
936 #+name: phi-space-history-scan
937 #+ATTR_LaTeX: :width 10cm
938 [[./images/aurellem-gray.png]]
940 =longest-thread= infers sensory data by stitching together pieces
941 from previous experience. It prefers longer chains of previous
942 experience to shorter ones. For example, during training the worm
943 might rest on the ground for one second before it performs its
944 excercises. If during recognition the worm rests on the ground for
945 five seconds, =longest-thread= will accomodate this five second
946 rest period by looping the one second rest chain five times.
948 =longest-thread= takes time proportinal to the average number of
949 entries in a proprioceptive bin, because for each element in the
950 starting bin it performes a series of set lookups in the preceeding
951 bins. If the total history is limited, then this is only a constant
952 multiple times the number of entries in the starting bin. This
953 analysis also applies even if the action requires multiple longest
954 chains -- it's still the average number of entries in a
955 proprioceptive bin times the desired chain length. Because
956 =longest-thread= is so efficient and simple, I can interpret
957 worm-actions in real time.
959 #+caption: Program to calculate empathy by tracing though \Phi-space
960 #+caption: and finding the longest (ie. most coherent) interpretation
961 #+caption: of the data.
962 #+name: longest-thread
963 #+attr_latex: [htpb]
964 #+begin_listing clojure
965 #+begin_src clojure
966 (defn longest-thread
967 "Find the longest thread from phi-index-sets. The index sets should
968 be ordered from most recent to least recent."
969 [phi-index-sets]
970 (loop [result '()
971 [thread-bases & remaining :as phi-index-sets] phi-index-sets]
972 (if (empty? phi-index-sets)
973 (vec result)
974 (let [threads
975 (for [thread-base thread-bases]
976 (loop [thread (list thread-base)
977 remaining remaining]
978 (let [next-index (dec (first thread))]
979 (cond (empty? remaining) thread
980 (contains? (first remaining) next-index)
981 (recur
982 (cons next-index thread) (rest remaining))
983 :else thread))))
984 longest-thread
985 (reduce (fn [thread-a thread-b]
986 (if (> (count thread-a) (count thread-b))
987 thread-a thread-b))
988 '(nil)
989 threads)]
990 (recur (concat longest-thread result)
991 (drop (count longest-thread) phi-index-sets))))))
992 #+end_src
993 #+end_listing
995 There is one final piece, which is to replace missing sensory data
996 with a best-guess estimate. While I could fill in missing data by
997 using a gradient over the closest known sensory data points,
998 averages can be misleading. It is certainly possible to create an
999 impossible sensory state by averaging two possible sensory states.
1000 Therefore, I simply replicate the most recent sensory experience to
1001 fill in the gaps.
1003 #+caption: Fill in blanks in sensory experience by replicating the most
1004 #+caption: recent experience.
1005 #+name: infer-nils
1006 #+attr_latex: [htpb]
1007 #+begin_listing clojure
1008 #+begin_src clojure
1009 (defn infer-nils
1010 "Replace nils with the next available non-nil element in the
1011 sequence, or barring that, 0."
1012 [s]
1013 (loop [i (dec (count s))
1014 v (transient s)]
1015 (if (zero? i) (persistent! v)
1016 (if-let [cur (v i)]
1017 (if (get v (dec i) 0)
1018 (recur (dec i) v)
1019 (recur (dec i) (assoc! v (dec i) cur)))
1020 (recur i (assoc! v i 0))))))
1021 #+end_src
1022 #+end_listing
1024 ** Efficient action recognition with =EMPATH=
1026 To use =EMPATH= with the worm, I first need to gather a set of
1027 experiences from the worm that includes the actions I want to
1028 recognize. The =generate-phi-space= program (listing
1029 \ref{generate-phi-space} runs the worm through a series of
1030 exercices and gatheres those experiences into a vector. The
1031 =do-all-the-things= program is a routine expressed in a simple
1032 muscle contraction script language for automated worm control. It
1033 causes the worm to rest, curl, and wiggle over about 700 frames
1034 (approx. 11 seconds).
1036 #+caption: Program to gather the worm's experiences into a vector for
1037 #+caption: further processing. The =motor-control-program= line uses
1038 #+caption: a motor control script that causes the worm to execute a series
1039 #+caption: of ``exercices'' that include all the action predicates.
1040 #+name: generate-phi-space
1041 #+attr_latex: [htpb]
1042 #+begin_listing clojure
1043 #+begin_src clojure
1044 (def do-all-the-things
1045 (concat
1046 curl-script
1047 [[300 :d-ex 40]
1048 [320 :d-ex 0]]
1049 (shift-script 280 (take 16 wiggle-script))))
1051 (defn generate-phi-space []
1052 (let [experiences (atom [])]
1053 (run-world
1054 (apply-map
1055 worm-world
1056 (merge
1057 (worm-world-defaults)
1058 {:end-frame 700
1059 :motor-control
1060 (motor-control-program worm-muscle-labels do-all-the-things)
1061 :experiences experiences})))
1062 @experiences))
1063 #+end_src
1064 #+end_listing
1066 #+caption: Use longest thread and a phi-space generated from a short
1067 #+caption: exercise routine to interpret actions during free play.
1068 #+name: empathy-debug
1069 #+attr_latex: [htpb]
1070 #+begin_listing clojure
1071 #+begin_src clojure
1072 (defn init []
1073 (def phi-space (generate-phi-space))
1074 (def phi-scan (gen-phi-scan phi-space)))
1076 (defn empathy-demonstration []
1077 (let [proprio (atom ())]
1078 (fn
1079 [experiences text]
1080 (let [phi-indices (phi-scan (:proprioception (peek experiences)))]
1081 (swap! proprio (partial cons phi-indices))
1082 (let [exp-thread (longest-thread (take 300 @proprio))
1083 empathy (mapv phi-space (infer-nils exp-thread))]
1084 (println-repl (vector:last-n exp-thread 22))
1085 (cond
1086 (grand-circle? empathy) (.setText text "Grand Circle")
1087 (curled? empathy) (.setText text "Curled")
1088 (wiggling? empathy) (.setText text "Wiggling")
1089 (resting? empathy) (.setText text "Resting")
1090 :else (.setText text "Unknown")))))))
1092 (defn empathy-experiment [record]
1093 (.start (worm-world :experience-watch (debug-experience-phi)
1094 :record record :worm worm*)))
1095 #+end_src
1096 #+end_listing
1098 The result of running =empathy-experiment= is that the system is
1099 generally able to interpret worm actions using the action-predicates
1100 on simulated sensory data just as well as with actual data. Figure
1101 \ref{empathy-debug-image} was generated using =empathy-experiment=:
1103 #+caption: From only proprioceptive data, =EMPATH= was able to infer
1104 #+caption: the complete sensory experience and classify four poses
1105 #+caption: (The last panel shows a composite image of \emph{wriggling},
1106 #+caption: a dynamic pose.)
1107 #+name: empathy-debug-image
1108 #+ATTR_LaTeX: :width 10cm :placement [H]
1109 [[./images/empathy-1.png]]
1111 One way to measure the performance of =EMPATH= is to compare the
1112 sutiability of the imagined sense experience to trigger the same
1113 action predicates as the real sensory experience.
1115 #+caption: Determine how closely empathy approximates actual
1116 #+caption: sensory data.
1117 #+name: test-empathy-accuracy
1118 #+attr_latex: [htpb]
1119 #+begin_listing clojure
1120 #+begin_src clojure
1121 (def worm-action-label
1122 (juxt grand-circle? curled? wiggling?))
1124 (defn compare-empathy-with-baseline [matches]
1125 (let [proprio (atom ())]
1126 (fn
1127 [experiences text]
1128 (let [phi-indices (phi-scan (:proprioception (peek experiences)))]
1129 (swap! proprio (partial cons phi-indices))
1130 (let [exp-thread (longest-thread (take 300 @proprio))
1131 empathy (mapv phi-space (infer-nils exp-thread))
1132 experience-matches-empathy
1133 (= (worm-action-label experiences)
1134 (worm-action-label empathy))]
1135 (println-repl experience-matches-empathy)
1136 (swap! matches #(conj % experience-matches-empathy)))))))
1138 (defn accuracy [v]
1139 (float (/ (count (filter true? v)) (count v))))
1141 (defn test-empathy-accuracy []
1142 (let [res (atom [])]
1143 (run-world
1144 (worm-world :experience-watch
1145 (compare-empathy-with-baseline res)
1146 :worm worm*))
1147 (accuracy @res)))
1148 #+end_src
1149 #+end_listing
1151 Running =test-empathy-accuracy= using the very short exercise
1152 program defined in listing \ref{generate-phi-space}, and then doing
1153 a similar pattern of activity manually yeilds an accuracy of around
1154 73%. This is based on very limited worm experience. By training the
1155 worm for longer, the accuracy dramatically improves.
1157 #+caption: Program to generate \Phi-space using manual training.
1158 #+name: manual-phi-space
1159 #+attr_latex: [htpb]
1160 #+begin_listing clojure
1161 #+begin_src clojure
1162 (defn init-interactive []
1163 (def phi-space
1164 (let [experiences (atom [])]
1165 (run-world
1166 (apply-map
1167 worm-world
1168 (merge
1169 (worm-world-defaults)
1170 {:experiences experiences})))
1171 @experiences))
1172 (def phi-scan (gen-phi-scan phi-space)))
1173 #+end_src
1174 #+end_listing
1176 After about 1 minute of manual training, I was able to achieve 95%
1177 accuracy on manual testing of the worm using =init-interactive= and
1178 =test-empathy-accuracy=. The majority of errors are near the
1179 boundaries of transitioning from one type of action to another.
1180 During these transitions the exact label for the action is more open
1181 to interpretation, and dissaggrement between empathy and experience
1182 is more excusable.
1184 ** Digression: bootstrapping touch using free exploration
1186 In the previous section I showed how to compute actions in terms of
1187 body-centered predicates which relied averate touch activation of
1188 pre-defined regions of the worm's skin. What if, instead of recieving
1189 touch pre-grouped into the six faces of each worm segment, the true
1190 topology of the worm's skin was unknown? This is more similiar to how
1191 a nerve fiber bundle might be arranged. While two fibers that are
1192 close in a nerve bundle /might/ correspond to two touch sensors that
1193 are close together on the skin, the process of taking a complicated
1194 surface and forcing it into essentially a circle requires some cuts
1195 and rerragenments.
1197 In this section I show how to automatically learn the skin-topology of
1198 a worm segment by free exploration. As the worm rolls around on the
1199 floor, large sections of its surface get activated. If the worm has
1200 stopped moving, then whatever region of skin that is touching the
1201 floor is probably an important region, and should be recorded.
1203 #+caption: Program to detect whether the worm is in a resting state
1204 #+caption: with one face touching the floor.
1205 #+name: pure-touch
1206 #+begin_listing clojure
1207 #+begin_src clojure
1208 (def full-contact [(float 0.0) (float 0.1)])
1210 (defn pure-touch?
1211 "This is worm specific code to determine if a large region of touch
1212 sensors is either all on or all off."
1213 [[coords touch :as touch-data]]
1214 (= (set (map first touch)) (set full-contact)))
1215 #+end_src
1216 #+end_listing
1218 After collecting these important regions, there will many nearly
1219 similiar touch regions. While for some purposes the subtle
1220 differences between these regions will be important, for my
1221 purposes I colapse them into mostly non-overlapping sets using
1222 =remove-similiar= in listing \ref{remove-similiar}
1224 #+caption: Program to take a lits of set of points and ``collapse them''
1225 #+caption: so that the remaining sets in the list are siginificantly
1226 #+caption: different from each other. Prefer smaller sets to larger ones.
1227 #+name: remove-similiar
1228 #+begin_listing clojure
1229 #+begin_src clojure
1230 (defn remove-similar
1231 [coll]
1232 (loop [result () coll (sort-by (comp - count) coll)]
1233 (if (empty? coll) result
1234 (let [[x & xs] coll
1235 c (count x)]
1236 (if (some
1237 (fn [other-set]
1238 (let [oc (count other-set)]
1239 (< (- (count (union other-set x)) c) (* oc 0.1))))
1240 xs)
1241 (recur result xs)
1242 (recur (cons x result) xs))))))
1243 #+end_src
1244 #+end_listing
1246 Actually running this simulation is easy given =CORTEX='s facilities.
1248 #+caption: Collect experiences while the worm moves around. Filter the touch
1249 #+caption: sensations by stable ones, collapse similiar ones together,
1250 #+caption: and report the regions learned.
1251 #+name: learn-touch
1252 #+begin_listing clojure
1253 #+begin_src clojure
1254 (defn learn-touch-regions []
1255 (let [experiences (atom [])
1256 world (apply-map
1257 worm-world
1258 (assoc (worm-segment-defaults)
1259 :experiences experiences))]
1260 (run-world world)
1261 (->>
1262 @experiences
1263 (drop 175)
1264 ;; access the single segment's touch data
1265 (map (comp first :touch))
1266 ;; only deal with "pure" touch data to determine surfaces
1267 (filter pure-touch?)
1268 ;; associate coordinates with touch values
1269 (map (partial apply zipmap))
1270 ;; select those regions where contact is being made
1271 (map (partial group-by second))
1272 (map #(get % full-contact))
1273 (map (partial map first))
1274 ;; remove redundant/subset regions
1275 (map set)
1276 remove-similar)))
1278 (defn learn-and-view-touch-regions []
1279 (map view-touch-region
1280 (learn-touch-regions)))
1281 #+end_src
1282 #+end_listing
1284 The only thing remining to define is the particular motion the worm
1285 must take. I accomplish this with a simple motor control program.
1287 #+caption: Motor control program for making the worm roll on the ground.
1288 #+caption: This could also be replaced with random motion.
1289 #+name: worm-roll
1290 #+begin_listing clojure
1291 #+begin_src clojure
1292 (defn touch-kinesthetics []
1293 [[170 :lift-1 40]
1294 [190 :lift-1 19]
1295 [206 :lift-1 0]
1297 [400 :lift-2 40]
1298 [410 :lift-2 0]
1300 [570 :lift-2 40]
1301 [590 :lift-2 21]
1302 [606 :lift-2 0]
1304 [800 :lift-1 30]
1305 [809 :lift-1 0]
1307 [900 :roll-2 40]
1308 [905 :roll-2 20]
1309 [910 :roll-2 0]
1311 [1000 :roll-2 40]
1312 [1005 :roll-2 20]
1313 [1010 :roll-2 0]
1315 [1100 :roll-2 40]
1316 [1105 :roll-2 20]
1317 [1110 :roll-2 0]
1318 ])
1319 #+end_src
1320 #+end_listing
1323 #+caption: The small worm rolls around on the floor, driven
1324 #+caption: by the motor control program in listing \ref{worm-roll}.
1325 #+name: worm-roll
1326 #+ATTR_LaTeX: :width 12cm
1327 [[./images/worm-roll.png]]
1330 #+caption: After completing its adventures, the worm now knows
1331 #+caption: how its touch sensors are arranged along its skin. These
1332 #+caption: are the regions that were deemed important by
1333 #+caption: =learn-touch-regions=. Note that the worm has discovered
1334 #+caption: that it has six sides.
1335 #+name: worm-touch-map
1336 #+ATTR_LaTeX: :width 12cm
1337 [[./images/touch-learn.png]]
1339 While simple, =learn-touch-regions= exploits regularities in both
1340 the worm's physiology and the worm's environment to correctly
1341 deduce that the worm has six sides. Note that =learn-touch-regions=
1342 would work just as well even if the worm's touch sense data were
1343 completely scrambled. The cross shape is just for convienence. This
1344 example justifies the use of pre-defined touch regions in =EMPATH=.
1346 * Contributions
1348 In this thesis you have seen the =CORTEX= system, a complete
1349 environment for creating simulated creatures. You have seen how to
1350 implement five senses including touch, proprioception, hearing,
1351 vision, and muscle tension. You have seen how to create new creatues
1352 using blender, a 3D modeling tool. I hope that =CORTEX= will be
1353 useful in further research projects. To this end I have included the
1354 full source to =CORTEX= along with a large suite of tests and
1355 examples. I have also created a user guide for =CORTEX= which is
1356 inculded in an appendix to this thesis.
1358 You have also seen how I used =CORTEX= as a platform to attach the
1359 /action recognition/ problem, which is the problem of recognizing
1360 actions in video. You saw a simple system called =EMPATH= which
1361 ientifies actions by first describing actions in a body-centerd,
1362 rich sense language, then infering a full range of sensory
1363 experience from limited data using previous experience gained from
1364 free play.
1366 As a minor digression, you also saw how I used =CORTEX= to enable a
1367 tiny worm to discover the topology of its skin simply by rolling on
1368 the ground.
1370 In conclusion, the main contributions of this thesis are:
1372 - =CORTEX=, a system for creating simulated creatures with rich
1373 senses.
1374 - =EMPATH=, a program for recognizing actions by imagining sensory
1375 experience.
1377 # An anatomical joke:
1378 # - Training
1379 # - Skeletal imitation
1380 # - Sensory fleshing-out
1381 # - Classification