FunctionBatchNorm_F64 extends BaseFunction<Tensor_F64> implements FunctionBatchNorm<Tensor_F64> { @Override public void setEPS( double EPS) { this.EPS = (double)EPS; } FunctionBatchNorm_F64(boolean requiresGammaBeta); @Override void _initialize(); @Override void _setParameters(List<Tensor_F64> parameters); @Override void _forward(Tensor_F64 input, Tensor_F64 output); @Override double getEPS(); @Override void setEPS( /**/double EPS); @Override boolean hasGammaBeta(); @Override Class<Tensor_F64> getTensorType();  }
@Test public void check_two() { for( boolean sub : new boolean[]{false,true}) { FunctionBatchNorm_F64 alg = new FunctionBatchNorm_F64(false); alg.initialize(d0, d1); alg.setEPS(EPS); Tensor_F64 input = TensorFactory_F64.random(random, sub, N, d0, d1); Tensor_F64 params = TensorFactory_F64.random(random, sub, d0, d1, 2); Tensor_F64 output = TensorFactory_F64.random(random, sub, N, d0, d1); Tensor_F64 expected = new Tensor_F64(N, d0, d1); for (int batch = 0; batch < N; batch++) { int indexIn = input.idx(batch, 0, 0); int indexP = params.idx(0,0,0); int indexOut = expected.idx(batch,0,0); for (int i = 0; i < D; i++) { double m = params.d[indexP++]; double v = params.d[indexP++]; expected.d[indexOut++] = (input.d[indexIn++]-m) / Math.sqrt(v+EPS); } } alg.setParameters(WT(params)); alg.forward(input, output); DeepUnitTest.assertEquals(expected,output, DeepBoofConstants.TEST_TOL_F64); } }
@Test public void check_four() { for( boolean sub : new boolean[]{false,true}) { FunctionBatchNorm_F64 alg = new FunctionBatchNorm_F64(true); alg.initialize(d0, d1); alg.setEPS(EPS); Tensor_F64 input = TensorFactory_F64.random(random, sub, N, d0, d1); Tensor_F64 params = TensorFactory_F64.random(random, sub, d0, d1, 4); Tensor_F64 output = TensorFactory_F64.random(random, sub, N, d0, d1); Tensor_F64 expected = new Tensor_F64(N, d0, d1); for (int batch = 0; batch < N; batch++) { int indexIn = input.idx(batch, 0, 0); int indexP = params.idx(0,0,0); int indexOut = expected.idx(batch,0,0); for (int i = 0; i < D; i++) { double m = params.d[indexP++]; double v = params.d[indexP++]; double g = params.d[indexP++]; double b = params.d[indexP++]; expected.d[indexOut++] = ((input.d[indexIn++]-m) / Math.sqrt(v+EPS))*g+b; } } alg.setParameters(WT(params)); alg.forward(input, output); DeepUnitTest.assertEquals(expected,output, DeepBoofConstants.TEST_TOL_F64); } }