org.neuroph.core.Layer Java Examples
The following examples show how to use
org.neuroph.core.Layer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Hopfield.java From NeurophFramework with Apache License 2.0 | 6 votes |
/** * Creates Hopfield network architecture * * @param neuronsCount * neurons number in Hopfied network * @param neuronProperties * neuron properties */ private void createNetwork(int neuronsCount, NeuronProperties neuronProperties) { // set network type this.setNetworkType(NeuralNetworkType.HOPFIELD); // createLayer neurons in layer Layer layer = LayerFactory.createLayer(neuronsCount, neuronProperties); // createLayer full connectivity in layer ConnectionFactory.fullConnect(layer, 0.1); // add layer to network this.addLayer(layer); // set input and output cells for this network NeuralNetworkFactory.setDefaultIO(this); // set Hopfield learning rule for this network //this.setLearningRule(new HopfieldLearning(this)); this.setLearningRule(new BinaryHebbianLearning()); }
Example #2
Source File: NetworkUtils.java From developerWorks with Apache License 2.0 | 6 votes |
/** * Returns a NxNxNxN style string showing the layer structure * of the specified network. * * @param network * @return */ public static String getNetworkStructure(NeuralNetwork<BackPropagation> network) { StringBuilder sb = new StringBuilder(); // // First the inputs if (network != null) { sb.append(network.getInputsCount()); // // Now for the hidden layers for (Layer layer : network.getLayers()) { sb.append("x"); sb.append(layer.getNeuronsCount()); } // // Finally, the outputs sb.append("x"); sb.append(network.getOutputsCount()); } return sb.toString(); }
Example #3
Source File: ResilientPropagation.java From NeurophFramework with Apache License 2.0 | 6 votes |
@Override protected void doBatchWeightsUpdate() { // iterate layers from output to input List<Layer> layers = neuralNetwork.getLayers(); for (int i = neuralNetwork.getLayersCount() - 1; i > 0; i--) { // iterate neurons at each layer for (Neuron neuron : layers.get(i).getNeurons()) { // iterate connections/weights for each neuron for (Connection connection : neuron.getInputConnections()) { // for each connection weight apply following changes Weight weight = connection.getWeight(); resillientWeightUpdate(weight); } } } }
Example #4
Source File: MatrixMlpLayer.java From NeurophFramework with Apache License 2.0 | 6 votes |
public MatrixMlpLayer(Layer sourceLayer, MatrixLayer previousLayer, TransferFunction transferFunction) { this.sourceLayer = sourceLayer; this.previousLayer = previousLayer; if (!(previousLayer instanceof MatrixInputLayer)) ((MatrixMlpLayer)previousLayer).setNextLayer(this); this.transferFunction = transferFunction; this.neuronsCount = sourceLayer.getNeuronsCount(); // if (sourceLayer.getNeuronAt(neuronsCount-1) instanceof BiasNeuron) this.neuronsCount = this.neuronsCount -1; this.inputsCount = previousLayer.getOutputs().length; outputs = new double[neuronsCount]; // biases = new double[neuronsCount]; // deltaBiases = new double[neuronsCount]; inputs = new double[inputsCount]; netInput = new double[neuronsCount]; weights = new double[neuronsCount][inputsCount]; deltaWeights = new double[neuronsCount][inputsCount]; errors = new double[neuronsCount]; copyNeuronsToMatrices(); }
Example #5
Source File: RecommenderNetwork.java From NeurophFramework with Apache License 2.0 | 6 votes |
private void createProductLabels(Layer layer) { layer.getNeuronAt(0).setLabel("Samsung LCD TV LE-32A330"); layer.getNeuronAt(1).setLabel("Samsung LCD TV LE-32A558"); layer.getNeuronAt(2).setLabel("LG LCD TV 32LG2000"); layer.getNeuronAt(3).setLabel("LG LCD TV 32LG5010"); layer.getNeuronAt(4).setLabel("Sony LCD TV KDL-32L4000K"); layer.getNeuronAt(5).setLabel("Sony LCD TV KDL-32S4000"); layer.getNeuronAt(6).setLabel("Sony LCD TV KDL-32W4000K"); layer.getNeuronAt(7).setLabel("Samsung Digital Camera S760"); layer.getNeuronAt(8).setLabel("Samsung Digital Camera L100"); layer.getNeuronAt(9).setLabel("Samsung Digital Camera S850"); layer.getNeuronAt(10).setLabel("LG Digital Camera DMCLS80E"); layer.getNeuronAt(11).setLabel("LG Digital Camera DMCLZ8E"); layer.getNeuronAt(12).setLabel("Sony Digital Camera DSCW120S"); layer.getNeuronAt(13).setLabel("Sony Digital Camera DSCW130S"); layer.getNeuronAt(14).setLabel("Samsung Mobile Phone E251"); layer.getNeuronAt(15).setLabel("Samsung Mobile Phone U600"); layer.getNeuronAt(16).setLabel("Sony Mobile Phone KP100"); layer.getNeuronAt(17).setLabel("Sony Mobile Phone KE850"); layer.getNeuronAt(18).setLabel("LG Mobile Phone K330"); layer.getNeuronAt(19).setLabel("LG Mobile Phone K660"); }
Example #6
Source File: SupervisedLearning.java From NeurophFramework with Apache License 2.0 | 6 votes |
private void applyWeightChanges() { List<Layer> layers = neuralNetwork.getLayers(); for (int i = neuralNetwork.getLayersCount() - 1; i > 0; i--) { // iterate neurons at each layer for (Neuron neuron : layers.get(i)) { // iterate connections/weights for each neuron for (Connection connection : neuron.getInputConnections()) { // for each connection weight apply accumulated weight change Weight weight = connection.getWeight(); if (!isBatchMode()) { weight.value += weight.weightChange; } else { weight.value += (weight.weightChange / getTrainingSet().size()); } weight.weightChange = 0; // reset deltaWeight } } } }
Example #7
Source File: SupervisedLearning.java From NeurophFramework with Apache License 2.0 | 6 votes |
/** * This method updates network weights in batch mode - use accumulated weights change stored in Weight.deltaWeight * It is executed after each learning epoch, only if learning is done in batch mode. * * @see SupervisedLearning#doLearningEpoch(org.neuroph.core.data.DataSet) */ protected void doBatchWeightsUpdate() { // iterate layers from output to input List<Layer> layers = neuralNetwork.getLayers(); for (int i = neuralNetwork.getLayersCount() - 1; i > 0; i--) { // iterate neurons at each layer for (Neuron neuron : layers.get(i).getNeurons()) { // iterate connections/weights for each neuron for (Connection connection : neuron.getInputConnections()) { // for each connection weight apply accumulated weight change Weight weight = connection.getWeight(); weight.value += weight.weightChange / getTrainingSet().size(); // apply delta weight which is the sum of delta weights in batch mode - TODO: add mini batch weight.weightChange = 0; // reset deltaWeight } } } }
Example #8
Source File: KohonenLearning.java From NeurophFramework with Apache License 2.0 | 6 votes |
private void learnPattern(DataSetRow dataSetRow, int neighborhood) { neuralNetwork.setInput(dataSetRow.getInput()); neuralNetwork.calculate(); Neuron winner = getClosestNeuron(); if (winner.getOutput() == 0) return; // ako je vec istrenirana jedna celija, izadji Layer mapLayer = neuralNetwork.getLayerAt(1); int winnerIdx = mapLayer.indexOf(winner); adjustCellWeights(winner, 0); int cellNum = mapLayer.getNeuronsCount(); for (int p = 0; p < cellNum; p++) { if (p == winnerIdx) continue; if (isNeighbor(winnerIdx, p, neighborhood)) { Neuron cell = mapLayer.getNeuronAt(p); adjustCellWeights(cell, 1); } // if } // for }
Example #9
Source File: QuickPropagation.java From NeurophFramework with Apache License 2.0 | 5 votes |
@Override protected void onStart() { super.onStart(); //To change body of generated methods, choose Tools | Templates. for (Layer layers : neuralNetwork.getLayers()) { for (Neuron neuron : layers.getNeurons()) { for (Connection connection : neuron.getInputConnections()) { //connection.getWeight().setTrainingData(new QuickPropData()); Weight<QuickPropData> qpWeight = new Weight<>(); qpWeight.setTrainingData(new QuickPropData()); connection.setWeight(qpWeight); } } } }
Example #10
Source File: ConnectionFactory.java From NeurophFramework with Apache License 2.0 | 5 votes |
/** * Creates full connectivity within layer - each neuron with all other * within the same layer */ public static void fullConnect(Layer layer) { int neuronNum = layer.getNeuronsCount(); for (int i = 0; i < neuronNum; i++) { for (int j = 0; j < neuronNum; j++) { if (j == i) continue; Neuron from = layer.getNeuronAt(i); Neuron to = layer.getNeuronAt(j); createConnection(from, to); } // j } // i }
Example #11
Source File: ConnectionFactory.java From NeurophFramework with Apache License 2.0 | 5 votes |
/** * Creates full connectivity between the two specified layers * * @param fromLayer * layer to connect * @param toLayer * layer to connect to */ public static void fullConnect(Layer fromLayer, Layer toLayer, boolean connectBiasNeuron) { for(Neuron fromNeuron : fromLayer.getNeurons()) { if (fromNeuron instanceof BiasNeuron) { continue; } for (Neuron toNeuron : toLayer.getNeurons()) { createConnection(fromNeuron, toNeuron); } } }
Example #12
Source File: LayerFactory.java From NeurophFramework with Apache License 2.0 | 5 votes |
public static Layer createLayer(List<NeuronProperties> neuronPropertiesVector) { Layer layer = new Layer(); for(NeuronProperties neuronProperties : neuronPropertiesVector) { Neuron neuron = NeuronFactory.createNeuron(neuronProperties); layer.addNeuron(neuron); } return layer; }
Example #13
Source File: ConvolutionalNetwork.java From NeurophFramework with Apache License 2.0 | 5 votes |
private FeatureMapsLayer getLastFeatureMapLayer() { Layer layer = getLastLayer(); if (layer instanceof FeatureMapsLayer) return (FeatureMapsLayer) layer; throw new RuntimeException("Unable to add next layer because previous layer is not FeatureMapLayer"); }
Example #14
Source File: SupervisedHebbianNetwork.java From NeurophFramework with Apache License 2.0 | 5 votes |
/** *Creates an instance of Supervised Hebbian Network with specified number * of neurons in input layer, output layer and transfer function * * @param inputNeuronsNum * number of neurons in input layer * @param outputNeuronsNum * number of neurons in output layer * @param transferFunctionType * transfer function type */ private void createNetwork(int inputNeuronsNum, int outputNeuronsNum, TransferFunctionType transferFunctionType) { // init neuron properties NeuronProperties neuronProperties = new NeuronProperties(); neuronProperties.setProperty("transferFunction", transferFunctionType); neuronProperties.setProperty("transferFunction.slope", new Double(1)); neuronProperties.setProperty("transferFunction.yHigh", new Double(1)); neuronProperties.setProperty("transferFunction.xHigh", new Double(1)); neuronProperties.setProperty("transferFunction.yLow", new Double(-1)); neuronProperties.setProperty("transferFunction.xLow", new Double(-1)); // set network type code this.setNetworkType(NeuralNetworkType.SUPERVISED_HEBBIAN_NET); // createLayer input layer Layer inputLayer = LayerFactory.createLayer(inputNeuronsNum, neuronProperties); this.addLayer(inputLayer); // createLayer output layer Layer outputLayer = LayerFactory.createLayer(outputNeuronsNum, neuronProperties); this.addLayer(outputLayer); // createLayer full conectivity between input and output layer ConnectionFactory.fullConnect(inputLayer, outputLayer); // set input and output cells for this network NeuralNetworkFactory.setDefaultIO(this); // set appropriate learning rule for this network this.setLearningRule(new SupervisedHebbianLearning()); }
Example #15
Source File: NeuralNetworkCODEC.java From NeurophFramework with Apache License 2.0 | 5 votes |
/** * Encode a network to an array. * @param network The network to encode. */ public static void network2array(NeuralNetwork network, double[] array) { int index = 0; List<Layer> layers = network.getLayers(); for (Layer layer : layers) { for (Neuron neuron : layer.getNeurons()) { for (Connection connection : neuron.getOutConnections()) { array[index++] = connection.getWeight().getValue(); } } } }
Example #16
Source File: HopfieldLearning.java From NeurophFramework with Apache License 2.0 | 5 votes |
/** * Calculates weights for the hopfield net to learn the specified training * set * * @param trainingSet * training set to learn */ public void learn(DataSet trainingSet) { int M = trainingSet.size(); int N = neuralNetwork.getLayerAt(0).getNeuronsCount(); Layer hopfieldLayer = neuralNetwork.getLayerAt(0); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (j == i) continue; Neuron ni = hopfieldLayer.getNeuronAt(i); Neuron nj = hopfieldLayer.getNeuronAt(j); Connection cij = nj.getConnectionFrom(ni); Connection cji = ni.getConnectionFrom(nj); double w = 0; for (int k = 0; k < M; k++) { DataSetRow trainingSetRow = trainingSet.getRowAt(k); double pki = trainingSetRow.getInput()[i]; double pkj = trainingSetRow.getInput()[j]; w = w + pki * pkj; } // k cij.getWeight().setValue(w); cji.getWeight().setValue(w); } // j } // i }
Example #17
Source File: ConvolutionalBackpropagation.java From NeurophFramework with Apache License 2.0 | 5 votes |
@Override protected void calculateErrorAndUpdateHiddenNeurons() { List<Layer> layers = neuralNetwork.getLayers(); for (int layerIdx = layers.size() - 2; layerIdx > 0; layerIdx--) { for (Neuron neuron : layers.get(layerIdx).getNeurons()) { double neuronError = this.calculateHiddenNeuronError(neuron); neuron.setDelta(neuronError); if (layers.get(layerIdx) instanceof ConvolutionalLayer) { // if it is convolutional layer c=adapt weughts, dont touch pooling. Pooling just propagate the error this.calculateWeightChanges(neuron); } } // for } // for }
Example #18
Source File: BackPropagation.java From NeurophFramework with Apache License 2.0 | 5 votes |
/** * This method implements weights adjustment for the hidden layers */ protected void calculateErrorAndUpdateHiddenNeurons() { List<Layer> layers = neuralNetwork.getLayers(); for (int layerIdx = layers.size() - 2; layerIdx > 0; layerIdx--) { for (Neuron neuron : layers.get(layerIdx).getNeurons()) { // calculate the neuron's error (delta) final double delta = calculateHiddenNeuronError(neuron); neuron.setDelta(delta); calculateWeightChanges(neuron); } // for } // for }
Example #19
Source File: Outstar.java From NeurophFramework with Apache License 2.0 | 5 votes |
/** * Creates Outstar architecture with specified number of neurons in * output layer * * @param outputNeuronsCount * number of neurons in output layer */ private void createNetwork(int outputNeuronsCount ) { // set network type this.setNetworkType(NeuralNetworkType.OUTSTAR); // init neuron settings for this type of network NeuronProperties neuronProperties = new NeuronProperties(); neuronProperties.setProperty("transferFunction", TransferFunctionType.STEP); // create input layer Layer inputLayer = LayerFactory.createLayer(1, neuronProperties); this.addLayer(inputLayer); // createLayer output layer neuronProperties.setProperty("transferFunction", TransferFunctionType.RAMP); Layer outputLayer = LayerFactory.createLayer(outputNeuronsCount, neuronProperties); this.addLayer(outputLayer); // create full conectivity between input and output layer ConnectionFactory.fullConnect(inputLayer, outputLayer); // set input and output cells for this network NeuralNetworkFactory.setDefaultIO(this); // set outstar learning rule for this network this.setLearningRule(new OutstarLearning()); }
Example #20
Source File: ConnectionFactory.java From NeurophFramework with Apache License 2.0 | 5 votes |
/** * Creates full connectivity within layer - each neuron with all other * within the same layer with the specified weight values for all * conections. */ public static void fullConnect(Layer layer, double weightVal) { int neuronNum = layer.getNeuronsCount(); for (int i = 0; i < neuronNum; i++) { for (int j = 0; j < neuronNum; j++) { if (j == i) continue; Neuron from = layer.getNeuronAt(i); Neuron to = layer.getNeuronAt(j); createConnection(from, to, weightVal); } // j } // i }
Example #21
Source File: ConnectionFactory.java From NeurophFramework with Apache License 2.0 | 5 votes |
/** * Creates full connectivity within layer - each neuron with all other * within the same layer with the specified weight and delay values for all * conections. */ public static void fullConnect(Layer layer, double weightVal, int delay) { int neuronNum = layer.getNeuronsCount(); for (int i = 0; i < neuronNum; i++) { for (int j = 0; j < neuronNum; j++) { if (j == i) continue; Neuron from = layer.getNeuronAt(i); Neuron to = layer.getNeuronAt(j); createConnection(from, to, weightVal, delay); } // j } // i }
Example #22
Source File: NeuralNetworkFactory.java From NeurophFramework with Apache License 2.0 | 5 votes |
/** * Sets default input and output neurons for network (first layer as input, * last as output) */ public static void setDefaultIO(NeuralNetwork nnet) { ArrayList<Neuron> inputNeuronsList = new ArrayList<>(); Layer firstLayer = nnet.getLayerAt(0); for (Neuron neuron : firstLayer.getNeurons() ) { if (!(neuron instanceof BiasNeuron)) { // dont set input to bias neurons inputNeuronsList.add(neuron); } } List<Neuron> outputNeurons = ((Layer) nnet.getLayerAt(nnet.getLayersCount()-1)).getNeurons(); nnet.setInputNeurons(inputNeuronsList); nnet.setOutputNeurons(outputNeurons); }
Example #23
Source File: Adaline.java From NeurophFramework with Apache License 2.0 | 5 votes |
/** * Creates adaline network architecture with specified number of input neurons * * @param inputNeuronsCount * number of neurons in input layer */ private void createNetwork(int inputNeuronsCount) { // set network type code this.setNetworkType(NeuralNetworkType.ADALINE); // create input layer neuron settings for this network NeuronProperties inNeuronProperties = new NeuronProperties(); inNeuronProperties.setProperty("transferFunction", TransferFunctionType.LINEAR); // createLayer input layer with specified number of neurons //Layer inputLayer = LayerFactory.createLayer(inputNeuronsCount, inNeuronProperties); Layer inputLayer = new InputLayer(inputNeuronsCount); inputLayer.addNeuron(new BiasNeuron()); // add bias neuron (always 1, and it will act as bias input for output neuron) this.addLayer(inputLayer); // create output layer neuron settings for this network NeuronProperties outNeuronProperties = new NeuronProperties(); outNeuronProperties.setProperty("transferFunction", TransferFunctionType.LINEAR); // was RAMP // outNeuronProperties.setProperty("transferFunction.slope", new Double(1)); // outNeuronProperties.setProperty("transferFunction.yHigh", new Double(1)); // outNeuronProperties.setProperty("transferFunction.xHigh", new Double(1)); // outNeuronProperties.setProperty("transferFunction.yLow", new Double(-1)); // outNeuronProperties.setProperty("transferFunction.xLow", new Double(-1)); // createLayer output layer (only one neuron) Layer outputLayer = LayerFactory.createLayer(1, outNeuronProperties); this.addLayer(outputLayer); // createLayer full conectivity between input and output layer ConnectionFactory.fullConnect(inputLayer, outputLayer); // set input and output cells for network NeuralNetworkFactory.setDefaultIO(this); // set LMS learning rule for this network this.setLearningRule(new LMS()); }
Example #24
Source File: NeuralNetworkCODEC.java From NeurophFramework with Apache License 2.0 | 5 votes |
/** * Decode a network from an array. * @param array The array used to decode. * @param network The network to decode into. */ public static void array2network(double[] array, NeuralNetwork network) { int index = 0; List<Layer> layers = network.getLayers(); for (Layer layer : layers) { for (Neuron neuron : layer.getNeurons()) { for (Connection connection : neuron.getOutConnections()) { connection.getWeight().setValue(array[index++]); //connection.getWeight().setPreviousValue(array[index++]); } } } }
Example #25
Source File: NeuralNetworkCODEC.java From NeurophFramework with Apache License 2.0 | 5 votes |
/** * Determine the array size for the given neural network. * @param network The neural network to determine for. * @return The size of the array necessary to hold that network. */ public static int determineArraySize(NeuralNetwork network) { int result = 0; List<Layer> layers = network.getLayers(); for (Layer layer : layers) { for (Neuron neuron : layer.getNeurons()) { result+=neuron.getOutConnections().size(); } } return result; }
Example #26
Source File: BackPropagationTest.java From NeurophFramework with Apache License 2.0 | 5 votes |
@Test public void testCalculateErrorAndUpdateHiddenNeurons() { NeuralNetwork<BackPropagation> nn = new NeuralNetwork<>(); nn.setInputNeurons(new ArrayList<Neuron>() { { add(new Neuron()); add(new Neuron()); } }); nn.setOutputNeurons(new ArrayList<Neuron>() { { add(new Neuron()); } }); nn.setLearningRule(instance); Layer l1 = new Layer(); Layer l2 = new Layer(); Layer l3 = new Layer(); Neuron n = new Neuron(); n.setDelta(0.5); Neuron n1 = new Neuron(); Linear transfer = new Linear(); n1.setTransferFunction(transfer); double weigth = 2; n.addInputConnection(new Connection(n1, n, weigth)); assertTrue(0 == n1.getDelta()); nn.addLayer(l1); nn.addLayer(l2); nn.addLayer(l3); l2.addNeuron(n1); instance.calculateErrorAndUpdateHiddenNeurons(); assertTrue(instance.calculateHiddenNeuronError(n1) == n1.getDelta()); }
Example #27
Source File: MatrixMultiLayerPerceptron.java From NeurophFramework with Apache License 2.0 | 5 votes |
private void createMatrixLayers() { matrixLayers = new MatrixLayer[sourceNetwork.getLayersCount()]; matrixLayers[0] = new MatrixInputLayer(sourceNetwork.getLayerAt(0).getNeuronsCount()); MatrixLayer prevLayer = matrixLayers[0]; for(int i =1; i < sourceNetwork.getLayersCount(); i++ ) { Layer layer = sourceNetwork.getLayerAt(i); MatrixMlpLayer newBpLayer = new MatrixMlpLayer(layer, prevLayer, new Tanh()); matrixLayers[i] = newBpLayer; prevLayer = newBpLayer; } }
Example #28
Source File: RandomizationSample.java From NeurophFramework with Apache License 2.0 | 5 votes |
public static void printWeights(NeuralNetwork<?> neuralNet) { for (Layer layer : neuralNet.getLayers()) { for (Neuron neuron : layer.getNeurons()) { for (Connection connection : neuron.getInputConnections()) { System.out.print(connection.getWeight().value + " "); } System.out.println(); } } }
Example #29
Source File: Model.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public NeuralNetwork<MomentumBackpropagation> createNeuralNetwork(Integer inValueCount, Integer outValueCount, Integer hiddenLayerCount) { NeuronProperties inputNeuronProperties = new NeuronProperties(InputNeuron.class, Linear.class); NeuronProperties hiddenNeuronProperties = new NeuronProperties(InputOutputNeuron.class, WeightedSum.class, Sigmoid.class); NeuronProperties outputNeuronProperties = new NeuronProperties(InputOutputNeuron.class, WeightedSum.class, Sigmoid.class); NeuralNetwork<MomentumBackpropagation> neuralNetwork = new NeuralNetwork<>(); neuralNetwork.setNetworkType(NeuralNetworkType.MULTI_LAYER_PERCEPTRON); Layer inputLayer = LayerFactory.createLayer(inValueCount, inputNeuronProperties); inputLayer.addNeuron(new BiasNeuron()); neuralNetwork.addLayer(inputLayer); List<Integer> hiddenNeurons = this.hiddenNeurons(inValueCount, outValueCount, hiddenLayerCount); for (Integer count : hiddenNeurons) { Layer layer = LayerFactory.createLayer(count, hiddenNeuronProperties); layer.addNeuron(new BiasNeuron()); neuralNetwork.addLayer(layer); } Layer outputLayer = LayerFactory.createLayer(outValueCount, outputNeuronProperties); neuralNetwork.addLayer(outputLayer); for (int i = 0; i < (neuralNetwork.getLayersCount() - 1); i++) { Layer prevLayer = neuralNetwork.getLayers().get(i); Layer nextLayer = neuralNetwork.getLayers().get(i + 1); ConnectionFactory.fullConnect(prevLayer, nextLayer); } neuralNetwork.setLearningRule(this.createMomentumBackpropagation( MapTools.getDouble(this.getPropertyMap(), PROPERTY_MLP_MAXERROR, DEFAULT_MLP_MAXERROR), MapTools.getInteger(this.getPropertyMap(), PROPERTY_MLP_MAXITERATION, DEFAULT_MLP_MAXITERATION), MapTools.getDouble(this.getPropertyMap(), PROPERTY_MLP_LEARNINGRATE, DEFAULT_MLP_LEARNINGRATE), MapTools.getDouble(this.getPropertyMap(), PROPERTY_MLP_MOMENTUM, DEFAULT_MLP_MOMENTUM))); NeuralNetworkFactory.setDefaultIO(neuralNetwork); neuralNetwork.randomizeWeights(); return neuralNetwork; }
Example #30
Source File: NeurophXOR.java From tutorials with MIT License | 5 votes |
public static NeuralNetwork assembleNeuralNetwork() { Layer inputLayer = new Layer(); inputLayer.addNeuron(new Neuron()); inputLayer.addNeuron(new Neuron()); Layer hiddenLayerOne = new Layer(); hiddenLayerOne.addNeuron(new Neuron()); hiddenLayerOne.addNeuron(new Neuron()); hiddenLayerOne.addNeuron(new Neuron()); hiddenLayerOne.addNeuron(new Neuron()); Layer hiddenLayerTwo = new Layer(); hiddenLayerTwo.addNeuron(new Neuron()); hiddenLayerTwo.addNeuron(new Neuron()); hiddenLayerTwo.addNeuron(new Neuron()); hiddenLayerTwo.addNeuron(new Neuron()); Layer outputLayer = new Layer(); outputLayer.addNeuron(new Neuron()); NeuralNetwork ann = new NeuralNetwork(); ann.addLayer(0, inputLayer); ann.addLayer(1, hiddenLayerOne); ConnectionFactory.fullConnect(ann.getLayerAt(0), ann.getLayerAt(1)); ann.addLayer(2, hiddenLayerTwo); ConnectionFactory.fullConnect(ann.getLayerAt(1), ann.getLayerAt(2)); ann.addLayer(3, outputLayer); ConnectionFactory.fullConnect(ann.getLayerAt(2), ann.getLayerAt(3)); ConnectionFactory.fullConnect(ann.getLayerAt(0), ann.getLayerAt(ann.getLayersCount() - 1), false); ann.setInputNeurons(inputLayer.getNeurons()); ann.setOutputNeurons(outputLayer.getNeurons()); ann.setNetworkType(NeuralNetworkType.MULTI_LAYER_PERCEPTRON); return ann; }