Last active
December 30, 2015 23:49
-
-
Save selfsame/7902992 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn calc-socket [proxy] | |
(let [direction (state proxy :tag) | |
weight (state proxy :weight) | |
node (GET-N (:parent proxy)) | |
value (state node :value) | |
inputs (state proxy :in) | |
outputs (state proxy :out)] | |
(cond | |
(= :in direction) (dorun | |
;(map #(* % weight ) | |
; (dorun (map (fn [uid] (calc-socket (first (find-link (GET-N uid) :in 0) ))) inputs)))) | |
(map (fn [uid] (calc-socket (first (find-link (GET-N uid) :out 0) ))) inputs) ) | |
(= :out direction) (* value weight)))) | |
(defn evaluate [n] | |
(when (not= (:type n) :input) | |
(let [ typ (:type n) | |
in-uids (apply concat (state n :in )) | |
in-nodes (map #(GET-N %) in-uids) | |
in-vals (map #(state % :value) in-nodes) | |
weighted-inputs (map calc-socket (filter (fn[c] (= (state c :tag) :in) ) (state n :children))) | |
final (cond | |
(= typ :linear) (apply + in-vals) | |
(= typ :boolean) (if (> (apply + in-vals) .5) 1.0 0.0) | |
(= typ :probability) (if (> (apply + in-vals) (rand 1)) 0.0 1.0) | |
(= typ :logarithmic) (* (apply + in-vals) (apply + in-vals) ) | |
(= typ :output) (apply + in-vals) | |
:else -1 | |
)] | |
(set-state n :value final) | |
))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment