1 (ns neural-net.perceptron
2 (:use neural-net.core))
4 (defn perceptron:run "Perceptron execution" [this x]
5 (reduce + (map (fn [x w] (* x w)) x (this :weights))))
7 (defn perceptron:learn "Perceptron learning" [this x y d]
8 (let [dir ((fn [dif] (cond (> dif 0) 1 (< dif 0) -1 true 0)) (- d y))]
9 (vec (map (fn [x] (* dir (this :eta) x)) x))))
11 (comment ; perceptron learning -- converting binary to decimal
12 (let [n {:phi perceptron:run
14 :learn perceptron:learn
16 (assoc n :weights (vec (map + (n :weights) delta))))
27 (second (train n (first p) (run n (first p)) (second p))))
28 m epic)) n (range 100))
29 :weights)) ; [2.0000000000000013 1.0000000000000007]
32 (comment ; perceptron learning over an arbitrary graph
33 (let [n {:phi perceptron:run
34 :learn perceptron:learn
37 (assoc n :weights (vec (map + (n :weights) delta))))
39 g (Graph. {:a n :b n :c n} [[:a :b] [:a :c] [:b :c]])
43 (run (second (train g x nil d)) x)))