use of org.apache.commons.rng.UniformRandomProvider in project GDSC-SMLM by aherbert.
the class AreaAverageFilterTest method areaAverageUsingSumsCorrectlyInterpolatesBetweenBlocks.
@SeededTest
void areaAverageUsingSumsCorrectlyInterpolatesBetweenBlocks(RandomSeed seed) {
final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
final int max = 50;
final float[] data = createData(rg, max, max);
final AreaAverageFilter filter = new AreaAverageFilter();
filter.setSimpleInterpolation(false);
final int n = 30;
final float[][] results = new float[n + 1][];
final double[] w = new double[n + 1];
int count = 0;
for (int i = 0; i <= n; i++) {
w[count] = i / 10.0;
results[count] = data.clone();
filter.areaAverageUsingSums(results[count], max, max, w[count]);
count++;
}
checkInterpolation(max, n, results, count);
}
use of org.apache.commons.rng.UniformRandomProvider in project GDSC-SMLM by aherbert.
the class TraceManagerTest method canTraceSinglePulseWithMovingCoords.
@SeededTest
void canTraceSinglePulseWithMovingCoords(RandomSeed seed) {
final UniformRandomProvider rand = RngUtils.create(seed.getSeed());
final float distance = 0.5f;
final float[] params = createParams(rand);
final Trace trace = new Trace();
for (int i = 0; i < 5; i++) {
move(rand, params, distance);
trace.add(new PeakResult(i, 0, 0, 0, 0, 0, 0, params, null));
}
runTracing(rand, distance, 1, trace);
}
use of org.apache.commons.rng.UniformRandomProvider in project GDSC-SMLM by aherbert.
the class TraceManagerTest method canTraceSinglePulseWithFixedCoords.
@SeededTest
void canTraceSinglePulseWithFixedCoords(RandomSeed seed) {
final UniformRandomProvider rand = RngUtils.create(seed.getSeed());
final float[] params = createParams(rand);
final Trace trace = new Trace();
for (int i = 0; i < 5; i++) {
trace.add(new PeakResult(i, 0, 0, 0, 0, 0, 0, params, null));
}
runTracing(rand, 0, 1, trace);
}
use of org.apache.commons.rng.UniformRandomProvider in project GDSC-SMLM by aherbert.
the class MultivariateGaussianMixtureExpectationMaximizationTest method testExpectationMaximizationSpeed.
/**
* Test the speed of implementations of the expectation maximization algorithm with a mixture of n
* ND Gaussian distributions.
*
* @param seed the seed
*/
@SpeedTag
@SeededTest
void testExpectationMaximizationSpeed(RandomSeed seed) {
Assumptions.assumeTrue(TestSettings.allow(TestComplexity.HIGH));
final MultivariateGaussianMixtureExpectationMaximization.DoubleDoubleBiPredicate relChecker = TestHelper.doublesAreClose(1e-6)::test;
// Create data
final UniformRandomProvider rng = RngUtils.create(seed.getSeed());
for (int n = 2; n <= 3; n++) {
for (int dim = 2; dim <= 4; dim++) {
final double[][][] data = new double[10][][];
final int nCorrelations = dim - 1;
for (int i = 0; i < data.length; i++) {
final double[] sampleWeights = createWeights(n, rng);
final double[][] sampleMeans = create(n, dim, rng, -5, 5);
final double[][] sampleStdDevs = create(n, dim, rng, 1, 10);
final double[][] sampleCorrelations = IntStream.range(0, n).mapToObj(component -> create(nCorrelations, rng, -0.9, 0.9)).toArray(double[][]::new);
data[i] = createDataNd(1000, rng, sampleWeights, sampleMeans, sampleStdDevs, sampleCorrelations);
}
final int numComponents = n;
// Time initial estimation and fitting
final TimingService ts = new TimingService();
ts.execute(new FittingSpeedTask("Commons n=" + n + " " + dim + "D", data) {
@Override
Object run(double[][] data) {
final MultivariateNormalMixtureExpectationMaximization fitter = new MultivariateNormalMixtureExpectationMaximization(data);
fitter.fit(MultivariateNormalMixtureExpectationMaximization.estimate(data, numComponents));
return fitter.getLogLikelihood();
}
});
ts.execute(new FittingSpeedTask("GDSC n=" + n + " " + dim + "D", data) {
@Override
Object run(double[][] data) {
final MultivariateGaussianMixtureExpectationMaximization fitter = new MultivariateGaussianMixtureExpectationMaximization(data);
fitter.fit(MultivariateGaussianMixtureExpectationMaximization.estimate(data, numComponents));
return fitter.getLogLikelihood();
}
});
ts.execute(new FittingSpeedTask("GDSC rel 1e-6 n=" + n + " " + dim + "D", data) {
@Override
Object run(double[][] data) {
final MultivariateGaussianMixtureExpectationMaximization fitter = new MultivariateGaussianMixtureExpectationMaximization(data);
fitter.fit(MultivariateGaussianMixtureExpectationMaximization.estimate(data, numComponents), 1000, relChecker);
return fitter.getLogLikelihood();
}
});
if (logger.isLoggable(Level.INFO)) {
logger.info(ts.getReport());
}
// More than twice as fast
Assertions.assertTrue(ts.get(-2).getMean() < ts.get(-3).getMean() / 2);
}
}
}
use of org.apache.commons.rng.UniformRandomProvider in project GDSC-SMLM by aherbert.
the class PeakResultDigestTest method sameSize1ResultsAreEqual.
@SeededTest
void sameSize1ResultsAreEqual(RandomSeed seed) {
final UniformRandomProvider r = RngUtils.create(seed.getSeed());
final PeakResult[] r1 = createResults(r, 1, 5, false, false, false, false);
final PeakResultsDigest digest = new PeakResultsDigest(r1);
Assertions.assertTrue(digest.matches(r1));
Assertions.assertTrue(digest.matches(digest));
}
Aggregations