use of org.apache.commons.math3.linear.RealVector in project narchy by automenta.
the class HordeSchedulerTest method testScheduler.
@Test
public void testScheduler() {
RealVector o_tp1 = new ArrayRealVector(1);
FakeDemon d1 = new FakeDemon(), d2 = new FakeDemon();
final List<FakeDemon> demons = Lists.newArrayList(d1, d2);
final FakeFunction[] beforeFunctions = { new FakeFunction(d1), new FakeFunction(d2) };
final FakeFunction[] afterFunctions = { new FakeFunction(d1), new FakeFunction(d2) };
Horde horde = new Horde(new HordeScheduler(3));
horde.beforeFunctions().addAll(Lists.newArrayList(beforeFunctions));
horde.demons().addAll(demons);
horde.afterFunctions().addAll(Lists.newArrayList(afterFunctions));
final RealVector x0 = new ArrayRealVector(1), x1 = new ArrayRealVector(1);
final Integer a0 = 0;
checkFunction(beforeFunctions, null, null, null, null, false);
checkFunction(afterFunctions, null, null, null, null, false);
horde.update(o_tp1, x0, a0, x1);
checkFunction(beforeFunctions, x0, a0, o_tp1, x1, false);
checkFunction(afterFunctions, x0, a0, o_tp1, x1, true);
checkDemon(d1, x0, a0, x1);
checkDemon(d2, x0, a0, x1);
}
use of org.apache.commons.math3.linear.RealVector in project narchy by automenta.
the class HordeTest method runExperiment.
protected void runExperiment(PredictionDemon predictionDemon, PredictionDemonVerifier demonVerifier, TimeToState timeToState, int maxStep) {
RealVector x_t = null;
int time = 0;
PredictionDemonVerifier.TDErrorMonitor verifier = demonVerifier.errorMonitor();
while (!verifier.errorComputed() || Math.abs(verifier.error()) >= verifier.precision()) {
RealVector x_tp1 = timeToState.get(time);
((RewardFunctionTest) predictionDemon.rewardFunction()).update(time);
predictionDemon.update(x_t, null, x_tp1);
demonVerifier.update(false);
x_t = x_tp1;
time++;
assertTrue(time < maxStep);
}
}
use of org.apache.commons.math3.linear.RealVector in project narchy by automenta.
the class ThreadVectorPool method newVector.
public ArrayRealVector newVector(RealVector v) {
assert dimension == v.getDimension();
ArrayRealVector w = vectorCached();
w.setSubVector(0, v);
return w;
}
use of org.apache.commons.math3.linear.RealVector in project pyramid by cheng-li.
the class GaussianDistribution method logDensity.
public double logDensity(RealVector x) {
RealVector diff = x.subtract(mean);
int dim = mean.getDimension();
return -0.5 * dim * Math.log(2 * Math.PI) - 0.5 * logDeterminant - 0.5 * (inverseCovariance.preMultiply(diff).dotProduct(diff));
}
use of org.apache.commons.math3.linear.RealVector 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