use of uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate in project GDSC-SMLM by aherbert.
the class TensorTest method canComputeSameTensor.
@SeededTest
void canComputeSameTensor(RandomSeed seed) {
final UniformRandomProvider random = RngUtils.create(seed.getSeed());
final int w = 3;
final int h = 4;
final float[] data = new float[w * h];
final DoubleDoubleBiPredicate predicate = TestHelper.doublesAreClose(1e-6, 0);
for (int i = 0; i < 10; i++) {
for (int j = data.length; j-- > 0; ) {
data[j] = random.nextFloat();
}
final Tensor2D t2 = new Tensor2D(data, w, h);
final Tensor3D t3 = new Tensor3D(new float[][] { data }, w, h);
final double[] com2 = t2.getCentreOfMass();
final double[] v2 = t2.getEigenValues();
final double[][] vv2 = t2.getEigenVectors();
final double[] com3 = t3.getCentreOfMass();
final double[] v3 = t3.getEigenValues();
final double[][] vv3 = t3.getEigenVectors();
for (int k = 0; k < 2; k++) {
Assertions.assertEquals(com2[k], com3[k]);
TestAssertions.assertTest(v2[k], v3[k + 1], predicate);
for (int kk = 0; kk < 2; kk++) {
// Swap vector direction
if (Math.signum(vv2[k][kk]) != Math.signum(vv3[k + 1][kk])) {
vv2[k][0] = -vv2[k][0];
vv2[k][1] = -vv2[k][1];
}
TestAssertions.assertTest(vv2[k][kk], vv3[k + 1][kk], predicate);
}
}
}
}
use of uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate in project GDSC-SMLM by aherbert.
the class GaussianKernelTest method canGetConversionFactor.
@Test
void canGetConversionFactor() {
final DoubleDoubleBiPredicate predicate = TestHelper.doublesAreClose(1e-10, 0);
for (int i = 0; i < 5; i++) {
final double s = 0.33 * (1 << i);
final double norm = 1.0 / (Math.sqrt(2 * Math.PI) * s);
final double var2 = 2 * s * s;
final GaussianKernel k = new GaussianKernel(s);
final double[] o = k.getGaussianKernel(1, 5, false);
final double f = k.getConversionFactor(o);
for (int u = o.length / 2, x = u; x >= 0; x--) {
final double e = norm * StdMath.exp(-(x - u) * (x - u) / var2);
TestAssertions.assertTest(e, f * o[x], predicate);
}
}
}
use of uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate in project GDSC-SMLM by aherbert.
the class GaussianKernelTest method canComputeDownscaleGaussianKernelIncScaleIncRange.
@Test
void canComputeDownscaleGaussianKernelIncScaleIncRange() {
final DoubleDoubleBiPredicate predicate = TestHelper.doublesAreClose(1e-10, 0);
for (int i = 0; i < 5; i++) {
final double s = 0.33 * (1 << i);
final GaussianKernel k = new GaussianKernel(s);
for (int scale = 1; scale <= 5; scale++) {
for (int range = 3; range < 5; range++) {
for (final boolean edgeCorrection : new boolean[] { true, false }) {
final double[] e = GaussianKernel.makeGaussianKernel(s / scale, range, edgeCorrection);
final double[] o = k.getDownscaleGaussianKernel(scale, range, edgeCorrection);
if (MathUtils.isPow2(scale)) {
Assertions.assertArrayEquals(e, o);
} else {
TestAssertions.assertArrayTest(e, o, predicate);
}
}
}
}
}
}
Aggregations