OSDN Git Service

[1] The function onehot was added.
authorU-tackya-PC\tackya <yammouch@users.sourceforge.jp>
Sat, 23 Jul 2011 12:02:55 +0000 (21:02 +0900)
committerU-tackya-PC\tackya <yammouch@users.sourceforge.jp>
Sat, 23 Jul 2011 12:02:55 +0000 (21:02 +0900)
dynamics/src/math.clj

index cb6e60a..c802d70 100755 (executable)
     (apply rec (sort-by stype-order args))
     ))
 
-(defn onehot [idxs tuple] 1)
+(defn onehot [idxs tuple]
+  (letfn [(rec [tuple pos]
+            (if (coll? tuple)
+              (cons (first tuple)
+                    (map #(rec %1 (cons %2 pos))
+                         (rest tuple)
+                         (iterate inc 0)))
+              (if (= (reverse pos) idxs) 1 0)
+              ))]
+    (rec tuple [])))