1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| ...
net = new NeuralNet();
// First, creates the three Layers
input = new SigmoidLayer();
hidden = new SigmoidLayer();
output = new SigmoidLayer();
input.setLayerName("input");
hidden.setLayerName("hidden");
output.setLayerName("output");
// sets their dimensions
input.setRows(4);
hidden.setRows(4);
output.setRows(2);
net.addLayer(input);
net.addLayer(hidden);
net.addLayer(output);
// Now create the two Synapses
FullSynapse synapse_IH = new FullSynapse(); /* input -> hidden conn. */
FullSynapse synapse_HO = new FullSynapse(); /* hidden -> output conn. */
synapse_IH.setName("IH");
synapse_HO.setName("HO");
// Connect the input layer whit the hidden layer
input.addOutputSynapse(synapse_IH);
hidden.addInputSynapse(synapse_IH);
// Connect the hidden layer whit the output layer
hidden.addOutputSynapse(synapse_HO);
output.addInputSynapse(synapse_HO);
...
// Create the Monitor object and set the learning parameters
monitor = new Monitor();
monitor.setLearningRate(0.1);
monitor.setMomentum(0.9);
net.setMonitor(monitor);
monitor.addNeuralNetListener(this);
MemoryInputSynapse inputStream = new MemoryInputSynapse();
// The first two columns contain the input values
inputStream.setInputArray(inputArray);
inputStream.setAdvancedColumnSelector("1-4");
// set the input data
net.addInputSynapse(inputStream);
TeachingSynapse trainer = new TeachingSynapse();
trainer.setMonitor(monitor);
MemoryInputSynapse samples = new MemoryInputSynapse();
// The output values are on the third column of the file
samples.setInputArray(inputArray);
samples.setAdvancedColumnSelector("5,6");
trainer.setDesired(samples);
// Connects the Teacher to the last layer of the net
net.addOutputSynapse(trainer);
net.start();
monitor.setTrainingPatterns(inputArray.length); // # of rows (patterns) contained in the input file
monitor.setTotCicles(8000); // How many times the net must be trained on the input patterns
monitor.setLearning(true); // The net must be trained
mills = System.currentTimeMillis();
monitor.Go(); // The net starts the training job |
Partager