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

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

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

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

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

........ ……………………………….... ……………………………….......... and I fully realise the consequences of plagiarising any of these sources...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... the work described within this project is the result of the investigation carried out by myself.............. Page 9 of 225 .......... has been submitted in candidature for any other award other than this being presently studied.... Student Name (Printed) Student Signature Registered Scheme of Study Date of Signing ……………………………….................... except where specific reference is made.. ………………………………..... Any material taken from published texts or computerised sources have been fully referenced.. nor any part of it........

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

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

A specific input accepts a data item (usually a binary digit. or one (activated) if the summed products are above a certain 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 stepping function can be used which will output zero (or non-activated) if the summed products are below a certain value. ℎ = × ℎ Equation 1 . real number.An artificial neuron The system devised with these components is as follows.Summation of the inputs and weights The next stage depends on the activation function chosen. Page 12 of 225 . or integer). Alternatively. 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. The activation function accepts this stored value.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Figure 2 .

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

of “n” nodes. when Werbos (Werbos. 2. 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.Advantages Neural networks make possible or practical many things that with conventional solutions would be extremely difficult. 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 .3. 1992). (Blum.3 . 1974) discovered the back-propagation algorithm (independently rediscovered by Parker in 1982 (Parker.Advantages and Disadvantages of Neural Networks 2. taking Page 14 of 225 .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. Werbos discovered the algorithm whilst working on his doctoral thesis in statistics and called it “dynamic feedback”. A good example of this is that neural networks have been implemented to run on architecture originally designed for processing three dimensional computer graphics. used on this architecture they become an extremely fast as well as flexible tool. 1982)). The next major advancement in neural networks was not until 1974. where “n” is an undefined number. Back-propagation allows for the training of multilayer perceptrons and in particular. Parker discovered it independently in 1982 whilst performing graduate work at Stanford University in the United States of America and called it “learning logic”. perceptrons with “n” hidden layers.

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 . Neural networks can excel at determining what data in a particular set is relevant. 3 Run the formulated model. 5 Build a system that incorporates what we have learned. to attempt to provide a more robust post-training network. 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. 4 Analyze the results. where explaining why you have arrived at a particular diagnosis is an important part of the process.2 .The statistical approach to deciding relevant data”. in fact.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. Page 15 of 225 . 2001). This is a large disadvantage in areas such as medical diagnosis. 2. noisy data is utilised during training upon occasion. Table 1 . 1 Decide on relevant data.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.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 Formulate a statistical model.3.

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. After the neural network’s training was complete. The training times on neural networks can also be a disadvantage. A classic example is that in the 1980s. a sunny day. 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. Page 16 of 225 . All the photographs with tanks were from a cloudy day and all the images without. there is no formal methodology with which to choose the architecture. Therefore. or even to verify the quality of the training. the US military wanted to use a neural network to analyse images and determine whether they contained a concealed tank.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. only to find that on this round of testing. A tool used to solve heuristic problems. 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. the network came up with apparently random answers. asked to differentiate between the two sets of pictures. requires largely heuristic construction and preparation. then a further one hundred images without. it can also be hard to tell how well (or how badly) trained a neural network is. Eventually the original data set was re-examined. with and without tanks. for obvious purposes. the network had trained itself to recognise whether the sky was cloudy or not. Fifty pictures of each set were set aside and the neural network trained with the remaining one hundred images with and without tanks. train the neural network. When using neural networks is that.

Testing may then take place with the “testing” set to determine accuracy with unseen 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 network training first takes place using the appropriate “training” set. 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.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.4 .1 . 2. the more accurate and in line with expectations and desires. This drawback is however one that is generally universal to computing (and many other areas) often referred to as “GIGO” or “Garbage in. Garbage out”. Fortunately since neural networks are (as has been mentioned above) good at ignoring irrelevant data. the usual best approach is to simply feed them as much data as can be obtained. lies in their ability for generalisation. Page 17 of 225 . The more time spent training the neural network on quality data sets. or it does exacerbate the problem with the time spent training the neural network. covering as many relevant situations as possible.Neural Networks in Medicine There is a large amount of research now covering the applications of neural networks in medicine. “training” and “testing”. One of the main research areas is using neural networks to recognise diseases/conditions via scans.Current Applications of Neural Networks 2. Data sets for training neural networks generally separate into two sub-sets. The real strength of neural networks.4. this has to be done within reason however. the eventual result will be. in the opinion of the author.

