Search in sources :

Example 21 with TimingService

use of uk.ac.sussex.gdsc.test.utils.TimingService in project GDSC-SMLM by aherbert.

the class GaussianFilterTest method floatFilterIsFasterThanDoubleFilter.

@SpeedTag
@SeededTest
void floatFilterIsFasterThanDoubleFilter(RandomSeed seed) {
    Assumptions.assumeTrue(TestSettings.allow(TestComplexity.MEDIUM));
    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(false), data, sigma));
        ts.execute(new MyTimingTask(new DpFilter(false), data, sigma));
        ts.execute(new MyTimingTask(new DoubleFilter(false), 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));
        }
    }
}
Also used : TimingResult(uk.ac.sussex.gdsc.test.utils.TimingResult) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) TimingService(uk.ac.sussex.gdsc.test.utils.TimingService) SpeedTag(uk.ac.sussex.gdsc.test.junit5.SpeedTag) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 22 with TimingService

use of uk.ac.sussex.gdsc.test.utils.TimingService in project GDSC-SMLM by aherbert.

the class KernelFilterTest method floatFilterIsFasterThanImageJFilter.

private void floatFilterIsFasterThanImageJFilter(RandomSeed seed, int kw) {
    Assumptions.assumeTrue(TestSettings.allow(TestComplexity.MEDIUM));
    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 float[] kernel = createKernel(kw, kw);
    for (final int border : borders) {
        final TimingService ts = new TimingService();
        ts.execute(new MyTimingTask(new ConvolverWrapper(kernel, kw, kw), data, border));
        ts.execute(new MyTimingTask(new KernelFilterWrapper(kernel, kw, kw), data, border));
        ts.execute(new MyTimingTask(new ZeroKernelFilterWrapper(kernel, kw, kw), data, border));
        final int size = ts.getSize();
        ts.repeat();
        if (logger.isLoggable(Level.INFO)) {
            logger.info(ts.getReport(size));
        }
        logger.log(TestLogUtils.getTimingRecord(ts.get(-3), ts.get(-1)));
    }
}
Also used : UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) TimingService(uk.ac.sussex.gdsc.test.utils.TimingService)

Example 23 with TimingService

use of uk.ac.sussex.gdsc.test.utils.TimingService in project GDSC-SMLM by aherbert.

the class FilterTest method directCompareMultiFilterIsFaster.

