use of org.ojalgo.matrix.store.PrimitiveDenseStore in project ojAlgo by optimatika.
the class MatrixUtils method getComplexArgument.
/**
* Extracts the argument of the ComplexNumber elements to a new primitive double valued matrix.
*/
public static PrimitiveDenseStore getComplexArgument(final Access2D<ComplexNumber> arg) {
final long tmpRows = arg.countRows();
final long tmpColumns = arg.countColumns();
final PrimitiveDenseStore retVal = PrimitiveDenseStore.FACTORY.makeZero(tmpRows, tmpColumns);
MatrixUtils.copyComplexArgument(arg, retVal);
return retVal;
}
use of org.ojalgo.matrix.store.PrimitiveDenseStore in project ojAlgo by optimatika.
the class GaussianProcessTest method testTutorial.
@Test
public void testTutorial() {
final GaussianField.Covariance<Double> tmpCovar = new GaussianField.Covariance<Double>() {
public void calibrate(final Collection<ComparableToDouble<Double>> observations, final Mean<Double> mean) {
}
public double invoke(final Double anArg1, final Double anArg2) {
return this.invoke(anArg1.doubleValue(), anArg2.doubleValue());
}
double invoke(final double anArg1, final double anArg2) {
final double tmpSF = 1.27;
final double tmpSN = 0.3;
final double tmpL = 1.0;
double retVal = tmpSF * tmpSF * PrimitiveFunction.EXP.invoke(-PrimitiveFunction.POW.invoke(anArg1 - anArg2, TWO) / (TWO * tmpL * tmpL));
if (anArg1 == anArg2) {
retVal += tmpSN * tmpSN;
}
return retVal;
}
};
final GaussianProcess tmpProc = new GaussianProcess(tmpCovar);
tmpProc.addObservation(-1.5, -1.6);
tmpProc.addObservation(-1.0, -1.1);
tmpProc.addObservation(-0.75, -0.4);
tmpProc.addObservation(-0.4, 0.1);
tmpProc.addObservation(-0.25, 0.5);
tmpProc.addObservation(0.0, 0.8);
final PrimitiveDenseStore tmpExpected = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.7029, 1.423379254178694, 1.2174807940480699, 0.8807634427271873, 0.7384394292014367, 0.5236319646022823 }, { 1.423379254178694, 1.7029, 1.5632762838868954, 1.3472073239852407, 1.2174807940480699, 0.9782733010505065 }, { 1.2174807940480699, 1.5632762838868954, 1.7029, 1.5170744874003474, 1.423379254178694, 1.2174807940480699 }, { 0.8807634427271873, 1.3472073239852407, 1.5170744874003474, 1.7029, 1.5948565596534579, 1.4888943550870049 }, { 0.7384394292014367, 1.2174807940480699, 1.423379254178694, 1.5948565596534579, 1.7029, 1.5632762838868954 }, { 0.5236319646022823, 0.9782733010505065, 1.2174807940480699, 1.4888943550870049, 1.5632762838868954, 1.7029 } });
TestUtils.assertEquals(tmpExpected, tmpProc.getCovariances(), new NumberContext(8, 2));
final Normal tmpDistr = tmpProc.getDistribution(0.2);
TestUtils.assertEquals("Mean", 0.911277527445648, tmpDistr.getExpected(), 0.005);
TestUtils.assertEquals("Variance", 0.20604504349662636, tmpDistr.getVariance(), 0.005);
}
Aggregations