use of gdsc.smlm.function.gaussian.erf.SingleFreeCircularErfGaussian2DFunction in project GDSC-SMLM by aherbert.
the class LSQLVMGradientProcedureTest method gradientProcedureComputesSameOutputWithBias.
@Test
public void gradientProcedureComputesSameOutputWithBias() {
ErfGaussian2DFunction func = new SingleFreeCircularErfGaussian2DFunction(blockWidth, blockWidth);
int nparams = func.getNumberOfGradients();
int iter = 100;
rdg = new RandomDataGenerator(new Well19937c(30051977));
ArrayList<double[]> paramsList = new ArrayList<double[]>(iter);
ArrayList<double[]> yList = new ArrayList<double[]>(iter);
ArrayList<double[]> alphaList = new ArrayList<double[]>(iter);
ArrayList<double[]> betaList = new ArrayList<double[]>(iter);
ArrayList<double[]> xList = new ArrayList<double[]>(iter);
// Manipulate the background
double defaultBackground = Background;
try {
Background = 1e-2;
createData(1, iter, paramsList, yList, true);
EJMLLinearSolver solver = new EJMLLinearSolver(1e-5, 1e-6);
for (int i = 0; i < paramsList.size(); i++) {
double[] y = yList.get(i);
double[] a = paramsList.get(i);
BaseLSQLVMGradientProcedure p = LSQLVMGradientProcedureFactory.create(y, func);
p.gradient(a);
double[] beta = p.beta;
alphaList.add(p.getAlphaLinear());
betaList.add(beta.clone());
for (int j = 0; j < nparams; j++) {
if (Math.abs(beta[j]) < 1e-6)
System.out.printf("[%d] Tiny beta %s %g\n", i, func.getName(j), beta[j]);
}
// Solve
if (!solver.solve(p.getAlphaMatrix(), beta))
throw new AssertionError();
xList.add(beta);
//System.out.println(Arrays.toString(beta));
}
//for (int b = 1; b < 1000; b *= 2)
for (double b : new double[] { -500, -100, -10, -1, -0.1, 0, 0.1, 1, 10, 100, 500 }) {
Statistics[] rel = new Statistics[nparams];
Statistics[] abs = new Statistics[nparams];
for (int i = 0; i < nparams; i++) {
rel[i] = new Statistics();
abs[i] = new Statistics();
}
for (int i = 0; i < paramsList.size(); i++) {
double[] y = add(yList.get(i), b);
double[] a = paramsList.get(i).clone();
a[0] += b;
BaseLSQLVMGradientProcedure p = LSQLVMGradientProcedureFactory.create(y, func);
p.gradient(a);
double[] beta = p.beta;
double[] alpha2 = alphaList.get(i);
double[] beta2 = betaList.get(i);
double[] x2 = xList.get(i);
Assert.assertArrayEquals("Beta", beta2, beta, 1e-10);
Assert.assertArrayEquals("Alpha", alpha2, p.getAlphaLinear(), 1e-10);
// Solve
solver.solve(p.getAlphaMatrix(), beta);
Assert.assertArrayEquals("X", x2, beta, 1e-10);
for (int j = 0; j < nparams; j++) {
rel[j].add(DoubleEquality.relativeError(x2[j], beta[j]));
abs[j].add(Math.abs(x2[j] - beta[j]));
}
}
for (int i = 0; i < nparams; i++) System.out.printf("Bias = %.2f : %s : Rel %g +/- %g: Abs %g +/- %g\n", b, func.getName(i), rel[i].getMean(), rel[i].getStandardDeviation(), abs[i].getMean(), abs[i].getStandardDeviation());
}
} finally {
Background = defaultBackground;
}
}
use of gdsc.smlm.function.gaussian.erf.SingleFreeCircularErfGaussian2DFunction in project GDSC-SMLM by aherbert.
the class FastMLEGradient2ProcedureTest method gradientCalculatorComputesGradient.
@Test
public void gradientCalculatorComputesGradient() {
gradientCalculatorComputesGradient(new SingleFreeCircularErfGaussian2DFunction(blockWidth, blockWidth));
// Use a reasonable z-depth function from the Smith, et al (2010) paper (page 377)
double gamma = 0.389;
double d = 0.531;
double Ax = -0.0708;
double Bx = -0.073;
double Ay = 0.164;
double By = 0.0417;
HoltzerAstimatismZModel zModel = HoltzerAstimatismZModel.create(gamma, d, Ax, Bx, Ay, By);
gradientCalculatorComputesGradient(new SingleAstigmatismErfGaussian2DFunction(blockWidth, blockWidth, zModel));
}
use of gdsc.smlm.function.gaussian.erf.SingleFreeCircularErfGaussian2DFunction in project GDSC-SMLM by aherbert.
the class FastMLEJacobianGradient2ProcedureTest method gradientCalculatorComputesGradient.
@Test
public void gradientCalculatorComputesGradient() {
gradientCalculatorComputesGradient(1, new SingleFreeCircularErfGaussian2DFunction(blockWidth, blockWidth));
gradientCalculatorComputesGradient(2, new MultiFreeCircularErfGaussian2DFunction(2, blockWidth, blockWidth));
// Use a reasonable z-depth function from the Smith, et al (2010) paper (page 377)
double gamma = 0.389;
double d = 0.531;
double Ax = -0.0708;
double Bx = -0.073;
double Ay = 0.164;
double By = 0.0417;
HoltzerAstimatismZModel zModel = HoltzerAstimatismZModel.create(gamma, d, Ax, Bx, Ay, By);
gradientCalculatorComputesGradient(1, new SingleAstigmatismErfGaussian2DFunction(blockWidth, blockWidth, zModel));
}
Aggregations