@SeededTest
void directCompareMultiFilterIsFaster(RandomSeed seed) {
    Assumptions.assumeTrue(TestSettings.allow(TestComplexity.MEDIUM));
    final UniformRandomProvider UniformRandomProvider = RngUtils.create(seed.getSeed());
    final MultiFilter f1 = new MultiFilter(0, 0, 0, 0, 0, 0, 0, 0, 0);
    final MultiFilter2 f2 = new MultiFilter2(0, 0, 0, 0, 0, 0, 0, 0, 0);
    final double[][][] data = new double[1000][][];
    for (int i = data.length; i-- > 0; ) {
        data[i] = new double[][] { random(f1.getNumberOfParameters(), UniformRandomProvider), random(f1.getNumberOfParameters(), UniformRandomProvider) };
    }
    final TimingService ts = new TimingService();
    ts.execute(new BaseTimingTask("MultiFilter") {

        @Override
        public Object getData(int index) {
            return new MultiFilter[] { (MultiFilter) f1.create(data[index][0]), (MultiFilter) f1.create(data[index][1]) };
        }

        @Override
        public Object run(Object data) {
            final MultiFilter f1 = ((MultiFilter[]) data)[0];
            final MultiFilter f2 = ((MultiFilter[]) data)[1];
            f1.weakest((Filter) f2);
            return null;
        }

        @Override
        public int getSize() {
            return data.length;
        }
    });
    ts.execute(new BaseTimingTask("MultiFilter direct") {

        @Override
        public Object getData(int index) {
            return new MultiFilter[] { (MultiFilter) f1.create(data[index][0]), (MultiFilter) f1.create(data[index][1]) };
        }

        @Override
        public Object run(Object data) {
            final MultiFilter f1 = ((MultiFilter[]) data)[0];
            final MultiFilter f2 = ((MultiFilter[]) data)[1];
            f1.weakest(f2);
            return null;
        }

        @Override
        public int getSize() {
            return data.length;
        }
    });
    ts.execute(new BaseTimingTask("MultiFilter2") {

        @Override
        public Object getData(int index) {
            return new MultiFilter2[] { (MultiFilter2) f2.create(data[index][0]), (MultiFilter2) f2.create(data[index][1]) };
        }

        @Override
        public Object run(Object data) {
            final MultiFilter2 f1 = ((MultiFilter2[]) data)[0];
            final MultiFilter2 f2 = ((MultiFilter2[]) data)[1];
            f1.weakest((Filter) f2);
            return null;
        }

        @Override
        public int getSize() {
            return data.length;
        }
    });
    ts.execute(new BaseTimingTask("MultiFilter2 direct") {

        @Override
        public Object getData(int index) {
            return new MultiFilter2[] { (MultiFilter2) f2.create(data[index][0]), (MultiFilter2) f2.create(data[index][1]) };
        }

        @Override
        public Object run(Object data) {
            final MultiFilter2 f1 = ((MultiFilter2[]) data)[0];
            final MultiFilter2 f2 = ((MultiFilter2[]) data)[1];
            f1.weakest(f2);
            return null;
        }

        @Override
        public int getSize() {
            return data.length;
        }
    });
    ts.check();
    final int size = ts.repeat();
    ts.repeat(size);
    if (logger.isLoggable(Level.INFO)) {
        logger.info(ts.getReport(size));
    }
    for (int i = 0; i < size; i += 2) {
        final TimingResult slow = ts.get(-(i + 2));
        final TimingResult fast = ts.get(-(i + 1));
        Assertions.assertTrue(slow.getMin() > fast.getMin());
    }
}
Also used : TimingResult(uk.ac.sussex.gdsc.test.utils.TimingResult) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) TimingService(uk.ac.sussex.gdsc.test.utils.TimingService) BaseTimingTask(uk.ac.sussex.gdsc.test.utils.BaseTimingTask) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Aggregations

TimingService (uk.ac.sussex.gdsc.test.utils.TimingService)23 SeededTest (uk.ac.sussex.gdsc.test.junit5.SeededTest)15 UniformRandomProvider (org.apache.commons.rng.UniformRandomProvider)14 SpeedTag (uk.ac.sussex.gdsc.test.junit5.SpeedTag)13 TimingResult (uk.ac.sussex.gdsc.test.utils.TimingResult)9 Test (org.junit.jupiter.api.Test)7 LocalList (uk.ac.sussex.gdsc.core.utils.LocalList)6 Gaussian2DFunction (uk.ac.sussex.gdsc.smlm.function.gaussian.Gaussian2DFunction)4 BaseTimingTask (uk.ac.sussex.gdsc.test.utils.BaseTimingTask)3 FloatProcessor (ij.process.FloatProcessor)2 MultivariateNormalMixtureExpectationMaximization (org.apache.commons.math3.distribution.fitting.MultivariateNormalMixtureExpectationMaximization)2 SharedStateContinuousSampler (org.apache.commons.rng.sampling.distribution.SharedStateContinuousSampler)2 DenseMatrix64F (org.ejml.data.DenseMatrix64F)2 GradientCalculator (uk.ac.sussex.gdsc.smlm.fitting.nonlinear.gradient.GradientCalculator)2 ValueProcedure (uk.ac.sussex.gdsc.smlm.function.ValueProcedure)2 Gaussian2DFunctionTest (uk.ac.sussex.gdsc.smlm.function.gaussian.Gaussian2DFunctionTest)2 ImageProcessor (ij.process.ImageProcessor)1 Rectangle (java.awt.Rectangle)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1