Search in sources :

Example 1 with DoubleConvolutionValueProcedure

use of uk.ac.sussex.gdsc.smlm.utils.Convolution.DoubleConvolutionValueProcedure in project GDSC-SMLM by aherbert.

the class ConvolutionTest method canComputeDoubleScaledConvolution.

@SeededTest
void canComputeDoubleScaledConvolution(RandomSeed seed) {
    final UniformRandomProvider random = RngUtils.create(seed.getSeed());
    final TDoubleArrayList list = new TDoubleArrayList();
    int size = 10;
    for (int i = 0; i < sizeLoops / 2; i++) {
        double sd = 0.5;
        for (int j = 0; j < sdLoops; j++) {
            final double[] data1 = randomData(random, size);
            final double[] data2 = randomData(random, size);
            final double[] kernel = createKernel(sd);
            for (int scale = 2; scale < 5; scale++) {
                final double[] e1 = convolve(kernel, data1, list, scale);
                final double[] e2 = convolve(kernel, data2, list, scale);
                final double[][] o = Convolution.convolve(kernel, data1, data2, scale);
                final double[][] o2 = new double[2][o[0].length];
                Convolution.convolve(kernel, data1, data2, scale, new DoubleConvolutionValueProcedure() {

                    int index = 0;

                    @Override
                    public boolean execute(double value1, double value2) {
                        o2[0][index] = value1;
                        o2[1][index] = value2;
                        index++;
                        return true;
                    }
                });
                Assertions.assertArrayEquals(e1, o[0]);
                Assertions.assertArrayEquals(e1, o2[0]);
                Assertions.assertArrayEquals(e2, o[1]);
                Assertions.assertArrayEquals(e2, o2[1]);
            }
            sd *= 2;
        }
        size *= 2;
    }
}
Also used : DoubleConvolutionValueProcedure(uk.ac.sussex.gdsc.smlm.utils.Convolution.DoubleConvolutionValueProcedure) TDoubleArrayList(gnu.trove.list.array.TDoubleArrayList) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 2 with DoubleConvolutionValueProcedure

use of uk.ac.sussex.gdsc.smlm.utils.Convolution.DoubleConvolutionValueProcedure in project GDSC-SMLM by aherbert.

the class ConvolutionTest method canComputeDoubleScaledConvolutionWithEarlyExit.

@SeededTest
void canComputeDoubleScaledConvolutionWithEarlyExit(RandomSeed seed) {
    final UniformRandomProvider random = RngUtils.create(seed.getSeed());
    int size = 10;
    final int sizeLoops = 4;
    final int sLoops = 2;
    for (int i = 0; i < sizeLoops; i++) {
        double sd = 0.5;
        for (int j = 0; j < sLoops; j++) {
            final double[] data1 = randomData(random, size);
            final double[] data2 = randomData(random, size);
            final double[] kernel = createKernel(sd);
            for (int scale = 2; scale < 5; scale++) {
                final double[][] e = Convolution.convolve(kernel, data1, data2, scale);
                final double[][] o = new double[2][e[0].length];
                final int limit = data1.length;
                Convolution.convolve(kernel, data1, data2, scale, new DoubleConvolutionValueProcedure() {

                    int index = 0;

                    @Override
                    public boolean execute(double value1, double value2) {
                        o[0][index] = value1;
                        o[1][index] = value1;
                        index++;
                        return index < limit;
                    }
                });
                int index = 0;
                for (; index < limit; index++) {
                    Assertions.assertEquals(e[0][index], o[0][index]);
                    Assertions.assertEquals(e[0][index], o[1][index]);
                }
                while (index < o.length) {
                    Assertions.assertEquals(0, o[0][index]);
                    Assertions.assertEquals(0, o[1][index]);
                    index++;
                }
            }
            sd *= 2;
        }
        size *= 2;
    }
}
Also used : DoubleConvolutionValueProcedure(uk.ac.sussex.gdsc.smlm.utils.Convolution.DoubleConvolutionValueProcedure) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Aggregations

UniformRandomProvider (org.apache.commons.rng.UniformRandomProvider)2 DoubleConvolutionValueProcedure (uk.ac.sussex.gdsc.smlm.utils.Convolution.DoubleConvolutionValueProcedure)2 SeededTest (uk.ac.sussex.gdsc.test.junit5.SeededTest)2 TDoubleArrayList (gnu.trove.list.array.TDoubleArrayList)1