Search in sources :

Example 26 with Gaussian2DFunction

use of gdsc.smlm.function.gaussian.Gaussian2DFunction in project GDSC-SMLM by aherbert.

the class EJMLLinearSolverTest method runSolverSpeedTest.

private void runSolverSpeedTest(int flags) {
    final Gaussian2DFunction f0 = GaussianFunctionFactory.create2D(1, 10, 10, flags, null);
    int n = f0.size();
    final double[] y = new double[n];
    final TurboList<DenseMatrix64F> aList = new TurboList<DenseMatrix64F>();
    final TurboList<DenseMatrix64F> bList = new TurboList<DenseMatrix64F>();
    double[] testbackground = new double[] { 0.2, 0.7 };
    double[] testsignal1 = new double[] { 30, 100, 300 };
    double[] testcx1 = new double[] { 4.9, 5.3 };
    double[] testcy1 = new double[] { 4.8, 5.2 };
    double[] testw1 = new double[] { 1.1, 1.2, 1.5 };
    int np = f0.getNumberOfGradients();
    GradientCalculator calc = GradientCalculatorFactory.newCalculator(np);
    final RandomDataGenerator rdg = new RandomDataGenerator(new Well19937c(30051977));
    //double lambda = 10;
    for (double background : testbackground) // Peak 1
    for (double signal1 : testsignal1) for (double cx1 : testcx1) for (double cy1 : testcy1) for (double w1 : testw1) {
        double[] p = new double[] { background, signal1, 0, cx1, cy1, w1, w1 };
        f0.initialise(p);
        f0.forEach(new ValueProcedure() {

            int i = 0;

            public void execute(double value) {
                // Poisson data 
                y[i++] = rdg.nextPoisson(value);
            }
        });
        double[][] alpha = new double[np][np];
        double[] beta = new double[np];
        //double ss = 
        calc.findLinearised(n, y, p, alpha, beta, f0);
        //System.out.printf("SS = %f\n", ss);
        // As per the LVM algorithm
        //for (int i = 0; i < np; i++)
        //	alpha[i][i] *= lambda;
        aList.add(EJMLLinearSolver.toA(alpha));
        bList.add(EJMLLinearSolver.toB(beta));
    }
    DenseMatrix64F[] a = aList.toArray(new DenseMatrix64F[aList.size()]);
    DenseMatrix64F[] b = bList.toArray(new DenseMatrix64F[bList.size()]);
    int runs = 100000 / a.length;
    TimingService ts = new TimingService(runs);
    TurboList<SolverTimingTask> tasks = new TurboList<SolverTimingTask>();
    tasks.add(new PseudoInverseSolverTimingTask(a, b));
    tasks.add(new LinearSolverTimingTask(a, b));
    tasks.add(new CholeskySolverTimingTask(a, b));
    tasks.add(new CholeskyLDLTSolverTimingTask(a, b));
    tasks.add(new DirectInversionSolverTimingTask(a, b));
    for (SolverTimingTask task : tasks) if (!task.badSolver)
        ts.execute(task);
    ts.repeat();
    ts.report();
}
Also used : ValueProcedure(gdsc.smlm.function.ValueProcedure) TurboList(gdsc.core.utils.TurboList) RandomDataGenerator(org.apache.commons.math3.random.RandomDataGenerator) Well19937c(org.apache.commons.math3.random.Well19937c) DenseMatrix64F(org.ejml.data.DenseMatrix64F) Gaussian2DFunction(gdsc.smlm.function.gaussian.Gaussian2DFunction) GradientCalculator(gdsc.smlm.fitting.nonlinear.gradient.GradientCalculator) TimingService(gdsc.core.test.TimingService)

Aggregations

Gaussian2DFunction (gdsc.smlm.function.gaussian.Gaussian2DFunction)26 Well19937c (org.apache.commons.math3.random.Well19937c)7 RandomDataGenerator (org.apache.commons.math3.random.RandomDataGenerator)6 Test (org.junit.Test)6 GradientCalculator (gdsc.smlm.fitting.nonlinear.gradient.GradientCalculator)4 ValueProcedure (gdsc.smlm.function.ValueProcedure)4 EllipticalGaussian2DFunction (gdsc.smlm.function.gaussian.EllipticalGaussian2DFunction)4 TimingService (gdsc.core.test.TimingService)3 DoubleEquality (gdsc.core.utils.DoubleEquality)3 Statistics (gdsc.core.utils.Statistics)3 TurboList (gdsc.core.utils.TurboList)3 ArrayList (java.util.ArrayList)3 FisherInformationMatrix (gdsc.smlm.fitting.FisherInformationMatrix)2 Gaussian2DFunctionTest (gdsc.smlm.function.gaussian.Gaussian2DFunctionTest)2 SingleCircularGaussian2DFunction (gdsc.smlm.function.gaussian.SingleCircularGaussian2DFunction)2 SingleEllipticalGaussian2DFunction (gdsc.smlm.function.gaussian.SingleEllipticalGaussian2DFunction)2 SingleFixedGaussian2DFunction (gdsc.smlm.function.gaussian.SingleFixedGaussian2DFunction)2 SingleFreeCircularGaussian2DFunction (gdsc.smlm.function.gaussian.SingleFreeCircularGaussian2DFunction)2 SingleNBFixedGaussian2DFunction (gdsc.smlm.function.gaussian.SingleNBFixedGaussian2DFunction)2 ConvergenceException (org.apache.commons.math3.exception.ConvergenceException)2