use of uk.ac.sussex.gdsc.smlm.ij.plugins.TrackPopulationAnalysis.BrownianDiffusionFunction in project GDSC-SMLM by aherbert.
the class TrackPopulationAnalysisTest method canComputeBrownianModelUsingFbmFunction.
@Test
void canComputeBrownianModelUsingFbmFunction() {
final int size = 10;
final DoubleDoubleBiPredicate test = TestHelper.doublesAreClose(1e-5);
final double alpha = 1.0;
for (final double t : new double[] { 0.8, 1, 1.2 }) {
final BrownianDiffusionFunction f1 = new BrownianDiffusionFunction(size, t);
final FbmDiffusionFunction f2 = new FbmDiffusionFunction(size, t);
for (final double d : new double[] { 0.8, 0.9, 1, 1.1, 1.2 }) {
for (final double s : new double[] { 2, 20 }) {
// Check the value and Jacobian
final RealVector point1 = new ArrayRealVector(new double[] { d, s, alpha }, false);
final Pair<RealVector, RealMatrix> p1 = f1.value(point1);
final double[] value1 = p1.getFirst().toArray();
final RealVector point2 = new ArrayRealVector(new double[] { d, s, alpha }, false);
final Pair<RealVector, RealMatrix> p2 = f2.value(point2);
final double[] value2 = p2.getFirst().toArray();
TestAssertions.assertArrayTest(value1, value2, test, "value");
final double[] dfda1 = p1.getSecond().getColumn(0);
final double[] dfdb1 = p1.getSecond().getColumn(1);
final double[] dfda2 = p2.getSecond().getColumn(0);
final double[] dfdb2 = p2.getSecond().getColumn(1);
TestAssertions.assertArrayTest(dfda1, dfda2, test, "jacobian dfda");
TestAssertions.assertArrayTest(dfdb1, dfdb2, test, "jacobian dfdb");
}
}
}
}
use of uk.ac.sussex.gdsc.smlm.ij.plugins.TrackPopulationAnalysis.BrownianDiffusionFunction in project GDSC-SMLM by aherbert.
the class TrackPopulationAnalysisTest method canComputeBrownianDiffusionFunction1.
@Test
void canComputeBrownianDiffusionFunction1() {
final int size = 10;
final double delta = 1e-6;
final DoubleDoubleBiPredicate test = TestHelper.doublesAreClose(1e-5);
for (final double t : new double[] { 0.8, 1, 1.2 }) {
final MultivariateJacobianFunction f = new BrownianDiffusionFunction(size, t);
for (final double d : new double[] { 0.8, 0.9, 1, 1.1, 1.2 }) {
for (final double s : new double[] { 2, 20 }) {
// Check the value and Jacobian
final RealVector point = new ArrayRealVector(new double[] { d, s }, false);
final Pair<RealVector, RealMatrix> p = f.value(point);
final double[] value = p.getFirst().toArray();
Assertions.assertEquals(size, value.length);
for (int n = 1; n <= size; n++) {
// MSD = 4Dt * (n - 1/3) + 4s^2
final double msd = 4 * d * t * (n - 1.0 / 3) + 4 * s * s;
TestAssertions.assertTest(msd, value[n - 1], test, "value");
}
// Columns of the Jacobian
final double[] dfda1 = p.getSecond().getColumn(0);
final double[] dfdb1 = p.getSecond().getColumn(1);
point.setEntry(0, d - delta);
RealVector v1 = f.value(point).getFirst();
point.setEntry(0, d + delta);
RealVector v2 = f.value(point).getFirst();
final double[] dfda = v2.subtract(v1).mapDivide(2 * delta).toArray();
point.setEntry(0, d);
point.setEntry(1, s - delta);
v1 = f.value(point).getFirst();
point.setEntry(1, s + delta);
v2 = f.value(point).getFirst();
final double[] dfdb = v2.subtract(v1).mapDivide(2 * delta).toArray();
// Element-by-element relative error
TestAssertions.assertArrayTest(dfda, dfda1, test, "jacobian dfda");
TestAssertions.assertArrayTest(dfdb, dfdb1, test, "jacobian dfdb");
}
}
}
}
Aggregations