public static void normalizeErrors( float[][][][] e, final float ignoreMin, final float ignoreMax) { final int nl = e[0][0][0].length; final int n1 = e[0][0].length; final int n2 = e[0].length; final int n3 = e.length; final float[][][][] ef = e; MinMax mm = Parallel.reduce( n3, new Parallel.ReduceInt<MinMax>() { public MinMax compute(int i3) { float emin = Float.MAX_VALUE; float emax = -Float.MAX_VALUE; for (int i2 = 0; i2 < n2; ++i2) { for (int i1 = 0; i1 < n1; ++i1) { for (int il = 0; il < nl; ++il) { float ei = ef[i3][i2][i1][il]; if (ei < emin && ei > ignoreMin) emin = ei; if (ei > emax && ei < ignoreMax) emax = ei; } } } return new MinMax(emin, emax); } public MinMax combine(MinMax mm1, MinMax mm2) { return new MinMax(min(mm1.emin, mm2.emin), max(mm1.emax, mm2.emax)); } }); shiftAndScale(mm.emin, mm.emax, e); }
/** * Computes the NRMS value of the warped PS trace {@code h} and the PP trace {@code f}. The NRMS * value is the RMS of the difference between {@code f} and {@code h} divided by the average RMS * of {@code f} and {@code h}. * * @param n1Max the length of {@code f} and {@code h} to use for this computation. * @param f the PP traces. * @param h the warped PS traces. * @return the NRMS value, this measure is between 0.0 and 2.0. */ public static float computeNrms(final int n1Max, final float[][][] f, final float[][][] h) { int n1f = f[0][0].length; int n1h = h[0][0].length; Check.argument(n1Max <= n1f, "n1Max<=n1f"); Check.argument(n1Max <= n1h, "n1Max<=n1h"); final int n3 = f.length; final int n2 = f[0].length; final int n23 = n2 * n3; float scale = 1.0f / (n1Max * n23); float[] rms = Parallel.reduce( n23, new Parallel.ReduceInt<float[]>() { @Override public float[] compute(int i23) { int i2 = i23 % n2; int i3 = i23 / n2; float[] fhdSq = new float[3]; for (int i1 = 0; i1 < n1Max; i1++) { float fv = f[i3][i2][i1]; float hv = h[i3][i2][i1]; fhdSq[0] += fv * fv; fhdSq[1] += hv * hv; fhdSq[2] += (hv - fv) * (hv - fv); } return fhdSq; } @Override public float[] combine(float[] fhdSq1, float[] fhdSq2) { float[] rms = new float[3]; rms[0] = fhdSq1[0] + fhdSq2[0]; rms[1] = fhdSq1[1] + fhdSq2[1]; rms[2] = fhdSq1[2] + fhdSq2[2]; return rms; } }); float frms = sqrt(rms[0] * scale); float hrms = sqrt(rms[1] * scale); float drms = sqrt(rms[2] * scale); float nrms = (2.0f * drms) / (frms + hrms); return nrms; }