OutputLayer extends AbstractLayer { @Override public void forward() { outputs.copyFrom(biases); for (int outCol = 0; outCol < outputs.getCols(); outCol++) { for (int inCol = 0; inCol < inputs.getCols(); inCol++) { outputs.add(outCol, inputs.get(inCol) * weights.get(inCol, outCol)); } outputs.set(outCol, ActivationFunctions.calc(activationType, outputs.get(outCol))); } } 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 testForward() { RandomGenerator.getDefault().initSeed(123); Tensor input = new Tensor(0.1f, 0.2f, 0.3f, 0.4f, 0.5f); Tensor weights = new Tensor(5, 10); WeightsInit.uniform(weights.getValues(), 5); Tensor expectedOutputs = new Tensor( 0.51053022f, 0.59142921f, 0.52648754f, 0.56102458f, 0.54380692f, 0.58635918f, 0.54137987f, 0.41367945f, 0.52289978f, 0.4961883f ); FullyConnectedLayer prevLayer = new FullyConnectedLayer(5); prevLayer.setOutputs(input); OutputLayer instance = new OutputLayer(10); instance.setPrevLayer(prevLayer); instance.init(); instance.setWeights(weights); instance.setBiases(new float[] {0.1f, 0.2f, 0.3f, 0.11f, 0.12f, 0.13f, 0.21f, 0.22f, 0.23f, 0.24f}); instance.forward(); Tensor actualOutputs = instance.getOutputs(); assertArrayEquals(actualOutputs.getValues(), expectedOutputs.getValues(), 1e-7f); }