use of uk.ac.sussex.gdsc.test.junit5.SpeedTag in project GDSC-SMLM by aherbert.
the class JTransformsTest method jtransforms2DDhtIsFasterThanFht2.
@SpeedTag
@SeededTest
void jtransforms2DDhtIsFasterThanFht2(RandomSeed seed) {
Assumptions.assumeTrue(TestSettings.allow(TestComplexity.MEDIUM));
// Test the forward DHT of data. and reverse transform or the pre-computed correlation.
final int size = 256;
final int w = size / 4;
final UniformRandomProvider r = RngUtils.create(seed.getSeed());
// Blob in the centre
FloatProcessor fp = createProcessor(size, size / 2 - w / 2, size / 2 - w / 2, w, w, null);
final Fht fht2 = new Fht((float[]) fp.getPixels(), size, false);
fht2.transform();
fht2.initialiseFastMultiply();
// Random blobs, original and correlated
final int N = 40;
final float[][] data = new float[N * 2][];
final int lower = w;
final int upper = size - w;
final int range = upper - lower;
for (int i = 0, j = 0; i < N; i++) {
final int x = lower + r.nextInt(range);
final int y = lower + r.nextInt(range);
fp = createProcessor(size, x, y, w, w, r);
final float[] pixels = (float[]) fp.getPixels();
data[j++] = pixels.clone();
final Fht fht1 = new Fht(pixels, size, false);
fht1.copyTables(fht2);
fht2.transform();
final float[] pixels2 = new float[pixels.length];
fht2.conjugateMultiply(fht2, pixels2);
data[j++] = pixels2;
}
// CommonUtils.setThreadsBeginN_1D_FFT_2Threads(Long.MAX_VALUE);
// CommonUtils.setThreadsBeginN_1D_FFT_4Threads(Long.MAX_VALUE);
CommonUtils.setThreadsBeginN_2D(Long.MAX_VALUE);
final TimingService ts = new TimingService();
ts.execute(new ImageJFhtSpeedTask(size, data));
ts.execute(new ImageJFht2SpeedTask(size, data));
ts.execute(new JTransformsDhtSpeedTask(size, data));
ts.repeat();
if (logger.isLoggable(Level.INFO)) {
logger.info(ts.getReport());
}
// Assertions.assertTrue(ts.get(-1).getMean() < ts.get(-2).getMean());
final TimingResult slow = ts.get(-2);
final TimingResult fast = ts.get(-1);
logger.log(TestLogUtils.getTimingRecord(slow, fast));
}
use of uk.ac.sussex.gdsc.test.junit5.SpeedTag in project GDSC-SMLM by aherbert.
the class GaussianFilterTest method floatFilterInternalIsFasterThanDoubleFilterInternal.
@SpeedTag
@SeededTest
void floatFilterInternalIsFasterThanDoubleFilterInternal(RandomSeed seed) {
Assumptions.assumeTrue(TestSettings.allow(TestComplexity.HIGH));
final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
final float[][] data = new float[10][];
for (int i = 0; i < data.length; i++) {
data[i] = createData(rg, size, size);
}
final TimingService ts = new TimingService();
for (final double sigma : sigmas) {
ts.execute(new MyTimingTask(new FloatFilter(true), data, sigma));
ts.execute(new MyTimingTask(new DpFilter(false), data, sigma));
ts.execute(new MyTimingTask(new DoubleFilter(true), data, sigma));
}
final int size = ts.getSize();
ts.repeat();
if (logger.isLoggable(Level.INFO)) {
logger.info(ts.getReport(size));
}
final int n = size / sigmas.length;
for (int i = 0, j = size; i < sigmas.length; i++, j += n) {
for (int k = 1; k < n; k++) {
final TimingResult slow = ts.get(j + k);
final TimingResult fast = ts.get(j);
logger.log(TestLogUtils.getTimingRecord(slow, fast));
}
}
}
use of uk.ac.sussex.gdsc.test.junit5.SpeedTag in project GDSC-SMLM by aherbert.
the class FastLogTest method canTestDoubleSpeedLog1P.
@SpeedTag
@SeededTest
void canTestDoubleSpeedLog1P(RandomSeed seed) {
// No assertions, this is just a report
Assumptions.assumeTrue(logger.isLoggable(Level.INFO));
Assumptions.assumeTrue(TestSettings.allow(TestComplexity.MEDIUM));
final UniformRandomProvider rng = RngUtils.create(seed.getSeed());
final double[] x = new double[1000000];
for (int i = 0; i < x.length; i++) {
x[i] = nextUniformDouble(rng);
}
final MathLog fl = new MathLog();
final TimingService ts = new TimingService(5);
// ts.execute(new DoubleTimingTask(new TestLog(fl), 0, x));
ts.execute(new DoubleTimingTask(new Test1PLog(fl), 0, x));
ts.execute(new DoubleTimingTask(new TestLog1P(fl), 0, x));
ts.execute(new DoubleTimingTask(new TestLog1PApache(fl), 0, x));
// ts.execute(new DoubleTimingTask(new TestLog(fl), 0, x));
ts.execute(new DoubleTimingTask(new Test1PLog(fl), 0, x));
ts.execute(new DoubleTimingTask(new TestLog1P(fl), 0, x));
ts.execute(new DoubleTimingTask(new TestLog1PApache(fl), 0, x));
final int size = ts.getSize();
ts.repeat(size);
logger.info(ts.getReport(size));
}
use of uk.ac.sussex.gdsc.test.junit5.SpeedTag in project GDSC-SMLM by aherbert.
the class FastLogTest method canTestFloatSpeed.
@SpeedTag
@SeededTest
void canTestFloatSpeed(RandomSeed seed) {
// No assertions, this is just a report
Assumptions.assumeTrue(logger.isLoggable(Level.INFO));
Assumptions.assumeTrue(TestSettings.allow(TestComplexity.MEDIUM));
final UniformRandomProvider rng = RngUtils.create(seed.getSeed());
final float[] x = new float[1000000];
for (int i = 0; i < x.length; i++) {
x[i] = nextUniformFloat(rng);
}
final TimingService ts = new TimingService(5);
ts.execute(new FloatTimingTask(new TestLog(new MathLog()), 0, x));
ts.execute(new FloatTimingTask(new TestLog(new FastMathLog()), 0, x));
for (final int q : new int[] { 11 }) {
final int n = 23 - q;
final IcsiFastLog fl = IcsiFastLog.create(n, DataType.FLOAT);
ts.execute(new FloatTimingTask(new TestLog(fl), q, x));
ts.execute(new FloatTimingTask(new TestFastLog(fl), q, x));
final FFastLog ff = new FFastLog(n);
ts.execute(new FloatTimingTask(new TestLog(ff), q, x));
ts.execute(new FloatTimingTask(new TestFastLog(ff), q, x));
final DFastLog df = new DFastLog(n);
ts.execute(new FloatTimingTask(new TestLog(df), q, x));
ts.execute(new FloatTimingTask(new TestFastLog(df), q, x));
final TurboLog tf = new TurboLog(n);
ts.execute(new FloatTimingTask(new TestLog(tf), q, x));
ts.execute(new FloatTimingTask(new TestFastLog(tf), q, x));
// TurboLog2 tf2 = new TurboLog2(n);
// ts.execute(new FloatTimingTask(new TestLog(tf2), q, x));
// ts.execute(new FloatTimingTask(new TestFastLog(tf2), q, x));
// For the same precision we can reduce n
final TurboLog2 tf3 = new TurboLog2(n - 1);
ts.execute(new FloatTimingTask(new TestLog(tf3), q + 1, x));
ts.execute(new FloatTimingTask(new TestFastLog(tf3), q + 1, x));
}
final int size = ts.getSize();
ts.repeat(size);
logger.info(ts.getReport(size));
}
use of uk.ac.sussex.gdsc.test.junit5.SpeedTag 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);
}
}
}
Aggregations