NN_AtmCorr { public static int compute(final float[][] in, final int getNumNodesInput, final float[][] out, final int getNumNodesOutput, final int width, final int[] mask, final int errmask, final float[] a) { final int rcheck[]; final int nodes_input = 18; final int nodes_output = 12; final int nodes_input_bias = 1; final int nodes_input_pca = 1; final int nodes_hidden = 80; final int nodes_hidden_bias = 1; final double nodes_hidden_temperature = 1.000000; final double t_input = nodes_hidden_temperature / (double) (nodes_input); final double t_hidden = nodes_hidden_temperature / (double) (nodes_hidden); final double[] vt; final double[] vt1; if (getNumNodesInput <= 0) { return (nodes_input); } if (getNumNodesOutput <= 0) { return (nodes_output); } if (getNumNodesInput != nodes_input) { return (-1); } if (getNumNodesOutput != nodes_output) { return (-2); } vt = new double[nodes_input + nodes_input_bias]; vt1 = new double[nodes_hidden + nodes_hidden_bias]; rcheck = new int[width]; for (int x = 0; x < width; x++) { rcheck[x] = 0; if (a[x] < 0.0f) { rcheck[x] = 1; } a[x] = 1.0f; } for (int x = 0; x < width; x++) { if (mask[x] == 0) { if (rcheck[x] != 0) { for (int i = 0; i < nodes_input && a[x] > 0.0f; i++) { if ((in[i][x] < (float) nodes_input_scale_limits_run19[i][0]) || (in[i][x] > (float) nodes_input_scale_limits_run19[i][1])) { a[x] -= 3.0f; } } if (a[x] < 0.0f) { mask[x] |= errmask; } } for (int i = 0; i < nodes_input; i++) { if (NN_General.NODES_INPUT_SCALE_FLAG[i] == -1) { in[i][x] = (float) Math.log((double) in[i][x]); } if (NN_General.NODES_INPUT_SCALE_FLAG[i] == -2) { in[i][x] = (float) Math.exp((double) in[i][x]); } } for (int i = 0; i < nodes_input; i++) { in[i][x] = (float) NN_General.NODES_INPUT_SCALE_OFF[i] + (in[i][x] - (float) nodes_input_scale_run19[i][0]) / (float) nodes_input_scale_run19[i][1]; } if (nodes_input_pca != 0) { for (int i = 0; i < nodes_input; i++) { vt[i] = (double) in[i][x]; if (NN_General.NODES_INPUT_SCALE_FLAG[i] == 1) { vt[i] = 0.0; for (int j = 0; j < nodes_input; j++) { if (NN_General.NODES_INPUT_SCALE_FLAG[j] == 1) { vt[i] += (double) in[j][x] * nodes_input_pca_evec_run19[j][i]; } } } } for (int i = 0; i < nodes_input; i++) { in[i][x] = (float) vt[i]; } } for (int i = 0; i < nodes_input; i++) { vt[i] = (double) in[i][x]; } for (int i = nodes_input; i < nodes_input + nodes_input_bias; i++) { vt[i] = 1.0; } for (int i = 0; i < nodes_hidden; i++) { vt1[i] = 0.0; for (int j = 0; j < nodes_input + nodes_input_bias; j++) { vt1[i] += vt[j] * nodes_hidden_weights_run19[j][i]; } } for (int i = 0; i < nodes_hidden; i++) { vt1[i] = 1.0 / (1.0 + Math.exp(-t_input * vt1[i])); } for (int i = nodes_hidden; i < nodes_hidden + nodes_hidden_bias; i++) { vt1[i] = 1.0f; } for (int i = 0; i < nodes_output; i++) { out[i][x] = 0.0f; for (int j = 0; j < nodes_hidden + nodes_hidden_bias; j++) { out[i][x] += (float) (vt1[j] * nodes_output_weights_run19[j][i]); } } for (int i = 0; i < nodes_output; i++) { out[i][x] = (float) (1.0 / (1.0 + Math.exp(-t_hidden * out[i][x]))); } for (int i = 0; i < nodes_output; i++) { out[i][x] = (float) nodes_output_scale_run19[i][0] + (out[i][x] - (float) nodes_output_scale_off_run19[i]) * (float) nodes_output_scale_run19[i][1]; } for (int i = 0; i < nodes_output; i++) { if (nodes_output_scale_flag_run19[i] == -1) { out[i][x] = (float) Math.log((double) out[i][x]); } if (nodes_output_scale_flag_run19[i] == -2) { out[i][x] = (float) Math.exp((double) out[i][x]); } } if (rcheck[x] != 0) { for (int i = 0; i < nodes_output && a[x] >= -2.0f; i++) { if ((out[i][x] < (float) nodes_output_scale_limits_run19[i][0]) || (out[i][x] > (float) nodes_output_scale_limits_run19[i][1])) { a[x] -= 20.0f; } } if (a[x] < 0.0f) { mask[x] |= errmask; } } } } return 0; }  static int compute(final float[][] in,
                              final int getNumNodesInput,
                              final float[][] out,
                              final int getNumNodesOutput,
                              final int width,
                              final int[] mask,
                              final int errmask,
                              final float[] a);  }
@Test public void testNN_AtmCorrGetNumInputNode() throws Exception { int numNodesInput = -1; int numNodesOutput = 1; int numInputNode = NN_AtmCorr.compute(in, numNodesInput, out, numNodesOutput, width, mask, 0, a); assertEquals(18, numInputNode); }
@Test public void testNN_AtmCorrGetNumOutputNode() throws Exception { int numNodesInput = 1; int numNodesOutput = -1; int numOutputNum = NN_AtmCorr.compute(in, numNodesInput, out, numNodesOutput, width, mask, 0, a); assertEquals(12, numOutputNum); }
@Test public void testNN_AtmCorrCheckOutputNode() throws Exception { int numNodesInput = 18; int numNodesOutput = 10; int checkOutputNode = NN_AtmCorr.compute(in, numNodesInput, out, numNodesOutput, width, mask, 0, a); assertEquals(-2, checkOutputNode); }
@Test public void testNN_AtmCorrCheckInputNode() throws Exception { int numNodesInput = 11; int numNodesOutput = 12; int checkOutputNode = NN_AtmCorr.compute(in, numNodesInput, out, numNodesOutput, width, mask, 0, a); assertEquals(-1, checkOutputNode); }
@Test public void testNN_AtmCorrCompute() throws Exception { final float[][] input = new float[][]{ {0.05943133f}, {0.05067047f}, {0.041214053f}, {0.037428323f}, {0.030080993f}, {0.024526045f}, {0.023756435f}, {0.022254849f}, {0.021630857f}, {0.021160515f}, {0.019966979f}, {0.019658221f}, {11.66836f}, {1023.05f}, {0.7145359f}, {-0.385183f}, {-0.385695f}, {0.83837545f}}; float[][] exOutput = new float[][]{ {0.0064101876f}, {0.006221302f}, {0.0067794686f}, {0.0054770103f}, {0.003863283f}, {0.0011327977f}, {7.242046E-4f}, {1.9468556E-4f}, {1.1322831f}, {1.0241352f}, {0.9826809f}, {0.93816406f}}; final int compute = NN_AtmCorr.compute(input, 18, out, 12, width, mask, 0, a); assertEquals(0, compute); assertArrayEquals(exOutput, out); }