use of org.apache.commons.math3.random.Well19937c 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();
}
use of org.apache.commons.math3.random.Well19937c in project GDSC-SMLM by aherbert.
the class FilterTest method canCompareMultiFilter.
@Test
public void canCompareMultiFilter() {
RandomGenerator randomGenerator = new Well19937c(System.currentTimeMillis() + System.identityHashCode(this));
MultiFilter f = new MultiFilter(0, 0, 0, 0, 0, 0, 0);
for (int i = 1000; i-- > 0; ) {
MultiFilter f1 = (MultiFilter) f.create(random(f.getNumberOfParameters(), randomGenerator));
MultiFilter f2 = (MultiFilter) f.create(random(f.getNumberOfParameters(), randomGenerator));
int e = f1.weakest((Filter) f2);
int o = f1.weakest(f2);
Assert.assertEquals(e, o);
}
}
Aggregations