William Sayers

2009
Milestone 3

05025397

Genetic Algorithms and Neural Networks

Genetic Algorithms and Neural Networks
William Sayers (05025397)
Supervised by: Colin W. Morris (BSc, MSc)
Backpropagation neural networks are usually trained using some iterative method derived from a mathematical analysis of the operation of the network. This technique is time consuming and requires understanding of the mathematical principles involved. This project will investigate the application of genetic algorithms to replace the "normal" training of the network. This involves setting up some candidate networks and then picking the best of these. The best of the population are then combined in some way to produce a new population of candidate networks. This procedure is continued until a satisfactory network is obtained.

William Keith Paul Sayers225 Page 1 of Faculty of Advanced Technology 22/04/2009

William Sayers

05025397

Genetic Algorithms and Neural Networks
Milestone 3

Contents
Contents ............................................................................................................................ 2 1 - Introduction ............................................................................................................... 10 2 - Research .................................................................................................................... 10 2.1 - Neural Networks ................................................................................................. 10 2.1.1 - The Biological Neuron................................................................................. 10 Figure 1 - A human neuron ............................................................................................ 10 2.1.2 - The Artificial Neuron................................................................................... 11 Figure 2 - An artificial neuron ........................................................................................ 12 Equation 1 - Summation of the inputs and weights ........................................................ 12 Figure 3 - The sigmoid function shape ........................................................................... 13 2.2 - The History of Neural Networks ........................................................................ 13 2.3 - Advantages and Disadvantages of Neural Networks ......................................... 14 2.3.1 - Advantages................................................................................................... 14 2.3.2 - Disadvantages .............................................................................................. 15 2.4 - Current Applications of Neural Networks .......................................................... 17 2.4.1 - Neural Networks in Medicine ...................................................................... 17 2.4.2 - Neural Networks in Business ....................................................................... 18 2.4.3 - Object Trajectories....................................................................................... 19 2.4.4 - Robot Control .............................................................................................. 19 2.5 - Back-propagation ............................................................................................... 20 2.5.1 - Back-propagation overview ......................................................................... 20 Page 2 of 225

William Sayers

05025397

Genetic Algorithms and Neural Networks
Milestone 3 2.5.2 - Back-propagation in depth ........................................................................... 20 2.5.3 - Back-propagation library ............................................................................. 22 2.6 - The FANN neural network library (Nissen, FANN) .......................................... 22 2.7 - Genetic Algorithms ............................................................................................ 22 2.7.1 - History of Genetic Algorithms .................................................................... 23 2.7.2 - Advantages and Disadvantages of Genetic Algorithms .............................. 24 Figure 4 - local optimum (units are undefined in this case). .......................................... 27 2.8 - Training Neural Networks with Genetic Algorithms ......................................... 28 2.8.1 - Determining Weight Values with Genetic Algorithms................................ 28 2.8.2 - Representation of a Neural Network within a Genetic Algrithm ................ 28 2.8.3 - Using Genetic Algorithms to Determine Neural Network Structure ........... 29 Figure 5 - A feed-forward neural network ..................................................................... 30 2.9 - Cascade Correlation............................................................................................ 32 2.10 - C# User Interface Programming ....................................................................... 37 2.11 - Writing C++/CLI Wrappers for Unmanaged C++ code................................... 37 2.12 - Application of Research ................................................................................... 38 3 - Design ....................................................................................................................... 38 3.1 - Program Requirements ....................................................................................... 39 3.2 - Design of the Class Structure ............................................................................. 39 3.3 - Linking C# code to managed dll’s...................................................................... 40 3.4 - Design of the User Interface ............................................................................... 40 Page 3 of 225

William Sayers

05025397

Genetic Algorithms and Neural Networks
Milestone 3 3.4.1 - Main Form ................................................................................................... 40 Figure 9 – Network and output tab design (Main form) ................................................ 41 Figure 10 - Mean squared error tab design (Main form) ................................................ 42 Figure 11 - Dataset tab design (Main form) ................................................................... 42 3.4.2 - New Network Wizard .................................................................................. 43 Figure 12 - Design of the training algorithm tab (Wizard form) .................................... 43 Figure 13 - Design of the network settings tab (Wizard form) ...................................... 44 Figure 14 - Dataset selection tab design (Wizard form)................................................. 44 3.4.3 - Working Form ............................................................................................. 44 Figure 15 - Working form design (Working form) ........................................................ 45 3.4.4 - About Form .................................................................................................. 45 Figure 16 - About form design (About form) ................................................................. 45 Figure 17 - Dataset display design (About form) ........................................................... 46 Figure 18 - Licenses display design (About form) ......................................................... 46 4 - Implementation ......................................................................................................... 46 4.1 - User Interface Implementation ........................................................................... 47 4.1.1 - Main Form ................................................................................................... 47 Figure 19 - Network and Output tab............................................................................... 47 Figure 20 - Mean squared error graph tab ..................................................................... 48 Figure 21 - The dataset tab ............................................................................................. 49 4.1.2 - New Neural Network Wizard ...................................................................... 50 Figure 22 - Learning Algorithm tab ............................................................................... 50 Figure 23 - Network Settings tab.................................................................................... 51

Page 4 of 225

..................... 54 4........ 56 4..................... main view ............ 58 5....3 .................The mean squared error at testing (XOR)............................................. 59 5.Cascade Correlation .....5 .......................................................1...............................................Graphs .................. 57 4..................Back-propagation ............Neural Network Implementation ..............About Form .......................2....Working form ..............1........................Data Parser Implementation ............................................................1 ....... 61 Figure 31 ...................4 ..................................................3 ...2 .................. 61 Figure 29 ............1..................................................................Back-propagation and Cascade Correlation Implementation ......... 52 Figure 25 .4 ............................Mean squared error upon last training test (XOR) ...........................3 ..........Number of iterations to achieve target (XOR) ...About form........................................................................................................................................................................Dataset tab ......................................About form............................. 56 4..........1..................................................... 54 Figure 28 ............................................................. 52 Figure 26 .................. 61 Figure 30 ................................................................................Testing Data ...........1 .... 62 Page 5 of 225 ..........1...................................................................................... 53 Figure 27 ..About form...........................Passing Information between Forms ............... 54 4... Licenses view .................... 60 5.............Keeping the User Interface Active whilst Processing is Occurring..............6 .......................................1........................Genetic Algorithm Implementation .. 51 4.........1.....................................1.............. 59 5............................................ 54 4........2 ... 57 5 .. 55 4......1 .........Working Form ......... Datasets view ........ 58 5...........William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Figure 24 ...................4 ..........XOR ...........................................................................................Genetic Algorithms ...............

....Cascade Correlation ..XOR ................................ 68 6.2 ..........1 ..............................Number of iterations to achieve target (Viruses) ......1 .............Fishers Iris Data ........................1............3 .................................... 67 Figure 36 ...............................................................................2 . 68 6..............................................................Virus Classification..Back-propagation .................................... 69 6...............Number of iterations to achieve target (Iris data) ........ 64 Figure 32 ..................................................2 .................3 ........ 64 Figure 34.............................. 65 5...............................3.....................................3.........................3............................... 63 5.. 67 Figure 37 ......................................... 63 5..............................Graphs ...................2 .Cascade Correlation and Genetic Algorithms ... 66 5..2 ......................... 68 6.......... 63 5.......Cascade Correlation .........2..........................The mean squared error at testing (Iris data) .................Comparisons .........................................................Mean squared error at testing (Viruses)........................................... 68 6 ...............................................2...............2.................4 ......................1...........................................1 .......................Fishers Iris data.......3 .............. 64 Figure 33..Back-propagation and Genetic Algorithms ........2............................Mean squared error upon last training test (Viruses)..............................Mean squared error upon last training test (Iris data) ........... 66 5.......................Genetic Algorithms ......................................4 ... 65 5........................Graphs ........................................ 63 5.................3 ...................................... 66 5................................... 67 Figure 35 .................................................................................. 69 Page 6 of 225 ....... 69 6.........................................3......................................................1..........................................................Genetic Algorithms ....................Virus Classification ............1 .............William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 5.Back-propagation ...............................................................

.........................................XOR ......................................................Appendices ..................... 210 10 ..................................Possible Training Algorithm Improvements ................................................................ 69 6.........5 .View ...........UML Class Diagram..............................................................................2 ................................1.............3 ................................................2 ........................................................... 204 9.........Fishers Iris Data .........................................1..........................3 ...... 158 9....4 .................................................. 70 7........................2.. 209 9................................................................Controller .......................................................................................................................................................................Source code ..................... 214 Page 7 of 225 ...1 ...............4 ................................................................ 109 9............ 74 9...............................1.....2.........3 .Possible User Interface Improvements ......Libraries Researched ..............Virus Classification.................Datasets................................2 ............................................... 211 11 ..................................... 71 8 .................Evaluation ............ 69 6.. 73 8......... 74 9.............................................................................................Works Cited ....Bibliography............How many of the original objectives were achieved? .... 72 8....... 174 9.... 207 9............................................... 73 9 ......Testing conclusions ..................................Possible Improvements ...1 ...................................................Objectives ................................................................................................................................................................1................................ 70 6..................................3 ...........Model ...................William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 6.....................................................................DLL Wrapper for FANN functions ............................... 75 9......................................1 .......2 ........................................2. 70 7 ..1 ............1 ............................................

...Table of tables ....................................................William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 12 ..............................................................Table of Figures .................................................................................................................... 220 13 ............2 ...........................Diary.......................................Table of Equations ...Tables ......................................................... 217 12.. 219 12.....................................................................1 ......................... 222 Page 8 of 225 ................................... 217 12...................3 ..

nor any part of it...................... the work described within this project is the result of the investigation carried out by myself............. Page 9 of 225 ..... ……………………………….......................... Student Name (Printed) Student Signature Registered Scheme of Study Date of Signing ……………………………….......William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 STATEMENT OF ORIGINALITY SCHOOL OF COMPUTING DEGREE SCHEME IN COMPUTING LEVEL THREE PROJECT This is to certify that......... and that neither this project.... ………………………………....... ………………………………... has been submitted in candidature for any other award other than this being presently studied.................... except where specific reference is made... Any material taken from published texts or computerised sources have been fully referenced..... and I fully realise the consequences of plagiarising any of these sources.....................

Although they are simple in concept.The Biological Neuron The human brain is composed of many millions of nerve cells called “Neurons”.Introduction The purpose of this report is to bring to a conclusion my final year project on neural networks and genetic algorithms. In addition. but in combination with a network of other neurons within the brain.1.1 .1 . 2 .Neural Networks Neural networks are networks of small-specialised units that sum the products of their inputs and the weights on those inputs. Neurons do not make decisions alone. compare and contrast three common learning algorithms that are applicable to neural networks.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 1 .A human neuron Page 10 of 225 . the report will investigate. 2.Research 2. This report encompasses design. development and final prototyping of the program developed for this project. they can produce immensely complex results. on the course “Computer Games Development”. Figure 1 .

