@Test(expected=IllegalArgumentException.class) public void testLearnWithNullInput(){ algorithm.learn(null, EXPECTED_LABELS, LEARNING_RATE); }
public double learn(double[] inputPattern, double[] expectedLabels, double learningRate) { if (inputPattern == null || inputPattern.length != neuralNet.getNetInputSize()) { throw new IllegalArgumentException("Specified input pattern vector is null " + "or does not match the input dimension of underlying neural network model."); } if (expectedLabels == null || expectedLabels.length != neuralNet.getNetOutputSize()) { throw new IllegalArgumentException("Specified expected labels vector is null " + "or does not match the output dimension of underlying neural network model."); } double[] networkOutputs = neuralNet.feedForward(inputPattern); double[] outputErrors = computeErrorsForNeurons(networkOutputs, expectedLabels); if (outputErrors == null) { return Double.NaN; } double weightsSquareSum = 0; int layersCount = neuralNet.getLayersCount(); for (int layerIndex = layersCount - 1; layerIndex > 0; layerIndex--) { List<Neuron> layer = neuralNet.getLayerUnits(layerIndex); if (layerIndex == layersCount - 1) { computeOutputLayerErrorTerms(layer, outputErrors); } else { List<Neuron> nextLayer = neuralNet.getLayerUnits(layerIndex + 1); computeHiddenLayerErrorTerms(layer, nextLayer); } List<Neuron> previousLayer = neuralNet.getLayerUnits(layerIndex - 1); double[] previousLayerOut = new double[previousLayer.size()]; int previousLayerSize = previousLayer.size(); for (int n = 0; n < previousLayerSize; n++) { previousLayerOut[n] = previousLayer.get(n).getOutput(); } for (Neuron neuron : layer) { double[] weights = neuron.getWeights(); for (double weight : weights) { weightsSquareSum += weight * weight; } } updateWeights(layer, previousLayerOut, learningRate); } double globalError = 0; for (double error : outputErrors) { globalError += Math.abs(error); } globalError += weightsDecayCost * 0.5 * weightsSquareSum; return globalError; }
BPMLLAlgorithm { public double learn(double[] inputPattern, double[] expectedLabels, double learningRate) { if (inputPattern == null || inputPattern.length != neuralNet.getNetInputSize()) { throw new IllegalArgumentException("Specified input pattern vector is null " + "or does not match the input dimension of underlying neural network model."); } if (expectedLabels == null || expectedLabels.length != neuralNet.getNetOutputSize()) { throw new IllegalArgumentException("Specified expected labels vector is null " + "or does not match the output dimension of underlying neural network model."); } double[] networkOutputs = neuralNet.feedForward(inputPattern); double[] outputErrors = computeErrorsForNeurons(networkOutputs, expectedLabels); if (outputErrors == null) { return Double.NaN; } double weightsSquareSum = 0; int layersCount = neuralNet.getLayersCount(); for (int layerIndex = layersCount - 1; layerIndex > 0; layerIndex--) { List<Neuron> layer = neuralNet.getLayerUnits(layerIndex); if (layerIndex == layersCount - 1) { computeOutputLayerErrorTerms(layer, outputErrors); } else { List<Neuron> nextLayer = neuralNet.getLayerUnits(layerIndex + 1); computeHiddenLayerErrorTerms(layer, nextLayer); } List<Neuron> previousLayer = neuralNet.getLayerUnits(layerIndex - 1); double[] previousLayerOut = new double[previousLayer.size()]; int previousLayerSize = previousLayer.size(); for (int n = 0; n < previousLayerSize; n++) { previousLayerOut[n] = previousLayer.get(n).getOutput(); } for (Neuron neuron : layer) { double[] weights = neuron.getWeights(); for (double weight : weights) { weightsSquareSum += weight * weight; } } updateWeights(layer, previousLayerOut, learningRate); } double globalError = 0; for (double error : outputErrors) { globalError += Math.abs(error); } globalError += weightsDecayCost * 0.5 * weightsSquareSum; return globalError; } }
BPMLLAlgorithm { public double learn(double[] inputPattern, double[] expectedLabels, double learningRate) { if (inputPattern == null || inputPattern.length != neuralNet.getNetInputSize()) { throw new IllegalArgumentException("Specified input pattern vector is null " + "or does not match the input dimension of underlying neural network model."); } if (expectedLabels == null || expectedLabels.length != neuralNet.getNetOutputSize()) { throw new IllegalArgumentException("Specified expected labels vector is null " + "or does not match the output dimension of underlying neural network model."); } double[] networkOutputs = neuralNet.feedForward(inputPattern); double[] outputErrors = computeErrorsForNeurons(networkOutputs, expectedLabels); if (outputErrors == null) { return Double.NaN; } double weightsSquareSum = 0; int layersCount = neuralNet.getLayersCount(); for (int layerIndex = layersCount - 1; layerIndex > 0; layerIndex--) { List<Neuron> layer = neuralNet.getLayerUnits(layerIndex); if (layerIndex == layersCount - 1) { computeOutputLayerErrorTerms(layer, outputErrors); } else { List<Neuron> nextLayer = neuralNet.getLayerUnits(layerIndex + 1); computeHiddenLayerErrorTerms(layer, nextLayer); } List<Neuron> previousLayer = neuralNet.getLayerUnits(layerIndex - 1); double[] previousLayerOut = new double[previousLayer.size()]; int previousLayerSize = previousLayer.size(); for (int n = 0; n < previousLayerSize; n++) { previousLayerOut[n] = previousLayer.get(n).getOutput(); } for (Neuron neuron : layer) { double[] weights = neuron.getWeights(); for (double weight : weights) { weightsSquareSum += weight * weight; } } updateWeights(layer, previousLayerOut, learningRate); } double globalError = 0; for (double error : outputErrors) { globalError += Math.abs(error); } globalError += weightsDecayCost * 0.5 * weightsSquareSum; return globalError; } BPMLLAlgorithm(NeuralNet neuralNet, double weightsDecayCost); }
BPMLLAlgorithm { public double learn(double[] inputPattern, double[] expectedLabels, double learningRate) { if (inputPattern == null || inputPattern.length != neuralNet.getNetInputSize()) { throw new IllegalArgumentException("Specified input pattern vector is null " + "or does not match the input dimension of underlying neural network model."); } if (expectedLabels == null || expectedLabels.length != neuralNet.getNetOutputSize()) { throw new IllegalArgumentException("Specified expected labels vector is null " + "or does not match the output dimension of underlying neural network model."); } double[] networkOutputs = neuralNet.feedForward(inputPattern); double[] outputErrors = computeErrorsForNeurons(networkOutputs, expectedLabels); if (outputErrors == null) { return Double.NaN; } double weightsSquareSum = 0; int layersCount = neuralNet.getLayersCount(); for (int layerIndex = layersCount - 1; layerIndex > 0; layerIndex--) { List<Neuron> layer = neuralNet.getLayerUnits(layerIndex); if (layerIndex == layersCount - 1) { computeOutputLayerErrorTerms(layer, outputErrors); } else { List<Neuron> nextLayer = neuralNet.getLayerUnits(layerIndex + 1); computeHiddenLayerErrorTerms(layer, nextLayer); } List<Neuron> previousLayer = neuralNet.getLayerUnits(layerIndex - 1); double[] previousLayerOut = new double[previousLayer.size()]; int previousLayerSize = previousLayer.size(); for (int n = 0; n < previousLayerSize; n++) { previousLayerOut[n] = previousLayer.get(n).getOutput(); } for (Neuron neuron : layer) { double[] weights = neuron.getWeights(); for (double weight : weights) { weightsSquareSum += weight * weight; } } updateWeights(layer, previousLayerOut, learningRate); } double globalError = 0; for (double error : outputErrors) { globalError += Math.abs(error); } globalError += weightsDecayCost * 0.5 * weightsSquareSum; return globalError; } BPMLLAlgorithm(NeuralNet neuralNet, double weightsDecayCost); NeuralNet getNetwork(); double getWeightsDecayCost(); double learn(double[] inputPattern, double[] expectedLabels, double learningRate); double getNetworkError(double[] inputPattern, double[] expectedLabels); }
BPMLLAlgorithm { public double learn(double[] inputPattern, double[] expectedLabels, double learningRate) { if (inputPattern == null || inputPattern.length != neuralNet.getNetInputSize()) { throw new IllegalArgumentException("Specified input pattern vector is null " + "or does not match the input dimension of underlying neural network model."); } if (expectedLabels == null || expectedLabels.length != neuralNet.getNetOutputSize()) { throw new IllegalArgumentException("Specified expected labels vector is null " + "or does not match the output dimension of underlying neural network model."); } double[] networkOutputs = neuralNet.feedForward(inputPattern); double[] outputErrors = computeErrorsForNeurons(networkOutputs, expectedLabels); if (outputErrors == null) { return Double.NaN; } double weightsSquareSum = 0; int layersCount = neuralNet.getLayersCount(); for (int layerIndex = layersCount - 1; layerIndex > 0; layerIndex--) { List<Neuron> layer = neuralNet.getLayerUnits(layerIndex); if (layerIndex == layersCount - 1) { computeOutputLayerErrorTerms(layer, outputErrors); } else { List<Neuron> nextLayer = neuralNet.getLayerUnits(layerIndex + 1); computeHiddenLayerErrorTerms(layer, nextLayer); } List<Neuron> previousLayer = neuralNet.getLayerUnits(layerIndex - 1); double[] previousLayerOut = new double[previousLayer.size()]; int previousLayerSize = previousLayer.size(); for (int n = 0; n < previousLayerSize; n++) { previousLayerOut[n] = previousLayer.get(n).getOutput(); } for (Neuron neuron : layer) { double[] weights = neuron.getWeights(); for (double weight : weights) { weightsSquareSum += weight * weight; } } updateWeights(layer, previousLayerOut, learningRate); } double globalError = 0; for (double error : outputErrors) { globalError += Math.abs(error); } globalError += weightsDecayCost * 0.5 * weightsSquareSum; return globalError; } BPMLLAlgorithm(NeuralNet neuralNet, double weightsDecayCost); NeuralNet getNetwork(); double getWeightsDecayCost(); double learn(double[] inputPattern, double[] expectedLabels, double learningRate); double getNetworkError(double[] inputPattern, double[] expectedLabels);  }