@@ -0,0 +1,893 @@
+package be.iminds.iot.dianne.nn.train.criterion;%0A%0Aimport be.iminds.iot.dianne.nn.train.Criterion;%0Aimport be.iminds.iot.dianne.tensor.Tensor;%0Aimport be.iminds.iot.dianne.tensor.TensorFactory;%0A%0Apublic class NLLCriterion implements Criterion %7B%0A%0A%09protected final TensorFactory factory;%0A%09%0A%09protected Tensor gradInput;%0A%09protected Tensor nll;%0A%09%0A%09public NLLCriterion(TensorFactory factory) %7B%0A%09%09this.factory = factory;%09%0A%09%09this.nll = factory.createTensor(1);%0A%09%7D%0A%09%0A%09@Override%0A%09public Tensor forward(final Tensor output, final Tensor target) %7B%0A%09%09nll.set(-output.get(factory.getTensorMath().argmax(target)), 0);%0A%09%09return nll;%0A%09%7D%0A%0A%09@Override%0A%09public Tensor backward(final Tensor output, final Tensor target) %7B%0A%09%09if(gradInput == null)%7B%0A%09%09%09gradInput = factory.createTensor(target.dims());%0A%09%09%7D%0A%09%09gradInput.fill(0.0f);%0A%09%09gradInput.set(-1.0f, factory.getTensorMath().argmax(target));%0A%09%09%0A%09%09return gradInput;%0A%09%7D%0A%7D%0A

implement NLLCriterion