Search in sources :

Example 1 with PoissonGradientProcedure

use of gdsc.smlm.fitting.nonlinear.gradient.PoissonGradientProcedure in project GDSC-SMLM by aherbert.

the class FastMLESteppingFunctionSolver method computeFisherInformationMatrix.

/*
	 * (non-Javadoc)
	 * 
	 * @see gdsc.smlm.fitting.nonlinear.SteppingFunctionSolver#computeFisherInformationMatrix()
	 */
@Override
protected FisherInformationMatrix computeFisherInformationMatrix() {
    // The fisher information is that for a Poisson process
    PoissonGradientProcedure p = PoissonGradientProcedureFactory.create(f2);
    // Assume preinitialised function
    p.computeFisherInformation(null);
    return new FisherInformationMatrix(p.getLinear(), gradientProcedure.n);
}
Also used : PoissonGradientProcedure(gdsc.smlm.fitting.nonlinear.gradient.PoissonGradientProcedure) FisherInformationMatrix(gdsc.smlm.fitting.FisherInformationMatrix)

Example 2 with PoissonGradientProcedure

use of gdsc.smlm.fitting.nonlinear.gradient.PoissonGradientProcedure in project GDSC-SMLM by aherbert.

the class MLELVMSteppingFunctionSolver method computeFisherInformationMatrix.

/*
	 * (non-Javadoc)
	 * 
	 * @see gdsc.smlm.fitting.nonlinear.SteppingFunctionSolver#computeFisherInformationMatrix()
	 */
@Override
protected FisherInformationMatrix computeFisherInformationMatrix() {
    // The Hessian matrix refers to the log-likelihood ratio.
    // Compute and invert a matrix related to the Poisson log-likelihood.
    // This assumes this does achieve the maximum likelihood estimate for a 
    // Poisson process.
    PoissonGradientProcedure p = PoissonGradientProcedureFactory.create(f1);
    p.computeFisherInformation(lastA);
    p.getLinear(walpha);
    return new FisherInformationMatrix(walpha, beta.length);
}
Also used : PoissonGradientProcedure(gdsc.smlm.fitting.nonlinear.gradient.PoissonGradientProcedure) FisherInformationMatrix(gdsc.smlm.fitting.FisherInformationMatrix)

Example 3 with PoissonGradientProcedure

use of gdsc.smlm.fitting.nonlinear.gradient.PoissonGradientProcedure in project GDSC-SMLM by aherbert.

the class BaseFunctionSolverTest method canFitSingleGaussian.

void canFitSingleGaussian(FunctionSolver solver, boolean applyBounds, NoiseModel noiseModel) {
    // Allow reporting the fit deviations
    boolean report = false;
    double[] crlb = null;
    SimpleArrayMoment m = null;
    double[] noise = getNoise(noiseModel);
    if (solver.isWeighted())
        solver.setWeights(getWeights(noiseModel));
    randomGenerator.setSeed(seed);
    for (double s : signal) {
        double[] expected = createParams(1, s, 0, 0, 1);
        double[] lower = createParams(0, s * 0.5, -0.2, -0.2, 0.8);
        double[] upper = createParams(3, s * 2, 0.2, 0.2, 1.2);
        if (applyBounds)
            solver.setBounds(lower, upper);
        if (report) {
            // Compute the CRLB for a Poisson process
            PoissonGradientProcedure gp = PoissonGradientProcedureFactory.create((Gradient1Function) ((BaseFunctionSolver) solver).getGradientFunction());
            gp.computeFisherInformation(expected);
            FisherInformationMatrix f = new FisherInformationMatrix(gp.getLinear(), gp.n);
            crlb = f.crlbSqrt();
            // Compute the deviations
            m = new SimpleArrayMoment();
        }
        double[] data = drawGaussian(expected, noise, noiseModel);
        for (double db : base) for (double dx : shift) for (double dy : shift) for (double dsx : factor) {
            double[] p = createParams(db, s, dx, dy, dsx);
            double[] fp = fitGaussian(solver, data, p, expected);
            for (int i = 0; i < expected.length; i++) {
                if (fp[i] < lower[i])
                    Assert.assertTrue(String.format("Fit Failed: [%d] %.2f < %.2f: %s != %s", i, fp[i], lower[i], Arrays.toString(fp), Arrays.toString(expected)), false);
                if (fp[i] > upper[i])
                    Assert.assertTrue(String.format("Fit Failed: [%d] %.2f > %.2f: %s != %s", i, fp[i], upper[i], Arrays.toString(fp), Arrays.toString(expected)), false);
                if (report)
                    fp[i] = expected[i] - fp[i];
            }
            // Store the deviations
            if (report)
                m.add(fp);
        }
        // Report
        if (report)
            System.out.printf("%s %s %f : CRLB = %s, Devaitions = %s\n", solver.getClass().getSimpleName(), noiseModel, s, Arrays.toString(crlb), Arrays.toString(m.getStandardDeviation()));
    }
}
Also used : SimpleArrayMoment(gdsc.core.math.SimpleArrayMoment) PoissonGradientProcedure(gdsc.smlm.fitting.nonlinear.gradient.PoissonGradientProcedure) FisherInformationMatrix(gdsc.smlm.fitting.FisherInformationMatrix)

Aggregations

FisherInformationMatrix (gdsc.smlm.fitting.FisherInformationMatrix)3 PoissonGradientProcedure (gdsc.smlm.fitting.nonlinear.gradient.PoissonGradientProcedure)3 SimpleArrayMoment (gdsc.core.math.SimpleArrayMoment)1