The Artificial Neuron In order to construct an artificial neuron we need a way of representing the same model in data structures and algorithms. the nucleus will generate an “action potential”. a number of weights associated with those inputs. (Barber. (Bourg & Seeman.2 . a synaptic gap occurs between the axon branch and the synapse. in order to allow the brain to control cells external to the brain. as mentioned above). Axon branches can connect to other types of cells also. a summing function. AI: Neural Network for Beginners pt. 2004). with extensions called “Dendrites” which are the neuronal inputs and a single extension called an “Axon” which is the output for that neuron.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 A neuron is composed of a cell body. If the inputs from the dendrites to the neuron nucleus when summed are past a certain threshold. Page 11 of 225 . or to another part of the program.1. the nucleus of the neuron cell processes them and produces an output. Axon branches connect to synapses to form the neural networks within the brain. 1. in this gap between neurons chemical reactions take place that will inhibit or excite the signal. The usual method for approaching this is to have a number of inputs. 2006) 2. This action potential extends down the axon to the cells at the end of the axon branches (often synapses connecting to other neuronal cells. The axon and dendrites both split before terminating into “Axon branches” and “Synapses”. an activation function and a method for representing an output – either to another artificial neuron in the next layer. In the case of the axon branches connecting to synapses that are part of a second neuron. Concerning inputs from the dendrites.

or one (activated) if the summed products are above a certain value.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Figure 2 . ℎ = × ℎ Equation 1 . real number. or integer). A stepping function can be used which will output zero (or non-activated) if the summed products are below a certain value.Summation of the inputs and weights The next stage depends on the activation function chosen. Alternatively. The activation function accepts this stored value. The product of the data item and its associated weighting is then stored before the summation of all the data items and associated weights occurs. a differentiable function of some kind (such as a sigmoid function) which will output values between zero and one depending on the value of the inputs is another possibility. A specific input accepts a data item (usually a binary digit. Page 12 of 225 .An artificial neuron The system devised with these components is as follows.

8 0. McCulloch and Pitts formulated the first neural network model which featured digital neurons but the neurons had no capability to learn (McCulloch & Pitts.4 0.A sigmoid function (Bourg & Seeman. (Bourg & Seeman. AI: Neural Network for Beginners pt. 2004). in 1958. (Barber. 2004). Page 13 of 225 .2 .2 1 0.2 0 -6 -4 -2 0 2 4 6 Figure 3 . In this example “y” is the function output and “t” is the function input. 1958).William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 1. William James and others. Frank Rosenblatt developed the perceptron model then.The sigmoid function shape = 1 1+ Equation 2 . 1. 2006) 2. contributed to the ideas that underpinned early neural network research.The History of Neural Networks The foundation of neural network research are in psychology.6 0. as defined in the graph above. 1943). the work of 19th century psychologists such as Freud. however he was unable to come up with a reliable mathematically accurate mechanism for allowing multilayer perceptrons to learn (Rosenblatt.

Parker discovered it independently in 1982 whilst performing graduate work at Stanford University in the United States of America and called it “learning logic”.Advantages Neural networks make possible or practical many things that with conventional solutions would be extremely difficult. (Blum. used on this architecture they become an extremely fast as well as flexible tool.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Two layer perceptrons were the subject of several experiments to determine their usage and effectiveness. One of the benefits of neural networks when compared with other problem solving techniques in that they are inherently parallel and thus can run very effectively and efficiently on parallel hardware.1 . 1974) discovered the back-propagation algorithm (independently rediscovered by Parker in 1982 (Parker. perceptrons with “n” hidden layers. Werbos discovered the algorithm whilst working on his doctoral thesis in statistics and called it “dynamic feedback”. 1982)). 2.3 . when Werbos (Werbos. The individual neurons in a neural network have no time dependencies on each other and each can therefore be run on a separate processor (or as separate threads on a single processor) if desired without causing the problems often associated with such parallelism.3. 1992). where “n” is an undefined number. The next major advancement in neural networks was not until 1974. taking Page 14 of 225 .Advantages and Disadvantages of Neural Networks 2. Back-propagation allows for the training of multilayer perceptrons and in particular. A good example of this is that neural networks have been implemented to run on architecture originally designed for processing three dimensional computer graphics. of “n” nodes.

1 Decide on relevant data. to attempt to provide a more robust post-training network. 3 Run the formulated model. in fact. We can simply present the neural network with all the data as opposed to following the circuitous and overly complex (by comparison) statistical approach demonstrated in “Table 1 .William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 advantage of the massively parallel architecture of this hardware and the programmable sections of the graphics pipeline (vector and fragment shaders) to produce extremely fast neural networks (Davis.2 .Disadvantages One disadvantage to neural networks can be that it is very difficult for a human being to analyse a trained neural network and describe why it may come up with one answer over another. When using a neural network there's no need to establish before attempting problem solving which data is relevant. 2001). 2 Formulate a statistical model. Table 1 . Page 15 of 225 .3. where explaining why you have arrived at a particular diagnosis is an important part of the process.The statistical approach to deciding relevant data”.The statistical approach to deciding relevant data Another advantage of neural networks is that noisy data is not a real problem for them to learn to interpret. noisy data is utilised during training upon occasion. as irrelevant data will simply end up weighted so that it has zero or close to zero actual effect on the solution produced by the network. This is a large disadvantage in areas such as medical diagnosis. 2. 5 Build a system that incorporates what we have learned. 4 Analyze the results. Neural networks can excel at determining what data in a particular set is relevant.

the network came up with apparently random answers. When using neural networks is that.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Once a neural network’s training is complete it is hard to tell why it is coming up with a particular solution. or even to verify the quality of the training. for obvious purposes. there is no formal methodology with which to choose the architecture. Therefore. the US military wanted to use a neural network to analyse images and determine whether they contained a concealed tank. although the length of time the problem would take to solve without employing a neural network must be taken into account when deciding how much of a disadvantage. A tool used to solve heuristic problems. a sunny day. asked to differentiate between the two sets of pictures. Fifty pictures of each set were set aside and the neural network trained with the remaining one hundred images with and without tanks. All the photographs with tanks were from a cloudy day and all the images without. After the neural network’s training was complete. requires largely heuristic construction and preparation. train the neural network. A classic example is that in the 1980s. with and without tanks. the network had trained itself to recognise whether the sky was cloudy or not. The training times on neural networks can also be a disadvantage. Eventually the original data set was re-examined. Page 16 of 225 . it can also be hard to tell how well (or how badly) trained a neural network is. only to find that on this round of testing. they tested the network with the remaining fifty images that the neural network had not seen before and the neural network correctly identified most of the tanks. then a further one hundred images without. The US military then tested the neural network with a further set of one hundred images. They collected one hundred images with a concealed tank.

Fortunately since neural networks are (as has been mentioned above) good at ignoring irrelevant data. This is generalisation and it is far more useful than it at first appears and similar from a very high-level perspective to how the human brain and brains in general function. The more time spent training the neural network on quality data sets.1 . Garbage out”. The real strength of neural networks. Data sets for training neural networks generally separate into two sub-sets. covering as many relevant situations as possible.4. One of the main research areas is using neural networks to recognise diseases/conditions via scans. This drawback is however one that is generally universal to computing (and many other areas) often referred to as “GIGO” or “Garbage in. “training” and “testing”. Testing may then take place with the “testing” set to determine accuracy with unseen data. Neural networks make it more apparent however because (as in the previous US Military example) it can be difficult sometimes to decide what constitutes good data.Neural Networks in Medicine There is a large amount of research now covering the applications of neural networks in medicine. The network training first takes place using the appropriate “training” set. lies in their ability for generalisation. the eventual result will be.4 .William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Another possible criticism is that neural networks are extremely dependant on the quality and content of the original training data set. the usual best approach is to simply feed them as much data as can be obtained. Page 17 of 225 . the more accurate and in line with expectations and desires. this has to be done within reason however. or it does exacerbate the problem with the time spent training the neural network. 2. in the opinion of the author.Current Applications of Neural Networks 2.

can fit very well into most business situations. You can also use the technology to model parts of the human biological system in order to better understand it. for example the human cardio-vascular system. However. merely a variety of scans covering all possible permutations of the disease or condition. The main reasons for using a neural network to model the human cardio-vascular system are that a neural network is capable of adjusting itself to be relevant to a particular individual and also to adapt by itself to changes in that individual.2 . mortgage screening.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 This is particularly suitable work for neural networks because you do not need perfect examples of how to recognise the diseases and conditions.Neural Networks in Business Neural networks. Businesses have used neural networks in the past for applications such as assisting the marketing control of airline seat allocations in the AMT (Airline Marketing Tactician). and assessing borrowers have all incorporated neural networks as an integral part of the system. a clear problem with this approach is that when using a neural network it would be difficult to tell how a neural network reached its conclusion. thus supplying information more or less directly linked to the airlines main income. Credit scoring. A back-propagation neural net is integrated with the airline marketing tactician which monitored and recommended on booking for each flight. research on using neural networks to diagnose diseases took place. 1997) Page 18 of 225 . In the 1980s.4. being good at analysing patterns and predicting future trends. (Stergiou & Dimitrios. (Stergiou & Dimitrios. 1997) 2.

Adjust the arm to the appropriate joint angles and close the effecter. A neural network allows the robotic arms to be very flexible in their operation and perform self-adjustments as time goes by. 1999) 2. (Marshall & Srikanth. Calculate the joint angles required for the arm to be in the appropriate position.4.Object Trajectories Predicting the trajectory of an object in real time is another area where neural networks have been utilised. velocity and acceleration of the object being estimated in those implementations by several neural networks using several of the most recent measurements of the object coordinates. When controlling manipulators a neural net must deal with four major problems (Robot Control.4 . 2008): • • • • Forward Kinematics Inverse Kinematics Dynamics Trajectory generation The ultimate goal of course is to position the “effecter” (I.3 .Robot Control Controlling manipulators (such as robotic arms in a car manufacturing plant) is usually how robotics and neural networks connect. (relatively speaking) involving the following steps (Robot Control.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 2.e. When a robot arm is one hundred percent accurate that is a simple task. The position.4. 2008): • • • Determine the target coordinates relative to the robot. compensating automatically for wear and tear on Page 19 of 225 . a robotic hand or any other similar manipulator) in the appropriate position to grasp or otherwise manipulate an object or part of an object.

2. allowing us to apply our learning algorithm. A commonly used function is the sigmoid function as described in section 2.3. 2008). In order to use a back-propagation training algorithm you must have a non-linear activation function for your artificial neuron.1 . based on the strength of the weights connecting them to the output neurons. This is far preferable to having to perform lengthy and expensive re-calibrations on any regular basis (Robot Control. The advantage of using a function like this is that it allows us to differentiate how close we came to the correct result. training by back-propagation involves the steps: • • • • • Present a set of training data Compare the network’s output to the desired output at each output neuron and calculate the error.Back-propagation 2.cs” lines 130-133.2 .1.2 -The Artificial Neuron. the disadvantage of a differentiable function is that it is by the use of these functions that local optima become apparent in the search space. 2. Assign responsibility to each of the neurons in the previous level. Adjust the weight of the output neurons to lessen the error.5.5.1 -“Network.Back-propagation in depth In a single layer neural network (or with a single node) the perceptron rule is applicable. Page 20 of 225 . The sigmoid function is in the source code at 9. This rule essentially describes adjusting the weight using the difference between the expected and actual outputs.1.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 themselves.Back-propagation overview In essence.5 . Adjust the weight of the neurons to minimise the responsibility.

ℎ : = [1 − ] . Equation 3 – The delta rule (Matthews. the following alteration to the perceptron learning rule would serve our purposes (Matthews. such as the sigmoid function (see 2. Back-propagation for the Uninitiated. The sigmoid function differentiates very neatly.Altered perceptron learning rule (Matthews. this rule has no positive effect in a multi-layer neural network.Altered delta calculation rule for the output layer (Matthews. Page 21 of 225 . Back-propagation for the Uninitiated.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 ∆ = ℎ = − . The effect that the change will have on the following neurons in the network is an extra factor. as the effect that the change in the weight will have on the rest of the network is a missing factor. the output layer nodes training function can be written as: = 1− − Equation 6 . 2002) Therefore.1.2 -The Artificial Neuron) an alteration can be made to the perceptron learning rule allowing this difficulty to be overcome. The other two values “di and yi” are the actual and desired outputs. Back-propagation for the Uninitiated. = 1− Equation 4 .differentiated sigmoid function (Matthews. respectively. 2002) Calculating the hidden layer deltas is a little more complicated. 2002): ∆ = ℎ = − Equation 5 . 2002) However. 2002) In this equation “w” and “x” are as before. Back-propagation for the Uninitiated. “n” is the learning rate of the neural network. Provided you are using a differentiable function. Assuming the sigmoid activation function is in use. Back-propagation for the Uninitiated.

1859) very neatly avoids one of the larger problems involved in software design: how to specify in advance all the possible permutations of the original problem and how the program should react to those permutations.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Equation 7 .The FANN neural network library (Nissen. open-source (allowing me to alter it if I needed too.Altered delta calculation rule for the hidden layer(s) (Matthews. saving me finding a separate library. 1859) Page 22 of 225 .Genetic Algorithms Genetic algorithms attempt to copy natural laws to a certain extent in order to apply a random search pattern to a defined search space. although as it turned out I did not). By using similar techniques to natural selection. easy to implement. Most organisms evolve by means of sexual reproduction and natural selection (Darwin. The FANN library was decided upon for several reasons. in order to apply this learning mechanism you start at the output of the network and work your way towards the inputs.3 . 2. 2002) As demonstrated above. 2. Back-propagation for the Uninitiated. FANN) The FANN library (see (9. in a language that can be linked to C# fairly easily and it also supports cascade neural networks.6 . it is possible to “breed” solutions to problems. Therefore. Natural selection (Darwin.Back-propagation library 2.7 .3 -Libraries Researched) for other libraries investigated) implements a back-propagation solution and this library will be used in the project to implement a feed-forward back-propagation neural network. to calculate the delta for a hidden layer requires the deltas for the following layers.5. it is fast. against which to compare the genetic algorithm trained neural network.

swapping genetic material.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Sexual reproduction ensures mixing and recombination of genes. including noisy and discontinuous data. or indeed multiple genomes in a population. mostly designed to help evolutionary biologists’ model aspects of natural evolution. during this process. This book presents the concepts of adaptive digital systems using mutation.7. the publication of the book “Adaptation in Natural and Artificial Systems” occurred. 2. Also in 1975. this mixing leads to much faster evolution than if off-spring simply copied the genetic material as it is in the parents. simulating processes of biological evolution. but this variety helps to prevent stagnation in the gene pool. then of the technical University of Berlin introduced a technique he named evolution strategy. During the process chromosomes line up together and then cross over partway along their length. At first. selection and crossover. occasionally causing the genetic information. genetic algorithms were becoming more widely used. This could result in either an effective or defective solution. built on papers both by himself and by other researchers. to alter slightly in a random way. across a range of subjects. although this technique involved no crossover. By the early 1980s. many researchers had independently developed evolution-inspired algorithms for function optimisation and machine learning but did not get much follow up to their work. Mutation plays a part in this as well. by the author John Holland. In 1975.1 . genetic Page 23 of 225 . In 1965 one Ingo Rechenberg. this application was largely theoretical. a dissertation by Kenneth De Jong established the potential of genetic algorithms by showing that they perform well on a wide variety of data. however. By 1962.History of Genetic Algorithms Genetic algorithms first appeared on computers in the late 1950’s and early 1960’s.

proceeding with other more likely candidates.Advantages and Disadvantages of Genetic Algorithms 2.1 . Thanks to the parallelism that is a genetic algorithms main advantage. 2004). Many other algorithms are largely serial and can only explore a search-tree so far in any one direction before abandoning all progress and starting again from the beginning. abandon that search. methods.7. 2004) 2. or further up the hierarchy. they are very well suited as a means of exploring search spaces too large to be effectively searched in a reasonable amount of time by other. These are “non-linear” Page 24 of 225 . (Marczyk.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 algorithms soon moved into commercial territory and nowadays help solve many problems in many different areas. This leads to the exploration of a large proportion of the search space. Genetic algorithms effectively explore many different branches of the tree at once and when a certain branch turns out to be non-optimal. a genetic algorithm is implicitly evaluating a much larger group of individuals. with processing power exponentially dedicated to better areas as the exploration progresses. more conventional. This is “Schema Theorem” and allows a genetic algorithm to move towards the searchspace with the most promising individuals in a timely fashion and then select the best member of that group (Marczyk. in the same way that the average response of a relatively small percentage of the population of any given country.7.2 .Advantages The primary advantage of genetic algorithms is their inherent parallelism.2. can be used to fairly accurately predict national trends. The real advantage of parallelism however is that by evaluating the relatively small search-space that it does.

such as crossover and mutation. Many real life problems are not like this. This non-linearity results in a huge increase in the search space. This allows them to discover solutions that other algorithms may have over-looked. they produce random changes to their candidates and then use the objective function to determine whether those changes are positive or negative overall. Without crossover. Selection allows the pruning of the least promising searches. due to their strength in navigating large search spaces (Marczyk. crossover allows promising solutions to share their success and mutation allows random changes in the local search space of a given solution. it is hard to know whether we have reached the global optimum. due again to the parallelism of their approach. or merely very good local optima. selection and mutation a genetic algorithm is metaphorically similar to a large number of parallel depth first algorithms. However. A good example of this is the concept Page 25 of 225 .William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 problems. they tend towards non-linearity where altering one component's fitness positively may make other components less fit and cause a ripple effect across the whole system. A third advantage of genetic algorithms is that they do not tend to be easily trapped by local optima. One of the largest strengths of genetic algorithms can at first glance appear to be their largest weakness. making genetic algorithms an effective way to search them. each component’s fitness is individual and any improvement to individual component's fitness is necessarily an improvement to the whole. 2004). each searching their own space for the best solution. genetic algorithms tend to give good results compared to other search strategies. Genetic algorithms have no prior knowledge about the problem they are trying to solve. the random nature of the various starting points of the initial population and the other methods they employ. or never contained in their search space in the first place. In a linear problem. In infinite or very large search spaces.

William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 of negative feedback. therefore no gradual increase can lead you to it. the global optima is at the far right. where the actual code of the program forms the genomes in the genetic algorithm and it can swap portions in or out.7. Likewise. 2004). rediscovered by genetic algorithms.2. Another method is to use genetic programming. integer. if the solutions to various problems are in areas of the search space that the fitness function would not consider likely. population size. a comparatively smaller segment of the search space will be covered and the eventual solution may take longer to reach or never be reached as a result. Generally. etc. 2. 2004). in a form that the genetic algorithm can use. If you have a poorly written fitness function. the investigation may cover too little of the search space to find the optimum solution (Marczyk. A second disadvantage of genetic algorithms is that the fitness function is crucial to the development of a suitable solution for the problem. A third issue is setting the correct mutation rate. or adjust them. 2004). but denied a patent for several years because it ran counter to established beliefs (Marczyk. A further problem is that fitness functions can be deceptive.Disadvantages One of the disadvantages of a genetic algorithm is the necessity of representing the problem the genetic algorithm is trying to solve. Page 26 of 225 .2 . there is no slope leading to it. For example in the diagram below. genetic algorithms use strings of binary. the system will never converge towards a suitable solution. with each number representing some distinct part of the solution (Marczyk. if the size of the population is too low. however if it is too low. If the mutation is too high. the genetic algorithm may end up solving an entirely different problem from the originally intended one. however that is only one point. or real-valued numbers. then genetic algorithms (and most other search techniques) are no better than a random search for finding the solution.

including sigma scaling and Boltzmann selection (Mitchell. 2004). There are various methods for solving this. Page 27 of 225 . Finally. 900 800 700 600 500 400 300 200 100 0 0 2 4 6 8 10 12 Figure 4 . but altogether easier to find. In this example a properly constructed genetic algorithm would be likely to settle on the marginally less optimal.local optimum (units are undefined in this case). 1996).William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 you either have the solution or you don’t. where analytical solutions exist they should be take precedence over genetic algorithms. A further problem is premature convergence: this occurs when a mutation early in the process produces a large leap in the fitness of that particular genome. lowering the diversity of the population and resulting in genetic algorithms possibly falling into the local optima that the mutation represents. unless by random chance it discovered the point with the most optimum solution. local optima in the centre of the diagram. which will then reproduce abundantly. This is because analytical solutions usually produce more accurate results faster than a genetic algorithm (or any heuristic method) is capable of (Marczyk.

2.Training Neural Networks with Genetic Algorithms Training neural networks is a form of problem solving. to test the appropriateness of a given genome. In addition. There are methods to try to avoid this problem when using back propagation. these are not a complete solution (Blum. the only information genetic algorithms require to train a neural network is an objective function (as described in 2.8 . not altering them besides that in any way. however.7 -Genetic Algorithms) are good at avoiding being stuck on local optima due to their searching several regions of search space simultaneously. however the method of choice for training neural networks is usually back propagation (see 2.Determining Weight Values with Genetic Algorithms Genetic algorithms (as described in 2.8.Representation of a Neural Network within a Genetic Algrithm As a rule.1 . a neural network representation within a genetic algorithm is a concatenation of all the weighs in the neural network. Page 28 of 225 . 1995). 1992).8.5 -Back-propagation) which is a gradient descent algorithm and as such can be easily trapped in local optima (Branke. since you are merely increasing the size of the genomes being worked with.7 -Genetic Algorithms).William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 2. involving finding the optimum values for a set of real numbers (connection weights) which will produce the least error in the results from the neural network. to try to help it move beyond local optima. 2. The error surfaces associated with these problems tend to be highly variable and contain many local optima. Genetic algorithms also have the benefit that they do not place any restrictions whatsoever on the architecture of the neural network. such as adding a “momentum” to the algorithm.2 .

Because of this it is helpful to keep functional units close together (I. These are all connected. Standard genetic algorithms use binary strings. it is also possible to use a genetic algorithm to evolve a structure for a neural network.3 . can lead to very large strings (thousands of bits) (Branke. outputs to inputs. one or two hidden layers of an indeterminate number of nodes and one output layer.Using Genetic Algorithms to Determine Neural Network Structure As well as using a genetic algorithm to evolve the weight set for a fixed-structure neural network. One of the most important decisions when deciding how to represent a neural network within a genome is whether to use binary strings or real number strings. side by side).William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Crossover can disrupt genes far apart. 1995). to form a feed forward network. however representing a large number of real valued numbers as a binary string. Page 29 of 225 .8. The problem at hand dictates the input and output layer structures. place a neurons input and output weights. a nodes input weights and the nodes of a layer. 2. but is less likely to do so for genes close together.e. The average neural network has an input layer.

a neural networks generalisation is its main strength and therefore you do not wish to lose it. There is also no method to check how optimal your solution is (Branke.0. a neural network topology to deal with that problem. given a specific problem. On the other hand.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Figure 5 . As mentioned in section 1. this is not necessarily the most efficient form for a network for any given problem and the trial and error method is an inefficient method for determining the correct architecture for an optimally performing neural network for the problem at hand. 1995).A feed-forward neural network This architecture is then altered (number of nodes in each hidden layer. the neural network will learn fast but will generate too specific a solution and will not generalize between similar inputs. However. the neural network will never learn to solve the problem (or come close enough to suggest a solution). Although network architecture plays such a large role in network performance. if the neural network architecture is too complex. If neural network architecture is too simplistic for the problem at hand. number of hidden layers) by trial and error and intuition to establish a neural network that performs well for the problem at hand. there is currently no method by which to establish. Page 30 of 225 .

In cases where a genetic algorithm determines the number of hidden layers and the number of nodes per hidden layer and the network itself is interconnected fully. indirect. the network is divided into areas and for each area the number of nodes and the density of connections to other nodes is determined (Branke. being able to contain the most optimum solution for the problem at hand. whereas high-level encodings group together connections and/or nodes.8.Representing neural network structure Representing the structure of a neural network within a genetic algorithm is not as straightforward as representing the weight values of a neural network within a genetic algorithm. you must remove all connections to or from that node completely. an exception is possible. Ideally.3. the strong. Page 31 of 225 . There are two methods for representing neural network topologies within a genetic algorithm.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 2. 1995). thus meaning that in order to remove a node completely. In one version of high level encoding of a neural network. direct. or high-level encoding (Branke. a representation is required which can accommodate all networks that will work for the problem but none that will not. Low-level encodings specify each connection individually. thus eliminating the searching of meaningless space and by definition.1 . Back propagation learning rate is also a parameter for one of these areas. the genetic algorithm represents the neural network by means of its connections. In direct encoding. or low-level encoding and the weak. 1995).

These are the Step-size problem. Page 32 of 225 . As mentioned in section 5. Therefore. will not ever succeed in learning the problem. The algorithm attempts to solve the issues associated with back-propagation that produce slow learning. The Cascade-Correlation Learning Architecture.Cascade Correlation The cascade learning architecture is a method by which the training algorithm builds the neural network as it proceeds. Neural networks that are too small on the other hand. by limiting the potential size of the networks evolved and preventing the generation of overly large and complex networks but on the other hand.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 One of the reasons why alternatives to low-level encoding arose is the exponential rise in the number of connections. 1991). as the size of the neural network increases. it is impossible to know whether these large and complex networks may be the most suitable way to solve the problem at hand. which is obviously undesirable. and the moving target problem (Fahlman & Lebiere. 2. These mapping methods are therefore more suitable for small networks or networks with a small number of connections. 1995). This can lead to human bias entering the system and affecting the outcome. a balance between speed of learning and generalisation exhibited in the trained network is necessary.9 . This could be useful. This section largely drawn from information in: “Curved trajectory prediction using a self-organizing neural network” (Branke. A problem with high level encoding is that regular networks are favoured but not every network is equally probable.2 neural networks that are too large will solve a problem fast but will not generalize well and therefore their usefulness is limited severely.

The “candidate” nodes take the neural net inputs. An Empirical Study of Learning Speed in Back-Propagation Networks.The definition of 's' given that 'o' is the network output at which the error is measured. The output units may use either a linear or differentiable activation function.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 The system begins with a basic neural network of inputs and outputs (numbers of each dictated by the task as usual) and no hidden layer. the residual output error at “o” (Fahlman & Lebiere. and attempt to maximise “s” the sum overall output units “o” of the magnitude of the correlation between “v”. plus the outputs of any previously created units. and “Eo”. = −` −` . The Cascade-Correlation Learning Architecture. or sometimes the quick prop rule (Fahlman. The Cascade-Correlation Learning Architecture. either an extra node is added. Equation 8 . 1991). the quantities ‘`v ’ and ‘`Eo’ are the values of v and Eo averaged over all patterns (Fahlman & Lebiere. 'v' is the candidate unit's value. the initiation of a number of “candidate” units takes place and trained using either the perceptron rule (2. There is also a bias input. After a number of training cycles pass with no substantial improvement (the precise number being determined by a user-supplied “patience” parameter). or if the networks output is of sufficient quality the training is ended.5. with the aim of getting as close to a solution as possible.2 -Back-propagation in depth). In order to maximise "s".2 -Back-propagation in depth) or the quick prop rule (Fahlman.5. The connection between each input and output is via an adjustable weight. the candidate unit’s value. 1988). It then trains the adjustable weights using the perceptron rule (as described in 2. Page 33 of 225 . 'p' is the training pattern. the partial derivative of "s" with respect to each of the candidate unit’s incoming weights "wi" is a necessity. If a trigger occurs for the addition of a unit. with a value of one. 1988). An Empirical Study of Learning Speed in BackPropagation Networks. 1991).

where ‘oo’ is the sign of the correlation between the candidates value output ‘o’. Expansion and differentiation of this calculation can then take place. Page 34 of 225 . or the completed training epochs reaches a maximum level. After these computations are complete. Equation 10 . The connection of the best of the candidates to the neural network as it stands takes place. Once the correlation on a candidate has reached an acceptable level.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Equation 9 . . ‘f'p’ is the derivative for pattern 'p' of the candidate unit's activation function with respect to the sum of it’s inputs and ‘Ii.The partial derivative of ‘s’ with respect to each of the candidates incoming weights ‘wi’.p’ is the input the candidate receives from unit ‘i’ for pattern ‘p’. Adjustable weights link the outputs for this node and all the output nodes inputs. a gradient descent to maximize "s" can take place. The training iterations for these adjustable weights in the main network then continue. = .The partial derivative of ’s’ (Fahlman & Lebiere. and the inputs for that node are frozen. −` ′ . 1991). The Cascade-Correlation Learning Architecture.

The second state of a cascade correlation neural network.The initial state of a cascade correlation neural network. 1991) Cascade-Correlation 1991). Page 35 of 225 . Figure 7 . 1991) Cascade-Correlation 1991). A first node has been added.William Sayers 05025397 Genetic Algorithms and Neural Networks Neural Milestone 3 Figure 6 . The Cascade Correlation Learning Architecture. The Cascade Correlation Learning Architecture. The square econd connections are locked weights (Fahlman & Lebiere. The circular connections are adjustable weights (Fahlman & Lebiere.

The Cascade-Correlation Learning Architecture. 1991).The third state of a cascade correlation neural network. with two nodes added (Fahlman & Lebiere.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Figure 8 . Page 36 of 225 .

William Sayers

05025397

Genetic Algorithms and Neural Networks
Milestone 3

2.10 - C# User Interface Programming
C# uses the Winforms API to create user interfaces. It allows you to “draw” objects on a form in a visual manner to design your layout and then access and alter properties and subproperties of those objects in your programming code. A separate thread for each Window in Winforms exists, in order to facilitate performance on modern multi-core machines, although it does make it more difficult to move data between the forms. A method using “delegate functions” (similar to “function pointers” in C++) and “events” (Lysle, 2007) is the method I will use. Another challenge is making the neural network training independent of the user interface, in order to avoid the interface freezing whilst training a neural network. The solution I plan for this is to use the background worker object provided with C#, which allows you to assign a delegate function to be your background task, and will trigger events upon completion, for which event handlers will be executed (Microsoft, BackgroundWorker Class, 2009). Making a C# user interface interact with C++/CLI dll’s simply involves adding a reference to the dll in your project, via the Visual Studio® user interface.

2.11 - Writing C++/CLI Wrappers for Unmanaged C++ code
The cleanest method of connecting a native C++ or C dll or piece of code to a managed C# interface is via a C++/CLI bridge class. The VC++ compiled can swap between managed and unmanaged code on the fly whilst compiling and allows you to have both managed and unmanaged code (in C++) as part of the same project. Thus, a managed class can communicate with the unmanaged class (performing appropriate marshalling of the non-primitive data types (Microsoft, Using C++ Interop (Implicit PInvoke), 2009)) and the C# code can then access it directly.

Page 37 of 225

William Sayers

05025397

Genetic Algorithms and Neural Networks
Milestone 3 Although it is possible for a C# program to interact with an un-managed dll directly, this method is less error-prone and more likely to be robust and stable, as well as making for cleaner code.

2.12 - Application of Research
The research presented here will help to produce the deliverables for milestone two and milestone three of my final year project: I plan to combine C# for the user interface and C++ for the neural network back-ends in order to create an efficient, powerful and fast solution. Section 2.11 -Writing C++/CLI Wrappers for Unmanaged C++ code, covers the combination of C# and C++ so I will not bother to cover it here, I plan to use the DLL method, with one DLL combining managed and unmanaged C++ linked into my C #user interface code. The user interface will then have methods to adjust parameters such as the genetic algorithms population size, number of generations, etc. In order to test and see what kind of genetic algorithm learns and develops fastest. It will also allow you to specify the number of back-propagation iterations. The use of this application will be in evaluating the difference in performance between a genetic algorithm, back-propagation algorithm and cascade correlation algorithm as neural network training algorithms.

3 - Design
The purpose of this application will be to allow the user to run a back-propagation trained neural network, or a genetic algorithm trained neural network and present the results of the network in such a fashion as to allow analysis and comparison of the training methods and their suitability in different situations.

Page 38 of 225

William Sayers

05025397

Genetic Algorithms and Neural Networks
Milestone 3

3.1 - Program Requirements
The program must be able to: • • • • • • Run a genetic algorithm on a feed forward fully interconnected neural network to train the network. Run a back propagation algorithm on a similar network to train the network. Run a cascade algorithm on a similar network to train the network. Allow the user to set appropriate variables (see 3.4.2 -New Network Wizard) to adjust the execution of the learning algorithm selected for the neural network. Allow the user to select which learning algorithm they wish to use. Display the results of running that algorithm on a neural network in a meaningful fashion.

3.2 - Design of the Class Structure
Before I discovered a simple to program and effective design, I tried and discarded two designs. I eventually used the third design and it is that third design documented here. The two prior designs to this involved representing neural networks via objects and compositions of objects in vectors, which lead to flexible, but slow and overly complex code upon experimentation. The final solution, the solution documented here, is a far simpler one (in terms of the neural network representation, it is far more detailed in the other areas than the initial designs were). This solution loosely follows a model, view, controller architecture. The solution enables easy replacement of sections of code as long as the interfaces and outputs remain the same. For more information on the class structure, see section 9.2 -UML Class Diagram.

Page 39 of 225

William Sayers

05025397

Genetic Algorithms and Neural Networks
Milestone 3

3.3 - Linking C# code to managed dll’s
Linking C# code and managed dll’s is a simple process (in Visual Studio) as explained in (2.11 -Writing C++/CLI Wrappers for Unmanaged C++ code) of selecting the references section in the C# project in question and adding the dll you wish to refer too. Then you can simply add a “using” directive to use the dll namespace and create, destroy, and use the classes within as if they were native C# classes. This can be seen in (9.1.2.6 “Algorithms\BackProp.cs”) and (9.1.2.4 -“Algorithms\CascadeCorrelation.cs”) with the “using FANN_Wrapper;” directive. This is superior to the direct C# to unmanaged code linking that used in milestone two, since it makes for cleaner and thus more easily maintainable code and the code is more robust in this fashion. The robustness comes from the fact that C++/CLI is far better at interacting with unmanaged C++ code than C# is. Indeed – they can even be in the same source file and compiled into one object. Therefore, by using a C++/CLI wrapper to interface to the unmanaged C++ and then interacting with the C++/CLI wrapper/s errors are less likely to arise.

3.4 - Design of the User Interface
The construction of the user interface utilised the Winforms based tools in visual studio 2008 (see 2.10 -C# User Interface Programming). I also used the ZedGraph control (ZedGraph) to display the graph of my results.

3.4.1 - Main Form
The main form is the crux of the application (as is default in C# Winforms programming) and if the main form is closed, all other forms and classes are disposed and the application terminates.

Page 40 of 225

1 .1. Figure 9 – Network and output tab design (Main form) 3. Three buttons will therefore be present.4. Page 41 of 225 . along with two displays.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 3.1.Network and Output tab This tab needs a method by which to initialise the adding of a new network (3.2 . which simply needs to display the graph of the mean squared error over the current epoch/generation.2 -New Network Wizard) a method to train the current network and a method to test that training. One display will show network details and one display will show the training and testing output.Mean Squared Error Graph tab The mean squared error graph tab is a simple tab.4.4.

to show the training data and to show the testing data.Dataset tab design (Main form) Page 42 of 225 .William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Figure 10 .3 . Figure 11 .4.Dataset tab This tab needs two display sections.Mean squared error tab design (Main form) 3.1.

New Network Wizard The new network wizard is the form that appears when the user selects the creation of a new network. 2. out of three choices previously mentioned (2.4.4.2.2 .5 -Back-propagation.2 .1 -Learning Algorithm tab (if no algorithm has yet been selected. Page 43 of 225 .7 Genetic Algorithms.4. The user can progress through the steps via the “previous” and “next” buttons or via the tabs at the top in whatever order you choose. 2. It allows you to move in a logical progression through the set up process of a new neural network and associated training algorithm.9 -Cascade Correlation).2.Design of the training algorithm tab (Wizard form) 3.4.Network Settings tab This tab allows you to set appropriate settings for the network and training algorithm you have selected in 3.1 . the default is genetic algorithm). Figure 12 .Learning Algorithm tab On the learning algorithm tab you select the learning algorithm for the neural network you are creating. 3.2.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 3. Verification of all data takes place before the form passes control back to the main form and triggers a main form event with a parameter that takes a specially constructed class to transfer the data from the wizard.

Page 44 of 225 .Working Form The working form is merely a small display shown as a dialog (lock out access to displaying form) which shows whilst a neural network is training.Dataset tab The dataset tab allows you either to select from two pre-setup datasets.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Figure 13 .Dataset selection tab design (Wizard form) 3. or to choose custom data sets from your hard disk for training and testing data (appropriately formatted in the FANN style).2.3 .4.Design of the network settings tab (Wizard form) 3. Figure 14 .3 .4. both to protect the main form from data inputs that may cause training problems and to provide a visual indicator of work taking place.

William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Figure 15 .4. project description). displays licensing information and displays information on the pre selected datasets.1 . Page 45 of 225 . project supervisor. Clicking the datasets button or the licenses button displays the appropriate information.About form design (About form) 3.Datasets display Clicking the data sets button displays a tabbed interface. one tab with XOR information and one tab with Fishers Iris Data information. clicking the same button again hides that information. Figure 16 .About Form The about form displays information about the application (author.4.4 .4.Working form design (Working form) 3.

Figure 18 .William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Figure 17 .Licenses display design (About form) 4 . depending on your selection. Page 46 of 225 .4. it will display the appropriate license.Implementation The implementation is largely in C#.2 .Licenses display Clicking the licenses button displays a small information panel with selection methods. with small portions in C++/CLI and the back-end FANN (Nissen.Dataset display design (About form) 3.4. FANN) library written in C and linked as a static library to the managed FANN_Wrapper dynamic link library.

User Interface Implementation The implementation of the user interface is mainly in C#. mostly via the visual design tools found in visual studio 2008.1.1 .1 . 4.Network and Output tab Figure 19 . 4.1.Main Form The main forms code is in section 9.1.cs”.1.1 .William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 4.Network and Output tab Page 47 of 225 .2 -“FrmMain.1.

1.Mean Squared Error Graph tab Figure 20 .1.Mean squared error graph tab Page 48 of 225 .2 .William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 4.

1.The dataset tab Page 49 of 225 .3 .Dataset tab Figure 21 .1.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 4.

William Sayers

05025397

Genetic Algorithms and Neural Networks
Milestone 3

4.1.2 - New Neural Network Wizard
4.1.2.1 - Learning Algorithm tab

Figure 22 - Learning Algorithm tab

Page 50 of 225

William Sayers

05025397

Genetic Algorithms and Neural Networks
Milestone 3

4.1.2.2 - Network Settings tab

Figure 23 - Network Settings tab

4.1.2.3 - Dataset tab

Figure 24 - Dataset tab

Page 51 of 225

William Sayers

05025397

Genetic Algorithms and Neural Networks
Milestone 3

4.1.3 - About Form

Figure 25 - About form, main view

Page 52 of 225

William Sayers

05025397

Genetic Algorithms and Neural Networks
Milestone 3

4.1.3.1 - Datasets View

Figure 26 - About form, Datasets view

Page 53 of 225

Licenses View Figure 27 .4 .2 .5 .Working form 4.Working Form Figure 28 .1.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 4.Passing Information between Forms Passing the data between the wizard form and the main form takes place as previously described (2.3.1.10 -C# User Interface Programming) via events and delegate functions. Licenses view 4.About form. Page 54 of 225 .1.

6 . 4. This leads to a user interface that is much more accessible (Microsoft.1.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 An event is a method of notifying a listening object that something has occurred.3 -“Wiz1.1. lines 266-281).1. lines 306-353.1. lines 29-44).1. lines 29 – 31). The declaration and association of a delegate and an event takes place in the form that needs to generate an event (9.1. Events. The declaration of a new event handler in the main form takes place prior to displaying the new neural network wizard form (see 9. The “NetworkUpdatedEventArgs” class is a storage class for passing data (see 9.2 -“FrmMain. 2009). The trigger of a new event takes place in the Wizard form when you are on the last tab and the user clicks “next” (see 9. the processing of the class sent from the Wizard form takes place (see 9.2 -“FrmMain.cs” lines 120-129). (See 9. BackgroundWorker Class.1.cs” lines 145-163).3 -“Wiz1.1 -“NetworkUpdatedEventHandler”). are associated with a delegate function to respond to that event (Lysle.1.1.1. 2007).1.1.2 -“FrmMain.Keeping the User Interface Active whilst Processing is Occurring The user interface delegates the processing to a background worker class. In the event handler in the main form.cs”.cs”. when instantiated.1. The two-event handling functions are at 9. the background worker class is instantiated and supplied with the event handler references functions (see 9.cs”.2 -“FrmMain. Page 55 of 225 .1.1.2 “FrmMain.1.cs” lines 70-119).1. Then the runworkerasync function executes and then shows the working form. Firstly.cs”.

1.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 4.1.cs” for the C# implementation) The main points to note in the code as it stands are: • The crossover (single-point) and mutation (random increment or decrement) implementations (see 9. when the C++ implementation of genetic algorithms that I wrote functioned.1 .1. • • The sorting implementation in GANetwork.NET sort methods in the sorting part of the genetic algorithm). FANN) which is a C programming language based neural network library. and the Dll linked to this to allow access to the functionality.1. There is an unmanaged C++ wrapper (9.5 “Algorithms\GeneticAlgorithm.2 -“GANetwork. The compilation of the FANN library is static.2. it was both faster than the C++ implementation (due mostly to my use of build in .cs” lines 51-126) 4. and didn’t suffer from the memory leaks (being managed code) so that’s the version that exists in the application today (see 9.3.3.NET built in functionality (see 9.2 -“GANetwork. Once this implementation was complete.4. Therefore. after having used C# extensively in the UI I felt more confident about the performance loss and the use of the programming language itself.Genetic Algorithm Implementation Although the original design was to implement genetic algorithms in C++.2 .cs that links into the .1.3 Page 56 of 225 .cs” lines 176204).2. but had issues with memory leaks and was slow.Back-propagation and Cascade Correlation Implementation The FANN library implements both cascade correlation and back propagation (Nissen.5 -“Algorithms\GeneticAlgorithm.2. I decided to try re-implementing it in C#.cs” lines 32-44). The neural network specific functionality added to the network model in the network specialisation class GANetwork (see 9.

2 -“DatasetParser.h”.1. Page 57 of 225 . the weights.3.1. In the constructor (lines 41 – 77).cpp”) for the unmanaged C++ classes.1. which using the data from the heading (number of epochs of data. The inputs and weights are structures so that the coordinates for an input. into arrays of strings.1. 9.cpp”) for the Cbased FANN functions in the DLL and a C++/CLI wrapper (9. the separation of the textual inputs takes place. will also be the coordinates for its corresponding weight (lines 17-19).h”. and nodes) the eventual implementation turned out to be basic yet effective (9.1. and the outputs. number of outputs) separates the data into two-dimensional arrays suitable to be passed to other functions. 9.2. In the initialisation routines (lines 28-124). number of inputs.1 -“FANN_Wrapper.4.1. these arrays form parameters for the other functions.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 “UnManaged_FANN_BackProp.h”. Three jagged arrays are utilised.4. the inputs.2 -“FANN_Wrapper.cs”) parses data directly from the rich text boxes that they’re displayed upon on the main form.5 -“UnManaged_FANN_CasC. via references to these objects passed down via the hierarchy (references are passed to avoid the necessity of passing entire strings down the hierarchy).Neural Network Implementation Although two previous attempts made at programming a neural network. 4.4 “UnManaged_FANN_BackProp.4.cpp”. C# accesses the C++/CLI class directly. 9. 9. which allows it to manipulate the FANN functions in the static library through this class. the initialisation of all the arrays to their correct sizes takes place and then the initialisation of the weights to a random double between zero and one.1.6 -“UnManaged_FANN_CasC.4. layers. From there. followed an object-based structure (network. 4.4 .Data Parser Implementation The data parser (9.4.1 -“Network.3 . which store respectively. via a number of designated separator characters.cs”).

Page 58 of 225 .Testing Data Testing took place several times for each algorithm and dataset (see 9.01 for XOR and 0. five times for Virus classification and Fishers iris data). All nodes determine their outputs using the sigmoid function (lines 130-133). input layer.4 -Datasets) (ten times for XOR. recording took place for analysis. The target error was 0. so repetition is instead used. 5.1 .XOR In the XOR dataset. and hidden layer which are all called by the public “run()” function (lines 241-270). and creating a neural network with a similar structure on an excel spreadsheet. Then entered the weights from the neural network program (by means of using the visual studio debugger to check variable values) into the spreadsheet and checked that the outputs coincided. 3. to run the output layer. there are three functions.02 for Fishers iris data and the virus classification data. the dataset is too small to split. The genetic algorithm and back-propagation neural networks each had four hidden nodes for each dataset. 1.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 The main functionality of the neural network class can be found in the “internal” region (lines 126-235). 5 . I tested the neural network implementation by creating a neural network with structure 2. As the program presented the data in each case.

Genetic Algorithm testing data (XOR) 5.00998032 0.009888967 0.009962559 0.009829335 0.00991907 0.00987211 0.00881867 0.1.009162436 0.1 .009157809 Table 2 .00990403 0.009162436 0.006150786 0.00881867 0.5 Result MSqE (GA) 0.0098402 0.0099765 0.00999069 0.009962559 0.009566951 0.00957518 0. because of floating point inaccuracies converting between double precision floating-point numbers in my code and single precision in the FANN code.00992081 0.009248076 0.Back-propagation In the back-propagation testing data.00998959 0. Iterations (BP) 345 287 319 327 301 323 421 315 362 325 332.009885499 Table 3 .2 .009375132 0.Genetic Algorithms Iterations (GA) 591 407 500 466 499 534 675 557 357 939 552.006150786 0.5 Result MSqE (BP) 0.00989974 0.00988863 0.00998027 0.009969323 Testing MSqE (BP) 0.00992291 0.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 5.0099113 0.00990161 0.009375132 0.009888967 0.00997699 0.00999799 0.009157809 Testing MSqE (GA) 0.00983181 0.00957518 0. the mean squared error from the network result and the testing mean squared error are different despite the data being the same.00995716 0.1.009829335 0.00988649 0.009566951 0.009248076 0.Back-propagation testing data (XOR) Page 59 of 225 .

the call back function triggers.14E-14 2. which is when the program records the mean squared error.00798691 0.99E-13 1.00960884 0.00889787 0.78E-14 1.43545E-13 Table 4 .00656719 0.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 5.00863005 0.02E-13 2.1.86E-14 1.Cascade Correlation In the cascade correlation data.Cascade Correlation testing data (XOR) Page 60 of 225 .18E-13 7. the network is trained more after that point (output weight training).02E-13 1.83E-13 2.00855044 0.008039565 Testing MSqE (CC) 7. At each node addition.00573252 0. the testing result differs quite widely from the network result.00585159 0.3 .00992534 0. but in the case of cascade training.22E-13 1.0086449 0. Nodes (CC) 2 2 2 2 2 2 2 2 2 2 2 Result MSqE (CC) 0.32E-13 2.

Graphs 1000 900 800 700 600 500 400 300 200 100 0 0 5 10 15 Iterations (GA) Iterations (BP) Nodes (CC) Figure 29 .012 0.Number of iterations to achieve target (XOR) 0.4 .008 0.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 5.Mean squared error upon last training test (XOR) Page 61 of 225 .01 0.1.006 0.004 0.002 0 0 5 10 15 Result MSqE (GA) Result MSqE (BP) Result MSqE (CC) Figure 30 .

004 0.002 0 0 5 10 15 Testing MSqE (GA) Testing MSqE (BP) Testing MSqE (CC) Figure 31 .006 0.The mean squared error at testing (XOR) Page 62 of 225 .01 0.012 0.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 0.008 0.

0189456 0.0143778 0.014116 0.019763877 0.014144 0.019719802 0.0195853 0.0158679 0.Back-propagation testing data (Iris data) 5.019763877 0.0199892 0.019719802 0.01956255614 Table 5 .3 .01956255614 Testing mean squared error (GA) 0.Fishers Iris data 5.0196297 0.0139982 0.01998996 Testing mean squared error (BP) 0.019751257 0.018789438 0.0141935 Table 6 .0199916 0.Cascade correlation testing data (Iris data) Page 63 of 225 .2.0199719 0.0193595 0.018789438 0.0141406 0.0199918 0.0160925 Table 7 .0199972 0.2.019775896 0.1 .William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 5.0140669 0.2.2 .0164964 0.Genetic Algorithms Iterations (GA) 1928 1834 1277 2835 8716 3318 Mean squared error (GA) 0.Cascade Correlation Nodes (CC) 2 2 2 2 2 2 Mean squared error (CC) 0.0198416 0.2 .0199999 0.0143806 0.Genetic algorithm testing data (Iris data) 5.Back-propagation Iterations (BP) 434 529 474 391 527 471 Mean squared error (BP) 0.019775896 0.01950238 Testing mean squared error (CC) 0.019751257 0.

0194 0.Mean squared error upon last training test (Iris data) Page 64 of 225 .0186 0 2 4 6 Mean squared error (GA) Mean squared error (BP) Mean squared error (CC) Figure 33.019 0.2.Number of iterations to achieve target (Iris data) 0.0196 0.0188 0.4 .Graphs 10000 9000 8000 7000 6000 5000 4000 3000 2000 1000 0 0 2 4 6 Iterations (GA) Iterations (BP) Nodes (CC) Figure 32 .02 0.0192 0.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 5.0198 0.0202 0.

The mean squared error at testing (Iris data) 5. and others. cucumber.3 .025 0.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 0. which are the number of amino acid residues per molecule of coat protein.015 0.005 0 0 2 4 6 Figure 34. There are 18 measurements on each virus.02 Testing mean squared error (GA) Testing mean squared error (BP) Testing mean squared error (CC) 0. The dataset is in order: • • • • Hordeviruses x3 Tobraviruses x6 Tobamoviruses x39 Furoviruses x13 Page 65 of 225 .01 0. tomato.Virus Classification This dataset covers 61 viruses affecting several crops including tobacco.

017723052 0.019927361 0.Genetic Algorithms testing data (Viruses) 5.0190612094 Table 8 .0185152 0.01983722 Mean Squared Error testing (BP) 0.Cascade Correlation testing data (Viruses) Page 66 of 225 .0190612094 Mean Squared Error testing (GA) 0.011585152 Table 10 .0199916 0.Genetic Algorithms Iterations (GA) 1818 1421 896 11676 1068 3375.8 Mean Squared Error training (GA) 0.0194383 0.00980208 0.3.03833646 Table 9 .0347797 0.019743 0.019092293 0.3 .Back-propagation Iterations (BP) 3275 10922 2800 3744 6295 5407.Cascade Correlation Nodes (CC) 1 2 1 2 1 1.019927361 0.0105845 0.0199621 0.0196959 0.01870197 0.019861371 0.2 Mean Squared Error training (BP) 0.1 .017723052 0.Back-propagation testing data (Viruses) 5.0350318 0.019861371 0.017043 0.2 .4 Mean Squared Error training (CC) 0.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 5.00979968 0.0391179 0.019092293 0.0165979 0.0111416 0.0197935 0.016183342 Mean Squared Error testing (CC) 0.0434423 0.00640291 0.0195173 0.3.0393106 0.3.01870197 0.

Graphs 14000 12000 10000 8000 6000 4000 2000 0 0 2 4 6 Iterations (GA) Iterations (BP) Nodes (CC) Figure 35 .015 0.Number of iterations to achieve target (Viruses) 0.01 0.025 0.Mean squared error upon last training test (Viruses) Page 67 of 225 .02 Mean Squared Error training (GA) Mean Squared Error training (BP) Mean Squared Error training (CC) 0.3.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 5.005 0 0 2 4 6 Figure 36 .4 .

025 0.005 0 0 2 4 6 Mean Squared Error testing (GA) Mean Squared Error testing (BP) Mean Squared Error testing (CC) Figure 37 .035 0.045 0.XOR As regards to the XOR problem.01 0. or possible inefficiencies in my programming. Genetic algorithm solutions are slightly more accurate.Back-propagation and Genetic Algorithms 6.04 0.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 0.1.1 .Comparisons 6.03 0. but to a negligible degree in this scenario.1 .015 0. Genetic algorithms take around five hundred iterations on average to produce a workable solution when aiming for a mean squared error of below 0. genetic algorithms and back-propagation offer similar performance in solving the problem.02 0. versus backpropagations 333 iterations on average.05 0. The back-propagation implementation seems to be slightly faster in real-time but this is possibly attributable to managed code inefficiencies versus unmanaged code.Mean squared error at testing (Viruses) 6 . Page 68 of 225 .01.

whereas the back-propagation solutions lost effectiveness on the training data. FANN)) this is around 300 epochs to solve the problem.2 epochs for backpropagation. with an average of 3375. The back-propagation generated networks were also more accurate overall (in fact on this particular problem analysed the testing data more effectively than the training data). The genetic algorithm solutions also held their effectiveness through to the testing data with extreme consistency.2.1.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 6. genetic algorithms taking 550 generations on average to solve the problem to a suitable accuracy.2 . 6.1.Virus Classification The solution of this problem was more effective by genetic algorithms than by backpropagation.Cascade Correlation and Genetic Algorithms 6. At a maximum of 150 epochs per node added (the default (Nissen.XOR This problem was solved more effectively by the Cascade algorithm than by genetic algorithms. 6.2.1 .2 .2 .8 generations versus 5407. whilst the cascade algorithm used 2 nodes to solve the problems. The cascade algorithm also achieves a higher degree of accuracy. With an average of 3318 generations for genetic algorithms versus 471 epochs for back-propagation this became clear. Page 69 of 225 .3 .Fishers Iris Data Again.Fishers Iris Data Genetic algorithms clearly found this a difficult problem to solve as opposed to backpropagation. 6. on this data set cascade training came to a satisfactory solution faster and more accurately than genetic algorithms.

the unavoidable conclusion is that cascade training is the most effective of the three training methods examined. with the information presented and discussed here.3 .Evaluation Overall. although there are further investigations I would like to continue with given more time (and may continue with in my own time). genetic algorithms fall down as a solution.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 6. I feel the project has been a success.2.Virus Classification With this data set cascade training again came to a satisfactory solution faster and more accurately than genetic algorithms did on the same data. more in-depth testing using more varied datasets a clearer comparison and possibly drawbacks associated with cascade training may become evident. 7 . 6.Testing conclusions Genetic algorithms are a valuable and effective means of training neural networks.3 . Page 70 of 225 . With more time. however. They are roughly as effective as back-propagation training and although back-propagation is faster for the most part. Compared to cascade correlation however. solutions developed using genetic algorithms tend to hold their effectiveness through to the data set effectively.

Build an application that is capable of training a neural network with a genetic algorithm and with a backpropagation system. Research current information on training neural networks using genetic algorithms. Identify the most effective ways of training neural networks using genetic algorithms. Build a user-interface for the aforementioned application allowing for easy alteration of appropriate variables.How many of the original objectives were achieved? The original objectives were as follows (9. and that allows manual adjustment of relevant variables. as well as previous research.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 7. and in which cases these methods are suitable. Using above application. leading to a more solid conclusion and more information on the various strengths and weaknesses of the various learning algorithms examined. Page 71 of 225 .1 .” With more time more advanced tests could be undertaken using larger data sets. “Identify the most effective ways of training neural networks using genetic algorithms.5 -Objectives): Research the fields of genetic algorithms and neural networks. and in which cases these methods are suitable. The only objective that I feel could be improved upon is the final objective. evaluate training methods for neural networks.

Due to small conflicts between managed and unmanaged memory. Page 72 of 225 . Improve memory management.Possible Improvements More advanced testing would be the biggest improvement that more time would make possible. Testing both with and without scaling and utilising different scaling methods. Testing with datasets that would take large amounts of time to train. Some forms of testing that would be possible are: • • • • • Testing with datasets with larger numbers of inputs Testing with large datasets that attempt to train the network to distinguish between small differences in data.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 8 . the program occasionally causes an exception (most specifically when creating cascade or back-propagation networks in quick succession). These could be resolved fairly simply (I believe) by implementing the iDispose interface in my managed code to allow it to be destroyed upon demand instead of waiting for the garbage collector.

Making the forms shown as dialogs. but still minimize instead of blocking other computer programs. Page 73 of 225 .William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 8. (the new network wizard and the working form) lock out the rest of the program. • Implement the cascade training algorithm in C# instead of C++. I would experiment with the following training algorithm improvements: • Improve the genetic algorithms crossover and mutation algorithms. Contrary to my opinion before undertaking extensive usage of C# I now believe the reduced development time. Implement the back-propagation algorithm in C# instead of C++. experimenting with multiple point crossover and other crossover forms. for the reasons stated above. • • Attempt to improve the speed of the genetic algorithm. as well as implementing roulette wheel selection.1 . Having the back-propagation algorithm in C# similar to the genetic algorithm would also allow a more “apples to apples” comparison. is worth the possibility of reduced performance. 8.2 . allowing more to be undertaken successfully.Possible Training Algorithm Improvements With more time.Possible User Interface Improvements The main improvements to the user interface that I would make if I had more time are: • • Increased number of variable options presented to the user (with appropriate defaults set).

1 . Although there was another section of the program compiled from source (the FANN library).Source code The source code in this section is organised first by which part of the application it represents and then by what source file it originally resided in. The code contains line numbering for pinpointing the precise lines in question within the body-text when crossreferencing.Appendices 9. and neither is the code for the prototype constructed in milestone two. Page 74 of 225 . The earlier attempts at genetic algorithm and neural network implementations are not included.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 9 . I have not included it in the source code listing. This section also contains only the final draft of the code. so that this listing contains only code I have personally written for the project. which this code is partially based upon.

Page 75 of 225 .1 .Controller. namespace _05025397.1.EventArgs { #region data /********************\ |* DATA *| \********************/ //Training Algorithm Identifier private int trainingalg.Generic.Linq. System. //Dataset identifier private int _TrDataSet. private double _CC_LearningRate. private int _CC_MaxNeurons.View 9. private bool _CC_ITerr.1 .Collections.1. //Cascade Correlation private double _CC_Terr.1.Classes { public class NetworkUpdateEventArgs : System. System.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 9.“NetworkUpdatedEventHandler” 00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000009 00000010 00000011 00000012 00000013 00000014 00000015 00000016 00000017 00000018 00000019 00000020 00000021 00000022 00000023 00000024 00000025 00000026 using using using using System.Text. System. private int _CC_Reports.

private int _BP_Reports. int CCMaxNeurons. double CCTerr. private double _BP_LearningRate. double CCLearningRate. private int _GA_GenLimit. int CCReports. private double _GA_Terr. private double _BP_Terr. private int _GA_Reports. //BackProp private int _BP_EpochLimit. #endregion #region constructor /********************\ |* CONSTRUCTOR *| \********************/ //Constructor to accept all necessary data public NetworkUpdateEventArgs (int Algorithm. private bool _BP_ITerr. private int _GA_Mutation. private bool _GA_ITerr. private int _BP_HiddenL. int GAPopSize. private int _GA_Crossover. private int _GA_HiddenL. Page 76 of 225 . bool CCITerr.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000027 00000028 00000029 00000030 00000031 00000032 00000033 00000034 00000035 00000036 00000037 00000038 00000039 00000040 00000041 00000042 00000043 00000044 00000045 00000046 00000047 00000048 00000049 00000050 00000051 00000052 00000053 00000054 00000055 00000056 //Genetic Algorithm private int _GA_PopSize.

_CC_LearningRate = CCLearningRate.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000057 00000058 00000059 00000060 00000061 00000062 00000063 00000064 00000065 00000066 00000067 00000068 00000069 00000070 00000071 00000072 00000073 00000074 00000075 00000076 00000077 00000078 00000079 00000080 00000081 00000082 00000083 00000084 00000085 00000086 int GAGenLimit. _GA_Terr = GATerr. int TrData_Set) { //Algorithm trainingalg = Algorithm. _GA_GenLimit = GAGenLimit. int GAMutation. //Backpropagation Algorithm _BP_EpochLimit = BPEpochLimit. double BPTerr. _GA_Mutation = GAMutation. //Cascade Correlation _CC_Terr = CCTerr. int BPHiddenL. int GACrossOver. int GAHiddenL. bool GAITerr. double BPLearningRate. int BPReports. _CC_MaxNeurons = CCMaxNeurons. Page 77 of 225 . _GA_HiddenL = GAHiddenL. //Genetic Algorithm _GA_PopSize = GAPopSize. bool BPITerr. _GA_Reports = GAReports. int BPEpochLimit. _CC_ITerr = CCITerr. double GATerr. _CC_Reports = CCReports. int GAReports. _GA_ITerr = GAITerr. _GA_Crossover = GACrossOver.

William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000087 00000088 00000089 00000090 00000091 00000092 00000093 00000094 00000095 00000096 00000097 00000098 00000099 00000100 00000101 00000102 00000103 00000104 00000105 00000106 00000107 00000108 00000109 00000110 00000111 00000112 00000113 00000114 00000115 00000116 _BP_HiddenL = BPHiddenL. _BP_Reports = BPReports. } } public int CC_MaxNeurons { get { return _CC_MaxNeurons. } } public double CC_LearningRate { get { return _CC_LearningRate. _TrDataSet = TrData_Set. _BP_ITerr = BPITerr. _BP_Terr = BPTerr. _BP_LearningRate = BPLearningRate. } } #endregion #region genetic_algorithms //Genetic Algorithm public int GA_PopSize { get { return _GA_PopSize. } } public int GA_GenLimit Page 78 of 225 . } } public bool CC_ITerr { get { return _CC_ITerr. } #endregion #region getters/setters #region cascade_correlation //Cascade Correlation public double CC_Terr { get { return _CC_Terr. } } public int CC_Reports { get { return _CC_Reports.

William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000117 00000118 00000119 00000120 00000121 00000122 00000123 00000124 00000125 00000126 00000127 00000128 00000129 00000130 00000131 00000132 00000133 00000134 00000135 00000136 00000137 00000138 00000139 00000140 00000141 00000142 00000143 00000144 00000145 00000146 { get { return _GA_GenLimit. } } public bool BP_ITerr { get { return _BP_ITerr. } } #endregion Page 79 of 225 . } } public int BP_Reports { get { return _BP_Reports. } } public int GA_Crossover { get { return _GA_Crossover. } } public bool GA_ITerr { get { return _GA_ITerr. } } public double BP_LearningRate { get { return _BP_LearningRate. } } public int GA_HiddenL { get { return _GA_HiddenL. } } public int GA_Reports { get { return _GA_Reports. } } public double BP_Terr { get { return _BP_Terr. } } public double GA_Terr { get { return _GA_Terr. } } public int BP_HiddenL { get { return _BP_HiddenL. } } public int GA_Mutation { get { return _GA_Mutation. } } #endregion #region back_propagation //Back propagation public int BP_EpochLimit { get { return _BP_EpochLimit.

} } public int TrainingAlgorithm { get { return trainingalg.“FrmMain.2 .Controller { public partial class FrmMain : Form Page 80 of 225 .Data. using ZedGraph.ComponentModel. System.Text. System. using _05025397.Generic.Linq. System.IO. } } #endregion } 9. System. namespace _05025397.1.Drawing.Forms.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000147 00000148 00000149 00000150 00000151 00000152 00000153 00000154 00000155 00000156 00000157 } #endregion #region external //General public int TrDataSet { get { return _TrDataSet. System. System.1.Windows.Collections. System.cs” 00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000009 00000010 00000011 00000012 00000013 00000014 00000015 00000016 00000017 using using using using using using using using using System. System.

TrainingAlgorithm network. //Background thread static BackgroundWorker bw = new BackgroundWorker(). bw.icon. } #endregion #region internal_functions /********************\ Page 81 of 225 .Algorithms.Working(). this. //Working dialog Controller.Icon = Properties.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted).William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000018 00000019 00000020 00000021 00000022 00000023 00000024 00000025 00000026 00000027 00000028 00000029 00000030 00000031 00000032 00000033 00000034 00000035 00000036 00000037 00000038 00000039 00000040 00000041 00000042 00000043 00000044 00000045 00000046 00000047 { #region data /********************\ |* DATA *| \********************/ //The neuralnetwork Controller.Working workingdialog = new Controller. bw.Resources. #endregion #region constructor /********************\ |* CONSTRUCTOR *| \********************/ public FrmMain() { InitializeComponent().DoWork += new DoWorkEventHandler(bw_DoWork).

CurveList. } private void updatenetwork(object sender. //Titles MSEpane. MSEpane.AxisChange().Clear().Red.TrainingAlgorithm == 0) { Page 82 of 225 . Color. try { if (e.Text = "Iteration".Text = "Mean Squared Error".zedGraphControl1. this.YAxis.zedGraphControl1. // Hide the legend MSEpane.zedGraphControl1. MSEpane.Legend.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000048 00000049 00000050 00000051 00000052 00000053 00000054 00000055 00000056 00000057 00000058 00000059 00000060 00000061 00000062 00000063 00000064 00000065 00000066 00000067 00000068 00000069 00000070 00000071 00000072 00000073 00000074 00000075 00000076 00000077 |* INTERNAL *| \********************/ private void plotgraphsMSE(PointPairList MSE) { this. MSE. MSEpane. Classes.XAxis.Title.NetworkUpdateEventArgs e) { LoadDataset(e.Text = "MSE".GraphPane.IsVisible = false. SymbolType.AddCurve("".GraphPane.Title.Circle).Title.TrDataSet). GraphPane MSEpane = this.

e. e.TrainingAlgorithm == 2) { network = new Controller.Algorithms.GA_Mutation.CascadeCorrelation (e.CC_Reports. e.BP_LearningRate.BP_HiddenL.GA_GenLimit. e.GA_ITerr. e. e. e. e.GeneticAlgorithm (e.GA_HiddenL.BP_Terr. e.CC_LearningRate. e. e. } } catch { Page 83 of 225 .BP_Reports. txtTrainData.BP_EpochLimit. txtTestData).GA_Reports.CC_Terr.BP_ITerr.Algorithms.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000078 00000079 00000080 00000081 00000082 00000083 00000084 00000085 00000086 00000087 00000088 00000089 00000090 00000091 00000092 00000093 00000094 00000095 00000096 00000097 00000098 00000099 00000100 00000101 00000102 00000103 00000104 00000105 00000106 00000107 network = new Controller. e.BackProp (e.TrainingAlgorithm == 1) { network = new Controller.GA_PopSize. e.GA_Terr.Algorithms. e. e. txtTestData). txtTrainData.CC_MaxNeurons. } if (e.GA_Crossover. e. txtTestData). txtTrainData. } if (e.CC_ITerr.

MessageBoxIcon.Text = Properties. Page 84 of 225 .William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000108 00000109 00000110 00000111 00000112 00000113 00000114 00000115 00000116 00000117 00000118 00000119 00000120 00000121 00000122 00000123 00000124 00000125 00000126 00000127 00000128 00000129 00000130 00000131 00000132 00000133 00000134 00000135 00000136 00000137 MessageBox. Application. txtTestData.Exit(). } private void LoadDataset(int Data_set) { switch (Data_set) { case (int)Dataset.Wiz1().network_details().OK.Resources.Wiz1 wizard = new Controller.Text = network.Text = Properties.NetworkUpdateHandler(updatenetwork).NetworkUpdated += new Controller.Show("Error creating new network". "Error".XORtrain. wizard. MessageBoxButtons.Wiz1. } } private void new_network() { Controller.ShowDialog().Error).XOR: txtTrainData. wizard. } if (network != null) { txtNetSettings.XORtest.Resources.

} } private void LoadCustomDataSet() { string trainpath = SelectTextFile(".CUSTOM: LoadCustomDataSet(). } catch { MessageBox.Resources. "Error!". string testpath = SelectTextFile(". try { train = LoadTxtFile(trainpath).Resources. "Select Testing Data").Error).FISHERtrain.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000138 00000139 00000140 00000141 00000142 00000143 00000144 00000145 00000146 00000147 00000148 00000149 00000150 00000151 00000152 00000153 00000154 00000155 00000156 00000157 00000158 00000159 00000160 00000161 00000162 00000163 00000164 00000165 00000166 00000167 break.Text = Properties. string train = "". break.\\".FISHER: txtTrainData.\\". } Page 85 of 225 . break. case (int)Dataset. case (int)Dataset.Show("Error: Problem loading training data". "Select Training Data"). txtTestData.OK. MessageBoxIcon.FISHERtest.Text = Properties. string test = "". MessageBoxButtons.

Read). } private string LoadTxtFile(string path) { string data = "". FileStream File = null. StreamReader Reader = null.OK.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000168 00000169 00000170 00000171 00000172 00000173 00000174 00000175 00000176 00000177 00000178 00000179 00000180 00000181 00000182 00000183 00000184 00000185 00000186 00000187 00000188 00000189 00000190 00000191 00000192 00000193 00000194 00000195 00000196 00000197 try { test = LoadTxtFile(testpath). MessageBoxButtons. try { File = new FileStream(path. MessageBoxIcon. Reader = new StreamReader(File). txtTrainData. "Error!". Page 86 of 225 . "Error!". } catch { MessageBox. } txtTestData. data = Reader.ReadToEnd().OK. MessageBoxButtons.Error).Show("Error: Problem loading testing data". MessageBoxIcon.Open.Text = train.Text = test. } catch { MessageBox.Error). FileAccess.Show("Error reading selected file: " + path. FileMode.

ShowDialog() == DialogResult.txt)|*.InitialDirectory = initialDirectory.*)|*. dialog.Close().*". } #endregion #region menu_items /********************\ |* MENU ITEMS *| \********************/ Page 87 of 225 . if (File != null) File.OK) ? dialog.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000198 00000199 00000200 00000201 00000202 00000203 00000204 00000205 00000206 00000207 00000208 00000209 00000210 00000211 00000212 00000213 00000214 00000215 00000216 00000217 00000218 00000219 00000220 00000221 00000222 00000223 00000224 00000225 00000226 00000227 data = "".Title = title. } private string SelectTextFile(string initialDirectory. dialog.Filter = "txt files (*. } finally { if (Reader != null) Reader.FileName : null. string title) { OpenFileDialog dialog = new OpenFileDialog(). return (dialog.Close().txt|All files (*. dialog. } return data.

Trained != false) { network.Show(). EventArgs e) { FrmAbout About = new FrmAbout(). } #endregion #region buttons Page 88 of 225 .William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000228 00000229 00000230 00000231 00000232 00000233 00000234 00000235 00000236 00000237 00000238 00000239 00000240 00000241 00000242 00000243 00000244 00000245 00000246 00000247 00000248 00000249 00000250 00000251 00000252 00000253 00000254 00000255 00000256 00000257 private void newNetworkToolStripMenuItem_Click(object sender.Close(). EventArgs e) { this. } private void runToolStripMenuItem_Click(object sender. EventArgs e) { if (network != null) { if (network. About. EventArgs e) { new_network(). } } } private void aboutToolStripMenuItem1_Click(object sender. } private void exitToolStripMenuItem_Click(object sender.Test().

Trained) Page 89 of 225 .ShowDialog().William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000258 00000259 00000260 00000261 00000262 00000263 00000264 00000265 00000266 00000267 00000268 00000269 00000270 00000271 00000272 00000273 00000274 00000275 00000276 00000277 00000278 00000279 00000280 00000281 00000282 00000283 00000284 00000285 00000286 00000287 /********************\ |* BUTTONS *| \********************/ private void btnNew_Click(object sender.IsBusy) { if (network != null) { if (!network. if (!bw. } private void btnTrain_Click(object sender. } } } } private void btnTest_Click(object sender.Trained) { bw. EventArgs e) { new_network().RunWorkerAsync(). EventArgs e) { if (network != null) { if (network. workingdialog. EventArgs e) { //Shouldn't be busy if the user managed to click this //but just make 100% certain.

if (network != null) { success = network.Train().SelectionStart = txtOutput. txtOutput. DoWorkEventArgs e) { bool success = true. txtOutput. txtOutput.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000288 00000289 00000290 00000291 00000292 00000293 00000294 00000295 00000296 00000297 00000298 00000299 00000300 00000301 00000302 00000303 00000304 00000305 00000306 00000307 00000308 00000309 00000310 00000311 00000312 00000313 00000314 00000315 00000316 00000317 { if (!network.Refresh().Clear(). if (success) { txtOutput. } Page 90 of 225 . } } } } } #endregion #region bg_worker /********************\ |* BG WORKER *| \********************/ private void bw_DoWork(object sender.Length.Tested) { bool success = network.Test().Text.ScrollToCaret().ReportData.Text = network. txtOutput.

txtOutput. txtOutput.Clear().OK.Text = network.Text.Error). MessageBoxIcon.Length.Error.Result.ToString(). } private void bw_RunWorkerCompleted(object sender.SelectionStart = txtOutput.getGraphData()). } Page 91 of 225 . plotgraphsMSE(network. RunWorkerCompletedEventArgs e) { bool success.Show("Error during network train: " + e. //Check for errors if (e.Error).Result = success. "Error training network!". "Error".Show("Error training network!".William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000318 00000319 00000320 00000321 00000322 00000323 00000324 00000325 00000326 00000327 00000328 00000329 00000330 00000331 00000332 00000333 00000334 00000335 00000336 00000337 00000338 00000339 00000340 00000341 00000342 00000343 00000344 00000345 00000346 00000347 e. MessageBoxButtons. if (success) { txtOutput. txtOutput.OK.ReportData. } else { MessageBox. MessageBoxIcon.Error != null) { MessageBox. } success = (bool) e.ScrollToCaret(). MessageBoxButtons.

Linq.1.3 .William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000348 00000349 00000350 00000351 00000352 00000353 00000354 00000355 00000356 00000357 00000358 00000359 00000360 00000361 00000362 00000363 00000364 00000365 00000366 } //Remove the dialog locking out the main form //and showing that we're currently working workingdialog. System.1. EventArgs e) { //Run the new neural net wizard new_network(). System.cs” 00000001 00000002 00000003 00000004 00000005 00000006 using using using using using using System. } #endregion } 9.Generic. Page 92 of 225 . } #endregion #region misc /********************\ |* MISC *| \********************/ private void FrmMain_Shown(object sender. System. System.Hide().Collections.“Wiz1. System.ComponentModel.Data.Drawing.

private int Trainset. namespace _05025397. enum Dataset { XOR. private int algorithm. CC }. Page 93 of 225 . using _05025397. FISHER.Controller { #region enums /********************\ |* ENUMS *| \********************/ enum Training { GA.Windows.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000007 00000008 00000009 00000010 00000011 00000012 00000013 00000014 00000015 00000016 00000017 00000018 00000019 00000020 00000021 00000022 00000023 00000024 00000025 00000026 00000027 00000028 00000029 00000030 00000031 00000032 00000033 00000034 00000035 00000036 using System.NetworkUpdateEventArgs e). using System. CUSTOM }. BP. Classes. #endregion public partial class Wiz1 : Form { #region data /********************\ |* DATA *| \********************/ public delegate void NetworkUpdateHandler(object sender. public event NetworkUpdateHandler NetworkUpdated.Text.Forms.

Resources.Close(). algorithm = (int)Training.Icon = Properties.icon.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000037 00000038 00000039 00000040 00000041 00000042 00000043 00000044 00000045 00000046 00000047 00000048 00000049 00000050 00000051 00000052 00000053 00000054 00000055 00000056 00000057 00000058 00000059 00000060 00000061 00000062 00000063 00000064 00000065 00000066 #endregion data #region constructor /********************\ |* CONSTRUCTOR *| \********************/ public Wiz1() { InitializeComponent(). EventArgs e) { this. } private void rBtnBackprop_CheckedChanged(object sender. Trainset = (int)Dataset. this.GA. EventArgs e) Page 94 of 225 . } #endregion #region control_events /********************\ |* CONTROL EVENTS *| \********************/ #region buttons /********************\ |* BUTTONS *| \********************/ private void btnCancel_Click(object sender.XOR.

Visible = false.BP. panBackprop.Resources.Properties.Visible = true.IMAGEBackProp. lblBP.Properties.Visible = true.Visible = true. panGeneticAlgorithm.IMAGECascadeCorrelation.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000067 00000068 00000069 00000070 00000071 00000072 00000073 00000074 00000075 00000076 00000077 00000078 00000079 00000080 00000081 00000082 00000083 00000084 00000085 00000086 00000087 00000088 00000089 00000090 00000091 00000092 00000093 00000094 00000095 00000096 { if (rBtnBackprop. lblGA.Visible = false. algorithm = (int)Training. algorithm = (int)Training. lblGA.Image = _05025397. EventArgs e) { if (rBtnCascadeCorrelation.Visible = true. lblBP. panBackprop.Visible = false. Page 95 of 225 .Visible = false. panCC. panGeneticAlgorithm.Checked == true) { picAlg. lblCC.CC.Visible = false.Visible = false.Visible = false.Visible = false.Resources. } } private void rBtnCascadeCorrelation_CheckedChanged(object sender. lblCC.Image = _05025397. panCC.Checked == true) { picAlg.

lblBP.GA.Visible = false.Visible = false. panGeneticAlgorithm. algorithm = (int)Training.Checked == true) { picAlg.Visible = true.Visible = true.SelectedIndex .Properties.Visible = false. panBackprop. EventArgs e) { Page 96 of 225 . lblGA. EventArgs e) { if (rBtnGeneticAlgorithm.IMAGEGeneticAlgorithm.Resources.Visible = false.1). panCC. EventArgs e) { if (tabControl1.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000097 00000098 00000099 00000100 00000101 00000102 00000103 00000104 00000105 00000106 00000107 00000108 00000109 00000110 00000111 00000112 00000113 00000114 00000115 00000116 00000117 00000118 00000119 00000120 00000121 00000122 00000123 00000124 00000125 00000126 } } private void rBtnGeneticAlgorithm_CheckedChanged(object sender. } } private void btnNext_Click(object sender.Image = _05025397.SelectTab(tabControl1.SelectedIndex > 0) { tabControl1. } } private void btnBack_Click(object sender. lblCC.

Checked.Text.BP_HiddenL. txtCC_MaxNeurons. check.TabCount . check.1) { tabControl1. Trainset). check.GA_Mutation. check.Text. txtGA_ProbM.CC_Terr. txtGA_MaxGen.Text. check.Checked.GA_Crossover. chkGA_IgnoreTarget.BP_EpochLimit. txtCC_Report. check.Text. txtBP_HiddenNodes. txtBP_Report.NetworkUpdateEventArgs (check. txtBP_Terr.Checked.Text.Text. chkBP_IgnoreTarget. txtBP_EpochLimit.SelectedIndex < tabControl1.Text.NetworkUpdateEventArgs args = new Classes. CC_ITerr.Text. check.Text. } else { VerifyData check = new VerifyData (algorithm. txtGA_Report.Text.GA_PopSize. check. txtGA_HiddenNodes. txtBP_LearnRate.SelectTab(tabControl1. txtGA_ProbX. txtGA_PopSize.SelectedIndex + 1).GA_Reports. Page 97 of 225 .CC_LearningRate.Text.GA_ITerr.CC_Reports.CC_ITerr.Text.Text.Verified) { Classes.GA_HiddenL.TrainingAlgorithm. check.Text. check.GA_GenLimit. check. check.CC_MaxNeurons.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000127 00000128 00000129 00000130 00000131 00000132 00000133 00000134 00000135 00000136 00000137 00000138 00000139 00000140 00000141 00000142 00000143 00000144 00000145 00000146 00000147 00000148 00000149 00000150 00000151 00000152 00000153 00000154 00000155 00000156 if (tabControl1. txtCC_TargetError. check.Text.GA_Terr. txtCC_LearningRate. if (check. check.Text. check. txtGA_Terr.

Resources.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000157 00000158 00000159 00000160 00000161 00000162 00000163 00000164 00000165 00000166 00000167 00000168 00000169 00000170 00000171 00000172 00000173 00000174 00000175 00000176 00000177 00000178 00000179 00000180 00000181 00000182 00000183 00000184 00000185 00000186 check.BP_ITerr. check.BP_Terr. NetworkUpdated(this.Properties.Image = _05025397.Exclamation).BP_LearningRate. MessageBoxIcon. check.Checked) { picDataset.OK.FISHER.TrDataSet).Show("Error Checking Data: Data could not be verified". "Error Checking Data".IMAGEIrisFlowers. EventArgs e) Page 98 of 225 . Trainset = (int)Dataset.BP_Reports. check.Dispose(). } } } #endregion #region checkboxes /********************\ |* CHECKBOXES *| \********************/ private void chkDatasetFisher_CheckedChanged(object sender. } else { MessageBox. this. } } private void chkDatasetXOR_CheckedChanged(object sender. MessageBoxButtons. EventArgs e) { if (chkDatasetFisher. check. args).

EventArgs e) { if (chkDatasetCustom.XOR. } } private void chkDatasetCustom_CheckedChanged(object sender.Resources.Properties.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000187 00000188 00000189 00000190 00000191 00000192 00000193 00000194 00000195 00000196 00000197 00000198 00000199 00000200 00000201 00000202 00000203 00000204 00000205 00000206 00000207 00000208 00000209 00000210 00000211 00000212 00000213 00000214 00000215 00000216 { if (chkDatasetXOR.Checked) { picDataset. Trainset = (int)Dataset.IMAGEQuestionMark. } Page 99 of 225 . Trainset = (int)Dataset.Checked) { picDataset.CUSTOM.Image = _05025397.Properties.Focus().Visible == true) { txtCC_TargetError. } } #endregion #region misc /********************\ |* MISC *| \********************/ private void tabControl1_SelectedIndexChanged(object sender.Image = _05025397. EventArgs e) { if (tabControl1.SelectedIndex == 1) { if (panCC.Resources.IMAGEXOR.

Focus().SelectTab(0).Focus(). } #endregion #endregion } Page 100 of 225 .William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000217 00000218 00000219 00000220 00000221 00000222 00000223 00000224 00000225 00000226 00000227 00000228 00000229 00000230 00000231 00000232 00000233 00000234 00000235 00000236 } if (panBackprop.Visible == true) { txtGA_PopSize.icon.Icon = Properties. } } } private void Wiz1_Load(object sender. tabControl1.Resources. } if (panGeneticAlgorithm. EventArgs e) { this.Visible == true) { txtBP_EpochLimit.

Collections. EventArgs e) { Page 101 of 225 .“FrmAbout.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 9.ComponentModel.Forms. } #endregion #region form /********************\ |* FORM *| \********************/ private void FrmAbout_Load(object sender. System.Data. System.Controller { public partial class FrmAbout : Form { #region constructor /********************\ |* CONSTRUCTOR *| \********************/ public FrmAbout() { InitializeComponent().Generic.Text.1. namespace _05025397.Drawing.Windows.Linq. System.cs” 00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000009 00000010 00000011 00000012 00000013 00000014 00000015 00000016 00000017 00000018 00000019 00000020 00000021 00000022 00000023 00000024 00000025 00000026 00000027 00000028 00000029 using using using using using using using using System. System.4 . System. System. System.1.

textBox5.icon. label5. MessageBoxButtons.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000030 00000031 00000032 00000033 00000034 00000035 00000036 00000037 00000038 00000039 00000040 00000041 00000042 00000043 00000044 00000045 00000046 00000047 00000048 00000049 00000050 00000051 00000052 00000053 00000054 00000055 00000056 00000057 00000058 00000059 this.Show("No e-mail program defined.LinkVisited = true. LinkLabelLinkClickedEventArgs e) { // Specify that the link was visited. } #endregion #region linklabels /********************\ |* LINKLABELS *| \********************/ private void linkLabel1_LinkClicked(object sender.LICENCE_LGPL21.Resources. try { // Navigate to a URL.Resources. MessageBoxIcon.linkLabel1.Information).Start("mailto:" + linkLabel1. } catch { MessageBox.".Text). this.ProductVersion.Text = Properties. System.OK. "Undefined Application".Icon = Properties.Diagnostics. } } private void linkLabel4_LinkClicked(object sender. LinkLabelLinkClickedEventArgs e) Page 102 of 225 .Process.Text = Application.

Diagnostics. "Error".Diagnostics.Process. LinkLabelLinkClickedEventArgs e) { try { System. MessageBoxIcon. MessageBoxButtons.Error).Process. } catch { MessageBox.OK.Text). "Error". MessageBoxIcon. LinkLabelLinkClickedEventArgs e) Page 103 of 225 .Start (linkLabel5.Start (linkLabel4.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000060 00000061 00000062 00000063 00000064 00000065 00000066 00000067 00000068 00000069 00000070 00000071 00000072 00000073 00000074 00000075 00000076 00000077 00000078 00000079 00000080 00000081 00000082 00000083 00000084 00000085 00000086 00000087 00000088 00000089 { try { System.".". MessageBoxButtons.Error).Text). } } private void linkLabel6_LinkClicked(object sender.Show("Error opening link. } catch { MessageBox.Show("Error opening link.OK. } } private void linkLabel5_LinkClicked(object sender.

MessageBoxButtons. "Error".OK.Show("Error opening link. LinkLabelLinkClickedEventArgs e) Page 104 of 225 .Start (linkLabel6.Start ("http://www.Show("Error opening link.co.". } catch { MessageBox. "Error". MessageBoxIcon. } } private void linkLabel2_LinkClicked(object sender.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000090 00000091 00000092 00000093 00000094 00000095 00000096 00000097 00000098 00000099 00000100 00000101 00000102 00000103 00000104 00000105 00000106 00000107 00000108 00000109 00000110 00000111 00000112 00000113 00000114 00000115 00000116 00000117 00000118 00000119 { try { System.Error).OK.Error).snikks.Text).".Diagnostics. LinkLabelLinkClickedEventArgs e) { try { System.Process.uk").Diagnostics. } catch { MessageBox. MessageBoxButtons. } } private void linkLabel7_LinkClicked(object sender. MessageBoxIcon.Process.

William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000120 00000121 00000122 00000123 00000124 00000125 00000126 00000127 00000128 00000129 00000130 00000131 00000132 00000133 00000134 00000135 00000136 00000137 00000138 00000139 00000140 00000141 00000142 00000143 00000144 00000145 00000146 00000147 00000148 00000149 { try { System.".gnu. pictureBox1.Process.Diagnostics. MessageBoxButtons.Visible = false.Visible = false. } catch { MessageBox.Error).html"). "Error". } else Page 105 of 225 .org/licenses/old-licenses/lgpl-2.Visible = false.1.Start ("http://www.Visible = true. } } #endregion #region buttons /********************\ |* BUTTONS *| \********************/ private void btnDatasets_Click(object sender. groupBox2.Show("Error opening link.Visible != true) { groupBox1. tabControl1.OK. MessageBoxIcon. EventArgs e) { if (tabControl1.

Visible = false.Visible = groupBox2.Visible = false. pictureBox1.Visible = false.Visible = false. EventArgs e) { if (groupBox2.Visible = true. groupBox2.Visible = false. } } private void btnOkay_Click(object sender.Visible = tabControl1. groupBox1.Visible } } private void btnLicences_Click(object sender. = true. Page 106 of 225 . EventArgs e) { this. false.Visible != true) { groupBox2. } else { groupBox1. } true.Dispose(). tabControl1. pictureBox1.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000150 00000151 00000152 00000153 00000154 00000155 00000156 00000157 00000158 00000159 00000160 00000161 00000162 00000163 00000164 00000165 00000166 00000167 00000168 00000169 00000170 00000171 00000172 00000173 00000174 00000175 00000176 00000177 00000178 00000179 { groupBox1. = false.Visible = true.Visible = true. tabControl1.Visible pictureBox1.

Text = Properties.Text = Properties.LICENCE_GPL30. EventArgs e) { if (radioButton1.Resources. EventArgs e) { if (radioButton3.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000180 00000181 00000182 00000183 00000184 00000185 00000186 00000187 00000188 00000189 00000190 00000191 00000192 00000193 00000194 00000195 00000196 00000197 00000198 00000199 00000200 00000201 00000202 00000203 00000204 00000205 } #endregion #region radiobuttons /********************\ |* RADIOBUTTONS *| \********************/ private void radioButton1_CheckedChanged(object sender. } #endregion } Page 107 of 225 .Checked == true) textBox5. } private void radioButton3_CheckedChanged(object sender. } private void radioButton2_CheckedChanged(object sender.LICENCE_LGPL21.Resources.Resources.LICENCE_LGPL30.Checked == true) textBox5.Checked == true) textBox5.Text = Properties. EventArgs e) { if (radioButton2.

System.Generic.“Working.Resources.Data.1.Forms.Windows.5 . } private void Working_Click(object sender.SystemSounds. System.Play().ComponentModel. EventArgs e) { System.cs” 00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000009 00000010 00000011 00000012 00000013 00000014 00000015 00000016 00000017 00000018 00000019 00000020 00000021 00000022 00000023 00000024 00000025 00000026 00000027 00000028 00000029 using using using using using using using using System.Beep.icon.Drawing.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 9.Linq. namespace _05025397.Collections. System. System. } #endregion } Page 108 of 225 . System. this.1.Media. System.Controller { public partial class Working : Form { #region functions /********************\ |* FUNCTIONS *| \********************/ public Working() { InitializeComponent().Text. System.Icon = Properties.

Linq. namespace _05025397. //Training Algorithm Identifier //1 = genetic algorith //2 = backprop //3 = cascade correlation private int trainingalg.1.Text.1 . //Dataset identifer //0 = XOR Page 109 of 225 .Collections.Controller { public class VerifyData { #region data /********************\ |* DATA *| \********************/ //Dataverified variable private bool verified.Forms.cs” 00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000009 00000010 00000011 00000012 00000013 00000014 00000015 00000016 00000017 00000018 00000019 00000020 00000021 00000022 00000023 00000024 00000025 using using using using using System.2 . System.1. System.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000030 } 9. System.Windows.Controller 9.Generic.“VerifyData. System.2.

private bool _GA_ITerr. #endregion Page 110 of 225 . private bool _BP_ITerr. private double _BP_Terr. //Cascade Correlation private double _CC_Terr. private double _BP_LearningRate. private int _BP_Reports. //Genetic Algorithm private int _GA_PopSize. private int _GA_Reports.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000026 00000027 00000028 00000029 00000030 00000031 00000032 00000033 00000034 00000035 00000036 00000037 00000038 00000039 00000040 00000041 00000042 00000043 00000044 00000045 00000046 00000047 00000048 00000049 00000050 00000051 00000052 00000053 00000054 00000055 //1 = FISHERS IRIS DATA //2 = CUSTOM private int _TDataSet. private int _GA_Mutation. private double _CC_LearningRate. private int _GA_GenLimit. private int _GA_HiddenL. private int _BP_HiddenL. private int _CC_MaxNeurons. private int _CC_Reports. private int _GA_Crossover. private bool _CC_ITerr. //BackProp private int _BP_EpochLimit. private double _GA_Terr.

string GATerr. bool CCITerr. string BPHiddenL. string GAPopSize. string CCTerr. string BPReports. string CCLearningRate. if (_TDataSet != (int)Dataset. string GAMutation. string GAGenLimit. string BPEpochLimit. string BPTerr. bool BPITerr. //DataSet _TDataSet = TData_Set. bool GAITerr. int TData_Set) { //Initially set to true. string CCMaxNeurons. string GAHiddenL.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000056 00000057 00000058 00000059 00000060 00000061 00000062 00000063 00000064 00000065 00000066 00000067 00000068 00000069 00000070 00000071 00000072 00000073 00000074 00000075 00000076 00000077 00000078 00000079 00000080 00000081 00000082 00000083 00000084 00000085 #region constructor /********************\ |* CONSTRUCTOR *| \********************/ public VerifyData (int Algorithm. will be changed to //false if any data verification errors occur verified = true. string BPLearningRate. string CCReports.XOR && _TDataSet != Page 111 of 225 . string GAReports. string GACrossOver. //Algorithm trainingalg = Algorithm.

CUSTOM) verified = false.OK. verified = false. _CC_ITerr = CCITerr. } } } Page 112 of 225 . if (verified) { if (trainingalg == 2) { try { //Cascade correlation _CC_Terr = Convert. _CC_Reports = Convert.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000086 00000087 00000088 00000089 00000090 00000091 00000092 00000093 00000094 00000095 00000096 00000097 00000098 00000099 00000100 00000101 00000102 00000103 00000104 00000105 00000106 00000107 00000108 00000109 00000110 00000111 00000112 00000113 00000114 00000115 (int)Dataset. MessageBoxButtons.ToSingle(CCTerr).ToInt32(CCReports). _CC_LearningRate = Convert.FISHER && _TDataSet != (int)Dataset. "Parsing Error".ToSingle(CCLearningRate).Show ("Parsing Error: Please check supplied cascade" + "correlation data values".Error). MessageBoxIcon. _CC_MaxNeurons = Convert.ToInt32(CCMaxNeurons). } catch (FormatException) { MessageBox.

ToInt32(GAReports). } } } if (verified) Page 113 of 225 .ToInt32(GAHiddenL). } catch (FormatException) { MessageBox. _GA_Reports = Convert.Error). _GA_Terr = Convert. _GA_HiddenL = Convert. _GA_ITerr = GAITerr. _GA_GenLimit = Convert.ToInt32(GACrossOver).OK.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000116 00000117 00000118 00000119 00000120 00000121 00000122 00000123 00000124 00000125 00000126 00000127 00000128 00000129 00000130 00000131 00000132 00000133 00000134 00000135 00000136 00000137 00000138 00000139 00000140 00000141 00000142 00000143 00000144 00000145 if (verified) { if (trainingalg == 0) { try { //Genetic algorithm _GA_PopSize = Convert. verified = false.ToInt32(GAPopSize). _GA_Mutation = Convert. MessageBoxButtons.Show ("Parsing Error: Please check supplied" +" genetic algorithm data values". _GA_Crossover = Convert. MessageBoxIcon.ToInt32(GAGenLimit).ToSingle(GATerr).ToInt32(GAMutation). "Parsing Error".

ToDouble(BPLearningRate). } catch (FormatException) { MessageBox.ToDouble(BPTerr).Error).ToInt32(BPReports). verified = false.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000146 00000147 00000148 00000149 00000150 00000151 00000152 00000153 00000154 00000155 00000156 00000157 00000158 00000159 00000160 00000161 00000162 00000163 00000164 00000165 00000166 00000167 00000168 00000169 00000170 00000171 00000172 00000173 00000174 00000175 { if (trainingalg == 1) { try { //Back-propagation _BP_EpochLimit = Convert.OK. } Page 114 of 225 .Show ("Parsing Error: Please check " + "supplied back propagation data values". _BP_LearningRate = Convert. _BP_Terr = Convert. "Parsing Error".ToInt32(BPHiddenL). _BP_HiddenL = Convert. MessageBoxIcon.ToInt32(BPEpochLimit). } } } if (verified) { verified = checkforsanity(). _BP_Reports = Convert. MessageBoxButtons. _BP_ITerr = BPITerr.

if (_GA_Crossover < 0 || _GA_Crossover > 100) { sanity = false. if (_GA_GenLimit < 1) sanity = false. Page 115 of 225 . } if (_GA_Mutation < 0 || _GA_Mutation > 100) { sanity = false. } if (_GA_Terr < 0 || _GA_Terr > 1) sanity = false. if (_GA_PopSize < 3) sanity = false.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000176 00000177 00000178 00000179 00000180 00000181 00000182 00000183 00000184 00000185 00000186 00000187 00000188 00000189 00000190 00000191 00000192 00000193 00000194 00000195 00000196 00000197 00000198 00000199 00000200 00000201 00000202 00000203 00000204 00000205 } #endregion #region internal /********************\ |* INTERNAL *| \********************/ private bool checkGAsanity() { bool sanity = true.

if (_BP_EpochLimit < 1) sanity = false. MessageBoxIcon. return sanity. MessageBoxButtons.Show ("Sanity Check Fail: Please check supplied " + "genetic algorithm data values". if (_GA_HiddenL < 1) sanity = false. if (!sanity) MessageBox.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000206 00000207 00000208 00000209 00000210 00000211 00000212 00000213 00000214 00000215 00000216 00000217 00000218 00000219 00000220 00000221 00000222 00000223 00000224 00000225 00000226 00000227 00000228 00000229 00000230 00000231 00000232 00000233 00000234 00000235 if (_GA_Reports < 1 || _GA_Reports > _GA_GenLimit) sanity = false. Page 116 of 225 . if (_BP_HiddenL < 1) sanity = false.Error). "Sanity Check Fail". if (_BP_Reports < 1 || _BP_Reports > _BP_EpochLimit) sanity = false.OK. } private bool checkBPsanity() { bool sanity = true.

} private bool checkCCsanity() { bool sanity = true. MessageBoxButtons. if (_CC_Terr < 0 || _CC_Terr > 1) sanity = false.Error). if (_CC_MaxNeurons < 1) sanity = false. MessageBoxIcon. if (!sanity) MessageBox. return sanity.OK. "Sanity Check Fail". Page 117 of 225 .Show ("Sanity Check Fail: Please check supplied " + "back propagation data values".William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000236 00000237 00000238 00000239 00000240 00000241 00000242 00000243 00000244 00000245 00000246 00000247 00000248 00000249 00000250 00000251 00000252 00000253 00000254 00000255 00000256 00000257 00000258 00000259 00000260 00000261 00000262 00000263 00000264 00000265 if (_BP_Terr < 0 || _BP_Terr > 1) sanity = false. if (_CC_Reports < 1 || _CC_Reports > _CC_MaxNeurons) sanity = false. if (_BP_LearningRate < 0 || _BP_LearningRate > 1) sanity = false.

We're also doing some very minor processing of the probability values. return sanity. if (trainingalg < 0 || trainingalg > 2) Page 118 of 225 . only //halt any values from proceeding that are so wrong they could cause //serious errors later down the line.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000266 00000267 00000268 00000269 00000270 00000271 00000272 00000273 00000274 00000275 00000276 00000277 00000278 00000279 00000280 00000281 00000282 00000283 00000284 00000285 00000286 00000287 00000288 00000289 00000290 00000291 00000292 00000293 00000294 00000295 if (_CC_LearningRate < 0 || _CC_LearningRate > 1) sanity = false. MessageBoxIcon. if they're greater than 1 but less than 100 scale them appropriately. "Sanity Check Fail".Error). } private bool checkforsanity() { //Some of the values that are allowed through here would not produce //good results .Show ("Sanity Check Fail: Please check supplied " + "cascade correlation data values". // // // // // bool Basically we're making sure the data is clean before it goes anywhere near a DLL. if (!sanity) MessageBox. sanity = true.however I don't want to prevent any flexibility.OK. MessageBoxButtons.

Error). } Page 119 of 225 . } if (trainingalg == 1) { sanity = checkBPsanity(). } } return sanity. } if (sanity) { if (trainingalg == 0) { sanity = checkGAsanity(). MessageBoxButtons. "Sanity Check Fail". MessageBox. MessageBoxIcon. } if (trainingalg == 2) { sanity = checkCCsanity().OK.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000296 00000297 00000298 00000299 00000300 00000301 00000302 00000303 00000304 00000305 00000306 00000307 00000308 00000309 00000310 00000311 00000312 00000313 00000314 00000315 00000316 00000317 00000318 00000319 00000320 00000321 00000322 00000323 00000324 00000325 { sanity = false.Show ("Sanity Check Fail: Training Algorithm not " + "selected or selected incorrectly".

} } public int GA_Crossover { get { return _GA_Crossover. } } public int GA_Mutation Page 120 of 225 .William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000326 00000327 00000328 00000329 00000330 00000331 00000332 00000333 00000334 00000335 00000336 00000337 00000338 00000339 00000340 00000341 00000342 00000343 00000344 00000345 00000346 00000347 00000348 00000349 00000350 00000351 00000352 00000353 00000354 00000355 #endregion #region getters/setters /********************\ |* EXTERNAL *| \********************/ #region cascade_correlation //Cascade Correlation public double CC_Terr { get { return _CC_Terr. } } public int GA_GenLimit { get { return _GA_GenLimit. } } public bool CC_ITerr { get { return _CC_ITerr. } } public double CC_LearningRate { get { return _CC_LearningRate. } } #endregion #region genetic_algorithm //Genetic Algorithm public int GA_PopSize { get { return _GA_PopSize. } } public int CC_Reports { get { return _CC_Reports. } } public int CC_MaxNeurons { get { return _CC_MaxNeurons.

} } public bool BP_ITerr { get { return _BP_ITerr. } } public double BP_Terr { get { return _BP_Terr. } } _GA_Terr.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000356 00000357 00000358 00000359 00000360 00000361 00000362 00000363 00000364 00000365 00000366 00000367 00000368 00000369 00000370 00000371 00000372 00000373 00000374 00000375 00000376 00000377 00000378 00000379 00000380 00000381 00000382 00000383 00000384 00000385 { get { return public double GA_Terr { get { return public int GA_Reports { get { return public int GA_HiddenL { get { return public bool GA_ITerr { get { return #endregion _GA_Mutation. } } _GA_Reports. } } #region back_propagation //Back propagation public int BP_EpochLimit { get { return _BP_EpochLimit. } } _GA_HiddenL. } } public double BP_LearningRate { get { return _BP_LearningRate. } } _GA_ITerr. } } public int BP_Reports { get { return _BP_Reports. } } public int BP_HiddenL { get { return _BP_HiddenL. } } #endregion #endregion #region external //Verification Page 121 of 225 .

} } #endregion } Page 122 of 225 .William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000386 00000387 00000388 00000389 00000390 00000391 00000392 00000393 00000394 00000395 00000396 00000397 00000398 } public bool Verified { get { return verified. } } //TrainingAlgorithm public int TrainingAlgorithm { get { return trainingalg. } } //Dataset public int TrDataSet { get { return _TDataSet.

System. private ArrayList aldata.Controller { public class DatasetParser { #region data /********************\ |* DATA *| \********************/ private bool _Verified.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 9.Linq. private string[] data.“DatasetParser.1.Generic. Page 123 of 225 .cs” 00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000009 00000010 00000011 00000012 00000013 00000014 00000015 00000016 00000017 00000018 00000019 00000020 00000021 00000022 00000023 00000024 00000025 00000026 00000027 00000028 00000029 using using using using using using System.Text. System.Collections. System.Collections. private ArrayList teoutputs.2 .2. private ArrayList teinputs. System. private ArrayList troutputs. private ArrayList altest. private ArrayList trinputs. private string[] test.Forms.Windows. System. namespace _05025397.

Text = txtTest. char[] delimiterChars = { '\n'. '\t'. teinputs = new ArrayList(). private double Niterations. '. #endregion #region constructor /********************\ |* CONSTRUCTOR *| \********************/ public DatasetParser(RichTextBox txtData. trinputs = new ArrayList().Trim().Text = txtData.' }. private double Noutputs.Text = txtTest. ""). txtTest.Trim().Text = txtData. troutputs = new ArrayList(). '.Text. altest = new ArrayList().'.Replace("\r". private double Ninputs.Replace("\r". "").Text. RichTextBox txtTest) { //Data init bool Verified = true.Text. Page 124 of 225 . txtTest. ' '. aldata = new ArrayList().Text. txtData. //Strip carriage returns and trim txtData. '\r'.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000030 00000031 00000032 00000033 00000034 00000035 00000036 00000037 00000038 00000039 00000040 00000041 00000042 00000043 00000044 00000045 00000046 00000047 00000048 00000049 00000050 00000051 00000052 00000053 00000054 00000055 00000056 00000057 00000058 00000059 //private Scaler scale. teoutputs = new ArrayList().

Length. Verified = parseTestingData(). } #endregion #region internal_functions /********************\ |* INTERNAL *| \********************/ private bool parseTrainingData() { bool success = true.Split(delimiterChars).Convert.ToDouble(data[0]). i++) Page 125 of 225 .Text. number of inputs //and number of outputs Niterations = System.Text. Ninputs = System. test = txtTest. Noutputs = System. try { for (int i = 3. //Get the number of iterations. //parse the data into appropriately //structured arrays Verified = parseTrainingData().Split(delimiterChars).ToDouble(data[2]).Convert.Convert. _Verified = Verified.ToDouble(data[1]). i < data.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000060 00000061 00000062 00000063 00000064 00000065 00000066 00000067 00000068 00000069 00000070 00000071 00000072 00000073 00000074 00000075 00000076 00000077 00000078 00000079 00000080 00000081 00000082 00000083 00000084 00000085 00000086 00000087 00000088 00000089 //Split at the chars specified above data = txtData.

Page 126 of 225 . j++) { troutputs. "Error". aldata. i++) { trinputs. } while (aldata.Count > 0) { for (int i = 0.Convert.Error). success = false.Add(aldata[0]). } return success. } private bool parseTestingData() { bool success = true. MessageBoxButtons. j < Noutputs. } } } catch { MessageBox. aldata.RemoveAt(0).OK.ToDouble(data[i])).Add(System.Add(aldata[0]). i < Ninputs. } for (int j = 0.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000090 00000091 00000092 00000093 00000094 00000095 00000096 00000097 00000098 00000099 00000100 00000101 00000102 00000103 00000104 00000105 00000106 00000107 00000108 00000109 00000110 00000111 00000112 00000113 00000114 00000115 00000116 00000117 00000118 00000119 { aldata. MessageBoxIcon.RemoveAt(0).Show("Error parsing training data".

i++) { teinputs. j < Noutputs.Add(System.OK.Add(altest[0]). } } } catch { MessageBox.Count > 0) { for (int i = 0. i < data.RemoveAt(0). } for (int j = 0. MessageBoxIcon. } while (altest. } Page 127 of 225 .Add(altest[0]).RemoveAt(0). j++) { teoutputs.Length. MessageBoxButtons. success = false. } return success.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000120 00000121 00000122 00000123 00000124 00000125 00000126 00000127 00000128 00000129 00000130 00000131 00000132 00000133 00000134 00000135 00000136 00000137 00000138 00000139 00000140 00000141 00000142 00000143 00000144 00000145 00000146 00000147 00000148 00000149 try { for (int i = 3. "Error". altest. altest.Error).ToDouble(data[i])). i++) { altest.Show("Error parsing testing data".Convert. i < Ninputs.

k++) { Page 128 of 225 . troutputdata = new double[troutputs. j+=(int) Ninputs. l++) { for (int k = 0. out double Nout) { Ninp = Ninputs. j < trinputs.Count / (int)Noutputs). for (int j = 0. out double[][] troutputdata) { trinputdata = new double[trinputs. i++) troutputdata[i] = new double[(int) Noutputs]. i < (trinputs. i++) trinputdata[i] = new double[(int) Ninputs]. l = 0.Count / (int) Noutputs][]. out double Ninp. iter = Niterations.Count.Count / (int)Ninputs). i < (troutputs. } public void GetTrainingData (out double[][] trinputdata.Count / (int) Ninputs][]. Nout = Noutputs. for (int i = 0. for (int i = 0. k < Ninputs.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000150 00000151 00000152 00000153 00000154 00000155 00000156 00000157 00000158 00000159 00000160 00000161 00000162 00000163 00000164 00000165 00000166 00000167 00000168 00000169 00000170 00000171 00000172 00000173 00000174 00000175 00000176 00000177 00000178 00000179 #endregion #region external_functions /********************\ |* EXTERNAL *| \********************/ public void GetStructure(out double iter.

William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000180 00000181 00000182 00000183 00000184 00000185 00000186 00000187 00000188 00000189 00000190 00000191 00000192 00000193 00000194 00000195 00000196 00000197 00000198 00000199 00000200 00000201 00000202 00000203 00000204 00000205 00000206 00000207 00000208 00000209 trinputdata[l][k] = (double) trinputs[j + } } for (int j = 0.Count / (int)Noutputs).Count.Count / (int)Ninputs][]. out double[][] teoutputdata) { teinputdata = new double[teinputs. l = 0. for (int i = 0. Page 129 of 225 . for (int i = 0. } } } public void GetTestingData (out double[][] teinputdata. j += (int)Ninputs. k]. i < (teinputs.Count / (int)Noutputs][]. k++) { troutputdata[l][k] = (double)troutputs[j + k]. i++) teoutputdata[i] = new double[(int)Noutputs]. l = 0. k < Noutputs. j += (int)Noutputs.Count. k < Ninputs. i++) teinputdata[i] = new double[(int)Ninputs].Count / (int)Ninputs). for (int j = 0. j < troutputs. l++) { for (int k = 0. i < (teoutputs. j < teinputs. k++) { teinputdata[l][k] = (double)teinputs[j + k]. l++) { for (int k = 0. teoutputdata = new double[teoutputs.

1. } } } public void GetTestingDataAL (out ArrayList teinputdata. Page 130 of 225 . l++) { for (int k = 0.Count.“Algorithms\TrainingAlgorithm.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000210 00000211 00000212 00000213 00000214 00000215 00000216 00000217 00000218 00000219 00000220 00000221 00000222 00000223 00000224 00000225 00000226 00000227 00000228 00000229 00000230 00000231 00000232 00000233 00000234 00000235 00000236 } } } for (int j = 0. j < teoutputs. } } #endregion } 9.cs” 00000001 using System. teoutputdata = teoutputs. j += (int)Noutputs. } public bool Verified { get { return _Verified. out ArrayList teoutputdata) { teinputdata = teinputs.2. l = 0. k++) { teoutputdata[l][k] = (double)teoutputs[j + k].3 . k < Noutputs.

protected int CurIt. private string _ReportData.Linq.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000009 00000010 00000011 00000012 00000013 00000014 00000015 00000016 00000017 00000018 00000019 00000020 00000021 00000022 00000023 00000024 00000025 00000026 00000027 00000028 00000029 00000030 00000031 using using using using using using System. protected PointPairList BestErrList. _05025397.Collections. namespace _05025397.Generic. protected bool _Trained. protected bool _ITerr.Text.Forms. private int _IterMax.Algorithms { public abstract class TrainingAlgorithm { #region data /********************\ |* DATA *| \********************/ private double _TargetError. System. private int _ReportInterval. ZedGraph. protected bool _Tested.Controller. System. System. Page 131 of 225 .Windows.

00. bool ITerr) { _TargetError = Target_Error. _IterMax = Iter_Max. _ReportInterval = Reports. //If the ignore target error is true //then set the target error to -1.0 //this is impossible to reach. int Reports. _ITerr = ITerr. getdata = new DatasetParser(txtData. protected DatasetParser getdata. BestErrList = new PointPairList(). RichTextBox txtData. } #endregion Page 132 of 225 . RichTextBox txtTest. int Iter_Max. #endregion #region constructor /********************\ |* CONSTRUCTOR *| \********************/ public TrainingAlgorithm(double Target_Error. txtTest). so the //network will loop to completion. if (_ITerr) _TargetError = -1.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000032 00000033 00000034 00000035 00000036 00000037 00000038 00000039 00000040 00000041 00000042 00000043 00000044 00000045 00000046 00000047 00000048 00000049 00000050 00000051 00000052 00000053 00000054 00000055 00000056 00000057 00000058 00000059 00000060 00000061 protected Random Rand = new Random().

} get { return _TargetError. } public double TargetError { set { _TargetError = value. } } Page 133 of 225 . public abstract bool Test(). public abstract string network_details().William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000062 00000063 00000064 00000065 00000066 00000067 00000068 00000069 00000070 00000071 00000072 00000073 00000074 00000075 00000076 00000077 00000078 00000079 00000080 00000081 00000082 00000083 00000084 00000085 00000086 00000087 00000088 00000089 00000090 00000091 #region internal /********************\ |* INTERNAL *| \********************/ protected void Report(string output) { _ReportData += output. public PointPairList getGraphData() { return BestErrList. } #endregion #region external /********************\ |* EXTERNAL *| \********************/ public abstract bool Train().

William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000092 00000093 00000094 00000095 00000096 00000097 00000098 00000099 00000100 00000101 00000102 00000103 00000104 00000105 00000106 00000107 00000108 00000109 00000110 00000111 00000112 00000113 00000114 00000115 00000116 00000117 00000118 00000119 } public int ReportInterval { get { return _ReportInterval. } } public int IterMax { get { return _IterMax. } } public string ReportData { get { return _ReportData. } set { _Trained = value. } } public bool Trained { get { return _Trained. } } public bool Tested { get { return _Tested. } } #endregion } Page 134 of 225 .

System.Generic. FANN_Cascade CCNet. System.Forms. _05025397. System.“Algorithms\CascadeCorrelation.Collections. FANN_Wrapper.Text. System. System.Windows.2. ZedGraph.IO. #endregion #region constructor Page 135 of 225 . System.4 .Collections. private double _LearnRate.Algorithms { public class CascadeCorrelation : TrainingAlgorithm { #region data /********************\ |* DATA *| \********************/ private double _InputL.Controller.1. namespace _05025397.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 9.cs” 00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000009 00000010 00000011 00000012 00000013 00000014 00000015 00000016 00000017 00000018 00000019 00000020 00000021 00000022 00000023 00000024 00000025 00000026 00000027 00000028 00000029 using using using using using using using using using using System. private double _OutputL.Linq.

TargetError. txtData. txtTest. CCNet = new FANN_Cascade((int)_InputL. out _OutputL). RichTextBox te) { Page 136 of 225 .ReportInterval. double iterations. Reports. _LearnRate. Iter_Max.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000030 00000031 00000032 00000033 00000034 00000035 00000036 00000037 00000038 00000039 00000040 00000041 00000042 00000043 00000044 00000045 00000046 00000047 00000048 00000049 00000050 00000051 00000052 00000053 00000054 00000055 00000056 00000057 00000058 00000059 /********************\ |* CONSTRUCTOR *| \********************/ public CascadeCorrelation(double LearnRate. double TargetError. RichTextBox txtData. base. int Iter_Max. saveDllData(txtData. ITerr) { _LearnRate = LearnRate. int Reports.GetStructure(out iterations. bool ITerr.IterMax). (int)_OutputL. out _InputL. base. } #endregion #region internal_functions /********************\ |* INTERNAL *| \********************/ private void saveDllData(RichTextBox tr. RichTextBox txtTest) : base(TargetError. base. txtTest). getdata.

tw.Close().Text). tw. (int)_OutputL)). tw.Format ("Network Details: \n Input Layer: {0:d}". } #endregion #region external_functions /********************\ |* EXTERNAL *| \********************/ public override string network_details() { StringBuilder output = new StringBuilder(). _LearnRate)).Append( Page 137 of 225 .Format ("\nLearning Rate: {0:0. (int)_InputL)). output.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000060 00000061 00000062 00000063 00000064 00000065 00000066 00000067 00000068 00000069 00000070 00000071 00000072 00000073 00000074 00000075 00000076 00000077 00000078 00000079 00000080 00000081 00000082 00000083 00000084 00000085 00000086 00000087 00000088 00000089 TextWriter tw = new StreamWriter("dlltrdata.Append( string. output.Write(te. output. tw.Format ("\t\t\t\t\tOutput Layer: {0:d}". output.Write(tr.Close().Append( string. tw = new StreamWriter("dlltedata.00000}".dat").Text).Append( string.dat").

_ITerr)). } catch { Page 138 of 225 .Format ("\nReport every {0:d} generations. output. output. base.IterMax)). } public override bool Train() { bool success = true.Format ("\t\tMaximum Nodes: {0:d}".ToString(). try { success = CCNet.00000}".William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000090 00000091 00000092 00000093 00000094 00000095 00000096 00000097 00000098 00000099 00000100 00000101 00000102 00000103 00000104 00000105 00000106 00000107 00000108 00000109 00000110 00000111 00000112 00000113 00000114 00000115 00000116 00000117 00000118 00000119 string. return output. Report(CCNet. base. base.ReportInterval)).".Format ("\t\t\tTarget Error: {0:0.Train().Append( string.Append( string.Append( string._tr_output). output.TargetError)).Format ("\t\t\t\t\t\tIgnore target error " + "(process all iterations): {0}".

Show("Error getting graph data from DLL"._Trained = success. i < besterrlist.Length.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000120 00000121 00000122 00000123 00000124 00000125 00000126 00000127 00000128 00000129 00000130 00000131 00000132 00000133 00000134 00000135 00000136 00000137 00000138 00000139 00000140 00000141 00000142 00000143 00000144 00000145 00000146 00000147 00000148 00000149 MessageBox. try { double[] besterrlist = CCNet. for (int i = 0.Error). MessageBoxIcon. MessageBoxButtons. success = false. MessageBoxButtons.besterrorlist.Add((double)i. } public bool getGraphDataFromDll() { bool success = true. besterrlist[i]). "Error". return success.Show("Error running Cascade training!".BestErrList.OK. i++) { base. MessageBoxIcon.Error). base. "Error". } Page 139 of 225 . } success = getGraphDataFromDll(). } } catch { MessageBox.OK. success = false.

Report(CCNet.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000150 00000151 00000152 00000153 00000154 00000155 00000156 00000157 00000158 00000159 00000160 00000161 00000162 00000163 00000164 00000165 00000166 00000167 00000168 00000169 00000170 00000171 00000172 00000173 } return success.Error). MessageBoxButtons. } catch { MessageBox. return success. try { success = CCNet.Show("Error running Cascade testing!". MessageBoxIcon.OK. } base.Test()._te_output)._Tested = success. } public override bool Test() { bool success = true. "Error". } #endregion } Page 140 of 225 . success = false.

Algorithms { public class GeneticAlgorithm : TrainingAlgorithm { #region data /********************\ |* DATA *| \********************/ //GA Data private int _PopSize. System.1.Collections.Generic.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 9.Controller. //Population Page 141 of 225 .Forms. ZedGraph.Linq.5 .Windows. _05025397.“Algorithms\GeneticAlgorithm.Collections.Text. private int _Crossover. private int _HiddenL.2. System. System. System. private double _OutputL. System. namespace _05025397. //Network Data private double _InputL.cs” 00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000009 00000010 00000011 00000012 00000013 00000014 00000015 00000016 00000017 00000018 00000019 00000020 00000021 00000022 00000023 00000024 00000025 00000026 00000027 00000028 00000029 using using using using using using using using System. private int _Mutation.

int Mutation. out _InputL. _Crossover = Crossover. RichTextBox txtData. for (int i = 0. out _OutputL).Add Page 142 of 225 . _HiddenL = HiddenL. double TargetError. bool ITerr. ITerr) { _PopSize = PopSize. RichTextBox txtTest) : base(TargetError. int HiddenL. Iter_Max. txtTest. int Reports. //Create new population references Population = new ArrayList(_PopSize). i++) { Population. int Iter_Max. i < _PopSize. txtData. Reports. //Init Network params double iterations.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000030 00000031 00000032 00000033 00000034 00000035 00000036 00000037 00000038 00000039 00000040 00000041 00000042 00000043 00000044 00000045 00000046 00000047 00000048 00000049 00000050 00000051 00000052 00000053 00000054 00000055 00000056 00000057 00000058 00000059 ArrayList Population. #endregion #region constructor /********************\ |* CONSTRUCTOR *| \********************/ public GeneticAlgorithm(int PopSize.GetStructure(out iterations. int Crossover. _Mutation = Mutation. getdata.

William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000060 00000061 00000062 00000063 00000064 00000065 00000066 00000067 00000068 00000069 00000070 00000071 00000072 00000073 00000074 00000075 00000076 00000077 00000078 00000079 00000080 00000081 00000082 00000083 00000084 00000085 00000086 00000087 00000088 00000089 (new Model. i < base.Next())). } } #endregion #region internal_functions /********************\ |* INTERNAL *| \********************/ private bool run() { bool success = true. i++) { //Get the msqe for (int j = 0. j++) { ((Model.getMsQE(inputs. double[][] inputs. } //Sort the functions according to fitness now.GANetwork) Population[j]).GANetwork( (int)_InputL. results).IterMax. for (int i = 0. out results). getdata. success = sort_fitnesses(). Page 143 of 225 . j < _PopSize. _HiddenL. Rand.GetScaledTrainingData(out inputs. (int)_OutputL. double[][] results.

"). break. } success = build_generation().TargetError) { Report("\nNetwork matching or improving upon target error"+ "found at iteration [ " + i + " ]. } base.CurIt = 0.Report("Best error at iteration [ " + i + " ] was " + ((Model.\n").GANetwork)Population[0]).BestErrList. //Check for having reached the target if (((Model.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000090 00000091 00000092 00000093 00000094 00000095 00000096 00000097 00000098 00000099 00000100 00000101 00000102 00000103 00000104 00000105 00000106 00000107 00000108 00000109 00000110 00000111 00000112 00000113 00000114 00000115 00000116 00000117 00000118 00000119 //Report if we're at a report iteration //Also update the besterrlist (for graphing) if (base. } private bool sort_fitnesses() { Page 144 of 225 .GANetwork)Population[0]).CurIt++. ((Model.CurIt == ReportInterval) { base. } return success. base.MSqE).MSqE <= base.GANetwork)Population[0]).Add ((double)i.MSqE + ". base.

//It selects two points from the start of the population //Then applies crossover if necessary (based on probability) Page 145 of 225 . } catch { MessageBox. selection2. double[] weightarray_f. try { Population.1).Sort(). i > (int)(_PopSize / 2). int selection1. MessageBoxButtons. MessageBoxIcon. } return success. double[] weightarray1. i--) { //This algorithm is altered from previous versions. for (int i = (_PopSize . } private bool build_generation() { bool success = true.OK. "Error".Error). double[] weightarray2.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000120 00000121 00000122 00000123 00000124 00000125 00000126 00000127 00000128 00000129 00000130 00000131 00000132 00000133 00000134 00000135 00000136 00000137 00000138 00000139 00000140 00000141 00000142 00000143 00000144 00000145 00000146 00000147 00000148 00000149 bool success = true.Show("Error sorting population". success = false.

". "Error". //Then it replaces the last position in the population //(ie. all the way to the middle of the population.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000150 00000151 00000152 00000153 00000154 00000155 00000156 00000157 00000158 00000159 00000160 00000161 00000162 00000163 00000164 00000165 00000166 00000167 00000168 00000169 00000170 00000171 00000172 00000173 00000174 00000175 00000176 00000177 00000178 00000179 //applies mutation if necessary (same again) //then if neither mutation or Xover have been applied //chooses position 1 or 2. //Next iteration it replaces the next to last. selection1 = Rand. if (Rand. //Just a quick error check if (weightarray1. weightarray1 = ((Model.getWeights().Error).Next((int)_PopSize / 2). weightarray2 = ((Model.Next((int)_PopSize / 2).OK. MessageBoxButtons.Length) { MessageBox. success = false.Length].Show("Error: 2D weight array length unequal.Next(100) < _Crossover) { //Choose a random position in the weight array //to be our crossover point Page 146 of 225 . selection2 = Rand.GANetwork)Population[selection1]). the least fit) with this new string. } try { weightarray_f = new double[weightarray1. MessageBoxIcon.Length != weightarray2. and //so on.getWeights().GANetwork)Population[selection1]).

Length .5. } else { weightarray_f[j] = weightarray2[j]. j++) { if (j < XPos) { weightarray_f[j] = weightarray1[j].Length.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000180 00000181 00000182 00000183 00000184 00000185 00000186 00000187 00000188 00000189 00000190 00000191 00000192 00000193 00000194 00000195 00000196 00000197 00000198 00000199 00000200 00000201 00000202 00000203 00000204 00000205 00000206 00000207 00000208 00000209 int XPos = Rand.Length. j++) { weightarray_f[j] += Rand.setWeights(weightarray_f). j < weightarray1.GANetwork)Population[i]).Next(1. j < weightarray_f. } } //Set the weights of the current member of the //population we're on ((Model.NextDouble() . } Page 147 of 225 .Next(100) < _Mutation) { //Jiggle the weights in the array //up or down by 0. } } } if (Rand.0. (weightarray1.5 for (int j = 0. //Simple single point crossover of the weights for (int j = 0.1)).

_Crossover)).Append( string.OK.Append( string. _PopSize)).William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000210 00000211 00000212 00000213 00000214 00000215 00000216 00000217 00000218 00000219 00000220 00000221 00000222 00000223 00000224 00000225 00000226 00000227 00000228 00000229 00000230 00000231 00000232 00000233 00000234 00000235 00000236 00000237 00000238 00000239 catch { MessageBox. } #endregion #region external_functions /********************\ |* EXTERNAL *| \********************/ public override string network_details() { //Add stringbuilder for efficiency here StringBuilder output = new StringBuilder(). "Error". output.Format("\t\t\tCrossover Probability: {0:d}".Append( Page 148 of 225 . output. _Mutation)). MessageBoxButtons.Format("Network Details: \n Population: {0:d}". output.Error). success = false.Show("Error building new generation". output.Append( string. MessageBoxIcon. } } return success.Format("\t\t\tMutation Probability: {0:d}".

base.Format("\nHidden layer: {0:d}".ToString(). base. } public override bool Test() Page 149 of 225 . output.Format("\t\t\t\t\t\t\tIgnore target error (process all iterations): {0}". } public override bool Train() { bool success = true. output.Format("\nReport every {0:d} generations.Append( string. _HiddenL)).Append( string.TargetError)).Format("\t\t\tMaximum Generation: {0:d}".00000}". _ITerr)).Format("\t\t\tTarget Error: {0:0. return output. base.IterMax)). base.Append( string.Append( string._Trained = success. output. return success. output.".ReportInterval)). success = run().William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000240 00000241 00000242 00000243 00000244 00000245 00000246 00000247 00000248 00000249 00000250 00000251 00000252 00000253 00000254 00000255 00000256 00000257 00000258 00000259 00000260 00000261 00000262 00000263 00000264 00000265 00000266 00000267 00000268 00000269 string.

tstinput[i][j])). j++) { output.GANetwork)Population[0]). for (int j = 0. getdata.Append(string.Format(" [{0:g}] ". try { for (int i = 0. i++) { ((Model. j++) { output.Format(" [{0:g}] ".Append("\nWith inputs:"). double[][] tstoutput.Length. i < tstinput. j < tstinput[i]. output.GetScaledTestingData(out tstinput. j < netoutput. out tstoutput). output.GANetwork)Population[0]). } output. for (int j = 0.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000270 00000271 00000272 00000273 00000274 00000275 00000276 00000277 00000278 00000279 00000280 00000281 00000282 00000283 00000284 00000285 00000286 00000287 00000288 00000289 00000290 00000291 00000292 00000293 00000294 00000295 00000296 00000297 00000298 00000299 { bool success = true.Append("\n\n\t\t\t~~Network Testing~~").Length. double[] netoutput.Append("\nOutput achieved was:"). double[][] tstinput. netoutput[j])).GetOutput().Append(string. StringBuilder output = new StringBuilder().Run(tstinput[i]).Length. Page 150 of 225 . netoutput = ((Model.

Show("Error Running Test.getMsQE(tstinput._Tested = success.ToString()). tstoutput[i][j])).Format(" [{0:g}] ". "Error". MessageBoxButtons. MessageBoxIcon. j < tstoutput[i]. ((Model.Append("\nOutput Desired was:").Append("\nMean Squared Error with these inputs and outputs is:"). (double) ((Model. } catch { MessageBox. output.".Format ("{0:g}".Append(string.GANetwork)Population[0]). } #endregion } Page 151 of 225 . } } output.GANetwork)Population[0]). return success.Length.OK.Error).MSqE)).Append( string. success = false. base.Report(output. for (int j = 0. j++) { output. } base.tstoutput).William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000300 00000301 00000302 00000303 00000304 00000305 00000306 00000307 00000308 00000309 00000310 00000311 00000312 00000313 00000314 00000315 00000316 00000317 00000318 00000319 00000320 00000321 00000322 00000323 00000324 00000325 00000326 00000327 00000328 } } output.

System.1. _05025397.2.cs” 00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000009 00000010 00000011 00000012 00000013 00000014 00000015 00000016 00000017 00000018 00000019 00000020 00000021 00000022 00000023 00000024 00000025 00000026 00000027 00000028 00000029 using using using using using using using using using using System.Linq.Algorithms { public class BackProp : TrainingAlgorithm { #region data /********************\ |* DATA *| \********************/ private double _InputL.6 . #endregion #region constructor Page 152 of 225 .Collections. private double _OutputL. ZedGraph. FANN_Wrapper.Collections. System.Controller. FANN_BackProp BPnet.Forms. System. System.Text. System.“Algorithms\BackProp.Windows. namespace _05025397.IO.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 9. System. private double _LearnRate. private int _HiddenL.Generic.

_LearnRate. Reports.TargetError. getdata. int Reports.IterMax). _LearnRate = LearnRate. double iterations. HiddenL. BPnet = new FANN_BackProp((int)_InputL. txtTest). ITerr) { _HiddenL = HiddenL. base. RichTextBox txtTest) : base(TargetError. double TargetError. Iter_Max. out _InputL. int Iter_Max. saveDllData(txtData. out _OutputL). double LearnRate. RichTextBox txtData. base.GetStructure(out iterations. txtTest. bool ITerr. base.ReportInterval. txtData. //Copy the training and testing data to the dat files //ready for the DLL's to access. } #endregion #region internal_functions /********************\ Page 153 of 225 .William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000030 00000031 00000032 00000033 00000034 00000035 00000036 00000037 00000038 00000039 00000040 00000041 00000042 00000043 00000044 00000045 00000046 00000047 00000048 00000049 00000050 00000051 00000052 00000053 00000054 00000055 00000056 00000057 00000058 00000059 /********************\ |* CONSTRUCTOR *| \********************/ public BackProp (int HiddenL. (int)_OutputL.

tw.Append( string.Close(). output.Text). (int) _InputL)). tw. tw = new StreamWriter("dlltedata.Write(tr.dat").Append( string.Format ("\t\t\tOutput Layer: {0:d}". (int) _OutputL)). RichTextBox te) { TextWriter tw = new StreamWriter("dlltrdata. tw.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000060 00000061 00000062 00000063 00000064 00000065 00000066 00000067 00000068 00000069 00000070 00000071 00000072 00000073 00000074 00000075 00000076 00000077 00000078 00000079 00000080 00000081 00000082 00000083 00000084 00000085 00000086 00000087 00000088 00000089 |* INTERNAL *| \********************/ private void saveDllData(RichTextBox tr.Write(te.Append( Page 154 of 225 .dat").Text). output. } #endregion #region external_functions /********************\ |* EXTERNAL *| \********************/ public override string network_details() { StringBuilder output = new StringBuilder().Close(). output.Format ("Network Details: \n Input Layer: {0:d}". tw.

ReportInterval)).William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000090 00000091 00000092 00000093 00000094 00000095 00000096 00000097 00000098 00000099 00000100 00000101 00000102 00000103 00000104 00000105 00000106 00000107 00000108 00000109 00000110 00000111 00000112 00000113 00000114 00000115 00000116 00000117 00000118 00000119 string.TargetError)). base.Format ("\t\t\tTarget Error: {0:0.Format ("\nReport every {0:d} generations. (int) _HiddenL)).".00000}". base.Format ("\t\tMaximum Epoch: {0:d}". output. output.IterMax)).Format ("\t\t\tHidden Layer: {0:d}". _ITerr)).Append( string. return output. output. base.Append( string.ToString().Format ("\t\t\t\t\t\tIgnore target error " + "(process all iterations): {0}".Append( string.00000}".Append( string. } public override bool Train() { Page 155 of 225 . output. _LearnRate)). output.Format ("\nLearning Rate: {0:0.Append( string.

try { double[] besterrlist = BPnet. MessageBoxButtons.Error). Page 156 of 225 . besterrlist[i]). MessageBoxIcon.Train(). success = false. return success. } success = getGraphDataFromDll().BestErrList. i++) { base.Length. for (int i = 0. } public bool getGraphDataFromDll() { bool success = true.besterrorlist._Trained = success.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000120 00000121 00000122 00000123 00000124 00000125 00000126 00000127 00000128 00000129 00000130 00000131 00000132 00000133 00000134 00000135 00000136 00000137 00000138 00000139 00000140 00000141 00000142 00000143 00000144 00000145 00000146 00000147 00000148 00000149 bool success = true. i < besterrlist. } catch { MessageBox._tr_output). Report(BPnet. base.Add((double)i.Show("Error running Backprop training!". try { success = BPnet.OK. "Error".

William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000150 00000151 00000152 00000153 00000154 00000155 00000156 00000157 00000158 00000159 00000160 00000161 00000162 00000163 00000164 00000165 00000166 00000167 00000168 00000169 00000170 00000171 00000172 00000173 00000174 00000175 00000176 00000177 00000178 00000179 } } catch { MessageBox.Error). } return success. "Error". } catch { MessageBox. "Error". MessageBoxButtons._te_output). success = false._Tested = success. MessageBoxButtons. Report(BPnet.Test().Error). MessageBoxIcon.OK. } #endregion Page 157 of 225 . try { success = BPnet. } public override bool Test() { bool success = true. MessageBoxIcon. return success. success = false.Show("Error running Backprop testing!". } base.OK.Show("Error getting graph data from DLL".

Page 158 of 225 . System. namespace _05025397.Model { public class Network { #region data /********************\ |* DATA *| \********************/ //[layer][node][input] protected double[][][] _inputs.3 . _05025397. protected double[][] _outputs.1.Windows.Forms.Generic.1 . protected int _numinputs.1.Text. System. System.cs” 00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000009 00000010 00000011 00000012 00000013 00000014 00000015 00000016 00000017 00000018 00000019 00000020 00000021 00000022 00000023 00000024 using using using using using using System. protected double[][][] _weights.3. protected int _hiddennodes. System. protected int _numoutputs.“Network.Linq.Model 9.Collections.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000180 00000181 } } 9.

i < _hiddennodes.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000025 00000026 00000027 00000028 00000029 00000030 00000031 00000032 00000033 00000034 00000035 00000036 00000037 00000038 00000039 00000040 00000041 00000042 00000043 00000044 00000045 00000046 00000047 00000048 00000049 00000050 00000051 00000052 00000053 00000054 protected Random Rand. _weights[1][i] = new double[_numinputs + 1]. _weights[0] = new double[_numinputs][]. _weights[1] = new double[_hiddennodes][]. i++) { _inputs[1][i] = new double[_numinputs + 1]. Page 159 of 225 . _weights[0][i] = new double[2]. for (int i = 0. _outputs[1] = new double[_hiddennodes]. #endregion #region init /********************\ |* INIT *| \********************/ private void init_inputlayer() { _inputs[0] = new double[_numinputs][]. i++) { _inputs[0][i] = new double[2]. } } private void init_hiddenlayer() { _inputs[1] = new double[_hiddennodes][]. for (int i = 0. _outputs[0] = new double[_numinputs]. i < _numinputs.

} } private void init_bias() { //Input bias for (int i = 0.0. _weights[2][i] = new double[_hiddennodes + 1].0. for (int i = 0. Page 160 of 225 .William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000055 00000056 00000057 00000058 00000059 00000060 00000061 00000062 00000063 00000064 00000065 00000066 00000067 00000068 00000069 00000070 00000071 00000072 00000073 00000074 00000075 00000076 00000077 00000078 00000079 00000080 00000081 00000082 00000083 00000084 } } private void init_outputlayer() { _inputs[2] = new double[_numoutputs][]. i++) { _inputs[2][i] = new double[_hiddennodes + 1]. i++) { _inputs[0][i][1] = 1. _outputs[2] = new double[_numoutputs].0. } //Hidden layer bias for (int i = 0. _weights[0][i][1] = 1. i++) { _inputs[1][i][_numinputs] = 1. _weights[1][i][_numinputs] = 1. _weights[2] = new double[_numoutputs][]. i < _numinputs. i < _hiddennodes.0. i < _numoutputs.

NextDouble(). } } private void init_inputweights() { for (int i = 0. i < _numinputs. i < _numoutputs. i++) { for (int j = 0.NextDouble(). i++) { _inputs[2][i][_hiddennodes] = 1. } } private void init_hiddenweights() { for (int i = 0.0. i < _hiddennodes. i++) { _weights[0][i][0] = Rand.0. _weights[2][i][_hiddennodes] = 1. j < _numinputs. j++) { _weights[1][i][j] = Rand.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000085 00000086 00000087 00000088 00000089 00000090 00000091 00000092 00000093 00000094 00000095 00000096 00000097 00000098 00000099 00000100 00000101 00000102 00000103 00000104 00000105 00000106 00000107 00000108 00000109 00000110 00000111 00000112 00000113 00000114 } //Output layer bias for (int i = 0. } } } private void init_outputweights() Page 161 of 225 .

E. j++) { _weights[2][i][j] = Rand.Pow(Math. i++) { for (int j = 0. i < _numinputs. i < _numoutputs. j < _hiddennodes. -input))). try { //Calculate results for this layer for (int i = 0. } } } #endregion #region internal /********************\ |* INTERNAL *| \********************/ private double sigmoid(double input) { return (1 / (1 + Math. i++) { Page 162 of 225 .0.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000115 00000116 00000117 00000118 00000119 00000120 00000121 00000122 00000123 00000124 00000125 00000126 00000127 00000128 00000129 00000130 00000131 00000132 00000133 00000134 00000135 00000136 00000137 00000138 00000139 00000140 00000141 00000142 00000143 00000144 { for (int i = 0.NextDouble(). double sum = 0. } private bool Runinput() { bool success = true.

MessageBoxButtons. } return success. } _outputs[0][i] = sigmoid(sum). Page 163 of 225 . j < 2. } } catch { MessageBox. } private bool Runhidden() { bool success = true. i++) { for (int j = 0. i < _hiddennodes. j < _numinputs. success = false. sum = 0. try { //Feed forward the results from input layer for (int i = 0.Show("Error processing input layer".Error). j++) { sum += (_inputs[0][i][j] * _weights[0][i][j]). MessageBoxIcon. "Error".William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000145 00000146 00000147 00000148 00000149 00000150 00000151 00000152 00000153 00000154 00000155 00000156 00000157 00000158 00000159 00000160 00000161 00000162 00000163 00000164 00000165 00000166 00000167 00000168 00000169 00000170 00000171 00000172 00000173 00000174 for (int j = 0.0.0. double sum = 0.OK. j++) { _inputs[1][i][j] = _outputs[0][j].

double sum = 0. } } catch { MessageBox.0. MessageBoxButtons. i++) { for (int j = 0. j < _numinputs + 1.0. } return success. i < _hiddennodes. } private bool Runoutput() { bool success = true.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000175 00000176 00000177 00000178 00000179 00000180 00000181 00000182 00000183 00000184 00000185 00000186 00000187 00000188 00000189 00000190 00000191 00000192 00000193 00000194 00000195 00000196 00000197 00000198 00000199 00000200 00000201 00000202 00000203 00000204 } } //Calculate results for this layer for (int i = 0.OK. sum = 0. j++) { sum += (_inputs[1][i][j] * _weights[1][i][j]). "Error". try Page 164 of 225 . success = false.Show("Error processing hidden layer". } _outputs[1][i] = sigmoid(sum).Error). MessageBoxIcon.

MessageBoxButtons. j < _hiddennodes + 1.Show("Error processing output layer". "Error".Error). } _outputs[2][i] = sigmoid(sum).OK. MessageBoxIcon. } Page 165 of 225 . i++) { for (int j = 0. i < _numoutputs. success = false. } return success. sum = 0. j++) { sum += (_inputs[2][i][j] * _weights[2][i][j]).William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000205 00000206 00000207 00000208 00000209 00000210 00000211 00000212 00000213 00000214 00000215 00000216 00000217 00000218 00000219 00000220 00000221 00000222 00000223 00000224 00000225 00000226 00000227 00000228 00000229 00000230 00000231 00000232 00000233 00000234 { //Feed forward the results from hidden layer for (int i = 0. i++) { for (int j = 0. i < _numoutputs. } } catch { MessageBox. j < _hiddennodes. j++) { _inputs[2][i][j] = _outputs[1][j].0. } } //Calculate results for this layer for (int i = 0.

i++) //Each input node has only one real input //and a bias . _inputs[0][i][0] = inputs[i]. MessageBoxIcon. i < _numinputs. Page 166 of 225 . MessageBoxButtons.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000235 00000236 00000237 00000238 00000239 00000240 00000241 00000242 00000243 00000244 00000245 00000246 00000247 00000248 00000249 00000250 00000251 00000252 00000253 00000254 00000255 00000256 00000257 00000258 00000259 00000260 00000261 00000262 00000263 00000264 #endregion #region external /********************\ |* EXTERNAL *| \********************/ public bool Run(double[] inputs) { bool success = true.Error). if(success) success = Runhidden(). } if (success) for (int i = 0.Show("Error: Incorrect number of inputs supplied to NN".Length != _numinputs) { MessageBox. success = false. if(success) success = Runinput().the number of nodes corresponds //to the number of inputs accepted.OK. //The numbers of inputs must match up if (inputs. "Incorrect number of inputs".

//Set network structure descriptors _numinputs = numinputs. int hiddennodes.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000265 00000266 00000267 00000268 00000269 00000270 00000271 00000272 00000273 00000274 00000275 00000276 00000277 00000278 00000279 00000280 00000281 00000282 00000283 00000284 00000285 00000286 00000287 00000288 00000289 00000290 00000291 00000292 00000293 00000294 if(success) success = Runoutput(). //We'll always have 3 layers Page 167 of 225 . } public double[] GetOutput() { //Return the outputs from the //output layer return _outputs[2]. } #endregion #region constructor /********************\ |* CONSTRUCTOR *| \********************/ public Network(int numinputs. int SetRandom) { //Set random number generator Rand = new Random(SetRandom). return success. _hiddennodes = hiddennodes. _numoutputs = numoutputs. int numoutputs.

William Sayers

05025397

Genetic Algorithms and Neural Networks
Milestone 3
00000295 00000296 00000297 00000298 00000299 00000300 00000301 00000302 00000303 00000304 00000305 00000306 00000307 00000308 00000309 00000310 } //Input, Hidden, and Output _inputs = new double[3][][]; _weights = new double[3][][]; _outputs = new double[3][]; init_inputlayer(); init_hiddenlayer(); init_outputlayer(); init_bias(); init_inputweights(); init_hiddenweights(); init_outputweights(); } #endregion }

9.1.3.2 - “GANetwork.cs”
00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000009 00000010 00000011 00000012 using using using using using using using System; System.Collections.Generic; System.Linq; System.Text; System.Windows.Forms; _05025397; System.Collections;

//This class contains Genetic Algorithm specific functions //in addition to the basic feed foward neural net functionality. namespace _05025397.Model

Page 168 of 225

William Sayers

05025397

Genetic Algorithms and Neural Networks
Milestone 3
00000013 { 00000014 00000015 00000016 00000017 00000018 00000019 00000020 00000021 00000022 00000023 00000024 00000025 00000026 00000027 00000028 00000029 00000030 00000031 00000032 00000033 00000034 00000035 00000036 00000037 00000038 00000039 00000040 00000041 00000042

public class GANetwork : Network, IComparable { #region data /********************\ |* DATA *| \********************/ double _MSqE; #endregion #region .NET /********************\ |* .NET *| \********************/ //Interface_Implementation //Return Value Meanings: //-<Zero: x < y //-Zero: x == y //->Zero: x > y public int CompareTo(object a) { GANetwork b; if (a is GANetwork) { b = a as GANetwork; return _MSqE.CompareTo(b.MSqE); }

Page 169 of 225

William Sayers

05025397

Genetic Algorithms and Neural Networks
Milestone 3
00000043 00000044 00000045 00000046 00000047 00000048 00000049 00000050 00000051 00000052 00000053 00000054 00000055 00000056 00000057 00000058 00000059 00000060 00000061 00000062 00000063 00000064 00000065 00000066 00000067 00000068 00000069 00000070 00000071 00000072 return 0; } #endregion #region external /********************\ |* EXTERNAL *| \********************/ public void getMsQE(double[][] inputs, double[][] outputs) { double sum = 0.0; int counter = 0; double[] netoutputs = new double[_numoutputs]; for (int i = 0; i < inputs.Length; i++) { base.Run(inputs[i]); netoutputs = base.GetOutput(); for (int j = 0; j < netoutputs.Length; j++) { sum += (outputs[i][j] - netoutputs[j]) * (outputs[i][j] - netoutputs[j]); counter++; } } _MSqE = (sum / counter); }

Page 170 of 225

William Sayers

05025397

Genetic Algorithms and Neural Networks
Milestone 3
00000073 00000074 00000075 00000076 00000077 00000078 00000079 00000080 00000081 00000082 00000083 00000084 00000085 00000086 00000087 00000088 00000089 00000090 00000091 00000092 00000093 00000094 00000095 00000096 00000097 00000098 00000099 00000100 00000101 00000102 public double[] getWeights() { ArrayList collater = new ArrayList(); //Collect all the weights in an array list //then spit them out as a 1D array of doubles try { for (int i = 0; i < _weights.Length; i++) { for (int j = 0; j < _weights[i].Length; j++) { for (int k = 0; k < _weights[i][j].Length; k++) { collater.Add(_weights[i][j][k]); } } } } catch { MessageBox.Show("Fatal Error collating weights to 1D array", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } return (double[])collater.ToArray(typeof(double)); } public void setWeights(double[] weights)

Page 171 of 225

MessageBoxIcon. i < _weights. j++) { for (int k = 0.Length. k < _weights[i][j].William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000103 00000104 00000105 00000106 00000107 00000108 00000109 00000110 00000111 00000112 00000113 00000114 00000115 00000116 00000117 00000118 00000119 00000120 00000121 00000122 00000123 00000124 00000125 00000126 00000127 00000128 00000129 00000130 00000131 00000132 { //Take a 1D array of doubles and apply //to the correct positions in our weights //array try { for (int i = 0.Show("Fatal Error adding 1D weight array to 3D weight array".Exit(). "Error".Length. wc = 0. MessageBoxButtons. } } } } catch { MessageBox. } } /********************\ |* GETTERS/SETTERS *| \********************/ public double MSqE { Page 172 of 225 .Error).OK. wc++) { _weights[i][j][k] = weights[wc]. j < _weights[i].Length. k++. Application. i++) { for (int j = 0.

int Nhnodes. Noutputs. } } #endregion #region constructor /********************\ |* CONSTRUCTOR *| \********************/ public GANetwork(int Ninputs. int Noutputs. int SetRandom) : base(Ninputs.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000133 00000134 00000135 00000136 00000137 00000138 00000139 00000140 00000141 00000142 00000143 00000144 00000145 00000146 00000147 00000148 00000149 00000150 00000151 } get { return _MSqE.0. Nhnodes. SetRandom) { MSqE = 0. } #endregion } Page 173 of 225 . } set { _MSqE = value.

William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 9. Page 174 of 225 .4 . public: /********************\ |* EXTERNAL *| \********************/ FANN_Cascade(int InputL. { public: /********************\ |* DATA *| \********************/ UnManaged_FANN_CasC* UMWrapper.h" using namespace System. int OutputL.1. using namespace System::Runtime::InteropServices.h" #include "UnManaged_FANN_CasC.1 .DLL Wrapper for FANN functions 9. double LearnRate. namespace FANN_Wrapper { public ref class FANN_Cascade //Managed wrapper for UnManaged_FANN_CasC //which is a C++ interface to the C programmed //FANN dll.4.“FANN_Wrapper.1. double TargetErr.h” 00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000009 00000010 00000011 00000012 00000013 00000014 00000015 00000016 00000017 00000018 00000019 00000020 00000021 00000022 00000023 00000024 00000025 00000026 #pragma once #include "UnManaged_FANN_BackProp.

public: /********************\ |* GETTERS/SETTERS *| \********************/ property String^ _te_output { String^ get() { return gcnew String((wchar_t *) UMWrapper->get_report_test()). int ~FANN_Cascade(void).William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000027 00000028 00000029 00000030 00000031 00000032 00000033 00000034 00000035 00000036 00000037 00000038 00000039 00000040 00000041 00000042 00000043 00000044 00000045 00000046 00000047 00000048 00000049 00000050 00000051 00000052 00000053 00000054 00000055 00000056 int ReportInterval. bool Train(void). Page 175 of 225 . } } property array<double>^ besterrorlist { array<double>^ get() MaxNeurons). bool Test(void). !FANN_Cascade(void). } } property String^ _tr_output { String^ get() { return gcnew String((wchar_t *) UMWrapper->get_report_train()).

} return arout. for(int i = 0. { public: /********************\ |* DATA *| \********************/ UnManaged_FANN_Backprop* UMWrapper. public: Page 176 of 225 .William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000057 00000058 00000059 00000060 00000061 00000062 00000063 00000064 00000065 00000066 00000067 00000068 00000069 00000070 00000071 00000072 00000073 00000074 00000075 00000076 00000077 00000078 00000079 00000080 00000081 00000082 00000083 00000084 00000085 00000086 { int size. public ref class FANN_BackProp //Managed wrapper for UnManaged_FANN_Backprop //which is a C++ interface to the C programmed //FANN dll. array<double>^ arout = gcnew array<double>(size). } } }. i < size. i++) { arout[i] = ar[i]. const double *ar = UMWrapper->get_besterrs(size).

double TargetErr. } } property String^ _tr_output { String^ get() { return gcnew String((wchar_t *) UMWrapper->get_report_train()). } Page 177 of 225 . !FANN_BackProp(void).William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000087 00000088 00000089 00000090 00000091 00000092 00000093 00000094 00000095 00000096 00000097 00000098 00000099 00000100 00000101 00000102 00000103 00000104 00000105 00000106 00000107 00000108 00000109 00000110 00000111 00000112 00000113 00000114 00000115 00000116 /********************\ |* EXTERNAL *| \********************/ FANN_BackProp(int InputL. int HiddenL. int MaximumIteration). int OutputL. bool Test(void). int ReportInterval. bool Train(void). double LearnRate. public: /********************\ |* GETTERS/SETTERS *| \********************/ property String^ _te_output { String^ get() { return gcnew String((wchar_t *) UMWrapper->get_report_test()). ~FANN_BackProp(void).

i++) { arout[i] = ar[i].William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000117 00000118 00000119 00000120 00000121 00000122 00000123 00000124 00000125 00000126 00000127 00000128 00000129 00000130 00000131 00000132 00000133 00000134 00000135 00000136 00000137 00000138 00000139 } } property array<double>^ besterrorlist { array<double>^ get() { int size. array<double>^ arout = gcnew array<double>(size). } return arout. for(int i = 0. Page 178 of 225 . i < size. const double *ar = UMWrapper->get_besterrs(size). } } }.

William Sayers

05025397

Genetic Algorithms and Neural Networks
Milestone 3

9.1.4.2 - “FANN_Wrapper.cpp”
00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000009 00000010 00000011 00000012 00000013 00000014 00000015 00000016 00000017 00000018 00000019 00000020 00000021 00000022 00000023 00000024 00000025 00000026 00000027 00000028 00000029 #include "stdafx.h" #include "FANN_Wrapper.h" namespace FANN_Wrapper { /********************\ |* FANN_BackProp *| \********************/ //Constructor FANN_BackProp::FANN_BackProp(int InputL, int HiddenL, int OutputL, double LearnRate, double TargetErr, int ReportInterval, int MaximumIteration) { UMWrapper = new UnManaged_FANN_Backprop( InputL, HiddenL, OutputL, LearnRate, TargetErr, ReportInterval, MaximumIteration); } //Destructor FANN_BackProp::~FANN_BackProp(void) { if (UMWrapper) { delete UMWrapper; UMWrapper = 0; } }

Page 179 of 225

William Sayers

05025397

Genetic Algorithms and Neural Networks
Milestone 3
00000030 00000031 00000032 00000033 00000034 00000035 00000036 00000037 00000038 00000039 00000040 00000041 00000042 00000043 00000044 00000045 00000046 00000047 00000048 00000049 00000050 00000051 00000052 00000053 00000054 00000055 00000056 00000057 00000058 00000059

//Finalizer FANN_BackProp::!FANN_BackProp(void) { if (UMWrapper) { delete UMWrapper; UMWrapper = 0; } }

//Train bool FANN_BackProp::Train(void) { return UMWrapper->Train(); } //Test bool FANN_BackProp::Test(void) { return UMWrapper->Test(); } /********************\ |* FANN_Cascade *| \********************/ //Constructor FANN_Cascade::FANN_Cascade(int InputL, int OutputL,

Page 180 of 225

William Sayers

05025397

Genetic Algorithms and Neural Networks
Milestone 3
00000060 00000061 00000062 00000063 00000064 00000065 00000066 00000067 00000068 00000069 00000070 00000071 00000072 00000073 00000074 00000075 00000076 00000077 00000078 00000079 00000080 00000081 00000082 00000083 00000084 00000085 00000086 00000087 00000088 00000089 double LearnRate, double TargetErr, int ReportInterval, int MaxNeurons) { UMWrapper = new UnManaged_FANN_CasC( InputL, OutputL, LearnRate, TargetErr, ReportInterval, MaxNeurons); } //Destructor FANN_Cascade::~FANN_Cascade(void) { if (UMWrapper) { delete UMWrapper; UMWrapper = 0; } } //Finalizer FANN_Cascade::!FANN_Cascade(void) { if (UMWrapper) { delete UMWrapper; UMWrapper = 0; } } //Train

Page 181 of 225

William Sayers

05025397

Genetic Algorithms and Neural Networks
Milestone 3
00000090 00000091 00000092 00000093 00000094 00000095 00000096 00000097 00000098 00000099 00000100 } bool FANN_Cascade::Train(void) { return UMWrapper->Train(); } //Test bool FANN_Cascade::Test(void) { return UMWrapper->Test(); }

Page 182 of 225

int _ReportInterval.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 9.h” 00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000009 00000010 00000011 00000012 00000013 00000014 00000015 00000016 00000017 00000018 00000019 00000020 00000021 00000022 00000023 00000024 00000025 00000026 00000027 00000028 00000029 #pragma once #include <iostream> #include <string> #include <sstream> #include <vector> #include <doublefann.3 .4. int _HiddenL.h> #include <fann_cpp. int _OutputL. double _Momentum. { private: /********************\ |* DATA *| \********************/ //Network Structure int _InputL.h> class UnManaged_FANN_Backprop //An interface to the C programmed //FANN dll.1. //Training Parameters double _LearnRate. int _MaximumIteration.“UnManaged_FANN_BackProp. double _TargetErr. //Output for C# Page 183 of 225 .

00000033 00000034 std::vector<double> vecbsterr. 00000031 std::wstringstream te_output. int MaximumIteration). 00000032 wchar_t *wchoutput. 00000048 int ReportInterval. 00000036 00000037 //FANN Data 00000038 struct fann *ann. int HiddenL. 00000056 bool Test(void). 00000052 00000053 //Interface functions 00000054 //accessed from C# 00000055 bool Train(void). int OutputL.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000030 std::wstringstream tr_output. 00000049 00000050 //Destructor 00000051 ~UnManaged_FANN_Backprop(void). 00000057 00000058 public: 00000059 /********************\ Page 184 of 225 . double TargetErr. 00000047 double LearnRate. 00000035 double *bsterr. 00000040 00000041 public: 00000042 /********************\ 00000043 |* EXTERNAL *| 00000044 \********************/ 00000045 //Constructor 00000046 UnManaged_FANN_Backprop(int InputL. 00000039 struct fann_train_data *data.

William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000060 00000061 00000062 00000063 00000064 00000065 00000066 }. const double* get_besterrs(int &size). |* GETTERS/SETTERS *| \********************/ const wchar_t* get_report_train(void). const wchar_t* get_report_test(void). Page 185 of 225 .

int HiddenL. _ReportInterval = ReportInterval. _OutputL = OutputL. int ReportInterval. double LearnRate. Page 186 of 225 .h" #include "UnManaged_FANN_BackProp.1.cpp” 00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000009 00000010 00000011 00000012 00000013 00000014 00000015 00000016 00000017 00000018 00000019 00000020 00000021 00000022 00000023 00000024 00000025 00000026 00000027 00000028 00000029 #include "StdAfx.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 9. bsterr = NULL. double TargetErr. _HiddenL = HiddenL.h" //Constructor UnManaged_FANN_Backprop::UnManaged_FANN_Backprop (int InputL.4.4 . int OutputL.“UnManaged_FANN_BackProp. _LearnRate = LearnRate. } //Destructor UnManaged_FANN_Backprop::~UnManaged_FANN_Backprop() { fann_destroy_train(data). _MaximumIteration = MaximumIteration. data = NULL. int MaximumIteration) { _InputL = InputL. ann = NULL. wchoutput = NULL. _TargetErr = TargetErr.

delete wchoutput. } if (fann_num_input_train_data(data) != _InputL) Page 187 of 225 . success = false.. bsterr = NULL. int reportcounter = 0. } catch(.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000030 00000031 00000032 00000033 00000034 00000035 00000036 00000037 00000038 00000039 00000040 00000041 00000042 00000043 00000044 00000045 00000046 00000047 00000048 00000049 00000050 00000051 00000052 00000053 00000054 00000055 00000056 00000057 00000058 00000059 delete bsterr..dat"). } //Train bool UnManaged_FANN_Backprop::Train(void) { static int firstrun = false. ann = fann_create_standard(3. try { data = fann_read_train_from_file("dlltrdata. _InputL.) { throw(""). double error. _OutputL). bool success = true. wchoutput = NULL. _HiddenL.

success = false. } if (fann_num_output_train_data(data) != _OutputL) { throw(""). } fann_set_activation_steepness_hidden(ann. FANN_SIGMOID). FANN_SIGMOID). //Sigmoid Activation Functions (the same one //the GA uses). success = false. fann_set_activation_function_output (ann. //Standard backprop fann_set_training_algorithm(ann.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000060 00000061 00000062 00000063 00000064 00000065 00000066 00000067 00000068 00000069 00000070 00000071 00000072 00000073 00000074 00000075 00000076 00000077 00000078 00000079 00000080 00000081 00000082 00000083 00000084 00000085 00000086 00000087 00000088 00000089 { throw(""). FANN_TRAIN_BATCH). 1). //Set the learning rate fann_set_learning_rate(ann. 1). //Same range the GA's weights are //initialised too Page 188 of 225 . fann_set_activation_steepness_output(ann. (float) _LearnRate). fann_set_activation_function_hidden (ann.

data). if (reportcounter == _ReportInterval) { tr_output << "Best error at iteration [ " << i << " ] was " << error << ". } } fann_destroy_train(data).\n". if (error < _TargetErr) { tr_output << "\nNetwork matching or improving upon target error" << "found at iteration [ " << i << " ].0). vecbsterr. i++) { //Train one epoch then check the //mean squared error error = (double) fann_train_epoch(ann.". } reportcounter++.push_back(error). 1. 0. i < _MaximumIteration. i = _MaximumIteration + 1. //Training Loop for (int i = 0. reportcounter = 0.0.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000090 00000091 00000092 00000093 00000094 00000095 00000096 00000097 00000098 00000099 00000100 00000101 00000102 00000103 00000104 00000105 00000106 00000107 00000108 00000109 00000110 00000111 00000112 00000113 00000114 00000115 00000116 00000117 00000118 00000119 fann_randomize_weights(ann. Page 189 of 225 .

1). j < _OutputL. j++) { te_output << " [" << data->input[i][j] << "] ". te_output << "\nWith inputs". for (int j = 0. te_output << "\n\n\t\t\t~~Network Testing~~". data = fann_read_train_from_file("dlltedata. j < _InputL. double *error = NULL. return true. for (int j = 0. for (unsigned int i = 0. j++) { Page 190 of 225 . i < fann_length_train_data(data). 0.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000120 00000121 00000122 00000123 00000124 00000125 00000126 00000127 00000128 00000129 00000130 00000131 00000132 00000133 00000134 00000135 00000136 00000137 00000138 00000139 00000140 00000141 00000142 00000143 00000144 00000145 00000146 00000147 00000148 00000149 firstrun = true. } te_output << "\nOutput achieved was". } //Test bool UnManaged_FANN_Backprop::Test(void) { fann_type *calc_out = NULL. i++) { calc_out = fann_run(ann. fann_scale_train_data(data. error = new double[fann_length_train_data(data)].dat"). data->input[i]).

delete error. wcscpy(wchoutput. delete calc_out. return true.str(). tr_output.c_str()). te_output << fann_test_data(ann. Page 191 of 225 . } //get_report const wchar_t* UnManaged_FANN_Backprop::get_report_train(void) { if (wchoutput != NULL) { delete wchoutput.length() + 1]. wchoutput = NULL. } } te_output << "\nMean Squared Error with these inputs and outputs is:". data).William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000150 00000151 00000152 00000153 00000154 00000155 00000156 00000157 00000158 00000159 00000160 00000161 00000162 00000163 00000164 00000165 00000166 00000167 00000168 00000169 00000170 00000171 00000172 00000173 00000174 00000175 00000176 00000177 00000178 00000179 te_output << " [" << calc_out[j] << "] ".str(). j < _OutputL. } te_output << "\nOutput Desired was". } wchoutput = new wchar_t[tr_output. for (int j = 0. j++) { te_output << " [" << data->output[i][j] << "] ".

size().str(). return wchoutput. } wchoutput = new wchar_t[te_output.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000180 00000181 00000182 00000183 00000184 00000185 00000186 00000187 00000188 00000189 00000190 00000191 00000192 00000193 00000194 00000195 00000196 00000197 00000198 00000199 00000200 00000201 00000202 00000203 00000204 00000205 00000206 00000207 00000208 00000209 return wchoutput. wchoutput = NULL. } bsterr = new double[vecbsterr.size()]. } const wchar_t* UnManaged_FANN_Backprop::get_report_test(void) { if (wchoutput != NULL) { delete wchoutput. } //get_besterrs const double* UnManaged_FANN_Backprop::get_besterrs(int &size) { if (bsterr == NULL) { delete bsterr. size = vecbsterr. wcscpy(wchoutput. Page 192 of 225 .c_str()).str(). bsterr = NULL.length() + 1]. te_output.

int _OutputL. 9. i < vecbsterr.clear().5 . i++) { bsterr[i] = vecbsterr[i].4.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000210 00000211 00000212 00000213 00000214 00000215 00000216 00000217 00000218 00000219 } for (unsigned int i = 0.“UnManaged_FANN_CasC.h” 00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000009 00000010 00000011 00000012 00000013 00000014 00000015 00000016 00000017 00000018 #pragma once #include <iostream> #include <string> #include <sstream> #include <vector> #include <doublefann.1. return bsterr.size(). //Training Parameters Page 193 of 225 .h> class UnManaged_FANN_CasC { public: /********************\ |* DATA *| \********************/ //Network Structure int _InputL. } vecbsterr.

int MaxNeurons). 00000043 00000044 //Constructor 00000045 UnManaged_FANN_CasC 00000046 (int InputL. 00000031 00000032 //FANN Data 00000033 struct fann *ann. 00000028 00000029 static std::vector<double> vecbsterr. 00000048 int ReportInterval.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000019 double _LearnRate. 00000020 double _TargetErr. 00000034 struct fann_train_data *data. 00000022 int _MaxNeurons. 00000035 00000036 public: 00000037 /********************\ 00000038 |* EXTERNAL *| 00000039 \********************/ 00000040 00000041 //Destructor 00000042 ~UnManaged_FANN_CasC(void). 00000027 wchar_t *wchoutput. int OutputL. 00000030 double *bsterr. 00000047 double LearnRate. 00000023 00000024 //Output for C# 00000025 static std::wstringstream tr_output. 00000021 int _ReportInterval. 00000026 std::wstringstream te_output. double TargetErr. Page 194 of 225 .

Page 195 of 225 . 00000057 unsigned int max_epochs. unsigned int epochs_between_reports. 00000053 bool Test(void). unsigned int epochs). 00000068 }. struct fann_train_data *train. 00000054 00000055 static int FANN_API Report_Callback 00000056 (struct fann *ann.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000049 00000050 //Interface functions 00000051 //accessed from C# 00000052 bool Train(void). 00000059 00000060 public: 00000061 /********************\ 00000062 |* GETTERS/SETTERS *| 00000063 \********************/ 00000064 const wchar_t* get_report_train(void). 00000058 float desired_error. 00000066 00000067 const double* get_besterrs(int &size). 00000065 const wchar_t* get_report_test(void).

William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 9. double TargetErr. bsterr = NULL. wchoutput = NULL.h" //Static variable declarations std::wstringstream UnManaged_FANN_CasC::tr_output. _ReportInterval = ReportInterval. int MaxNeurons) { _InputL = InputL. std::vector<double> UnManaged_FANN_CasC::vecbsterr.1. _LearnRate = LearnRate. int OutputL. } //Destructor UnManaged_FANN_CasC::~UnManaged_FANN_CasC(void) Page 196 of 225 . _OutputL = OutputL. _MaxNeurons = MaxNeurons.cpp” 00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000009 00000010 00000011 00000012 00000013 00000014 00000015 00000016 00000017 00000018 00000019 00000020 00000021 00000022 00000023 00000024 00000025 00000026 00000027 00000028 00000029 #include "StdAfx.“UnManaged_FANN_CasC. int ReportInterval. double LearnRate.h" #include "UnManaged_FANN_CasC.4. data = NULL. ann = NULL. _TargetErr = TargetErr.6 . //Constructor UnManaged_FANN_CasC::UnManaged_FANN_CasC (int InputL.

William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000030 00000031 00000032 00000033 00000034 00000035 00000036 00000037 00000038 00000039 00000040 00000041 00000042 00000043 00000044 00000045 00000046 00000047 00000048 00000049 00000050 00000051 00000052 00000053 00000054 00000055 00000056 00000057 00000058 00000059 { delete bsterr. } wchoutput = new wchar_t[tr_output. tr_output.c_str()). return wchoutput. } const wchar_t* UnManaged_FANN_CasC::get_report_test(void) { if (wchoutput != NULL) { delete wchoutput. wchoutput = NULL.str(). delete wchoutput. Page 197 of 225 . } //get_report const wchar_t* UnManaged_FANN_CasC::get_report_train(void) { if (wchoutput != NULL) { delete wchoutput.length() + 1]. fann_destroy_train(data). wcscpy(wchoutput. wchoutput = NULL. bsterr = NULL.str().

William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000060 00000061 00000062 00000063 00000064 00000065 00000066 00000067 00000068 00000069 00000070 00000071 00000072 00000073 00000074 00000075 00000076 00000077 00000078 00000079 00000080 00000081 00000082 00000083 00000084 00000085 00000086 00000087 00000088 00000089 wchoutput = NULL.clear(). } //get_besterrs const double* UnManaged_FANN_CasC::get_besterrs(int &size) { if (bsterr == NULL) { delete bsterr.str(). return bsterr. bsterr = NULL. wcscpy(wchoutput. return wchoutput. } bsterr = new double[vecbsterr. for (unsigned int i = 0. } vecbsterr. size = vecbsterr. } wchoutput = new wchar_t[te_output.c_str()).length() + 1]. te_output. i < vecbsterr.str().size()]. i++) { bsterr[i] = vecbsterr[i].size().size(). } Page 198 of 225 .

00000116 00000117 fann_set_quickprop_decay(ann.. 0. 00000096 00000097 try 00000098 { 00000099 data = fann_read_train_from_file("dlltrdata. 00000118 00000119 fann_set_quickprop_mu(ann. _InputL. Page 199 of 225 . _OutputL). 00000111 00000112 fann_set_learning_rate(ann.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000090 //Train 00000091 bool UnManaged_FANN_CasC::Train() 00000092 { 00000093 int reportcounter = 0. (float)_LearnRate). 2. 00000113 00000114 //Some more network customisation here 00000115 //might be nice in future. 00000100 } 00000101 catch(. 00000104 } 00000105 00000106 if (fann_num_input_train_data(data) != _InputL) 00000107 throw("").0).dat"). 00000094 00000095 ann = fann_create_shortcut(2..) 00000102 { 00000103 throw(""). 00000108 00000109 if (fann_num_output_train_data(data) != _OutputL) 00000110 throw("").0).

00000131 00000132 fann_set_activation_function_hidden(ann. FANN_SIGMOID). 00000140 00000141 fann_set_callback(ann. 00000146 } 00000147 00000148 //Callback for reporting 00000149 int FANN_API UnManaged_FANN_CasC::Report_Callback Page 200 of 225 .William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000120 00000121 fann_set_cascade_weight_multiplier(ann. _MaxNeurons. FANN_SIGMOID). 00000139 fann_set_train_stop_function(ann. 00000124 00000125 fann_set_activation_steepness_output(ann. 00000126 fann_set_activation_steepness_hidden(ann. 00000127 00000128 fann_set_learning_rate(ann. 150). 1). FANN_STOPFUNC_MSE). (float) _TargetErr).01f). 1.0. 1). 0. 00000133 00000134 fann_set_activation_function_output(ann. 00000137 fann_set_cascade_output_change_fraction(ann. 00000135 00000136 fann_randomize_weights(ann. 00000142 00000143 fann_cascadetrain_on_data(ann. 1). 00000138 fann_set_cascade_candidate_change_fraction(ann. 00000129 00000130 fann_set_training_algorithm(ann. 0. 0.01f). UnManaged_FANN_CasC::Report_Callback). 00000122 00000123 fann_set_cascade_max_out_epochs(ann. data. 00000144 00000145 return true.0). _ReportInterval. FANN_TRAIN_QUICKPROP). (float) _LearnRate).

". } //Test bool UnManaged_FANN_CasC::Test() { fann_type *calc_out = NULL. 1). } node++. float desired_error. vecbsterr. Page 201 of 225 . struct fann_train_data *train. unsigned int max_epochs. 0. data = fann_read_train_from_file("dlltedata. static int node = 1. return 0. unsigned int epochs_between_reports.push_back(MSqE). if (MSqE <= desired_error) { tr_output << "\nNetwork matching or improving upon target error" << "found at node [ " << node << " ].dat").\n". double *error = NULL. unsigned int epochs) { double MSqE = fann_get_MSE(ann).William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000150 00000151 00000152 00000153 00000154 00000155 00000156 00000157 00000158 00000159 00000160 00000161 00000162 00000163 00000164 00000165 00000166 00000167 00000168 00000169 00000170 00000171 00000172 00000173 00000174 00000175 00000176 00000177 00000178 00000179 (struct fann *ann. tr_output << "Best error at node [ " << node << " ] was " << MSqE << ". fann_scale_train_data(data.

i < fann_length_train_data(data). te_output << "\nWith inputs:". j < _OutputL. } } te_output << "\nMean Squared Error with these inputs and outputs is:". error = new double[fann_length_train_data(data)]. te_output << "\n\n\t\t\t~~Network Testing~~". for (unsigned int i = 0. } te_output << "\nOutput achieved was:". data->input[i]). j++) { te_output << " [" << calc_out[j] << "] ". Page 202 of 225 . j++) { te_output << " [" << data->input[i][j] << "] ". te_output << fann_test_data(ann. j < _OutputL. for (int j = 0. j < _InputL. for (int j = 0. } te_output << "\nOutput Desired was:". for (int j = 0. NULL). i++) { calc_out = fann_run(ann.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000180 00000181 00000182 00000183 00000184 00000185 00000186 00000187 00000188 00000189 00000190 00000191 00000192 00000193 00000194 00000195 00000196 00000197 00000198 00000199 00000200 00000201 00000202 00000203 00000204 00000205 00000206 00000207 00000208 00000209 fann_set_callback(ann. j++) { te_output << " [" << data->output[i][j] << "] ". data).

return true.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000210 00000211 00000212 00000213 00000214 00000215 } delete error. Page 203 of 225 . delete calc_out.

2 . Page 204 of 225 .UML Class Diagram The class diagram on the following pages represents the structure of the various classes within the program and how they are combined together to create a whole.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 9.

William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Page 205 of 225 .

William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Page 206 of 225 .

mit.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 -BackProp Previous Page -CascadeCorrelation 1 FANN_Cascade -UMWrapper +FANN_Cascade(in AllDataToFillAttributes) +Train() : bool +Test() : bool 1 -UMWrapper 1 FANN_BackProp +FANN_BackProp(in AllDataToFillAttributes) +Train() : bool +Test() : bool 1 1 1 UnManaged_FANN_BackProp -_InputL : int -_HiddenL : int -_OutputL : int -_LearnRate : double -_TargetErr : double -_ReportInterval : int -_MaximumIteration : int -_Momentum : double -tr_output -te_output -wchoutput -vecbsterr -bsterr -ann -data +UnManaged_FANN_Backprop(in AddDataToFillAttributes) +~UnManaged_FANN_Backprop() +Train() : bool +Test() : bool UnManaged_FANN_CasC -_InputL : int -_OutputL : int -_LearnRate : double -_TargetErr : double -_ReportInterval : int -_MaxNeurons : int -tr_output -te_output -wchoutput -vecbsterr -bsterr -ann -data +UnManaged_FANN_CasC(in AllDataToAFillAttributes) +~UnManaged_FANN_CasC() +Train() : bool +Test() : bool +Report_Callback(in Attributes) : int 1 1 1 1 FANN_Library 9.Libraries Researched • GALib o Matthew Wall o http://lancet.3 .edu/ga/ o Accessed: 31/10/2008 Page 207 of 225 .

html o Accessed: 31/10/2008 • Flood o Roberto Lopez o http://www. Franklin o http://ieee.cimne.sourceforge.edu/au/~daniel/software/libneural/ o Accessed: 31/10/2008 • Libann o Anonymous o http://www.com/flood/ o Accessed: 31/10/2008 • Annie o Asim Shankar o http://annie.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 • Libneural o D.org/libann/index.net/ o Accessed: 31/10/2008 • FANN (Fast Artificial Neural Network Library) o Steffen Nissen Page 208 of 225 .uow.nongnu.

html Page 209 of 225 .dk/fann/index.4 .stats.uk/pub/PRNN/README.php o Accessed: 31/10/2008 9.uah.math.Datasets • XOR 1 0 1 0 1 1 1 1 0 0 0 0 • • Fishers Iris Data o http://www.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 o http://leenissen.ac.edu/stat/data/Fisher.ox.xhtml Virus Classification o http://www.

and that allows manual adjustment of relevant variables. Build a user-interface for the aforementioned application allowing for easy alteration of appropriate variables. as well as previous research. evaluate training methods for neural networks. Using above application. and the conclusions derived from that evaluation.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 9. Build an application that is capable of training a neural network with a genetic algorithm and with a backpropagation system. Page 210 of 225 . Identify the most effective ways of training neural networks using genetic algorithms. and a document describing its implementation and usage. • • • Deliverable one: A research document describing and detailing the research done for objectives one and two.5 . Research current information on training neural networks using genetic algorithms. Deliverable three: A document detailing and explaining the evaluation of different training techniques.Objectives FINAL YEAR DEGREE PROJECT Project Objectives & Deliverables • • • • • • Research the fields of genetic algorithms and neural networks. and in which cases these methods are suitable. Deliverable two: An application meeting the requirements of objectives three and four.

D.cmu.. Wiley Professional Computing.edu/user/sef/www/publications/cascor-tr.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 10 . G.cmu.com/UploadFile/scottlysle/PassData01142007013005AM/PassData. Bourg. from http://www. Curved trajectory prediction using a self-organizing neural network. January 16).edu/user/sef/www/publications/qp-tr.de/~jbr/Papers/GaNNOverview. Retrieved April 16. (1992). An Empirical Study of Learning Speed in Back-Propagation Networks. (2007. C. S. from Codeproject: www. Chapter 14: Neural Networks.com/KB/recipes/NeuralNetwork_1. 2009.cs. E. (1991). (1859). Neural Network in C++. AI: Neural Network for Beginners pt. (1995). E. M.Works Cited Barber. In D.cs.ps.cmu.aspx Page 211 of 225 . S. S. & G.codeproject.cmu. 2009. AI for Game Developers (pp. Retrieved April 13.. Retrieved April 16. Retrieved April 16. O'Reilly. Passing Data between Windows Forms. Carnegie Mellon: http://www2. 356-358). from C# Corner: http://www. C. Retrieved April 13.aspx Blum. 2009. from School of Computer Science.edu/~chris2d/papers/CED_thesis. M. Davis.ps Fahlman.gz Darwin. (2001). Carnegie Mellon: http://www-2. Graphics processing unit computation of neural networks.aifb. E. 2009. 2009.unm.cs. or the preservation of favoured races in the struggle for life. C. (2006). London: John Murray. J.edu/afs/cs.unikarlsruhe. S. & Seeman. from School of Computer Science. 1. Retrieved April 13.ps Lysle. from http://www.edu/afs/cs. Branke. The Cascade-Correlation Learning Architecture. Bourg. On the origin of the species by means of natural selection. & Lebiere. (1988).pdf Fahlman. 2009. Seeman.csharpcorner. (2004). A.

The perceptron: A probabilistic theory for information storage and organization in the brain. Retrieved April 15. Using C++ Interop (Implicit PInvoke).html Marshall.com/faqs/genalg/genalg. (1943). from MSDN: http://msdn.d. Page 212 of 225 . & Srikanth. (2009). A. 2009. 2009. 2009.asp McCulloch.com/robotcontrol. (1999). Retrieved April 16.aspx Mitchell. (1996).com/en-us/library/system. J.. (1958).William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Marczyk.microsoft. 386-408.backgroundworker.htm Rosenblatt. from generation5: http://www. Massachusetts: MIT Press.UNC-Chapel Hill: http://www. (2004). Psychological Review . Bulletin of Mathematical Biophysics . A logical calculus of the ideas immanent in nervous activity.. (2009). S. B. from http://www. 2009. Retrieved April 15.componentmodel.learnartificialneuralnetworks. Retrieved April 16. from FANN: http://leenissen. M. Retrieved 21 01. Nissen.talkorigins. from MSDN: http://msdn.aspx Microsoft. (1982). & Pitts.unc. 5. (2008).). 115-133. A. W. Robot Control.gz Matthews. V. Invention Report S81-64. 2009. from Computer Science . Microsoft. Stanford University.edu/~marshall/WWW/PAPERS/curve9912. Back-propagation for the Uninitiated.com/en-us/library/2x8kf7zx. Curved trajectory prediction using a selforganizing neural network. 2009. D. Genetic algorithms and evolutionary computation. BackgroundWorker Class. An introduction to genetic algorithms.cs. from Artificial Neural Networks: http://www. Retrieved April 15. 65. Learning Logic.generation5.microsoft. F. Retrieved April 13. 2009.org/content/2002/bp. (2002).ps. (n. Office of Technology Licensing. W. J.dk/fann/ Parker.

html#Contents Werbos.ic. from Imperial College London: http://www. Neural Networks.ac. ZedGraph. PhD. (1974).php?title=Main_Page Page 213 of 225 ..).uk/~nd/surprise_96/journal/vol4/cs11/report. Retrieved 21 01.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Stergiou. Beyond Regression: New tools for prediction and analysis in the behavioral sciences.d. Harvard University. (n. 2009. from http://zedgraph. (1997). P. Retrieved April 15.doc. 2009.org/wiki/index. C. & Dimitrios. S.

Retrieved April 13. 2009.. Graphics processing unit computation of neural networks. (2006).edu/~chris2d/papers/CED_thesis. G. E. M.unikarlsruhe. (1992).aspx Barber. AI for Game Developers (pp. August 6). 356-358). from http://www.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 11 .php/c9855/ Page 214 of 225 . from Codeproject: www. 2009. or the preservation of favoured races in the struggle for life.gz Darwin. S. Wiley Professional Computing. S. Chapter 14: Neural Networks.codeproject.unm.microsoft. P. (2001).com/KB/recipes/Backprop_ANN. from MSDN: http://msdn. O'Reilly. from Codeproject: http://www. A. & Seeman. Retrieved April 13. from Codeproject: http://www.aspx DLL Tutorial for Beginners.aspx Barber. (2007. London: John Murray. Neural Network in C++. AI: Neural Network for Beginners pt. Branke. D. (2002).codeproject. AI: Neural Network for Beginners pt. Retrieved April 13.de/~jbr/Papers/GaNNOverview. Retrieved April 13. Davis. Curved trajectory prediction using a self-organizing neural network. (2006). On the origin of the species by means of natural selection. C.com/Cpp/Cpp/cpp_mfc/tutorials/article.com/KB/cs/GA_ANN_XOR.aspx Blum. from Codeguru: http://www. Bourg. Retrieved April 13. Retrieved April 13.aifb. Bourg.codeproject. 2009.pdf DiLascia. S.com/KB/recipes/NeuralNetwork_1.codeguru. 2009. 2. C.com/enus/magazine/cc301501. (2004). 2009. Call Unmanaged DLLs from C#. Seeman. In D.cs. Killing Processes Cleanly.ps. Retrieved April 13. (1859). (1995).Bibliography Barber. 2009. J. & G. from http://www. 3. AI: Neural Network for Beginners pt. (2006). 1. M. 2009.

S. An Empirical Study of Learning Speed in Back-Propagation Networks.com/p/googlechartsharp/ Lysle.edu/afs/cs.asp Matthews. January 16). Retrieved 21 01. Back-Propagation: CBPNet.edu/~marshall/WWW/PAPERS/curve9912. Retrieved April 16. (1988). from C# Corner: http://www. (2000).asp McCulloch..csharpcorner.cmu. Retrieved 26 01. (n.org/content/2000/xorga. & Lebiere. & Srikanth.com/faqs/genalg/genalg.edu/afs/cs. The Cascade-Correlation Learning Architecture.cs.d.gz Matthews. (1999). 2009.edu/user/sef/www/publications/qp-tr. 2009.ps Fahlman. S.org/content/2002/bp. Retrieved April 15.cmu. A logical calculus of the ideas immanent in nervous activity. generation5..talkorigins. 2009. J.html Marshall.edu/user/sef/www/publications/cascor-tr.UNC-Chapel Hill: http://www.unc. 2009. Retrieved April 16. A.org/content/2000/cbpnet. & Pitts.asp Matthews. from School of Computer Science.com/UploadFile/scottlysle/PassData01142007013005AM/PassData. 2009.cs. 5.). J. E. Curved trajectory prediction using a selforganizing neural network.. (2004).generation5. Retrieved April 16. from http://www.d. W. (1943). Carnegie Mellon: http://www2. 2009. J. W. (n. E. Carnegie Mellon: http://www-2. Page 215 of 225 . from generation5: http://www. from School of Computer Science. J.). from XORGA: http://www. Retrieved April 13. Passing Data between Windows Forms. Back-propagation for the Uninitiated. 2009.ps. (1991). (2007. S. 2009. (2002).cs. Retrieved April 15.cmu. V. Retrieved April 15. C. Genetic algorithms and evolutionary computation. from generation5: http://www.generation5.ps GoogleChartSharp.google.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Fahlman. 115-133.aspx Marczyk. 2009. from Computer Science .cmu. Bulletin of Mathematical Biophysics .generation5. A. from http://code.

BackgroundWorker Class. B. from FANN: http://leenissen. 2009.). Reference Manual.componentmodel. Massachusetts: MIT Press. S.microsoft.d. 2009. (2008). 1990 IJCNN International Joint Conference on .backgroundworker.com/en-us/library/2x8kf7zx. from FANN: http://leenissen. (n.html#fann_train_enum Nissen. from FANN: http://leenissen. (n. Retrieved April 16. (2009). 2009. Nguyen. S. Invention Report S81-64.com/robotcontrol.d. M. from Datatypes: http://leenissen. Retrieved April 15.aspx Mitchell.dk/fann/ Nissen.).). 2009. Retrieved 21 01. Retrieved 21 01.html Nissen.d. 2009. (1990). An introduction to genetic algorithms. Robot Control. S.. 2009.dk/fann/html/files/fann-h.learnartificialneuralnetworks. D.). from Artificial Neural Networks: http://www.dk/fann/fann_1_2_0/r1597. Retrieved April 16.d. (n. (n. Retrieved 21 01.html Nplot Charting Library for . Nissen.com/en-us/library/system. struct fann_train_data. (n. B. Office of Technology Licensing. from MSDN: http://msdn. 2009.org/nplot/wiki/ Parker. D. & Widrow. Retrieved 21 01.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Microsoft.).d. Stanford University.d. Improving the learning speed of 2-layer neural networks by choosinginitial values of the adaptive weights. (1982). struct fann.aspx Microsoft. (1996). S. Neural Networks. Using C++ Interop (Implicit PInvoke). Retrieved 21 01. 21-26. (2009). from MSDN: http://msdn. from http://netcontrols.NET. 1990. 2009. S.dk/fann/html/files/fann_data-h.microsoft. (n.dk/fann/fann_1_2_0/r1837.).. Learning Logic. Retrieved 26 01. 2009.htm Page 216 of 225 . from FANN: http://leenissen.html Nissen.

.......William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Rosenblatt....The initial state of a cascade correlation neural network.... (1958)............ 30 Figure 6 ..... 386-408..... & Dimitrios.. 10 Figure 2 ....... 12 Figure 3 .Table of Figures Figure 1 ............d.. 13 Figure 4 ............. Beyond Regression: New tools for prediction and analysis in the behavioral sciences......................... ............. 27 Figure 5 ...... Psychological Review ......The sigmoid function shape .........php?title=Main_Page 12 ............. Retrieved 21 01.................. 2009.....org/wiki/index.................................. ........ (1997)............ S..Tables 12............................... The perceptron: A probabilistic theory for information storage and organization in the brain. 65... 1991).uk/~nd/surprise_96/journal/vol4/cs11/report.. from http://zedgraph...................... C. P.... (n.)..........An artificial neuron .......... 35 Page 217 of 225 ......................... (1974).A feed-forward neural network .html#Contents Werbos................. Harvard University........ The circular connections are adjustable weights (Fahlman & Lebiere........local optimum (units are undefined in this case).. from Imperial College London: http://www. Stergiou........... 2009..........doc...............ac............ Retrieved April 15....A human neuron . Neural Networks... F..................ic........ The Cascade-Correlation Learning Architecture.................. ZedGraph.......................... PhD........1 .....................

................................................................. 47 Figure 20 .................... A first node has been added..........................................................................................Design of the training algorithm tab (Wizard form) ..........Learning Algorithm tab ............ 51 Page 218 of 225 .......................................................Dataset display design (About form) ....................... 36 Figure 9 – Network and output tab design (Main form) ..About form design (About form) ....... 1991).. 44 Figure 14 ................. The CascadeCorrelation Learning Architecture............ 48 Figure 21 ......................Licenses display design (About form) ....................................................................................... 42 Figure 11 ....................... 43 Figure 13 ................................... 1991)..........................Dataset selection tab design (Wizard form)......... 35 Figure 8 .......................................................Design of the network settings tab (Wizard form) ...................................The second state of a cascade correlation neural network...................William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Figure 7 ........................Network and Output tab..........................................Mean squared error tab design (Main form) .................. 45 Figure 17 .......Mean squared error graph tab .... 41 Figure 10 ........The dataset tab ........................ ................................ The square connections are locked weights(Fahlman & Lebiere......... 45 Figure 16 ..........................................Dataset tab design (Main form) .......... 46 Figure 19 .. The Cascade-Correlation Learning Architecture. 46 Figure 18 ...............Working form design (Working form) .....................Network Settings tab..... 50 Figure 23 ...... with two nodes added (Fahlman & Lebiere....................The third state of a cascade correlation neural network........ 42 Figure 12 ................................................................................ 49 Figure 22 ........................................ 44 Figure 15 ..........

.....................Table of Equations Equation 1 ............ 64 Figure 33................... 68 12.............. Licenses view .................. main view .... as defined in the graph above....................................................... 67 Figure 36 ...............About form..................................Number of iterations to achieve target (Viruses) ... 61 Figure 30 ... 62 Figure 32 ............................................................ 2004). 51 Figure 25 ........................................................Summation of the inputs and weights ......................The mean squared error at testing (Iris data) ....... 52 Figure 26 ....................... ................................. Datasets view ..................... 53 Figure 27 ........2 .. 21 Page 219 of 225 .........................About form.......................................... 67 Figure 37 ..............Mean squared error upon last training test (Iris data) .... 65 Figure 35 .A sigmoid function(Bourg & Seeman.......................................Mean squared error upon last training test (XOR) ....Mean squared error upon last training test (Viruses)...........................................Mean squared error at testing (Viruses).....William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Figure 24 .............. 54 Figure 28 ........................ 2002) . In this example “y” is the function output and “t” is the function input........ 64 Figure 34.....................Dataset tab ... 12 Equation 2 .......... 61 Figure 31 ...................................Number of iterations to achieve target (XOR) ........................The mean squared error at testing (XOR)...................................Working form ................................ 54 Figure 29 ...............Number of iterations to achieve target (Iris data) .................................................. 13 Equation 3 – The delta rule(Matthews... Back-propagation for the Uninitiated.................About form.....................

..The partial derivative of ’s’ (Fahlman & Lebiere.......... 21 Equation 7 ... 22 Equation 8 .......... ‘f'p’ is the derivative for pattern 'p' of the candidate unit's activation function with respect to the sum of it’s inputs and ‘Ii....Altered delta calculation rule for the output layer(Matthews.... Backpropagation for the Uninitiated.................... 2002).................................................................differentiated sigmoid function (Matthews............... 2002) ...................... 15 Table 2 ............ 21 Equation 5 ..... 1991).................Altered perceptron learning rule (Matthews.................................. Back-propagation for the Uninitiated........................... 34 Equation 10 .............................. 'p' is the training pattern....................... Back-propagation for the Uninitiated.... 1991)........................................ 33 Equation 9 ......3 ............ Backpropagation for the Uninitiated. The Cascade-Correlation Learning Architecture............................................ 34 12.................................... 59 Table 3 ............ The CascadeCorrelation Learning Architecture...........The partial derivative of ‘s’ with respect to each of the candidates incoming weights ‘wi’...................................... 'v' is the candidate unit's value........ 21 Equation 6 ............................................................... where ‘oo’ is the sign of the correlation between the candidates value output ‘o’...p’ is the input the candidate receives from unit ‘i’ for pattern ‘p’...The statistical approach to deciding relevant data ................Genetic Algorithm testing data (XOR) ............The definition of 's' given that 'o' is the network output at which the error is measured........Back-propagation testing data (XOR)................................................ 2002)................. 59 Page 220 of 225 ... ........................... ..........................................................Table of tables Table 1 ................................. the quantities ‘`v ’ and ‘`Eo’ are the values of v and Eo averaged over all patterns (Fahlman & Lebiere.............................Altered delta calculation rule for the hidden layer(s) (Matthews................. 2002) ...................William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Equation 4 ................................

.....................................................Cascade Correlation testing data (Viruses) .... 66 Table 10 .........Cascade Correlation testing data (XOR) .................... 63 Table 8 .................William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Table 4 ............................................Genetic algorithm testing data (Iris data) .................Cascade correlation testing data (Iris data) ......................................Genetic Algorithms testing data (Viruses) ................. 63 Table 6 ...........................Back-propagation testing data (Iris data) ...................................... 66 Table 9 ...................... 60 Table 5 ...................... 63 Table 7 ........................Back-propagation testing data (Viruses) .... 66 Page 221 of 225 ....................................

o Decided on XOR as a starting point. o Submitted objectives. 17/10/2008 o Investigating more deeply into journals based on research already conducted. back-propagation network was running and learning XOR. o Decision made to adjust the weights of the neural network during training as opposed to using a genetic algorithm to establish network structure. • 24/10/2008 o University computers were down so code demo was impossible. however.Diary • 01/10/2008 – Research progress satisfactory.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 13 . o Agreed on further investigation into GALib and genetic algorithms. • 31/10/2008 o First presentation complete and ready o References building up o Project plan complete • 10/11/2008 o Presentation went well o Progress satisfactory • 14/11/2008 o Discussed document formatting and layout Page 222 of 225 . • 10/10/2008 o GALib decided as a genetic algorithm starting point o Further non-web references as a goal • • 16/10/2008 o Investigation into various neural network libraries taking place.

• • • • • • • • • 19/11/2008 o Milestone one submitted successfully.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 o Progress satisfactory. 13/02/2009 o Have decided to extend the project by including cascade correlation learning algorithm and comparison to genetic algorithms. 21/11/2008 o Progress satisfactory 28/11/2008 o Progress satisfactory 05/12/2008 o Progress satisfactory 12/12/2008 o Progress satisfactory 09/01/2009 o Progress satisfactory 16/01/2009 o Progress satisfactory 23/01/2009 o Progress satisfactory 30/01/2009 o Milestone two has been successfully submitted o Started investigating other areas to explore outside of project requirements. o Progress satisfactory • 20/02/2009 o Progress satisfactory Page 223 of 225 . • • 06/02/2009 o Still exploring extra areas for project to cover.

o Have started report • 02/04/2009 o Main problems experienced with genetic algorithm seem related to memory leaks. o Report satisfactory • 05/04/2009 o Further work on user interface needed o Finish C# genetic algorithm code (C++ code does work but is very slow) o Report satisfactory • 06/04/2009 o C# genetic algorithm code is complete.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 • • • • 27/02/2009 o Progress satisfactory 06/03/2009 o Project progress delayed by other coursework 13/03/2009 o Project progress delayed by other coursework 20/03/2009 o Project progressing. have decided to implement in managed language (C#) to try to solve this o Report continues satisfactorily • 04/04/2009 o To do: About box Add dataset notes Decided on virus classification as a third dataset via the custom dataset functionality. catch-up time for previous two weeks will be used over Easter break. is much faster (fixed several bugs along the way) and retains none of the problematic memory leaks. Page 224 of 225 .

Page 225 of 225 . o Report satisfactory.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 o Report satisfactory • 10/04/2009 o Fully functional project – commencing report.

Sign up to vote on this title
UsefulNot useful