Skip to content

Instantly share code, notes, and snippets.

@selfsame
Last active December 30, 2015 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save selfsame/7902992 to your computer and use it in GitHub Desktop.
Save selfsame/7902992 to your computer and use it in GitHub Desktop.
(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