use of uk.ac.sussex.gdsc.test.junit5.RandomSeed in project GDSC-SMLM by aherbert.
the class PeakResultDigestTest method sameResultsAreEqualWithId.
@SeededTest
void sameResultsAreEqualWithId(RandomSeed seed) {
final UniformRandomProvider r = RngUtils.create(seed.getSeed());
final PeakResult[] r1 = createResults(r, 10, 5, false, true, false, false);
final PeakResultsDigest digest = new PeakResultsDigest(r1);
Assertions.assertTrue(digest.matches(r1));
Assertions.assertTrue(digest.matches(digest));
}
use of uk.ac.sussex.gdsc.test.junit5.RandomSeed in project GDSC-SMLM by aherbert.
the class PeakResultDigestTest method digestMatchesPeakResultDigest.
@SeededTest
void digestMatchesPeakResultDigest(RandomSeed seed) {
final UniformRandomProvider r = RngUtils.create(seed.getSeed());
for (int size = 1; size < 5; size++) {
final PeakResult[] r1 = createResults(r, size, 5, false, false, false, false);
final PeakResultsDigest digest = new PeakResultsDigest(r1);
final PeakResultDigest d = new PeakResultDigest();
for (final PeakResult rr : r1) {
d.update(rr);
}
Assertions.assertEquals(d.digest(), digest.getDigest());
}
}
use of uk.ac.sussex.gdsc.test.junit5.RandomSeed in project GDSC-SMLM by aherbert.
the class PeakResultsReaderTest method canConvertMalkToNmAndPhotons.
@SeededTest
void canConvertMalkToNmAndPhotons(RandomSeed seed) {
final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
final MemoryPeakResults out = createResults(rg, 200, false, false, false, false, false);
// Output in pixel and count
final CalibrationWriter cal = new CalibrationWriter(out.getCalibration());
cal.setDistanceUnit(DistanceUnit.PIXEL);
cal.setIntensityUnit(IntensityUnit.COUNT);
out.setCalibration(cal.getCalibration());
out.setPsf(PsfHelper.create(PSFType.CUSTOM));
final String filename = createFile();
writeFile(false, ResultsFileFormat.MALK, false, false, false, false, false, false, out, filename);
final MemoryPeakResults in = readFile(filename, false);
// Change to nm and photon for the validation
out.convertToUnits(DistanceUnit.NM, IntensityUnit.PHOTON, null);
checkEqual(ResultsFileFormat.MALK, false, false, false, false, false, false, out, in);
}
use of uk.ac.sussex.gdsc.test.junit5.RandomSeed in project GDSC-SMLM by aherbert.
the class MultivariateGaussianMixtureExpectationMaximizationTest method testExpectationMaximizationSpeedWithDifferentNumberOfComponents.
/**
* Test the speed of implementations of the expectation maximization algorithm with a mixture of n
* 2D Gaussian distributions.
*
* @param seed the seed
*/
@SpeedTag
@SeededTest
void testExpectationMaximizationSpeedWithDifferentNumberOfComponents(RandomSeed seed) {
Assumptions.assumeTrue(TestSettings.allow(TestComplexity.HIGH));
// Create data
final UniformRandomProvider rng = RngUtils.create(seed.getSeed());
for (int n = 2; n <= 4; n++) {
final double[][][] data = new double[10][][];
for (int i = 0; i < data.length; i++) {
final double[] sampleWeights = createWeights(n, rng);
final double[][] sampleMeans = create(n, 2, rng, -5, 5);
final double[][] sampleStdDevs = create(n, 2, rng, 1, 10);
final double[] sampleCorrelations = create(n, rng, -0.9, 0.9);
data[i] = createData2d(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 + " 2D", 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 + " 2D", data) {
@Override
Object run(double[][] data) {
final MultivariateGaussianMixtureExpectationMaximization fitter = new MultivariateGaussianMixtureExpectationMaximization(data);
fitter.fit(MultivariateGaussianMixtureExpectationMaximization.estimate(data, numComponents));
return fitter.getLogLikelihood();
}
});
if (logger.isLoggable(Level.INFO)) {
logger.info(ts.getReport());
}
// More than twice as fast
Assertions.assertTrue(ts.get(-1).getMean() < ts.get(-2).getMean() / 2);
}
}
use of uk.ac.sussex.gdsc.test.junit5.RandomSeed in project GDSC-SMLM by aherbert.
the class PerPixelCameraModelTest method canCropAndConvertDataWithCropBounds.
@SeededTest
void canCropAndConvertDataWithCropBounds(RandomSeed seed) {
final PerPixelCameraModelTestData data = (PerPixelCameraModelTestData) dataCache.computeIfAbsent(seed, PerPixelCameraModelTest::createData);
final PerPixelCameraModel model = new PerPixelCameraModel(w, h, data.bias, data.gain, data.variance);
final UniformRandomProvider rand = RngUtils.create(seed.getSeed());
final ImageExtractor ie = ImageExtractor.wrap(data.bias, w, h);
for (int j = 0; j < 10; j++) {
final Rectangle bounds = getBounds(rand, ie);
checkConversion(data, bounds, model.crop(bounds, false));
}
}
Aggregations