Graph:train is cleaned up and working
[neural-net.git] / neural-net.org
blob221b7c4bb9ed54d90dc6038d1ea7d288c7fa517b
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.  Source code is available from
10 http://gitweb.adaptive.cs.unm.edu/neural-net.git.
12 - a [[http://clojure.org/data_structures#Data Structures-Maps (IPersistentMap)][Map]] specifies a single neuron e.g.
13   #+begin_src clojure
14     ;; a simple neuron which sums two unit inputs
15     (run {:phi     identity
16           :accum   (comp (partial reduce +) (partial map *))
17           :weights [1 1]}
18          [1 1]) ; => 2
19   #+end_src
20   #+begin_src latex  :file data/map.pdf :border 1em :packages '(("" "tikz")) :exports none
21     \usetikzlibrary{arrows}
22     \tikzstyle{neuron} = [circle, draw, text centered, font=\footnotesize]
23     \begin{tikzpicture}[->,>=stealth', shorten >=1pt, auto]
24       \node [neuron] (neuron) at (0,0)     {$\Sigma$};
25       \node          (input1) at (-2,1)    {$x_{1}=1$};
26       \node          (input2) at (-2,-1)   {$x_{2}=1$};
27       \node          (weight) at (0,1)     {$\overrightarrow{w}=[1,1]$};
28       \node          (output) at (3,0)     {$y=2$};
29     
30       \draw (input1) -- (neuron);
31       \draw (input2) -- (neuron);
32       \draw (neuron) -- node[above] {$\Phi=identity$} (output);
33     \end{tikzpicture}
34   #+end_src
35   [[file:data/map.png]]
36   
37 - [[http://clojure.org/data_structures#Data Structures-Vectors (IPersistentVector)][Vectors]] are used to represent an /ordered/ series of neural elements
38   to be executed in /serial/
39   #+begin_src clojure
40     ;; two neurons in serial
41     (let [n {:phi identity
42              :accum (comp (partial reduce +) (partial map *))}
43           net [(assoc n :weights [1 1]) (assoc n :weights [2])]]
44       (run net [1 1])) ; => 4
45   #+end_src
46   #+begin_src latex  :file data/vector.pdf :border 1em :packages '(("" "tikz")) :exports none
47     \usetikzlibrary{arrows}
48     \tikzstyle{neuron} = [circle, draw, text centered, font=\footnotesize]
49     \begin{tikzpicture}[->,>=stealth', shorten >=1pt, auto]
50       \node [neuron] (neuron1) at (0,0)     {$\Sigma$};
51       \node [neuron] (neuron2) at (2,0)     {$\Sigma$};
52       \node          (input1)  at (-2,1)    {$x_{1}=1$};
53       \node          (input2)  at (-2,-1)   {$x_{2}=1$};
54       \node          (weight)  at (-2,0)    {$\overrightarrow{w}=[1,1]$};
55       \node          (output)  at (4,0)     {$y=4$};
56     
57       \draw (input1) -- (neuron1);
58       \draw (input2) -- (neuron1);
59       \draw (neuron1) -- node[above] {$\overrightarrow{w}=[2]$} (neuron2);
60       \draw (neuron2) -- (output);
61     \end{tikzpicture}
62   #+end_src
63   [[file:data/vector.png]]
65 - [[http://clojure.org/data_structures#Data Structures-Lists (IPersistentList)][Lists]] are used to represent a /unordered/ series of neural elements
66   to be executed in /parallel/.
67   #+begin_src clojure
68     ;; a layer of three neurons in parallel followed by a single neuron
69     (let [n {:phi identity
70              :accum (comp (partial reduce +) (partial map *))
71              :weights [2 2 2]}
72           net [(list n n n) n]]
73       (run net [1 1 1])) ; => 36
74   #+end_src
75   #+begin_src latex  :file data/list.pdf :border 1em :packages '(("" "tikz")) :exports none
76     \usetikzlibrary{arrows}
77     \tikzstyle{neuron} = [circle, draw, text centered, font=\footnotesize]
78     \begin{tikzpicture}[->,>=stealth', shorten >=1pt, auto]
79       \node          (input1)  at (-2,1)    {$x_{1}=1$};
80       \node          (input2)  at (-2,0)    {$x_{2}=1$};
81       \node          (input3)  at (-2,-1)   {$x_{3}=1$};
82       \node [neuron] (neuron1) at (0,1)     {$\Sigma$};
83       \node [neuron] (neuron2) at (0,0)     {$\Sigma$};
84       \node [neuron] (neuron3) at (0,-1)    {$\Sigma$};
85       \node [neuron] (neuron4) at (2,0)     {$\Sigma$};
86       \node          (output)  at (4,0)     {$y=36$};
87     
88       \node          (weight1) at (0,1.75)  {$\overrightarrow{w}=[2, 2, 2]$};
89       \node          (weight1) at (2,0.75)  {$\overrightarrow{w}=[2, 2, 2]$};
90     
91       \foreach \a in {1,2,3}
92       {
93         \foreach \b in {1,2,3}
94         {
95           \draw (input\a) -- (neuron\b);
96         }
97         \draw (neuron\a) -- (neuron4);
98       }
99       \draw (neuron4) -- (output);
100     \end{tikzpicture}
101   #+end_src
102   [[file:data/list.png]]
104 - Graphs -- unlike the previous data types which are built into
105   Clojure Graphs are specific to this library
106   #+begin_src clojure
107     (let [n {:phi identity
108              :accum (comp (partial reduce +) (partial map *))
109              :weights [2 2]}
110           g (Graph. {:a n :b n :c n} [[:a :b] [:a :c] [:b :c]])]
111       (run g [1 1 1]))
112   #+end_src
113   #+begin_src latex  :file data/graph.pdf :border 1em :packages '(("" "tikz")) :exports none
114     \usetikzlibrary{arrows}
115     \tikzstyle{neuron} = [circle, draw, text centered, font=\footnotesize]
116     \begin{tikzpicture}[->,>=stealth', shorten >=1pt, auto]
117       \node          (input1)  at (-2,1)   {$x_{1}=1$};
118       \node          (input2)  at (-2,0)   {$x_{2}=1$};
119       \node          (input3)  at (-2,-1)  {$x_{3}=1$};
120       \node [neuron] (a)       at (0,0.5)  {$:a$};
121       \node [neuron] (b)       at (1,-0.5) {$:b$};
122       \node [neuron] (c)       at (2.5,0)  {$:c$};
123       \node          (output)  at (4,0)    {$y=?$};
124     
125       \draw (input1) -- (a);
126       \draw (input2) -- (a);
127       \draw (input3) -- (b);
128       \draw (a)      -- (b);
129       \draw (a)      -- (c);
130       \draw (b)      -- (c);
131       \draw (c)      -- (output);
132     \end{tikzpicture}
133   #+end_src
134   [[file:data/graph.png]]
136 Example implementations are given for the following types of neural
137 networks.
138 - [[file:src/neural_net/perceptron.clj][perceptrons]]
139 - [[file:src/neural_net/back-propagation.clj][back propagation]] networks
140 - [[file:src/neural_net/radial-basis.clj][radial basis]] neurons /pending/
142 * License
143 Copyright (C) 2010 Eric Schulte
145 This program is free software: you can redistribute it and/or modify
146 it under the terms of the GNU General Public License as published by
147 the Free Software Foundation, either version 3 of the License, or
148 (at your option) any later version.
150 This program is distributed in the hope that it will be useful,
151 but WITHOUT ANY WARRANTY; without even the implied warranty of
152 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
153 GNU General Public License for more details.
155 You should have received a [[file:COPYING][copy of the GNU General Public License]]
156 along with this program.  If not, see <http://www.gnu.org/licenses/>.