diff org/worm_learn.clj @ 413:54ef2e06c3ef

gave main worm a consistent muscle order.
author Robert McIntyre <rlm@mit.edu>
date Wed, 19 Mar 2014 14:24:13 -0400
parents a331d5ff73e0
children 634795361af8
line wrap: on
line diff
     1.1 --- a/org/worm_learn.clj	Wed Mar 19 13:21:49 2014 -0400
     1.2 +++ b/org/worm_learn.clj	Wed Mar 19 14:24:13 2014 -0400
     1.3 @@ -11,6 +11,10 @@
     1.4    (:import (com.aurellem.capture Capture IsoTimer))
     1.5    (:import (com.jme3.math Vector3f ColorRGBA)))
     1.6  
     1.7 +(import org.apache.commons.math3.transform.TransformType)
     1.8 +(import org.apache.commons.math3.transform.FastFourierTransformer)
     1.9 +(import org.apache.commons.math3.transform.DftNormalization)
    1.10 +
    1.11  (use 'clojure.pprint)
    1.12  (use 'clojure.set)
    1.13  (dorun (cortex.import/mega-import-jme3))
    1.14 @@ -58,10 +62,10 @@
    1.15          worm-keys
    1.16          ["key-f" "key-r"
    1.17           "key-g" "key-t"
    1.18 -         "key-y" "key-h"
    1.19 +         "key-h" "key-y"
    1.20           "key-j" "key-u"
    1.21 -         "key-i" "key-k"
    1.22 -         "key-o" "key-l"]]
    1.23 +         "key-k" "key-i"
    1.24 +         "key-l" "key-o"]]
    1.25      {:motor-control
    1.26       (fn [effectors]
    1.27        (doall
    1.28 @@ -83,11 +87,11 @@
    1.29  (def period 18)
    1.30  
    1.31  (def worm-muscle-labels
    1.32 -  [:base-up :base-down
    1.33 +  [:base-down :base-up
    1.34     :a-down :a-up
    1.35 -   :b-up :b-down
    1.36 +   :b-down :b-up
    1.37     :c-down :c-up
    1.38 -   :d-up :d-down])
    1.39 +   :d-down :d-up])
    1.40  
    1.41  (defn gen-wiggle [[flexor extensor :as muscle-pair] time-base]
    1.42    (let [period period
    1.43 @@ -166,10 +170,17 @@
    1.44        (- 1)
    1.45        (Math/abs)))
    1.46  
    1.47 +(defn fft [nums]
    1.48 +  (.transform
    1.49 +   (FastFourierTransformer. DftNormalization/UNITARY)
    1.50 +   (double-array nums) TransformType/FORWARD))
    1.51 +
    1.52 +(def indexed (partial map-indexed vector))
    1.53 +
    1.54  (defn wiggling?
    1.55    "Is the worm wiggling?"
    1.56    [experiences]
    1.57 -  (vector:last-n experiences 200)
    1.58 +  (map (comp first :muscle) (vector:last-n experiences 200))
    1.59    
    1.60  )
    1.61