<CENTER>6 D9 p6 o& Y" m+ Y0 e
<H1>NNUGA </H1> . h' R! t6 N1 n<H2>Neural Network Using Genetic Algorithms </H2>4 ~, e: B0 O2 j4 \* Y
<H2>By <a href="http://www.cs.bgu.ac.il/~omri" target="_blank" >Omri Weisman</A> and <a href="http://www.cs.bgu.ac.il/~pollack" target="_blank" >Ziv Pollack</A> </H2>/ b0 H p- a0 E
<H3>A final project in the course Robotics 95 </H3><IMG src="http://www.cs.bgu.ac.il/images/lines/rainban.gif"></CENTER>; x. T; s+ J& @5 y/ S5 X0 \
<DL> y& V3 ^ `' e/ ~( P! Z7 O
<DT>6 e+ ~( n/ R5 F) ~! ~9 U
<H3><FONT size=3>Using Genetic Algorithms in Computer Learning</FONT></H3> # V3 n4 r; B. Y8 k( g- r5 e9 w<DD><FONT size=3>Essentially, <B>Genetic Algorithms</B> (GA) are a method of "breeding" computer programs and solutions to optimization or search problems by means of <B>simulated evolution</B>. Processes loosely based on <B>natural selection, crossover, and mutation</B> are repeatedly applied to a <B>population</B> of binary strings which represent potential solutions. Over time, the number of above-average individuals increases, and better fit individuals are created, until a good solution to the problem at hand is found. " C9 c1 d/ s% m1 { `) }$ U7 m8 j2 m! j, G' P
</FONT> 1 d0 h( U( e, c7 H9 U7 ~<><FONT size=3>In NNUGA, we are using GA to find the solution to a <B>classification problem</B> with a <B>neural network</B> (NN). The neural network is a structure which is able to respond with <I>True</I> (1) or <I>False</I> (0) to a given input vector. We are trying to "teach" our neural network to correctly classify a set of input vectors, which can be thought of as <B>learning a concept</B>. We then expect that when the neural network will be presented with a vector P not from this set, it will tend to exhibit <B>generalization</B> by responding with an output similar to target vectors for input vectors close to the previously unseen input vector P. 7 y2 g2 k1 _9 p6 [5 J% V* Q 2 P c2 J9 X1 y I! q {1 j* ]3 ^</FONT>& o. K C' T9 }8 i
<><FONT size=3>Our genetic algorithm works with not one but <B>multiple populations</B>, all of which evolve seperately most of the time, except for once every several generations where we allow different populations to mix with each other. 0 b6 o0 ?! b3 D; f( ^6 ?
2 ^( S- p, x+ Q7 S ; o* w, J: A" @8 @$ Z</FONT></P> , J# L# E0 k* R- I$ {<DT>8 P0 V8 w$ S K% M
<H3><FONT size=3>The Neural Network</FONT></H3>- B! J6 k" S b' }/ `
<DD><FONT size=3>Our neural network has 2 inputs and 1 output. It is constructed from 6 neurons in the first layer and 1 neuron in a second layer. / I5 b! T$ M5 l; O) \# y2 l# J ! o" \: b# T1 o i- M' Q</FONT>; V8 |2 o: O9 T: _2 `
<><FONT size=3>In the first layer we have 2 neurons with atan transfer functions: 8 h! l2 V2 Y1 I& o. T7 t$ |9 ~( a5 g% J1 R6 c+ g% z/ n" Z( t- g9 [/ l
</FONT>: p; [$ d1 W1 z# m
<><FONT size=3></FONT><RE><FONT size=3> atan( P * W + b )2 `& `$ {- C3 f1 `5 Z
</FONT></PRE><FONT size=3>2 with linear transfer functions: </FONT><RE><FONT size=3> P * W + b0 A) `# x$ z4 j$ v' e
</FONT></PRE><FONT size=3>and 2 with hardlim transfer functions: </FONT><RE><FONT size=3> P * W + b > 0 4 K9 i8 [8 c2 l6 |+ P3 b </FONT></PRE><FONT size=3>where P is the input vector presented to the network, W is the vector of weights and b is the bias of the neuron. ; |- n8 t! U9 z; w" x & {- R' U6 G: p2 Q' |* @* S0 L5 l</FONT> % a5 R/ ~! S$ R3 N<><FONT size=3>The output function of the neuron in the second layer is: </FONT><RE><FONT size=3> A * W + b > 0 - F+ o+ M1 }, E </FONT></PRE><FONT size=3>where A is the vector of the outputs of the neurons in the first layer, W is the vector of weights and b is its bias. The output of this neuron is also the output of the network. 1 \: A8 A( Q2 z p* n; c8 U' f! N( h # _" u \! B0 D" K$ F- _7 j; a, i% m
, A1 R# O$ z; b" r
</FONT>& G" U% R% s' ]# f- M
<DT> 0 j8 V" N6 N( M1 J* a( v<H3><FONT size=3>The Learning Method</FONT></H3>6 M, d$ D# J2 m4 F/ C/ m) y
<DD><FONT size=3>As stated earlier, the neural network learns using genetic algorithms. This means that the weights and biases of all the neurons are joined to created a single vector. A certain set of vectors is a correct solution to the classification problem at hand. We are hoping to find one of these vectors using an evolutionary algorithm. x3 y! O- k" H4 r3 z0 T3 x9 u2 [6 C/ B4 i
</FONT> 8 s; Q- Z3 `8 f h3 I. V: R<><FONT size=3>The Canonical GA (pseudo code): 1 _( p7 k: L8 F/ Q v, p V2 M. W/ G8 r$ L" I" [</FONT>% H5 ]; t3 [7 P' Y/ x) y" T" Q6 \
<><FONT size=3></FONT><RE><FONT size=3> choose initial population% u4 \9 @3 j7 W% U' L# q( Z
evaluate each individual's fitness' T! f v. _0 h. x2 i
repeat# Y5 B6 C) z D7 H Y" [0 w! E
select individuals to reproduce) t) e6 r K9 J- C. b
mate pairs at random ! |; r* d' i& U6 l" c# V! ?* t apply crossover operator ; `$ f# }8 V- t. c) ` apply mutation operator 4 g5 R) o' R3 K ^4 S& t5 y/ ` evaluate each individual's fitness / r3 O" T6 c9 |! z. \8 `! c until terminating condition7 C: X0 L2 c0 H- O5 a3 q
</FONT></PRE><FONT size=3>The learning loop can terminate either if a satisfactory solution is found, or the number of generations pass a preset limit, suggesting that a complete solution will not be found with this set of individuals. : x9 B9 ?* k' n- x- d8 y" ~
/ d/ m. q* B$ e</FONT>; c4 z- i% _6 h: y8 {
<><FONT size=3>In our case, we have several seperated populations, all of which evolve seperately. Once every several generations we allow cross-over from different populations. 9 R3 @6 {' x+ c
; p1 u( q+ q) B$ [) ]: H! n</FONT>& G0 C" z0 I$ M/ K! u4 t
<><FONT size=3></FONT></P> * v7 E5 U3 e, m) L# o: N<DT> , i8 g; m" h! x9 G. p2 V<H3><FONT size=3>Limitations</FONT></H3> 1 e2 Z; k' L( `% Q9 X9 K; O5 B; ^9 u<DD><FONT size=3>Sometimes it could happen that though the NN could theoretically solve a certain classification problem, our system will not return a correct solution. This is because of the random nature of the algorithm and its reliance on natural selection, mutation and cross-overs. Naturally, it could happen that a certain flow of events that would lead to a correct solution will not occure and thus a solution will not be found. However, by using several unrelated populations we have decreased the probabilty of this happening, since if some population has poor individuals the solution could still be found at another. * a; I5 Y" Q6 H
! g" r! w, P1 ?# `/ h</FONT>+ r! g4 [! y5 ~2 B: ^9 l) R- e
<DT>+ ?# `7 x- e9 ~ ]; c; a& m
<H3><FONT size=3>Our Implementation</FONT></H3>2 ^6 Y9 q& X$ I, V' U. ?
<DD><FONT size=3>We implemented a network with 2 inputs. The input for the neural network can be taken from a graphic user interface, by clicking on points in a board. A click with the left mouse button generates a '+' sign on the board, marking that it's a point where the NN should respond with 'True'. A click with the right mouse button generates a '-' sign on the board, marking that it's a point where the NN should respond with 'False'. When enough points have been entered, the user can click on 'Start', which will introduce these points as inputs to the NN, have it learn these input vectors and show a group of lines which corresponds to the division of the plane into regions of opposite neuron response. While the learning takes place, a textual indication of the learning process is presented on the standard output; This includes the fitness of the best individual in each population on each generation, and a schematic textual division of the plane once every 50 generations, to allow the user to inpect the progress. 4 f! U8 [% {% l K+ x/ u, m2 F v- O/ A! `' d' j
</FONT> 8 k3 }. h6 |4 D<><FONT size=3>Here's an example of a screen shot: ( ]+ L$ Q2 Z/ a3 H6 w; T! X$ s0 v) Q2 U5 G
+ w6 W- P7 ?% I</FONT>- X4 k# H7 A, P% \. @
<><FONT size=3></FONT> " N* y1 A: B. W6 I$ Z( J<CENTER><FONT size=3><IMG src="http://www.cs.bgu.ac.il/~omri/NNUGA/nnuga.gif"></FONT></CENTER>( d( X- S' r# f: q
<><FONT size=3></FONT></P>. C4 }; z2 o$ M5 Q
<DT> 6 K# e% u; v4 C0 y; w7 y! t/ T<H3><FONT size=3>Examples</FONT></H3> 7 m, S1 b% V0 z0 @, D<DD><FONT size=3>Here are more examples of screen shots. 8 K2 G+ E3 V+ \( f- ^! ^9 @3 H0 _; E# h9 J% S) v+ m5 M
</FONT>) }! a6 @0 k) }! p9 L( B
<UL> 8 Q; X2 T. W4 x4 }4 R<LI><a href="http://www.cs.bgu.ac.il/~omri/NNUGA/nnuga1.gif" target="_blank" ><FONT size=3>Example 1 </FONT></A><FONT size=3>( GIF, 10K ) % }8 w }6 {' p8 N7 X; r+ e y- E# s& H# I% ?2 P( H</FONT>/ Y* S( {. K9 M5 E; `# j, J. h
<LI><a href="http://www.cs.bgu.ac.il/~omri/NNUGA/nnuga2.gif" target="_blank" ><FONT size=3>Example 2 </FONT></A><FONT size=3>( GIF, 10K ) " O! W0 G1 D/ b5 e
w9 f* D Q2 b1 t1 ]
</FONT> * d: G1 K; s( J' x, X<LI><a href="http://www.cs.bgu.ac.il/~omri/NNUGA/nnuga3.gif" target="_blank" ><FONT size=3>Example 3 </FONT></A><FONT size=3>( GIF, 10K ) ( U- f! |* g5 l. \+ r( E7 F0 D7 Z) x, c
</FONT> U& o+ U0 V. N# c5 S
<LI><a href="http://www.cs.bgu.ac.il/~omri/NNUGA/nnuga4.gif" target="_blank" ><FONT size=3>Example 4 </FONT></A><FONT size=3>( GIF, 10K ) . ]" @8 }$ C7 b9 q, Z" i2 l/ ^5 z: \* o$ o- o7 {, o
</FONT> 2 d+ V) Y: S& t2 o0 n9 i! \) {9 c<LI><a href="http://www.cs.bgu.ac.il/~omri/NNUGA/nnuga5.gif" target="_blank" ><FONT size=3>Example 5 </FONT></A><FONT size=3>( GIF, 10K ) </FONT></LI></UL>( ^6 b+ j0 p% [- E: I
<><FONT size=3></FONT></P> ( }4 y. X! j: p+ q1 g<DT> 7 O3 T% d8 }- g<H3><FONT size=3>Source Code</FONT></H3> ( `' p" ]3 V: @& p$ w, T<DD><FONT size=3>In order to be able to run the program, save all these files in a directory, type 'make', and use 'nnuga' to start the system.The program should run under all platforms which support Tk, though we tested it for UNIX SunOS only. ' X6 @3 C. C% c9 s9 ^
) r# s: f& W5 G n3 ~/ J
</FONT># X% m& F: E& m7 U
<> 9 w1 a3 f- m) u" d<UL>3 r, o5 {* k/ Q* Q* G+ g. B% m
<LI><a href="http://www.cs.bgu.ac.il/~omri/NNUGA/nnuga" target="_blank" ><FONT size=3>nnuga </FONT></A><FONT size=3>- The Tk interface (8K). " i- L7 k+ y) v! b
2 K7 O& h v' E! T$ ]6 a
</FONT>; R5 @- \3 R6 o+ X- m! D
<LI><a href="http://www.cs.bgu.ac.il/~omri/NNUGA/nnuga.c" target="_blank" ><FONT size=3>nnuga.c </FONT></A><FONT size=3>- The actual Neural Network, C code (18K). & Y# e" {* [% x7 i3 e# {( s4 K4 Z3 ]. h1 e: V9 K
</FONT> " s+ v- v( U1 u) U% ]<LI><a href="http://www.cs.bgu.ac.il/~omri/NNUGA/README" target="_blank" ><FONT size=3>readme </FONT></A><FONT size=3>- The readme file (very much like this file) (6K). ' \3 T2 S, B' i# k9 H6 e
1 d7 ^" J' L; v: i/ N8 g
</FONT> 7 ]' D) m% ]1 j7 n- h8 O<LI><a href="http://www.cs.bgu.ac.il/~omri/NNUGA/makefile" target="_blank" ><FONT size=3>makefile </FONT></A><FONT size=3>- The (trivial) makefile (<1K). </FONT></LI></UL>$ r! N5 e8 G7 q$ I- E7 ?% l
<><FONT size=3>You can also grab all these files in one </FONT><a href="http://www.cs.bgu.ac.il/~omri/NNUGA/nnuga.tar.gz" target="_blank" ><FONT size=3>tarred gzipped file </FONT></A><FONT size=3>(8K) . % x W2 i7 ] a) X! y( e9 V ; v' Z- i. ~* T" e/ U</FONT> 8 J, |$ e5 ^9 }' d4 Z9 W _<><FONT size=3><I>Note: This code is free and is in the public domain. You may copy, use, and change it as much as you like. However, the writers take no responsibility for the results of using this program.</I> ! R3 Q) b1 z- J* R9 O2 ]6 I% m% C1 V6 a6 r8 ~+ c0 P3 _
</FONT>+ C' M- e* ], r! R4 m! B4 R5 ~
<><FONT size=3></FONT></P>8 ~$ u$ X) H q' k
<DT> 2 f( V0 b# W( N* @% T; s; u* O( v) `<H3><FONT size=3>See Also</FONT></H3>' b* _# a9 h2 d: l+ T
<UL>4 z6 I5 Y! I9 Z% O) C) x; L1 a
<LI><a href="http://www.cs.bgu.ac.il/~omri/Perceptron/" target="_blank" ><FONT size=3>The Perceptron </FONT></A></LI></UL></DT></DL><FONT size=3> 0 Y, ?8 R, Q/ C8 R<HR>' g" w2 k# I- [: F8 W
</FONT> # g/ M4 S& W" o& d; n/ g. {/ a<><I><FONT size=3>Last updated August 13th 1995) W7 f* D8 ^8 I. D4 N: S" _+ a! |
Created by </FONT><a href="http://www.cs.bgu.ac.il/~omri" target="_blank" ><FONT size=3>Omri Weisman</FONT></A><FONT size=3> </FONT></I></P> - z' X3 c* C) ^7 r5 O1 T$ `