OutputLayer extends AbstractLayer { @Override public void applyWeightChanges() { if (batchMode) { deltaWeights.div(batchSize); Tensor.div(deltaBiases, batchSize); } Tensor.copy(deltaWeights, prevDeltaWeights); weights.add(deltaWeights); Tensor.copy(deltaBiases, prevDeltaBiases); Tensor.add(biases, deltaBiases); if (batchMode) { deltaWeights.fill(0); Tensor.fill(deltaBiases, 0); } } OutputLayer(int width);  OutputLayer(int width, ActivationType activationFunction);  OutputLayer(String[] labels);  OutputLayer(String[] labels, ActivationType activationFunction); final void setOutputErrors(final float[] outputErrors); final float[] getOutputErrors(); final LossType getLossType(); void setLossType(LossType lossType); @Override void init(); @Override void forward(); @Override void backward(); @Override void applyWeightChanges();  }
@Test public void testApplyWeightChanges() { OutputLayer instance = new OutputLayer(10); FullyConnectedLayer prevLayer = new FullyConnectedLayer(5); instance.setPrevLayer(prevLayer); instance.init(); Tensor weights = new Tensor(5, 10); WeightsInit.initSeed(123); WeightsInit.uniform(weights.getValues(), 5); Tensor biases = new Tensor(10); WeightsInit.randomize(weights.getValues()); WeightsInit.randomize(biases.getValues()); instance.setWeights(weights); instance.setBiases(biases.getValues()); instance.setDeltas(new Tensor(10)); instance.deltaWeights = new Tensor(5, 10); WeightsInit.randomize(instance.deltaWeights.getValues()); WeightsInit.randomize(instance.deltaBiases); instance.applyWeightChanges(); Tensor expectedWeights = new Tensor(-0.30327034f, -0.23136496f, -0.1402145f, -0.65223693f, -0.27131938f, -0.10264724f, -0.09167038f, 0.0578903f, -0.20470357f, 0.63714188f, -0.35844476f, -0.33212315f, 0.4615165f, 0.13870019f, -0.40853286f, 0.27610147f, 0.2458809f, 0.2741896f, -0.06043624f, 0.49228281f, -0.09033686f, 0.49088883f, -0.00958961f, -0.81646843f, -0.44407541f, 0.02067602f, 0.02200854f, -0.30582535f, -0.67090463f, -0.62103487f, -0.52198958f, -0.35070544f, 0.56883705f, 0.15350276f, -0.24242462f, 0.42086977f, 0.11694991f, 0.31048643f, 0.80725021f, -0.55393618f, 0.45647371f, 0.16600942f, 0.44481963f, -0.17407107f, -0.01234454f, 0.34930807f, -0.6269967f, -0.73286462f, 0.18214393f, 0.61640269f); Tensor expectedBiases = new Tensor(-0.39718491f, -0.49185896f, 0.9268741f, 0.38542312f, 0.34024281f, 0.22455698f, 0.05115265f, 0.01640982f, 0.03978152f, 0.14766884f); assertArrayEquals(weights.getValues(), expectedWeights.getValues(), 1e-7f); assertArrayEquals(biases.getValues(), expectedBiases.getValues(), 1e-7f); }