1 (ns neural-net.radial-basis
4 (:use clojure.contrib.math))
6 (defn radial:run "Run a Gaussian radial basis neuron" [this x]
7 (expt Math/E (/ (sqrt (reduce + (map (comp #(* % %) -) (this :t) x)))
8 (* 2 (sqrt (this :std))))))
15 (take 100 (repeatedly (fn []
16 [(vec (map + c (take 2 (repeatedly rand))))
23 ;; run a radial basis neuron
24 (let [x1s (map (fn [[[x1 x2] o]] x1) training)
25 x2s (map (fn [[[x1 x2] o]] x2) training)
26 std (sqrt (/ (+ (expt (- (apply max x1s) (apply min x1s)) 2)
27 (expt (- (apply max x2s) (apply min x2s)) 2))
32 p {:phi perceptron:run
33 :weights (vec (take 3 (repeatedly rand-weight)))
34 :learn perceptron:learn
36 (assoc n :weights (vec (map + (n :weights) delta))))
38 (run [(list (assoc rb :t [(pick x1s) (pick x2s)])
39 (assoc rb :t [(pick x1s) (pick x2s)])
40 (assoc rb :t [(pick x1s) (pick x2s)])) p]
41 (first (first training))))
43 ;; training is working... sort of
44 (let [training (map (fn [p] [[(nth p 2) (nth p 3)] (nth p 0)]) training)
45 testing (map (fn [p] [[(nth p 2) (nth p 3)] (nth p 0)]) testing)
46 x1s (map (fn [[[x1 x2] o]] x1) training)
47 x2s (map (fn [[[x1 x2] o]] x2) training)
48 std (sqrt (/ (+ (expt (- (apply max x1s) (apply min x1s)) 2)
49 (expt (- (apply max x2s) (apply min x2s)) 2))
54 :learn (fn [this x y d] (map (fn [_] 0) (this :weights)))
55 :train (fn [n delta] n)}
56 p {:phi perceptron:run
57 :weights (vec (take 3 (repeatedly rand-weight)))
58 :learn perceptron:learn
60 (assoc n :weights (vec (map + (n :weights) delta))))
62 net [(list (assoc rb :t [(pick x1s) (pick x2s)])
63 (assoc rb :t [(pick x1s) (pick x2s)])
64 (assoc rb :t [(pick x1s) (pick x2s)])) p]]
67 (println (format "%S\t%S\t%S" index
68 (rms-error m training) (epic-error m testing)))
71 (second (train n (first p) (run n (first p)) (second p))))