renaming neural-net.self-organizing-maps to neural-net.som
[neural-net.git] / neural-net.org
blobaf50428e5945d64933bd0aee529c04b0ef47da2e
1 #+Title: Neural Network
2 #+Author: Eric Schulte
3 #+STYLE: <link rel="stylesheet" href="/~eschulte/classes/stylesheet.css" type="text/css">
4 #+Startup: hideblocks
5 #+Options: toc:nil num:nil
7 * Neural Networks
8 A domain specific language for expressing neural networks using
9 Clojure data types.
11 - a [[http://clojure.org/data_structures#Data Structures-Maps (IPersistentMap)][Map]] specifies a single neuron e.g.
12   #+begin_src clojure
13     ;; a simple neuron which sums two unit inputs
14     (run {:phi (fn [n x] (reduce + (map * (n :weights) x)))
15           :weights [1 1]}
16          [1 1]) ; => 2
17   #+end_src
18   #+begin_src latex  :file data/map.pdf :border 1em :packages '(("" "tikz")) :exports none
19     \usetikzlibrary{arrows}
20     \tikzstyle{neuron} = [circle, draw, text centered, font=\footnotesize]
21     \begin{tikzpicture}[->,>=stealth', shorten >=1pt, auto]
22       \node [neuron] (neuron) at (0,0)     {$\Sigma$};
23       \node          (input1) at (-2,1)    {$x_{1}=1$};
24       \node          (input2) at (-2,-1)   {$x_{2}=1$};
25       \node          (weight) at (0,1)     {$\overrightarrow{w}=[1,1]$};
26       \node          (output) at (3,0)     {$y=2$};
27     
28       \draw (input1) -- (neuron);
29       \draw (input2) -- (neuron);
30       \draw (neuron) -- node[above] {$\Phi=identity$} (output);
31     \end{tikzpicture}
32   #+end_src
33   [[http://cs.unm.edu/~eschulte/src/neural-net/data/map.png]]
35 - [[http://clojure.org/data_structures#Data Structures-Vectors (IPersistentVector)][Vectors]] are used to represent an /ordered/ series of neural elements
36   to be executed in /serial/
37   #+begin_src clojure
38     ;; two neurons in serial
39     (let [n {:phi (fn [n x] (reduce + (map * (n :weights) x)))}
40           net [(assoc n :weights [1 1]) (assoc n :weights [2])]]
41       (run net [1 1])) ; => 4
42   #+end_src
43   #+begin_src latex  :file data/vector.pdf :border 1em :packages '(("" "tikz")) :exports none
44     \usetikzlibrary{arrows}
45     \tikzstyle{neuron} = [circle, draw, text centered, font=\footnotesize]
46     \begin{tikzpicture}[->,>=stealth', shorten >=1pt, auto]
47       \node [neuron] (neuron1) at (0,0)     {$\Sigma$};
48       \node [neuron] (neuron2) at (2,0)     {$\Sigma$};
49       \node          (input1)  at (-2,1)    {$x_{1}=1$};
50       \node          (input2)  at (-2,-1)   {$x_{2}=1$};
51       \node          (weight)  at (-2,0)    {$\overrightarrow{w}=[1,1]$};
52       \node          (output)  at (4,0)     {$y=4$};
53     
54       \draw (input1) -- (neuron1);
55       \draw (input2) -- (neuron1);
56       \draw (neuron1) -- node[above] {$\overrightarrow{w}=[2]$} (neuron2);
57       \draw (neuron2) -- (output);
58     \end{tikzpicture}
59   #+end_src
60   [[http://cs.unm.edu/~eschulte/src/neural-net/data/vector.png]]
62 - [[http://clojure.org/data_structures#Data Structures-Lists (IPersistentList)][Lists]] are used to represent a /unordered/ series of neural elements
63   to be executed in /parallel/.
64   #+begin_src clojure
65     ;; a layer of three neurons in parallel followed by a single neuron
66     (let [n {:phi (fn [n x] (reduce + (map * (n :weights) x)))
67              :weights [2 2 2]}
68           net [(list n n n) n]]
69       (run net [1 1 1])) ; => 36
70   #+end_src
71   #+begin_src latex  :file data/list.pdf :border 1em :packages '(("" "tikz")) :exports none
72     \usetikzlibrary{arrows}
73     \tikzstyle{neuron} = [circle, draw, text centered, font=\footnotesize]
74     \begin{tikzpicture}[->,>=stealth', shorten >=1pt, auto]
75       \node          (input1)  at (-2,1)    {$x_{1}=1$};
76       \node          (input2)  at (-2,0)    {$x_{2}=1$};
77       \node          (input3)  at (-2,-1)   {$x_{3}=1$};
78       \node [neuron] (neuron1) at (0,1)     {$\Sigma$};
79       \node [neuron] (neuron2) at (0,0)     {$\Sigma$};
80       \node [neuron] (neuron3) at (0,-1)    {$\Sigma$};
81       \node [neuron] (neuron4) at (2,0)     {$\Sigma$};
82       \node          (output)  at (4,0)     {$y=36$};
83     
84       \node          (weight1) at (0,1.75)  {$\overrightarrow{w}=[2, 2, 2]$};
85       \node          (weight1) at (2,0.75)  {$\overrightarrow{w}=[2, 2, 2]$};
86     
87       \foreach \a in {1,2,3}
88       {
89         \foreach \b in {1,2,3}
90         {
91           \draw (input\a) -- (neuron\b);
92         }
93         \draw (neuron\a) -- (neuron4);
94       }
95       \draw (neuron4) -- (output);
96     \end{tikzpicture}
97   #+end_src
98   [[http://cs.unm.edu/~eschulte/src/neural-net/data/list.png]]
100 - Graphs -- unlike the previous data types which are built into
101   Clojure Graphs are specific to this library
103   (note: this functionality is still in development, specifically
104   training may still be buggy)
105   #+begin_src clojure
106     ;; three neurons connected using an arbitrary edge set
107     (let [n {:phi (fn [n x] (reduce + (map * (n :weights) x)))
108              :weights [2 2]}
109           g (Graph. {:a n :b n :c n} [[:a :b] [:a :c] [:b :c]])]
110       (run g [1 1 1])) ; [28]
111   #+end_src
112   #+begin_src latex  :file data/graph.pdf :border 1em :packages '(("" "tikz")) :exports none
113     % {:c 28, :b 10, :a 4}
114     \usetikzlibrary{arrows}
115     \tikzstyle{neuron} = [circle, draw, text centered, font=\footnotesize]
116     \tikzstyle{value} = [text centered, font=\footnotesize]
117     \begin{tikzpicture}[->,>=stealth', shorten >=1pt, auto]
118       \node          (input1)  at (-2,1)    {$x_{1}=1$};
119       \node          (input2)  at (-2,0)    {$x_{2}=1$};
120       \node          (input3)  at (-2,-1)   {$x_{3}=1$};
121       \node [neuron] (a)       at (0,0.75)  {$:a$};
122       \node [neuron] (b)       at (1,-0.75) {$:b$};
123       \node [neuron] (c)       at (2.5,0)   {$:c$};
124       \node          (output)  at (4,0)     {$y=28$};
125     
126       \draw (input1) -- (a);
127       \draw (input2) -- (a);
128       \draw (input3) -- (b);
129       \draw (a)      -- node[value] {$4$} (b);
130       \draw (a)      -- node[value] {$4$} (c);
131       \draw (b)      -- node[value] {$10$} (c);
132       \draw (c)      -- (output);
133     \end{tikzpicture}
134   #+end_src
135   [[http://cs.unm.edu/~eschulte/src/neural-net/data/graph.png]]
137 Example implementations are given for the following types of neural
138 networks.
139 - [[http://repo.or.cz/w/neural-net.git/blob/HEAD:/src/neural_net/perceptron.clj][perceptrons]]
140 - [[http://repo.or.cz/w/neural-net.git/blob/HEAD:/src/neural_net/back_propagation.clj][back propagation]] networks
141 - [[http://repo.or.cz/w/neural-net.git/blob/HEAD:/src/neural_net/radial_basis.clj][radial basis]] neurons
142 - [[http://repo.or.cz/w/neural-net.git/blob/HEAD:/src/neural_net/self_organizing_maps.clj][self organizing maps]]
144 * License
145 Copyright (C) 2010 Eric Schulte
147 This program is free software: you can redistribute it and/or modify
148 it under the terms of the GNU General Public License as published by
149 the Free Software Foundation, either version 3 of the License, or
150 (at your option) any later version.
152 This program is distributed in the hope that it will be useful,
153 but WITHOUT ANY WARRANTY; without even the implied warranty of
154 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
155 GNU General Public License for more details.
157 You should have received a [[file:COPYING][copy of the GNU General Public License]]
158 along with this program.  If not, see <http://www.gnu.org/licenses/>.