Credit scoring. thus supplying information more or less directly linked to the airlines main income.2 . 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). for example the human cardio-vascular system. mortgage screening. can fit very well into most business situations.Neural Networks in Business Neural networks. research on using neural networks to diagnose diseases took place. being good at analysing patterns and predicting future trends.4. 1997) Page 18 of 225 . merely a variety of scans covering all possible permutations of the disease or condition. 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. (Stergiou & Dimitrios. A back-propagation neural net is integrated with the airline marketing tactician which monitored and recommended on booking for each flight. In the 1980s. (Stergiou & Dimitrios. and assessing borrowers have all incorporated neural networks as an integral part of the system. You can also use the technology to model parts of the human biological system in order to better understand it.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. 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. 1997) 2. However.

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

Assign responsibility to each of the neurons in the previous level. 2. allowing us to apply our learning algorithm.1 -“Network.5 .1.Back-propagation 2. This is far preferable to having to perform lengthy and expensive re-calibrations on any regular basis (Robot Control.1. This rule essentially describes adjusting the weight using the difference between the expected and actual outputs. Adjust the weight of the neurons to minimise the responsibility.5.cs” lines 130-133.1 . The sigmoid function is in the source code at 9.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 themselves. The advantage of using a function like this is that it allows us to differentiate how close we came to the correct result. A commonly used function is the sigmoid function as described in section 2.2 -The Artificial Neuron. Page 20 of 225 . 2008). 2. 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.3.Back-propagation overview In essence. In order to use a back-propagation training algorithm you must have a non-linear activation function for your artificial neuron.2 .5. based on the strength of the weights connecting them to the output neurons. 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.Back-propagation in depth In a single layer neural network (or with a single node) the perceptron rule is applicable. Adjust the weight of the output neurons to lessen the error.

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

it is possible to “breed” solutions to problems. 2002) As demonstrated above. Natural selection (Darwin. although as it turned out I did not).3 . it is fast. FANN) The FANN library (see (9.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Equation 7 . against which to compare the genetic algorithm trained neural network. in a language that can be linked to C# fairly easily and it also supports cascade neural networks. 1859) Page 22 of 225 .Altered delta calculation rule for the hidden layer(s) (Matthews. Back-propagation for the Uninitiated.The FANN neural network library (Nissen.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.5. to calculate the delta for a hidden layer requires the deltas for the following layers. 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.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. open-source (allowing me to alter it if I needed too. By using similar techniques to natural selection. The FANN library was decided upon for several reasons. saving me finding a separate library.6 . easy to implement. 2. in order to apply this learning mechanism you start at the output of the network and work your way towards the inputs. Most organisms evolve by means of sexual reproduction and natural selection (Darwin.Back-propagation library 2. Therefore.7 . 2.

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

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.Advantages and Disadvantages of Genetic Algorithms 2. The real advantage of parallelism however is that by evaluating the relatively small search-space that it does. 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. methods.7.2.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. proceeding with other more likely candidates. 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. more conventional. These are “non-linear” Page 24 of 225 .2 . a genetic algorithm is implicitly evaluating a much larger group of individuals. or further up the hierarchy. with processing power exponentially dedicated to better areas as the exploration progresses. in the same way that the average response of a relatively small percentage of the population of any given country. abandon that search. Thanks to the parallelism that is a genetic algorithms main advantage.Advantages The primary advantage of genetic algorithms is their inherent parallelism. 2004).7. Genetic algorithms effectively explore many different branches of the tree at once and when a certain branch turns out to be non-optimal. 2004) 2. can be used to fairly accurately predict national trends.1 . This leads to the exploration of a large proportion of the search space. (Marczyk.

A good example of this is the concept Page 25 of 225 . A third advantage of genetic algorithms is that they do not tend to be easily trapped by local optima. the random nature of the various starting points of the initial population and the other methods they employ. Many real life problems are not like this. One of the largest strengths of genetic algorithms can at first glance appear to be their largest weakness. it is hard to know whether we have reached the global optimum. Genetic algorithms have no prior knowledge about the problem they are trying to solve. 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. Selection allows the pruning of the least promising searches. However. due to their strength in navigating large search spaces (Marczyk. 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. such as crossover and mutation. making genetic algorithms an effective way to search them. or never contained in their search space in the first place. crossover allows promising solutions to share their success and mutation allows random changes in the local search space of a given solution. or merely very good local optima. In infinite or very large search spaces. In a linear problem. due again to the parallelism of their approach. each component’s fitness is individual and any improvement to individual component's fitness is necessarily an improvement to the whole. selection and mutation a genetic algorithm is metaphorically similar to a large number of parallel depth first algorithms. 2004). genetic algorithms tend to give good results compared to other search strategies.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 problems. 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. each searching their own space for the best solution.

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

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

1 . to test the appropriateness of a given genome. however. There are methods to try to avoid this problem when using back propagation.Determining Weight Values with Genetic Algorithms Genetic algorithms (as described in 2.Representation of a Neural Network within a Genetic Algrithm As a rule.8 . not altering them besides that in any way. a neural network representation within a genetic algorithm is a concatenation of all the weighs in the neural network. since you are merely increasing the size of the genomes being worked with.7 -Genetic Algorithms) are good at avoiding being stuck on local optima due to their searching several regions of search space simultaneously. In addition. 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.5 -Back-propagation) which is a gradient descent algorithm and as such can be easily trapped in local optima (Branke.2 . these are not a complete solution (Blum. 1995). 1992).7 -Genetic Algorithms). however the method of choice for training neural networks is usually back propagation (see 2. Page 28 of 225 . to try to help it move beyond local optima.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 2.8. 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. the only information genetic algorithms require to train a neural network is an objective function (as described in 2.Training Neural Networks with Genetic Algorithms Training neural networks is a form of problem solving.8. such as adding a “momentum” to the algorithm. 2.

outputs to inputs.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. 1995). Standard genetic algorithms use binary strings. 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. The average neural network has an input layer. 2. side by side). it is also possible to use a genetic algorithm to evolve a structure for a neural network. Page 29 of 225 . The problem at hand dictates the input and output layer structures.3 . a nodes input weights and the nodes of a layer. to form a feed forward network. one or two hidden layers of an indeterminate number of nodes and one output layer.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Crossover can disrupt genes far apart.8. however representing a large number of real valued numbers as a binary string.e. These are all connected. but is less likely to do so for genes close together. Because of this it is helpful to keep functional units close together (I. can lead to very large strings (thousands of bits) (Branke. place a neurons input and output weights.

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

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.8. you must remove all connections to or from that node completely. In one version of high level encoding of a neural network. the strong.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. Ideally. thus eliminating the searching of meaningless space and by definition. the genetic algorithm represents the neural network by means of its connections. an exception is possible. Page 31 of 225 . whereas high-level encodings group together connections and/or nodes. or high-level encoding (Branke. being able to contain the most optimum solution for the problem at hand. indirect. 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. Back propagation learning rate is also a parameter for one of these areas. or low-level encoding and the weak. 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). Low-level encodings specify each connection individually. thus meaning that in order to remove a node completely. In direct encoding. a representation is required which can accommodate all networks that will work for the problem but none that will not.1 . 1995). direct.3.

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

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

p’ is the input the candidate receives from unit ‘i’ for pattern ‘p’.The partial derivative of ’s’ (Fahlman & Lebiere. a gradient descent to maximize "s" can take place. Page 34 of 225 . 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. Expansion and differentiation of this calculation can then take place. . ‘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’. Adjustable weights link the outputs for this node and all the output nodes inputs. The Cascade-Correlation Learning Architecture. or the completed training epochs reaches a maximum level. and the inputs for that node are frozen. The training iterations for these adjustable weights in the main network then continue.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Equation 9 . −` ′ . where ‘oo’ is the sign of the correlation between the candidates value output ‘o’. = . 1991). After these computations are complete. Equation 10 .

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

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

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

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

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

5 -Back-propagation.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 3.2. 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. out of three choices previously mentioned (2. Page 43 of 225 .4.2 .4. It allows you to move in a logical progression through the set up process of a new neural network and associated training algorithm.4.Learning Algorithm tab On the learning algorithm tab you select the learning algorithm for the neural network you are creating. 2.Network Settings tab This tab allows you to set appropriate settings for the network and training algorithm you have selected in 3.2.New Network Wizard The new network wizard is the form that appears when the user selects the creation of a new network.1 . 3.2. the default is genetic algorithm).4. Figure 12 .2 .7 Genetic Algorithms.9 -Cascade Correlation).1 -Learning Algorithm tab (if no algorithm has yet been selected. 2. 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.Design of the training algorithm tab (Wizard form) 3.

William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 Figure 13 . Page 44 of 225 . or to choose custom data sets from your hard disk for training and testing data (appropriately formatted in the FANN style).Dataset tab The dataset tab allows you either to select from two pre-setup datasets. Figure 14 .2.4.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.4.3 .Dataset selection tab design (Wizard form) 3.3 .Design of the network settings tab (Wizard form) 3. both to protect the main form from data inputs that may cause training problems and to provide a visual indicator of work taking place.

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

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

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

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

1.Dataset tab Figure 21 .3 .The dataset tab Page 49 of 225 .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

10 -C# User Interface Programming) via events and delegate functions.5 .1. Licenses view 4.2 .3.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. Page 54 of 225 .4 .1.Licenses View Figure 27 .About form.Working Form Figure 28 .1.Working form 4.

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

2 -“GANetwork.cs” lines 51-126) 4.Back-propagation and Cascade Correlation Implementation The FANN library implements both cascade correlation and back propagation (Nissen. FANN) which is a C programming language based neural network library. The compilation of the FANN library is static.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.3 Page 56 of 225 .2.5 “Algorithms\GeneticAlgorithm. and the Dll linked to this to allow access to the functionality. Once this implementation was complete. and didn’t suffer from the memory leaks (being managed code) so that’s the version that exists in the application today (see 9.1.2 -“GANetwork. when the C++ implementation of genetic algorithms that I wrote functioned. The neural network specific functionality added to the network model in the network specialisation class GANetwork (see 9. 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++.cs” lines 32-44).3.2 .4.1.2.1.2.NET sort methods in the sorting part of the genetic algorithm).NET built in functionality (see 9.1 .1. I decided to try re-implementing it in C#.5 -“Algorithms\GeneticAlgorithm. • • The sorting implementation in GANetwork.1.cs that links into the .3. it was both faster than the C++ implementation (due mostly to my use of build in .cs” lines 176204). but had issues with memory leaks and was slow. There is an unmanaged C++ wrapper (9.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 4. Therefore.

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

The target error was 0. there are three functions. 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. The genetic algorithm and back-propagation neural networks each had four hidden nodes for each dataset.1 . to run the output layer.01 for XOR and 0. Page 58 of 225 . input layer. recording took place for analysis.4 -Datasets) (ten times for XOR. All nodes determine their outputs using the sigmoid function (lines 130-133). 3.02 for Fishers iris data and the virus classification data.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). I tested the neural network implementation by creating a neural network with structure 2. 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. 1. 5.Testing Data Testing took place several times for each algorithm and dataset (see 9. the dataset is too small to split. 5 . As the program presented the data in each case. so repetition is instead used. five times for Virus classification and Fishers iris data).XOR In the XOR dataset.

Back-propagation testing data (XOR) Page 59 of 225 .00983181 0.00998027 0.006150786 0.2 .009829335 0.00957518 0.009888967 0.009829335 0.009566951 0.00957518 0.009248076 0.0099765 0.5 Result MSqE (GA) 0.1.00988863 0.009162436 0.009375132 0. Iterations (BP) 345 287 319 327 301 323 421 315 362 325 332.00997699 0.Genetic Algorithm testing data (XOR) 5.00995716 0. because of floating point inaccuracies converting between double precision floating-point numbers in my code and single precision in the FANN code.00881867 0.009888967 0.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 5.00881867 0.00990161 0.00987211 0.0098402 0.009375132 0.5 Result MSqE (BP) 0.009157809 Table 2 .00991907 0.009962559 0.009566951 0.009969323 Testing MSqE (BP) 0.00998032 0.006150786 0.00992081 0.Genetic Algorithms Iterations (GA) 591 407 500 466 499 534 675 557 357 939 552.1 .00990403 0.00992291 0.00998959 0.009962559 0.00999799 0.009248076 0. the mean squared error from the network result and the testing mean squared error are different despite the data being the same.00989974 0.00988649 0.009885499 Table 3 .00999069 0.Back-propagation In the back-propagation testing data.0099113 0.009162436 0.1.009157809 Testing MSqE (GA) 0.

99E-13 1.43545E-13 Table 4 .Cascade Correlation testing data (XOR) Page 60 of 225 . which is when the program records the mean squared error.78E-14 1.18E-13 7. At each node addition.Cascade Correlation In the cascade correlation data.22E-13 1.14E-14 2.32E-13 2. Nodes (CC) 2 2 2 2 2 2 2 2 2 2 2 Result MSqE (CC) 0.83E-13 2.3 . but in the case of cascade training.0086449 0.00863005 0.86E-14 1.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 5.02E-13 2.008039565 Testing MSqE (CC) 7.1.00855044 0.00656719 0.00798691 0.00889787 0.00992534 0. the testing result differs quite widely from the network result.00573252 0.02E-13 1. the call back function triggers.00960884 0.00585159 0. the network is trained more after that point (output weight training).

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

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

0198416 0.0199916 0.018789438 0.019775896 0.0199719 0.018789438 0.019719802 0.019751257 0.Back-propagation testing data (Iris data) 5.019775896 0.Fishers Iris data 5.0196297 0.0193595 0.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 5.0141406 0.2.0195853 0.0143806 0.Back-propagation Iterations (BP) 434 529 474 391 527 471 Mean squared error (BP) 0.019763877 0.Genetic algorithm testing data (Iris data) 5.0140669 0.019751257 0.2 .1 .0158679 0.0160925 Table 7 .0139982 0.0189456 0.2 .0199972 0.0143778 0.014144 0.01956255614 Testing mean squared error (GA) 0.Cascade correlation testing data (Iris data) Page 63 of 225 .2.01950238 Testing mean squared error (CC) 0.0199892 0.014116 0.0199918 0.019719802 0.01998996 Testing mean squared error (BP) 0.Genetic Algorithms Iterations (GA) 1928 1834 1277 2835 8716 3318 Mean squared error (GA) 0.2.3 .0164964 0.Cascade Correlation Nodes (CC) 2 2 2 2 2 2 Mean squared error (CC) 0.0141935 Table 6 .01956255614 Table 5 .019763877 0.0199999 0.

0192 0.0186 0 2 4 6 Mean squared error (GA) Mean squared error (BP) Mean squared error (CC) Figure 33.2.0202 0.019 0.0196 0.Graphs 10000 9000 8000 7000 6000 5000 4000 3000 2000 1000 0 0 2 4 6 Iterations (GA) Iterations (BP) Nodes (CC) Figure 32 .Mean squared error upon last training test (Iris data) Page 64 of 225 .William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 5.02 0.0194 0.4 .0198 0.Number of iterations to achieve target (Iris data) 0.0188 0.

015 0.The mean squared error at testing (Iris data) 5.005 0 0 2 4 6 Figure 34.01 0. and others.3 .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 . which are the number of amino acid residues per molecule of coat protein. cucumber. There are 18 measurements on each virus.Virus Classification This dataset covers 61 viruses affecting several crops including tobacco. tomato.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 0.025 0.

019861371 0.0105845 0.03833646 Table 9 .019861371 0.00640291 0.019092293 0.0350318 0.Genetic Algorithms testing data (Viruses) 5.Cascade Correlation testing data (Viruses) Page 66 of 225 .00979968 0.01870197 0.0199621 0.0185152 0.019927361 0.017723052 0.3.019743 0.019927361 0.0347797 0.0434423 0.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 5.0190612094 Table 8 .017723052 0.0393106 0.0199916 0.2 Mean Squared Error training (BP) 0.016183342 Mean Squared Error testing (CC) 0.0194383 0.0190612094 Mean Squared Error testing (GA) 0.019092293 0.01983722 Mean Squared Error testing (BP) 0.0391179 0.Back-propagation testing data (Viruses) 5.0111416 0.0196959 0.017043 0.00980208 0.0195173 0.3.2 .Back-propagation Iterations (BP) 3275 10922 2800 3744 6295 5407.0165979 0.Genetic Algorithms Iterations (GA) 1818 1421 896 11676 1068 3375.Cascade Correlation Nodes (CC) 1 2 1 2 1 1.0197935 0.011585152 Table 10 .1 .01870197 0.8 Mean Squared Error training (GA) 0.4 Mean Squared Error training (CC) 0.3 .3.

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

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

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

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

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

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. the program occasionally causes an exception (most specifically when creating cascade or back-propagation networks in quick succession). Testing with datasets that would take large amounts of time to train.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 8 . Testing both with and without scaling and utilising different scaling methods. Improve memory management. Due to small conflicts between managed and unmanaged memory. 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. Page 72 of 225 .Possible Improvements More advanced testing would be the biggest improvement that more time would make possible.

for the reasons stated above. is worth the possibility of reduced performance. • • Attempt to improve the speed of the genetic algorithm. 8. Page 73 of 225 . but still minimize instead of blocking other computer programs.1 . as well as implementing roulette wheel selection.Possible Training Algorithm Improvements With more time. allowing more to be undertaken successfully. experimenting with multiple point crossover and other crossover forms.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 8. 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++.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). Having the back-propagation algorithm in C# similar to the genetic algorithm would also allow a more “apples to apples” comparison. I would experiment with the following training algorithm improvements: • Improve the genetic algorithms crossover and mutation algorithms. (the new network wizard and the working form) lock out the rest of the program. Making the forms shown as dialogs. • Implement the cascade training algorithm in C# instead of C++.2 .

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

1.“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.View 9.1.Generic.Text. private int _CC_Reports.1 . System.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 9.Classes { public class NetworkUpdateEventArgs : System.1. //Dataset identifier private int _TrDataSet. System. private double _CC_LearningRate.EventArgs { #region data /********************\ |* DATA *| \********************/ //Training Algorithm Identifier private int trainingalg.Controller.Collections.1 . private int _CC_MaxNeurons. private bool _CC_ITerr. namespace _05025397.Linq. System. //Cascade Correlation private double _CC_Terr. Page 75 of 225 .

int CCMaxNeurons. private double _BP_Terr. int CCReports. private int _GA_GenLimit. 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. double CCLearningRate. private int _GA_HiddenL. private bool _BP_ITerr. private double _GA_Terr. private double _BP_LearningRate. private int _GA_Reports. #endregion #region constructor /********************\ |* CONSTRUCTOR *| \********************/ //Constructor to accept all necessary data public NetworkUpdateEventArgs (int Algorithm. //BackProp private int _BP_EpochLimit. private int _BP_Reports. double CCTerr. private int _BP_HiddenL. int GAPopSize. private bool _GA_ITerr. private int _GA_Crossover. Page 76 of 225 . private int _GA_Mutation.

_CC_LearningRate = CCLearningRate. _GA_ITerr = GAITerr. _GA_Reports = GAReports. _GA_HiddenL = GAHiddenL. int GAMutation. _CC_ITerr = CCITerr. double GATerr. Page 77 of 225 . bool GAITerr. _CC_Reports = CCReports. _GA_Terr = GATerr. //Genetic Algorithm _GA_PopSize = GAPopSize. int TrData_Set) { //Algorithm trainingalg = Algorithm. _GA_Mutation = GAMutation. int GAHiddenL. _GA_GenLimit = GAGenLimit. int GACrossOver. _CC_MaxNeurons = CCMaxNeurons.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. bool BPITerr. int BPReports. int BPEpochLimit. int BPHiddenL. //Backpropagation Algorithm _BP_EpochLimit = BPEpochLimit. double BPLearningRate. int GAReports. _GA_Crossover = GACrossOver. //Cascade Correlation _CC_Terr = CCTerr. double BPTerr.

} } public int CC_Reports { get { return _CC_Reports. } #endregion #region getters/setters #region cascade_correlation //Cascade Correlation public double CC_Terr { get { return _CC_Terr. } } public bool CC_ITerr { get { return _CC_ITerr. _BP_ITerr = BPITerr. _TrDataSet = TrData_Set. _BP_Terr = BPTerr. } } public int CC_MaxNeurons { get { return _CC_MaxNeurons. } } public int GA_GenLimit Page 78 of 225 .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. } } #endregion #region genetic_algorithms //Genetic Algorithm public int GA_PopSize { get { return _GA_PopSize. _BP_Reports = BPReports. } } public double CC_LearningRate { get { return _CC_LearningRate. _BP_LearningRate = BPLearningRate.

} } public double BP_Terr { get { return _BP_Terr. } } public int GA_Crossover { get { return _GA_Crossover. } } #endregion #region back_propagation //Back propagation public int BP_EpochLimit { get { return _BP_EpochLimit. } } public bool GA_ITerr { get { return _GA_ITerr.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 int BP_Reports { get { return _BP_Reports. } } public double BP_LearningRate { get { return _BP_LearningRate. } } public double GA_Terr { get { return _GA_Terr. } } #endregion Page 79 of 225 . } } public int BP_HiddenL { get { return _BP_HiddenL. } } public int GA_Reports { get { return _GA_Reports. } } public bool BP_ITerr { get { return _BP_ITerr. } } public int GA_Mutation { get { return _GA_Mutation. } } public int GA_HiddenL { get { return _GA_HiddenL.

System.1.ComponentModel.Data.IO.Windows.Drawing. System. using _05025397. System.1. namespace _05025397.Forms. System.Generic. System.Linq.2 .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.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. } } public int TrainingAlgorithm { get { return trainingalg. using ZedGraph. System.Text.“FrmMain.Controller { public partial class FrmMain : Form Page 80 of 225 .Collections. System. } } #endregion } 9. System.

TrainingAlgorithm network.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.icon.Algorithms. //Working dialog Controller.Working().Working workingdialog = new Controller.DoWork += new DoWorkEventHandler(bw_DoWork).Resources. bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted).Icon = Properties. } #endregion #region internal_functions /********************\ Page 81 of 225 . //Background thread static BackgroundWorker bw = new BackgroundWorker(). #endregion #region constructor /********************\ |* CONSTRUCTOR *| \********************/ public FrmMain() { InitializeComponent(). bw. this.

Title.Text = "Iteration".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.TrDataSet).TrainingAlgorithm == 0) { Page 82 of 225 .Text = "MSE". MSEpane.Title. MSEpane. Classes.zedGraphControl1. GraphPane MSEpane = this.AxisChange().Title. MSE.YAxis.IsVisible = false.GraphPane.NetworkUpdateEventArgs e) { LoadDataset(e.Text = "Mean Squared Error". try { if (e. } private void updatenetwork(object sender.Circle).XAxis. // Hide the legend MSEpane. //Titles MSEpane.CurveList.zedGraphControl1.GraphPane. Color.Red.AddCurve("". MSEpane. this.Legend.Clear(). SymbolType.zedGraphControl1.

e.CC_ITerr. } if (e.GA_PopSize. e.BP_EpochLimit.TrainingAlgorithm == 2) { network = new Controller. } } catch { Page 83 of 225 .CascadeCorrelation (e.BP_ITerr.BP_Reports.TrainingAlgorithm == 1) { network = new Controller. e.BackProp (e. e. e. e.BP_LearningRate.CC_MaxNeurons.GA_Crossover.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.CC_LearningRate. } if (e. txtTestData). e.BP_HiddenL.GeneticAlgorithm (e.GA_ITerr. txtTestData). e. txtTestData). e.GA_Reports. e. e. e.GA_Terr. txtTrainData. txtTrainData.CC_Terr.GA_Mutation. txtTrainData. e. e.Algorithms. e.BP_Terr.GA_HiddenL. e.GA_GenLimit.CC_Reports.Algorithms.

} if (network != null) { txtNetSettings.NetworkUpdated += new Controller. MessageBoxButtons.Wiz1().Exit().Text = network.Resources.network_details(). } private void LoadDataset(int Data_set) { switch (Data_set) { case (int)Dataset. MessageBoxIcon. txtTestData.Text = Properties.XOR: txtTrainData. wizard.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.Text = Properties. "Error".Error).Show("Error creating new network".Wiz1.NetworkUpdateHandler(updatenetwork).Wiz1 wizard = new Controller.ShowDialog().Resources.XORtrain. } } private void new_network() { Controller. Page 84 of 225 .XORtest. wizard.OK. Application.

Text = Properties.Text = Properties. } Page 85 of 225 . string test = "".\\".\\".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. txtTestData. "Select Training Data"). } } private void LoadCustomDataSet() { string trainpath = SelectTextFile(".Error).FISHER: txtTrainData. case (int)Dataset.Resources.FISHERtest. "Select Testing Data"). } catch { MessageBox.CUSTOM: LoadCustomDataSet(). try { train = LoadTxtFile(trainpath).FISHERtrain. MessageBoxButtons. "Error!". break.OK.Resources. MessageBoxIcon.Show("Error: Problem loading training data". case (int)Dataset. break. string train = "". string testpath = SelectTextFile(".

Reader = new StreamReader(File). } private string LoadTxtFile(string path) { string data = "". } catch { MessageBox. data = Reader.Read).Error).Open. Page 86 of 225 . txtTrainData.Text = test.OK. "Error!".Show("Error reading selected file: " + path.Text = train. "Error!". MessageBoxButtons.OK. FileMode. } catch { MessageBox. MessageBoxButtons. MessageBoxIcon. } txtTestData.Error).Show("Error: Problem loading testing data". MessageBoxIcon. FileStream File = null.ReadToEnd(). StreamReader Reader = null. FileAccess.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). try { File = new FileStream(path.

} #endregion #region menu_items /********************\ |* MENU ITEMS *| \********************/ Page 87 of 225 .Title = title.*".txt)|*.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 = "". dialog. } private string SelectTextFile(string initialDirectory.InitialDirectory = initialDirectory.Close().FileName : null.Close().Filter = "txt files (*.txt|All files (*. dialog. if (File != null) File. return (dialog.*)|*. string title) { OpenFileDialog dialog = new OpenFileDialog().OK) ? dialog. } finally { if (Reader != null) Reader. dialog. } return data.ShowDialog() == DialogResult.

Test(). EventArgs e) { if (network != null) { if (network. About. } #endregion #region buttons Page 88 of 225 . } private void exitToolStripMenuItem_Click(object sender.Show().Close().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. EventArgs e) { FrmAbout About = new FrmAbout(). EventArgs e) { this. EventArgs e) { new_network(). } private void runToolStripMenuItem_Click(object sender. } } } private void aboutToolStripMenuItem1_Click(object sender.Trained != false) { network.

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. EventArgs e) { new_network().Trained) Page 89 of 225 .IsBusy) { if (network != null) { if (!network.RunWorkerAsync(). if (!bw.Trained) { bw. EventArgs e) { //Shouldn't be busy if the user managed to click this //but just make 100% certain. } private void btnTrain_Click(object sender. EventArgs e) { if (network != null) { if (network. workingdialog. } } } } private void btnTest_Click(object sender.

txtOutput.Text = network.Text. txtOutput. } } } } } #endregion #region bg_worker /********************\ |* BG WORKER *| \********************/ private void bw_DoWork(object sender.Test(). DoWorkEventArgs e) { bool success = true. txtOutput.Train().Tested) { bool success = network. if (success) { txtOutput.Length. } Page 90 of 225 .ReportData.SelectionStart = txtOutput.Clear(). if (network != null) { success = network.Refresh(). txtOutput.ScrollToCaret().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.

RunWorkerCompletedEventArgs e) { bool success.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.Show("Error training network!".OK.getGraphData()).Text.Length. plotgraphsMSE(network. "Error".Text = network.Error != null) { MessageBox.Error).Error). } Page 91 of 225 .ScrollToCaret(). MessageBoxIcon. //Check for errors if (e. MessageBoxButtons. } else { MessageBox.Result = success.Error.ReportData. MessageBoxIcon.OK.SelectionStart = txtOutput. txtOutput.ToString().Show("Error during network train: " + e. } success = (bool) e. txtOutput. "Error training network!".Clear(). txtOutput. MessageBoxButtons. if (success) { txtOutput. } private void bw_RunWorkerCompleted(object sender.Result.

EventArgs e) { //Run the new neural net wizard new_network().ComponentModel. System.1.1.Collections.Linq.cs” 00000001 00000002 00000003 00000004 00000005 00000006 using using using using using using System.3 .Data. System.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. } #endregion } 9. System. System.Generic. Page 92 of 225 . } #endregion #region misc /********************\ |* MISC *| \********************/ private void FrmMain_Shown(object sender.Hide().“Wiz1.Drawing. System.

enum Dataset { XOR.Forms. namespace _05025397.Controller { #region enums /********************\ |* ENUMS *| \********************/ enum Training { GA.Text. using _05025397. BP.Windows. #endregion public partial class Wiz1 : Form { #region data /********************\ |* DATA *| \********************/ public delegate void NetworkUpdateHandler(object sender. Classes.NetworkUpdateEventArgs e). CUSTOM }. using System. private int algorithm. FISHER. private int Trainset. public event NetworkUpdateHandler NetworkUpdated. Page 93 of 225 . CC }.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.

} private void rBtnBackprop_CheckedChanged(object sender.XOR. algorithm = (int)Training.Close(). Trainset = (int)Dataset.GA.icon. } #endregion #region control_events /********************\ |* CONTROL EVENTS *| \********************/ #region buttons /********************\ |* BUTTONS *| \********************/ private void btnCancel_Click(object sender. EventArgs e) Page 94 of 225 . this. EventArgs e) { this.Resources.Icon = Properties.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().

Visible = true.Visible = false. panBackprop.Visible = false. EventArgs e) { if (rBtnCascadeCorrelation.Checked == true) { picAlg.Visible = true. algorithm = (int)Training.Visible = false. panCC.Image = _05025397.CC.Visible = false.Visible = false. lblBP. panCC. lblCC.Resources.IMAGEBackProp.Properties. lblGA. panGeneticAlgorithm.Resources. lblCC. lblGA.Visible = false.BP.Visible = true.Visible = false.Properties.Visible = false. algorithm = (int)Training. } } private void rBtnCascadeCorrelation_CheckedChanged(object sender. lblBP.Visible = true. panGeneticAlgorithm. panBackprop.Checked == true) { picAlg.Image = _05025397.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. Page 95 of 225 .IMAGECascadeCorrelation.

Visible = false.Image = _05025397.SelectTab(tabControl1.Visible = true. EventArgs e) { Page 96 of 225 . } } private void btnBack_Click(object sender.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.Visible = false. lblGA.Visible = false.SelectedIndex . algorithm = (int)Training.Visible = false.1).Checked == true) { picAlg. panCC.Visible = true.Resources.IMAGEGeneticAlgorithm. EventArgs e) { if (rBtnGeneticAlgorithm.GA. lblCC. EventArgs e) { if (tabControl1.Properties. panGeneticAlgorithm. panBackprop.SelectedIndex > 0) { tabControl1. lblBP. } } private void btnNext_Click(object sender.

} else { VerifyData check = new VerifyData (algorithm.CC_MaxNeurons. txtGA_MaxGen.Text. check.Text.Text.Text.CC_Terr. txtBP_Terr.1) { tabControl1.GA_Terr. chkGA_IgnoreTarget. txtGA_Terr.CC_LearningRate.Text. CC_ITerr.Checked.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.Verified) { Classes.SelectedIndex + 1). txtGA_Report.Text. txtGA_ProbM. check. check. txtCC_TargetError.Text. check. if (check.Text.BP_HiddenL.Checked. check. txtBP_HiddenNodes. Page 97 of 225 . chkBP_IgnoreTarget. txtBP_Report.CC_ITerr. check.Checked. txtGA_PopSize. check.GA_Mutation. txtBP_LearnRate.Text.CC_Reports.SelectTab(tabControl1.NetworkUpdateEventArgs args = new Classes. check. check.GA_GenLimit.Text.GA_Reports. Trainset).GA_Crossover. txtBP_EpochLimit. check.Text.GA_HiddenL.Text. txtCC_Report.NetworkUpdateEventArgs (check.Text.TabCount . check. txtGA_HiddenNodes. check.TrainingAlgorithm.Text.Text. check.Text.BP_EpochLimit. txtCC_LearningRate. txtCC_MaxNeurons.GA_ITerr.GA_PopSize. txtGA_ProbX.SelectedIndex < tabControl1. check. check.

BP_Terr.BP_ITerr. MessageBoxButtons.Dispose(). this.Exclamation).IMAGEIrisFlowers. EventArgs e) Page 98 of 225 .Properties. check.BP_LearningRate. check.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. } } private void chkDatasetXOR_CheckedChanged(object sender.Checked) { picDataset. args). } } } #endregion #region checkboxes /********************\ |* CHECKBOXES *| \********************/ private void chkDatasetFisher_CheckedChanged(object sender.OK. Trainset = (int)Dataset.BP_Reports. NetworkUpdated(this. MessageBoxIcon.FISHER.Show("Error Checking Data: Data could not be verified".Image = _05025397.TrDataSet). check. check. "Error Checking Data".Resources. } else { MessageBox. EventArgs e) { if (chkDatasetFisher.

Checked) { picDataset.Visible == true) { txtCC_TargetError.IMAGEXOR. Trainset = (int)Dataset. EventArgs e) { if (tabControl1.CUSTOM.Image = _05025397.Properties.Properties. } Page 99 of 225 .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.Resources. } } private void chkDatasetCustom_CheckedChanged(object sender.XOR. EventArgs e) { if (chkDatasetCustom.Resources. Trainset = (int)Dataset.Image = _05025397.SelectedIndex == 1) { if (panCC.Checked) { picDataset. } } #endregion #region misc /********************\ |* MISC *| \********************/ private void tabControl1_SelectedIndexChanged(object sender.Focus().IMAGEQuestionMark.

} if (panGeneticAlgorithm.Icon = Properties.Focus().Resources. } #endregion #endregion } Page 100 of 225 .SelectTab(0). tabControl1.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. } } } private void Wiz1_Load(object sender. EventArgs e) { this.Focus().icon.Visible == true) { txtBP_EpochLimit.Visible == true) { txtGA_PopSize.

Text.4 .1.Linq. EventArgs e) { Page 101 of 225 . System.Collections.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.Drawing. System.“FrmAbout. namespace _05025397. System. System.Generic. System.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 9. System. System.1.Windows.ComponentModel. } #endregion #region form /********************\ |* FORM *| \********************/ private void FrmAbout_Load(object sender.Forms.Data.Controller { public partial class FrmAbout : Form { #region constructor /********************\ |* CONSTRUCTOR *| \********************/ public FrmAbout() { InitializeComponent().

} } private void linkLabel4_LinkClicked(object sender.Resources.linkLabel1.Resources. System.OK. LinkLabelLinkClickedEventArgs e) { // Specify that the link was visited. try { // Navigate to a URL.Text). textBox5.LICENCE_LGPL21.icon.Text = Application.LinkVisited = true.Process.Information).Start("mailto:" + linkLabel1.Text = Properties.ProductVersion. LinkLabelLinkClickedEventArgs e) Page 102 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 this. MessageBoxButtons. this. } #endregion #region linklabels /********************\ |* LINKLABELS *| \********************/ private void linkLabel1_LinkClicked(object sender. label5.Diagnostics.Show("No e-mail program defined. MessageBoxIcon.Icon = Properties.". } catch { MessageBox. "Undefined Application".

"Error".Error). MessageBoxButtons. } } private void linkLabel5_LinkClicked(object sender.Process.Start (linkLabel4.".Diagnostics.Diagnostics.Start (linkLabel5. LinkLabelLinkClickedEventArgs e) Page 103 of 225 .Show("Error opening link. } catch { MessageBox.Process. } catch { MessageBox.Text).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. MessageBoxIcon. } } private void linkLabel6_LinkClicked(object sender.Text).". MessageBoxButtons. "Error".Show("Error opening link. MessageBoxIcon.Error).OK. LinkLabelLinkClickedEventArgs e) { try { System.OK.

OK.OK.".Start (linkLabel6.Error).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. MessageBoxIcon.Process. } } private void linkLabel2_LinkClicked(object sender.Diagnostics. "Error".Show("Error opening link. MessageBoxButtons. "Error". } } private void linkLabel7_LinkClicked(object sender. MessageBoxButtons.Diagnostics.uk").Show("Error opening link.co. } catch { MessageBox.Start ("http://www. MessageBoxIcon. LinkLabelLinkClickedEventArgs e) Page 104 of 225 .Process.Error). LinkLabelLinkClickedEventArgs e) { try { System.Text). } catch { MessageBox.".snikks.

} } #endregion #region buttons /********************\ |* BUTTONS *| \********************/ private void btnDatasets_Click(object sender.Visible = false. "Error". } else Page 105 of 225 .". MessageBoxIcon.OK.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.1.Start ("http://www. MessageBoxButtons.Show("Error opening link.Process.gnu.Visible = false.Diagnostics.html"). pictureBox1. EventArgs e) { if (tabControl1.Visible = false.Visible != true) { groupBox1. tabControl1.Visible = true. groupBox2.org/licenses/old-licenses/lgpl-2.Error). } catch { MessageBox.

pictureBox1. = false.Dispose().Visible = false. EventArgs e) { if (groupBox2.Visible = false. false. tabControl1. groupBox1. Page 106 of 225 .Visible = groupBox2.Visible = true.Visible != true) { groupBox2. } } private void btnOkay_Click(object sender. } true.Visible = tabControl1.Visible } } private void btnLicences_Click(object sender.Visible = false. pictureBox1. EventArgs e) { this.Visible = true. = true. tabControl1.Visible = true.Visible pictureBox1. groupBox2.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.Visible = false. } else { groupBox1.Visible = false.

EventArgs e) { if (radioButton2. EventArgs e) { if (radioButton1.LICENCE_GPL30.Resources.Text = Properties.Resources.Checked == true) textBox5. } private void radioButton3_CheckedChanged(object sender. } #endregion } Page 107 of 225 .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.LICENCE_LGPL21.Text = Properties. EventArgs e) { if (radioButton3.Resources. } private void radioButton2_CheckedChanged(object sender.LICENCE_LGPL30.Checked == true) textBox5.Text = Properties.Checked == true) textBox5.

System.Text.Media.Forms.Collections. System.1.ComponentModel.Icon = Properties.“Working. System.Linq. System.Controller { public partial class Working : Form { #region functions /********************\ |* FUNCTIONS *| \********************/ public Working() { InitializeComponent(). System. System.Data.Generic. EventArgs e) { System. namespace _05025397.icon.Windows.Resources.5 .William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 9. } private void Working_Click(object sender. System.1.SystemSounds. this.Play(). } #endregion } Page 108 of 225 .Drawing.Beep.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.

Forms.Collections.“VerifyData.Controller 9.1.2 .Controller { public class VerifyData { #region data /********************\ |* DATA *| \********************/ //Dataverified variable private bool verified.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000030 } 9.Generic.2.1.Text. System.1 . //Training Algorithm Identifier //1 = genetic algorith //2 = backprop //3 = cascade correlation private int trainingalg.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.Linq.Windows. //Dataset identifer //0 = XOR Page 109 of 225 . System. System. namespace _05025397. System.

private double _CC_LearningRate. private int _GA_Reports. private int _BP_HiddenL. private int _GA_HiddenL. //Genetic Algorithm private int _GA_PopSize. private int _BP_Reports. private double _BP_Terr. //BackProp private int _BP_EpochLimit. private int _GA_GenLimit. //Cascade Correlation private double _CC_Terr. private bool _GA_ITerr. private int _CC_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 double _BP_LearningRate. #endregion Page 110 of 225 . private int _GA_Crossover. private bool _BP_ITerr. private int _GA_Mutation. private int _CC_MaxNeurons. private double _GA_Terr. private bool _CC_ITerr.

XOR && _TDataSet != Page 111 of 225 . string GAMutation. string GAReports. string CCReports. string CCMaxNeurons. //Algorithm trainingalg = Algorithm. string GATerr. if (_TDataSet != (int)Dataset.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. bool GAITerr. string CCLearningRate. string GAHiddenL. bool BPITerr. string BPTerr. string GACrossOver. string GAPopSize. int TData_Set) { //Initially set to true. string BPLearningRate. will be changed to //false if any data verification errors occur verified = true. string BPEpochLimit. string BPHiddenL. string CCTerr. string BPReports. string GAGenLimit. //DataSet _TDataSet = TData_Set. bool CCITerr.

} } } Page 112 of 225 .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.ToSingle(CCLearningRate). if (verified) { if (trainingalg == 2) { try { //Cascade correlation _CC_Terr = Convert.CUSTOM) verified = false.Show ("Parsing Error: Please check supplied cascade" + "correlation data values". } catch (FormatException) { MessageBox.OK.Error). _CC_ITerr = CCITerr. _CC_LearningRate = Convert.ToSingle(CCTerr). _CC_Reports = Convert. "Parsing Error".ToInt32(CCMaxNeurons).FISHER && _TDataSet != (int)Dataset. verified = false.ToInt32(CCReports). MessageBoxIcon. MessageBoxButtons. _CC_MaxNeurons = Convert.

_GA_ITerr = GAITerr. "Parsing Error". _GA_GenLimit = Convert. verified = false.ToInt32(GAGenLimit).ToInt32(GAHiddenL). _GA_HiddenL = Convert. } catch (FormatException) { MessageBox. MessageBoxIcon. _GA_Crossover = Convert. _GA_Terr = Convert. _GA_Mutation = Convert.Show ("Parsing Error: Please check supplied" +" genetic algorithm data values".OK.ToSingle(GATerr).ToInt32(GAReports).ToInt32(GAMutation). } } } if (verified) Page 113 of 225 .ToInt32(GACrossOver). _GA_Reports = Convert. MessageBoxButtons.Error).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.ToInt32(GAPopSize).

_BP_LearningRate = Convert.ToInt32(BPHiddenL).ToDouble(BPLearningRate). MessageBoxIcon. } catch (FormatException) { MessageBox. MessageBoxButtons. _BP_HiddenL = Convert. } } } if (verified) { verified = checkforsanity(). "Parsing Error".Error). verified = false. } Page 114 of 225 .ToInt32(BPReports).OK. _BP_Reports = Convert.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.ToDouble(BPTerr).Show ("Parsing Error: Please check " + "supplied back propagation data values". _BP_Terr = Convert.ToInt32(BPEpochLimit). _BP_ITerr = BPITerr.

} if (_GA_Mutation < 0 || _GA_Mutation > 100) { sanity = false. if (_GA_Crossover < 0 || _GA_Crossover > 100) { sanity = false. Page 115 of 225 .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 (_GA_Terr < 0 || _GA_Terr > 1) sanity = false. if (_GA_GenLimit < 1) sanity = false. if (_GA_PopSize < 3) sanity = false.

if (_GA_HiddenL < 1) sanity = false.Show ("Sanity Check Fail: Please check supplied " + "genetic algorithm data values".OK. } private bool checkBPsanity() { bool sanity = true.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. "Sanity Check Fail". if (_BP_EpochLimit < 1) sanity = false. if (!sanity) MessageBox. if (_BP_HiddenL < 1) sanity = false. MessageBoxButtons. return sanity. if (_BP_Reports < 1 || _BP_Reports > _BP_EpochLimit) sanity = false. MessageBoxIcon.Error). Page 116 of 225 .

return sanity. MessageBoxIcon. "Sanity Check Fail". if (_CC_MaxNeurons < 1) sanity = false. if (!sanity) MessageBox.OK. if (_CC_Reports < 1 || _CC_Reports > _CC_MaxNeurons) sanity = false. Page 117 of 225 . if (_BP_LearningRate < 0 || _BP_LearningRate > 1) sanity = false. MessageBoxButtons.Error). } private bool checkCCsanity() { bool sanity = true.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_Terr < 0 || _CC_Terr > 1) sanity = false.

if they're greater than 1 but less than 100 scale them appropriately. only //halt any values from proceeding that are so wrong they could cause //serious errors later down the line.OK.Show ("Sanity Check Fail: Please check supplied " + "cascade correlation data values". } private bool checkforsanity() { //Some of the values that are allowed through here would not produce //good results . return sanity. "Sanity Check Fail". MessageBoxIcon.Error). MessageBoxButtons. We're also doing some very minor processing of the probability values. sanity = true.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.however I don't want to prevent any flexibility. if (!sanity) MessageBox. // // // // // bool Basically we're making sure the data is clean before it goes anywhere near a DLL. if (trainingalg < 0 || trainingalg > 2) Page 118 of 225 .

} if (sanity) { if (trainingalg == 0) { sanity = checkGAsanity(). } } return sanity.OK. } if (trainingalg == 1) { sanity = checkBPsanity().Error). } if (trainingalg == 2) { sanity = checkCCsanity(). MessageBoxIcon.Show ("Sanity Check Fail: Training Algorithm not " + "selected or selected incorrectly". "Sanity Check Fail".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. MessageBox. } Page 119 of 225 . MessageBoxButtons.

} } public double CC_LearningRate { get { return _CC_LearningRate. } } public int GA_Crossover { get { return _GA_Crossover. } } public int GA_GenLimit { get { return _GA_GenLimit. } } public bool CC_ITerr { get { return _CC_ITerr. } } public int CC_MaxNeurons { get { return _CC_MaxNeurons. } } 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. } } #endregion #region genetic_algorithm //Genetic Algorithm public int GA_PopSize { get { return _GA_PopSize. } } public int CC_Reports { get { return _CC_Reports.

} } _GA_Terr. } } public int BP_HiddenL { get { return _BP_HiddenL. } } _GA_Reports. } } public bool BP_ITerr { get { return _BP_ITerr.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_ITerr. } } #region back_propagation //Back propagation public int BP_EpochLimit { get { return _BP_EpochLimit. } } public int BP_Reports { get { return _BP_Reports. } } #endregion #endregion #region external //Verification Page 121 of 225 . } } _GA_HiddenL. } } public double BP_LearningRate { get { return _BP_LearningRate. } } public double BP_Terr { get { return _BP_Terr.

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. } } #endregion } Page 122 of 225 . } } //Dataset public int TrDataSet { get { return _TDataSet.

namespace _05025397. private ArrayList trinputs.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 9. System.Forms.2 .Windows. private ArrayList troutputs. private string[] test. 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 System. private ArrayList teinputs. private ArrayList altest.“DatasetParser.Collections.2. private ArrayList aldata. Page 123 of 225 . private string[] data.1. System. System.Linq.Generic.Collections.Controller { public class DatasetParser { #region data /********************\ |* DATA *| \********************/ private bool _Verified. System. private ArrayList teoutputs.Text.

'\t'. txtTest. txtData. teinputs = new ArrayList(). '. #endregion #region constructor /********************\ |* CONSTRUCTOR *| \********************/ public DatasetParser(RichTextBox txtData.Text = txtTest. trinputs = new ArrayList(). Page 124 of 225 . //Strip carriage returns and trim txtData. txtTest.Replace("\r".'.Trim(). char[] delimiterChars = { '\n'.Text. private double Noutputs.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.Replace("\r". teoutputs = new ArrayList(). ' '. altest = new ArrayList(). troutputs = new ArrayList().Trim().Text.Text.Text = txtData. '. private double Niterations.Text = txtData. RichTextBox txtTest) { //Data init bool Verified = true.' }. private double Ninputs.Text. '\r'. aldata = new ArrayList(). "").Text = txtTest. "").

Verified = parseTestingData().Convert.ToDouble(data[0]).Text.Split(delimiterChars).Length.Convert. Noutputs = System. try { for (int i = 3. _Verified = Verified.Convert.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. i++) Page 125 of 225 . i < data.ToDouble(data[1]).ToDouble(data[2]). } #endregion #region internal_functions /********************\ |* INTERNAL *| \********************/ private bool parseTrainingData() { bool success = true. //parse the data into appropriately //structured arrays Verified = parseTrainingData(). //Get the number of iterations.Split(delimiterChars). number of inputs //and number of outputs Niterations = System. test = txtTest.Text. Ninputs = System.

MessageBoxButtons.RemoveAt(0).Add(aldata[0]). i < Ninputs. } while (aldata.Error). aldata. } return success.OK. aldata.Add(aldata[0]).Add(System.RemoveAt(0). i++) { trinputs. Page 126 of 225 . MessageBoxIcon.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.Show("Error parsing training data". } private bool parseTestingData() { bool success = true.ToDouble(data[i])). } } } catch { MessageBox.Count > 0) { for (int i = 0. j < Noutputs. } for (int j = 0. "Error".Convert. success = false. j++) { troutputs.

} while (altest.Length. i < Ninputs.Add(altest[0]).Show("Error parsing testing data". i++) { altest.OK.Count > 0) { for (int i = 0. i < data.Error). } return success. altest. j++) { teoutputs. i++) { teinputs. } } } catch { MessageBox.ToDouble(data[i])). MessageBoxButtons. } Page 127 of 225 . "Error".RemoveAt(0).Add(altest[0]).Convert.Add(System. MessageBoxIcon. } for (int j = 0. success = false.RemoveAt(0). j < Noutputs. altest.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.

out double[][] troutputdata) { trinputdata = new double[trinputs. i++) trinputdata[i] = new double[(int) Ninputs]. troutputdata = new double[troutputs. Nout = Noutputs.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. i < (troutputs.Count / (int)Noutputs). l++) { for (int k = 0.Count.Count / (int)Ninputs). k++) { Page 128 of 225 . i < (trinputs.Count / (int) Noutputs][].Count / (int) Ninputs][]. i++) troutputdata[i] = new double[(int) Noutputs]. for (int i = 0. out double Nout) { Ninp = Ninputs. for (int i = 0. out double Ninp. for (int j = 0. j < trinputs. } public void GetTrainingData (out double[][] trinputdata. k < Ninputs. l = 0. j+=(int) Ninputs. iter = Niterations.

k < Ninputs. k]. i < (teoutputs. for (int i = 0.Count / (int)Ninputs). j < teinputs.Count / (int)Ninputs][]. l = 0. teoutputdata = new double[teoutputs. l = 0. k++) { troutputdata[l][k] = (double)troutputs[j + k]. for (int j = 0. Page 129 of 225 . j += (int)Ninputs.Count / (int)Noutputs][]. j < troutputs.Count. } } } public void GetTestingData (out double[][] teinputdata. i < (teinputs.Count / (int)Noutputs). k < Noutputs. l++) { for (int k = 0. for (int i = 0.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. j += (int)Noutputs. out double[][] teoutputdata) { teinputdata = new double[teinputs. k++) { teinputdata[l][k] = (double)teinputs[j + k]. i++) teinputdata[i] = new double[(int)Ninputs].Count. l++) { for (int k = 0. i++) teoutputdata[i] = new double[(int)Noutputs].

j += (int)Noutputs. Page 130 of 225 . k++) { teoutputdata[l][k] = (double)teoutputs[j + k]. } } } public void GetTestingDataAL (out ArrayList teinputdata.1. teoutputdata = teoutputs.“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.2. } } #endregion } 9.cs” 00000001 using System.3 . l = 0.Count. k < Noutputs. l++) { for (int k = 0. out ArrayList teoutputdata) { teinputdata = teinputs. } public bool Verified { get { return _Verified. j < teoutputs.

System.Collections. private int _ReportInterval. private int _IterMax.Forms. protected bool _Trained. protected bool _Tested. protected bool _ITerr.Algorithms { public abstract class TrainingAlgorithm { #region data /********************\ |* DATA *| \********************/ private double _TargetError. private string _ReportData.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 int CurIt. ZedGraph. System. namespace _05025397. System.Controller. protected PointPairList BestErrList.Text.Generic.Windows. _05025397. Page 131 of 225 .Linq.

so the //network will loop to completion. _ITerr = ITerr. protected DatasetParser getdata. bool ITerr) { _TargetError = Target_Error. if (_ITerr) _TargetError = -1. } #endregion Page 132 of 225 . RichTextBox txtData. RichTextBox txtTest. txtTest).0 //this is impossible to reach. //If the ignore target error is true //then set the target error to -1. _ReportInterval = Reports.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(). BestErrList = new PointPairList(). #endregion #region constructor /********************\ |* CONSTRUCTOR *| \********************/ public TrainingAlgorithm(double Target_Error. _IterMax = Iter_Max. int Iter_Max.00. getdata = new DatasetParser(txtData. int Reports.

} } Page 133 of 225 . } #endregion #region external /********************\ |* EXTERNAL *| \********************/ public abstract bool Train(). public abstract string network_details(). } get { return _TargetError. } public double TargetError { set { _TargetError = value. public abstract bool Test().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.

} } public bool Tested { get { return _Tested. } } public int IterMax { get { return _IterMax.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 string ReportData { get { return _ReportData. } set { _Trained = value. } } public bool Trained { get { return _Trained. } } #endregion } Page 134 of 225 .

System.Controller. #endregion #region constructor Page 135 of 225 .2. System.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 9.Collections. System.Forms. FANN_Wrapper. System.Collections. private double _OutputL.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. ZedGraph. FANN_Cascade CCNet.1.Text. System.Generic.IO.4 .Algorithms { public class CascadeCorrelation : TrainingAlgorithm { #region data /********************\ |* DATA *| \********************/ private double _InputL.“Algorithms\CascadeCorrelation. private double _LearnRate.Windows. _05025397. System.Linq. namespace _05025397.

getdata.TargetError. _LearnRate. base. Reports. double iterations. } #endregion #region internal_functions /********************\ |* INTERNAL *| \********************/ private void saveDllData(RichTextBox tr. bool ITerr. CCNet = new FANN_Cascade((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 /********************\ |* CONSTRUCTOR *| \********************/ public CascadeCorrelation(double LearnRate. int Iter_Max. int Reports. out _OutputL). (int)_OutputL. ITerr) { _LearnRate = LearnRate. Iter_Max.IterMax). txtTest).GetStructure(out iterations. double TargetError.ReportInterval. txtTest. saveDllData(txtData. base. base. out _InputL. RichTextBox txtData. RichTextBox te) { Page 136 of 225 . txtData. RichTextBox txtTest) : base(TargetError.

Text). (int)_InputL)).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.dat").Append( string.Format ("\nLearning Rate: {0:0. output. output. tw.Format ("Network Details: \n Input Layer: {0:d}".Append( string.Close().Append( string.Format ("\t\t\t\t\tOutput Layer: {0:d}".Text). tw = new StreamWriter("dlltedata. _LearnRate)). output. (int)_OutputL)).Write(te.dat").Write(tr. tw. output. } #endregion #region external_functions /********************\ |* EXTERNAL *| \********************/ public override string network_details() { StringBuilder output = new StringBuilder().Append( Page 137 of 225 .Close(). tw.00000}". tw.

ToString().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. Report(CCNet. output.Format ("\t\t\t\t\t\tIgnore target error " + "(process all iterations): {0}". base.Format ("\t\t\tTarget Error: {0:0.". try { success = CCNet. _ITerr)).Append( string.Train().Append( string.ReportInterval)). } public override bool Train() { bool success = true.Format ("\nReport every {0:d} generations. base. output.IterMax)).TargetError)). return output. output.Append( string. base. } catch { Page 138 of 225 ._tr_output).Format ("\t\tMaximum Nodes: {0:d}".

MessageBoxButtons.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. success = false. i < besterrlist.Add((double)i. "Error". i++) { base.Length. } Page 139 of 225 .OK. } public bool getGraphDataFromDll() { bool success = true.BestErrList. "Error". } success = getGraphDataFromDll().OK.besterrorlist. base.Error).Error). besterrlist[i]). success = false. } } catch { MessageBox. MessageBoxIcon.Show("Error getting graph data from DLL". try { double[] besterrlist = CCNet. MessageBoxButtons._Trained = success. return success. for (int i = 0. MessageBoxIcon.Show("Error running Cascade training!".

} base. success = false._te_output).Show("Error running Cascade testing!"._Tested = success.Error). MessageBoxIcon. MessageBoxButtons. return success. } #endregion } Page 140 of 225 . Report(CCNet. try { success = CCNet.Test(). } public override bool Test() { bool success = true. } catch { MessageBox. "Error".OK.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.

//Population Page 141 of 225 .2.Generic. private int _Crossover. System.Collections. _05025397. System. ZedGraph.Controller.Text. //Network Data private double _InputL.5 . namespace _05025397. private double _OutputL.Algorithms { public class GeneticAlgorithm : TrainingAlgorithm { #region data /********************\ |* DATA *| \********************/ //GA Data private int _PopSize. System. private int _HiddenL.1.“Algorithms\GeneticAlgorithm.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 9.Linq.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.Forms. System. System.Collections. private int _Mutation.Windows.

txtData. getdata. Reports. Iter_Max. //Init Network params double iterations. double TargetError.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. int Iter_Max. RichTextBox txtData. for (int i = 0. int Reports. int HiddenL.GetStructure(out iterations. #endregion #region constructor /********************\ |* CONSTRUCTOR *| \********************/ public GeneticAlgorithm(int PopSize. _Mutation = Mutation. int Mutation. _HiddenL = HiddenL. out _InputL.Add Page 142 of 225 . i++) { Population. bool ITerr. int Crossover. //Create new population references Population = new ArrayList(_PopSize). out _OutputL). i < _PopSize. ITerr) { _PopSize = PopSize. RichTextBox txtTest) : base(TargetError. _Crossover = Crossover. txtTest.

} //Sort the functions according to fitness now. j++) { ((Model. j < _PopSize. Page 143 of 225 . _HiddenL. for (int i = 0. success = sort_fitnesses(). double[][] results. getdata.GANetwork) Population[j]).getMsQE(inputs.GANetwork( (int)_InputL. i < base.Next())).IterMax. } } #endregion #region internal_functions /********************\ |* INTERNAL *| \********************/ private bool run() { bool success = true.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++) { //Get the msqe for (int j = 0. out results). Rand.GetScaledTrainingData(out inputs. double[][] inputs. (int)_OutputL. results).

base.TargetError) { Report("\nNetwork matching or improving upon target error"+ "found at iteration [ " + i + " ].BestErrList. ((Model. break.GANetwork)Population[0]). //Check for having reached the target if (((Model.CurIt == ReportInterval) { base.GANetwork)Population[0]).GANetwork)Population[0]). } return success.CurIt = 0.MSqE + ".\n").").Add ((double)i. } private bool sort_fitnesses() { Page 144 of 225 .MSqE). } success = build_generation(). } base.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.MSqE <= base.Report("Best error at iteration [ " + i + " ] was " + ((Model. base.CurIt++.

selection2. MessageBoxIcon. "Error". } catch { MessageBox. for (int i = (_PopSize . try { Population.Error). int selection1. } private bool build_generation() { bool success = true. double[] weightarray1.1).Sort().Show("Error sorting population". double[] weightarray2. i--) { //This algorithm is altered from previous versions. double[] weightarray_f. i > (int)(_PopSize / 2). success = false.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.OK. //It selects two points from the start of the population //Then applies crossover if necessary (based on probability) Page 145 of 225 . } return success. MessageBoxButtons.

success = false. "Error". selection2 = Rand. //Next iteration it replaces the next to last.Next((int)_PopSize / 2). selection1 = Rand.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 . //Just a quick error check if (weightarray1.Length != weightarray2. weightarray2 = ((Model.GANetwork)Population[selection1]). weightarray1 = ((Model. MessageBoxButtons. all the way to the middle of the population. //Then it replaces the last position in the population //(ie.Length) { MessageBox. MessageBoxIcon.Next((int)_PopSize / 2). and //so on. the least fit) with this new string.Length].OK.getWeights(). } try { weightarray_f = new double[weightarray1.getWeights(). if (Rand.".GANetwork)Population[selection1]).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 //applies mutation if necessary (same again) //then if neither mutation or Xover have been applied //chooses position 1 or 2.

} Page 147 of 225 .Length. j++) { weightarray_f[j] += Rand. } } } if (Rand. j++) { if (j < XPos) { weightarray_f[j] = weightarray1[j]. } else { weightarray_f[j] = weightarray2[j].1)).Length . } } //Set the weights of the current member of the //population we're on ((Model. (weightarray1.Next(1.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.5.Next(100) < _Mutation) { //Jiggle the weights in the array //up or down by 0.5 for (int j = 0.setWeights(weightarray_f).GANetwork)Population[i]).NextDouble() .0. //Simple single point crossover of the weights for (int j = 0.Length. j < weightarray1. j < weightarray_f.

Show("Error building new generation". _Mutation)). } } return success.OK. } #endregion #region external_functions /********************\ |* EXTERNAL *| \********************/ public override string network_details() { //Add stringbuilder for efficiency here StringBuilder output = new StringBuilder(). _PopSize)).Error).Append( Page 148 of 225 . success = false. output. _Crossover)). MessageBoxIcon.Format("\t\t\tCrossover Probability: {0:d}". output. MessageBoxButtons. output. output.Format("\t\t\tMutation Probability: {0:d}".Append( string.Format("Network Details: \n Population: {0:d}".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. "Error".Append( string.Append( string.

Append( string.". base.TargetError)). _ITerr)).Append( string. return success. output.Format("\nHidden layer: {0:d}". base. return output. _HiddenL)). success = run().Append( string.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.ToString(). output.ReportInterval)). } public override bool Test() Page 149 of 225 .Format("\t\t\t\t\t\t\tIgnore target error (process all iterations): {0}".00000}".Format("\nReport every {0:d} generations. } public override bool Train() { bool success = true.Format("\t\t\tTarget Error: {0:0. output.Append( string.Format("\t\t\tMaximum Generation: {0:d}"._Trained = success. base. base. output.IterMax)).

Append("\nOutput achieved was:"). i++) { ((Model. getdata.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. output. out tstoutput). } output.Format(" [{0:g}] ". i < tstinput. try { for (int i = 0. Page 150 of 225 .Format(" [{0:g}] ". for (int j = 0. double[][] tstoutput.Length.Length. j++) { output. netoutput = ((Model. netoutput[j])). j < tstinput[i]. tstinput[i][j])). double[][] tstinput. output.GetScaledTestingData(out tstinput.Run(tstinput[i]).Append("\n\n\t\t\t~~Network Testing~~").Append(string. j < netoutput.Append("\nWith inputs:"). StringBuilder output = new StringBuilder(). j++) { output.GANetwork)Population[0]).GetOutput(). double[] netoutput. for (int j = 0.GANetwork)Population[0]).Length.Append(string.

} base. j++) { output. MessageBoxButtons.GANetwork)Population[0]).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. base.ToString()). tstoutput[i][j])). } } output. ((Model. "Error".Append("\nOutput Desired was:").GANetwork)Population[0]). } catch { MessageBox. j < tstoutput[i].Append(string.tstoutput). MessageBoxIcon.getMsQE(tstinput.Length. } #endregion } Page 151 of 225 . (double) ((Model._Tested = success.Append("\nMean Squared Error with these inputs and outputs is:").Report(output.Error). output.Format(" [{0:g}] ".".Format ("{0:g}". return success.OK. for (int j = 0. success = false.MSqE)).Show("Error Running Test.Append( string.

System. private double _LearnRate.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. System.6 . System.“Algorithms\BackProp.Text.IO. System.1. FANN_BackProp BPnet.Forms.Algorithms { public class BackProp : TrainingAlgorithm { #region data /********************\ |* DATA *| \********************/ private double _InputL.2.Windows.Collections. _05025397.Controller. System.Linq.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 9. namespace _05025397. ZedGraph. #endregion #region constructor Page 152 of 225 . System.Generic. FANN_Wrapper.Collections. private int _HiddenL. private double _OutputL.

ITerr) { _HiddenL = HiddenL. HiddenL. txtTest. } #endregion #region internal_functions /********************\ Page 153 of 225 . out _InputL. double LearnRate. txtTest).IterMax). out _OutputL). _LearnRate = LearnRate. double TargetError. base. txtData. int Reports.TargetError.GetStructure(out iterations. saveDllData(txtData. Reports. _LearnRate. getdata. base. Iter_Max. int Iter_Max. BPnet = new FANN_BackProp((int)_InputL. bool ITerr.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.ReportInterval. double iterations. (int)_OutputL. //Copy the training and testing data to the dat files //ready for the DLL's to access. RichTextBox txtTest) : base(TargetError. RichTextBox txtData. base.

RichTextBox te) { TextWriter tw = new StreamWriter("dlltrdata. tw = new StreamWriter("dlltedata.Format ("\t\t\tOutput Layer: {0:d}". (int) _InputL)).Close().Write(tr. (int) _OutputL)). output.Text). tw.Text). output. output. } #endregion #region external_functions /********************\ |* EXTERNAL *| \********************/ public override string network_details() { StringBuilder output = new StringBuilder().Append( Page 154 of 225 . 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.dat"). tw.Close().Append( string.Format ("Network Details: \n Input Layer: {0:d}".Append( string. tw.dat").

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.".Append( string.Format ("\nLearning Rate: {0:0.00000}".Format ("\nReport every {0:d} generations.Append( string.Format ("\t\t\tHidden Layer: {0:d}". } public override bool Train() { Page 155 of 225 .IterMax)). output. output. _ITerr)). output. base. _LearnRate)).Append( string.ReportInterval)).Format ("\t\t\tTarget Error: {0:0.Format ("\t\tMaximum Epoch: {0:d}".ToString(). return output. output.Append( string. (int) _HiddenL)).TargetError)).Append( string. base.Format ("\t\t\t\t\t\tIgnore target error " + "(process all iterations): {0}".00000}". base. output.

Length. "Error"._Trained = success. } success = getGraphDataFromDll().OK. base._tr_output). i < besterrlist. besterrlist[i]). i++) { base.Add((double)i. try { success = BPnet.BestErrList. MessageBoxIcon. Page 156 of 225 . success = false.besterrorlist.Error). Report(BPnet. return success. for (int i = 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 bool success = true. } catch { MessageBox.Show("Error running Backprop training!". MessageBoxButtons.Train(). try { double[] besterrlist = BPnet. } public bool getGraphDataFromDll() { bool success = true.

OK.Show("Error running Backprop testing!". MessageBoxButtons. return success. try { success = BPnet.Error). MessageBoxIcon. } catch { MessageBox. } base. } #endregion Page 157 of 225 . "Error". } public override bool Test() { bool success = true.Test(). MessageBoxIcon.OK.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.Show("Error getting graph data from DLL". } return success. success = false. MessageBoxButtons. Report(BPnet. "Error"._te_output). success = false._Tested = success.Error).

Generic.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.“Network. protected int _numoutputs.1.Collections. protected double[][][] _weights.Windows.1.Linq. protected int _numinputs. _05025397.Model { public class Network { #region data /********************\ |* DATA *| \********************/ //[layer][node][input] protected double[][][] _inputs.3. protected int _hiddennodes.Model 9.Text. System. namespace _05025397. protected double[][] _outputs.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 00000180 00000181 } } 9.Forms. Page 158 of 225 .1 . System. System. System.3 .

#endregion #region init /********************\ |* INIT *| \********************/ private void init_inputlayer() { _inputs[0] = new double[_numinputs][]. Page 159 of 225 . _weights[1][i] = new double[_numinputs + 1]. i++) { _inputs[1][i] = new double[_numinputs + 1]. _outputs[0] = new double[_numinputs]. i < _numinputs. for (int i = 0. } } private void init_hiddenlayer() { _inputs[1] = new double[_hiddennodes][]. for (int i = 0.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] = new double[_hiddennodes][]. i++) { _inputs[0][i] = new double[2]. _outputs[1] = new double[_hiddennodes]. _weights[0][i] = new double[2]. i < _hiddennodes. _weights[0] = new double[_numinputs][].

i++) { _inputs[0][i][1] = 1.0. Page 160 of 225 . i++) { _inputs[1][i][_numinputs] = 1. i < _numoutputs.0. } //Hidden layer bias for (int i = 0. i < _hiddennodes. for (int i = 0. i++) { _inputs[2][i] = new double[_hiddennodes + 1]. } } private void init_bias() { //Input bias for (int i = 0. i < _numinputs. _weights[2][i] = new double[_hiddennodes + 1].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][].0. _weights[0][i][1] = 1. _outputs[2] = new double[_numoutputs]. _weights[1][i][_numinputs] = 1. _weights[2] = new double[_numoutputs][].0.

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.0. _weights[2][i][_hiddennodes] = 1.NextDouble(). i < _numinputs. j++) { _weights[1][i][j] = Rand.NextDouble(). i++) { for (int j = 0. i < _hiddennodes. i++) { _weights[0][i][0] = Rand. } } } private void init_outputweights() Page 161 of 225 . } } private void init_hiddenweights() { for (int i = 0.0. i < _numoutputs. j < _numinputs. i++) { _inputs[2][i][_hiddennodes] = 1. } } private void init_inputweights() { for (int i = 0.

0. i < _numinputs. j++) { _weights[2][i][j] = Rand. } } } #endregion #region internal /********************\ |* INTERNAL *| \********************/ private double sigmoid(double input) { return (1 / (1 + Math. i++) { Page 162 of 225 . i < _numoutputs. -input))). i++) { for (int j = 0.Pow(Math.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. j < _hiddennodes.E. double sum = 0. try { //Calculate results for this layer for (int i = 0. } private bool Runinput() { bool success = true.NextDouble().

OK. j < _numinputs. i < _hiddennodes.Show("Error processing input layer". j < 2. } _outputs[0][i] = sigmoid(sum).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. } private bool Runhidden() { bool success = true. success = false. MessageBoxIcon. try { //Feed forward the results from input layer for (int i = 0. sum = 0. j++) { _inputs[1][i][j] = _outputs[0][j]. } return success.0. Page 163 of 225 .0. double sum = 0. MessageBoxButtons. j++) { sum += (_inputs[0][i][j] * _weights[0][i][j]). "Error". } } catch { MessageBox. i++) { for (int j = 0.

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. try Page 164 of 225 .0. } _outputs[1][i] = sigmoid(sum). MessageBoxButtons. sum = 0.Error). MessageBoxIcon. "Error".Show("Error processing hidden layer". } return success. } } catch { MessageBox. } private bool Runoutput() { bool success = true. success = false. double sum = 0. j++) { sum += (_inputs[1][i][j] * _weights[1][i][j]).OK. j < _numinputs + 1. i < _hiddennodes. i++) { for (int j = 0.0.

j < _hiddennodes. MessageBoxButtons. j++) { _inputs[2][i][j] = _outputs[1][j]. } Page 165 of 225 . } } catch { MessageBox. } _outputs[2][i] = sigmoid(sum). j < _hiddennodes + 1.Show("Error processing output layer".OK.Error). "Error". success = false. j++) { sum += (_inputs[2][i][j] * _weights[2][i][j]).0. i < _numoutputs. sum = 0.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. } } //Calculate results for this layer for (int i = 0. i++) { for (int j = 0. i < _numoutputs. } return success. i++) { for (int j = 0. MessageBoxIcon.

MessageBoxIcon. } if (success) for (int i = 0. success = false. MessageBoxButtons. //The numbers of inputs must match up if (inputs.Length != _numinputs) { MessageBox. if(success) success = Runinput().Show("Error: Incorrect number of inputs supplied to NN".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. _inputs[0][i][0] = inputs[i]. if(success) success = Runhidden(). "Incorrect number of inputs". Page 166 of 225 .the number of nodes corresponds //to the number of inputs accepted. i++) //Each input node has only one real input //and a bias .Error). i < _numinputs.OK.

_numoutputs = numoutputs. int numoutputs. //Set network structure descriptors _numinputs = numinputs. } #endregion #region constructor /********************\ |* CONSTRUCTOR *| \********************/ public Network(int numinputs. int SetRandom) { //Set random number generator Rand = new Random(SetRandom). return success. //We'll always have 3 layers Page 167 of 225 . int hiddennodes. _hiddennodes = hiddennodes. } public double[] GetOutput() { //Return the outputs from the //output layer return _outputs[2].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().

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

} } /********************\ |* GETTERS/SETTERS *| \********************/ public double MSqE { Page 172 of 225 . Application. wc++) { _weights[i][j][k] = weights[wc].Length.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".Length. k++. j < _weights[i].Error). k < _weights[i][j]. i++) { for (int j = 0.Length. j++) { for (int k = 0.OK. i < _weights. } } } } catch { MessageBox. MessageBoxButtons. MessageBoxIcon.Exit(). "Error". wc = 0.

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. } set { _MSqE = value. int Nhnodes. Nhnodes. } #endregion } Page 173 of 225 . int SetRandom) : base(Ninputs. int Noutputs.0. SetRandom) { MSqE = 0. Noutputs. } } #endregion #region constructor /********************\ |* CONSTRUCTOR *| \********************/ public GANetwork(int Ninputs.

int OutputL. using namespace System::Runtime::InteropServices.DLL Wrapper for FANN functions 9. double LearnRate.1. Page 174 of 225 .4.4 . { public: /********************\ |* DATA *| \********************/ UnManaged_FANN_CasC* UMWrapper.“FANN_Wrapper. public: /********************\ |* EXTERNAL *| \********************/ FANN_Cascade(int InputL.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. 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.1 .h" #include "UnManaged_FANN_CasC.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 9.1.h" using namespace System. double TargetErr.

bool Test(void). int ~FANN_Cascade(void). } } property array<double>^ besterrorlist { array<double>^ get() MaxNeurons).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. public: /********************\ |* GETTERS/SETTERS *| \********************/ property String^ _te_output { String^ get() { return gcnew String((wchar_t *) UMWrapper->get_report_test()). bool Train(void). !FANN_Cascade(void). Page 175 of 225 . } } property String^ _tr_output { String^ get() { return gcnew String((wchar_t *) UMWrapper->get_report_train()).

array<double>^ arout = gcnew array<double>(size). i < size. { public: /********************\ |* DATA *| \********************/ UnManaged_FANN_Backprop* UMWrapper. } return arout. public ref class FANN_BackProp //Managed wrapper for UnManaged_FANN_Backprop //which is a C++ interface to the C programmed //FANN dll. for(int i = 0. public: Page 176 of 225 . i++) { arout[i] = ar[i]. } } }.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. const double *ar = UMWrapper->get_besterrs(size).

int ReportInterval. public: /********************\ |* GETTERS/SETTERS *| \********************/ property String^ _te_output { String^ get() { return gcnew String((wchar_t *) UMWrapper->get_report_test()). double TargetErr. int OutputL. int HiddenL. } } property String^ _tr_output { String^ get() { return gcnew String((wchar_t *) UMWrapper->get_report_train()). bool Test(void). bool Train(void). ~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. !FANN_BackProp(void). } Page 177 of 225 . double LearnRate. int MaximumIteration).

const double *ar = UMWrapper->get_besterrs(size).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. i < size. } return arout. array<double>^ arout = gcnew array<double>(size). } } }. i++) { arout[i] = ar[i]. Page 178 of 225 . for(int i = 0.

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

“UnManaged_FANN_BackProp.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. //Training Parameters double _LearnRate.h> class UnManaged_FANN_Backprop //An interface to the C programmed //FANN dll. int _OutputL. int _ReportInterval. int _MaximumIteration.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 9.4. double _TargetErr.1.3 . { private: /********************\ |* DATA *| \********************/ //Network Structure int _InputL. int _HiddenL. double _Momentum.h> #include <fann_cpp. //Output for C# Page 183 of 225 .

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

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

data = NULL. int OutputL. ann = NULL.1. _OutputL = OutputL. } //Destructor UnManaged_FANN_Backprop::~UnManaged_FANN_Backprop() { fann_destroy_train(data).h" //Constructor UnManaged_FANN_Backprop::UnManaged_FANN_Backprop (int InputL. _HiddenL = HiddenL. Page 186 of 225 . double TargetErr. wchoutput = NULL.h" #include "UnManaged_FANN_BackProp.“UnManaged_FANN_BackProp. _ReportInterval = ReportInterval. double LearnRate. int HiddenL. _MaximumIteration = MaximumIteration.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.4 . _LearnRate = LearnRate. int ReportInterval.4. _TargetErr = TargetErr. int MaximumIteration) { _InputL = InputL. bsterr = NULL.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 9.

_InputL..) { throw(""). _OutputL). bsterr = NULL. success = false..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. _HiddenL. int reportcounter = 0. ann = fann_create_standard(3. wchoutput = NULL. try { data = fann_read_train_from_file("dlltrdata. } //Train bool UnManaged_FANN_Backprop::Train(void) { static int firstrun = false. delete wchoutput. bool success = true.dat"). } if (fann_num_input_train_data(data) != _InputL) Page 187 of 225 . double error. } catch(.

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_set_activation_steepness_hidden(ann. FANN_SIGMOID). 1). success = false. success = false. //Sigmoid Activation Functions (the same one //the GA uses). fann_set_activation_steepness_output(ann. FANN_TRAIN_BATCH). (float) _LearnRate). //Set the learning rate fann_set_learning_rate(ann. fann_set_activation_function_output (ann. } if (fann_num_output_train_data(data) != _OutputL) { throw(""). //Standard backprop fann_set_training_algorithm(ann. //Same range the GA's weights are //initialised too Page 188 of 225 . fann_set_activation_function_hidden (ann. 1). FANN_SIGMOID).

i++) { //Train one epoch then check the //mean squared error error = (double) fann_train_epoch(ann. reportcounter = 0. i = _MaximumIteration + 1.\n". } } fann_destroy_train(data). 1. } reportcounter++. data).".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. if (reportcounter == _ReportInterval) { tr_output << "Best error at iteration [ " << i << " ] was " << error << ".push_back(error). Page 189 of 225 . //Training Loop for (int i = 0. vecbsterr. i < _MaximumIteration.0. if (error < _TargetErr) { tr_output << "\nNetwork matching or improving upon target error" << "found at iteration [ " << i << " ]. 0.

for (int j = 0. } te_output << "\nOutput achieved was". data = fann_read_train_from_file("dlltedata. i++) { calc_out = fann_run(ann.dat"). 0. j++) { te_output << " [" << data->input[i][j] << "] ". for (unsigned int i = 0. double *error = NULL.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. fann_scale_train_data(data. error = new double[fann_length_train_data(data)]. j++) { Page 190 of 225 . i < fann_length_train_data(data). 1). return true. te_output << "\nWith inputs". j < _InputL. te_output << "\n\n\t\t\t~~Network Testing~~". data->input[i]). j < _OutputL. for (int j = 0. } //Test bool UnManaged_FANN_Backprop::Test(void) { fann_type *calc_out = NULL.

return true. j++) { te_output << " [" << data->output[i][j] << "] ". wcscpy(wchoutput. } te_output << "\nOutput Desired was". } //get_report const wchar_t* UnManaged_FANN_Backprop::get_report_train(void) { if (wchoutput != NULL) { delete wchoutput.length() + 1]. tr_output. } } te_output << "\nMean Squared Error with these inputs and outputs is:".c_str()).str(). } wchoutput = new wchar_t[tr_output.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] << "] ". delete error.str(). te_output << fann_test_data(ann. wchoutput = NULL. data). j < _OutputL. delete calc_out. for (int j = 0. Page 191 of 225 .

bsterr = NULL. } bsterr = new double[vecbsterr. wchoutput = NULL. } const wchar_t* UnManaged_FANN_Backprop::get_report_test(void) { if (wchoutput != NULL) { delete wchoutput. return wchoutput. size = vecbsterr. } wchoutput = new wchar_t[te_output.str().size(). } //get_besterrs const double* UnManaged_FANN_Backprop::get_besterrs(int &size) { if (bsterr == NULL) { delete bsterr. Page 192 of 225 .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.length() + 1].c_str()).size()].str(). wcscpy(wchoutput. te_output.

//Training Parameters Page 193 of 225 . i < vecbsterr.clear(). int _OutputL.5 .1.4.h> class UnManaged_FANN_CasC { public: /********************\ |* DATA *| \********************/ //Network Structure int _InputL.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. 9. i++) { bsterr[i] = vecbsterr[i].size().“UnManaged_FANN_CasC. return bsterr. } vecbsterr.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.

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

00000053 bool Test(void). 00000054 00000055 static int FANN_API Report_Callback 00000056 (struct fann *ann. unsigned int epochs). 00000065 const wchar_t* get_report_test(void). unsigned int epochs_between_reports.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). Page 195 of 225 . struct fann_train_data *train. 00000058 float desired_error. 00000057 unsigned int max_epochs. 00000068 }. 00000066 00000067 const double* get_besterrs(int &size).

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 "UnManaged_FANN_CasC.h" //Static variable declarations std::wstringstream UnManaged_FANN_CasC::tr_output. int ReportInterval.6 . _OutputL = OutputL. int OutputL.4. _ReportInterval = ReportInterval. double TargetErr. _TargetErr = TargetErr. ann = NULL.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 9.1. _LearnRate = LearnRate. wchoutput = NULL.“UnManaged_FANN_CasC. double LearnRate. std::vector<double> UnManaged_FANN_CasC::vecbsterr. data = NULL. //Constructor UnManaged_FANN_CasC::UnManaged_FANN_CasC (int InputL. } //Destructor UnManaged_FANN_CasC::~UnManaged_FANN_CasC(void) Page 196 of 225 . int MaxNeurons) { _InputL = InputL. _MaxNeurons = MaxNeurons. bsterr = NULL.

str(). tr_output.str().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.length() + 1]. } wchoutput = new wchar_t[tr_output. fann_destroy_train(data). bsterr = NULL. delete wchoutput.c_str()). return wchoutput. wchoutput = NULL. wchoutput = NULL. } //get_report const wchar_t* UnManaged_FANN_CasC::get_report_train(void) { if (wchoutput != NULL) { delete wchoutput. } const wchar_t* UnManaged_FANN_CasC::get_report_test(void) { if (wchoutput != NULL) { delete wchoutput. Page 197 of 225 . wcscpy(wchoutput.

return bsterr.length() + 1]. wcscpy(wchoutput. i < vecbsterr.size()]. bsterr = NULL. te_output. size = vecbsterr.str(). } vecbsterr.c_str()). } Page 198 of 225 . return wchoutput.clear().size().size(). i++) { bsterr[i] = vecbsterr[i]. for (unsigned int i = 0. } wchoutput = new wchar_t[te_output.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. } //get_besterrs const double* UnManaged_FANN_CasC::get_besterrs(int &size) { if (bsterr == NULL) { delete bsterr. } bsterr = new double[vecbsterr.

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

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

data = fann_read_train_from_file("dlltedata. } //Test bool UnManaged_FANN_CasC::Test() { fann_type *calc_out = NULL. tr_output << "Best error at node [ " << node << " ] was " << MSqE << ". fann_scale_train_data(data. float desired_error.". return 0. Page 201 of 225 . unsigned int epochs_between_reports.dat"). } node++. static int node = 1. unsigned int max_epochs. double *error = NULL. unsigned int epochs) { double MSqE = fann_get_MSE(ann). 1). vecbsterr.\n". 0. if (MSqE <= desired_error) { tr_output << "\nNetwork matching or improving upon target error" << "found at node [ " << node << " ]. struct fann_train_data *train.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.push_back(MSqE).

error = new double[fann_length_train_data(data)]. j < _OutputL. data). j++) { te_output << " [" << calc_out[j] << "] ". for (int j = 0. } } te_output << "\nMean Squared Error with these inputs and outputs is:". for (int j = 0.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 < _OutputL. te_output << "\n\n\t\t\t~~Network Testing~~". for (unsigned int i = 0. i < fann_length_train_data(data). j < _InputL. j++) { te_output << " [" << data->output[i][j] << "] ". NULL). i++) { calc_out = fann_run(ann. Page 202 of 225 . data->input[i]). for (int j = 0. j++) { te_output << " [" << data->input[i][j] << "] ". } te_output << "\nOutput achieved was:". te_output << fann_test_data(ann. te_output << "\nWith inputs:". } te_output << "\nOutput Desired was:".

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

2 .William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 9. 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 Page 205 of 225 .

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

edu/ga/ o Accessed: 31/10/2008 Page 207 of 225 .Libraries Researched • GALib o Matthew Wall o http://lancet.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.3 .

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

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

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

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

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

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

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

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

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

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

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

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

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

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

back-propagation network was running and learning XOR.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 13 . o Agreed on further investigation into GALib and genetic algorithms. however. • 24/10/2008 o University computers were down so code demo was impossible. • 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. o Decided on XOR as a starting point. o Submitted objectives. o Decision made to adjust the weights of the neural network during training as opposed to using a genetic algorithm to establish network structure. • 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 . 17/10/2008 o Investigating more deeply into journals based on research already conducted.Diary • 01/10/2008 – Research 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. • • • • • • • • • 19/11/2008 o Milestone one submitted successfully.William Sayers 05025397 Genetic Algorithms and Neural Networks Milestone 3 o Progress satisfactory.

is much faster (fixed several bugs along the way) and retains none of the problematic memory leaks. o Have started report • 02/04/2009 o Main problems experienced with genetic algorithm seem related to memory leaks.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. catch-up time for previous two weeks will be used over Easter break. 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. Page 224 of 225 . 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 o Report satisfactory • 10/04/2009 o Fully functional project – commencing report. o Report satisfactory. Page 225 of 225 .

Sign up to vote on this title
UsefulNot useful