@Test public void testGetNetworkError(){ assertEquals("Learning errors should be same unless another learn iteration is performed.", algorithm.getNetworkError(INPUT_PATTERN, EXPECTED_LABELS), algorithm.getNetworkError(INPUT_PATTERN, EXPECTED_LABELS), 0); }
public double getNetworkError(double[] inputPattern, double[] expectedLabels) { 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 = 1; layerIndex < layersCount; layerIndex++) { List<Neuron> layer = neuralNet.getLayerUnits(layerIndex); for (Neuron neuron : layer) { double[] weights = neuron.getWeights(); for (double weight : weights) { weightsSquareSum += weight * weight; } } } double globalError = 0; for (double error : outputErrors) { globalError += Math.abs(error); } globalError += weightsDecayCost * 0.5 * weightsSquareSum; return globalError; }
BPMLLAlgorithm { public double getNetworkError(double[] inputPattern, double[] expectedLabels) { 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 = 1; layerIndex < layersCount; layerIndex++) { List<Neuron> layer = neuralNet.getLayerUnits(layerIndex); for (Neuron neuron : layer) { double[] weights = neuron.getWeights(); for (double weight : weights) { weightsSquareSum += weight * weight; } } } double globalError = 0; for (double error : outputErrors) { globalError += Math.abs(error); } globalError += weightsDecayCost * 0.5 * weightsSquareSum; return globalError; } }
BPMLLAlgorithm { public double getNetworkError(double[] inputPattern, double[] expectedLabels) { 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 = 1; layerIndex < layersCount; layerIndex++) { List<Neuron> layer = neuralNet.getLayerUnits(layerIndex); for (Neuron neuron : layer) { double[] weights = neuron.getWeights(); for (double weight : weights) { weightsSquareSum += weight * weight; } } } 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 getNetworkError(double[] inputPattern, double[] expectedLabels) { 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 = 1; layerIndex < layersCount; layerIndex++) { List<Neuron> layer = neuralNet.getLayerUnits(layerIndex); for (Neuron neuron : layer) { double[] weights = neuron.getWeights(); for (double weight : weights) { weightsSquareSum += weight * weight; } } } 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 getNetworkError(double[] inputPattern, double[] expectedLabels) { 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 = 1; layerIndex < layersCount; layerIndex++) { List<Neuron> layer = neuralNet.getLayerUnits(layerIndex); for (Neuron neuron : layer) { double[] weights = neuron.getWeights(); for (double weight : weights) { weightsSquareSum += weight * weight; } } } 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);  }