Search in sources :

Example 71 with PrimitiveDenseStore

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;
}
Also used : PrimitiveDenseStore(org.ojalgo.matrix.store.PrimitiveDenseStore)

Example 72 with PrimitiveDenseStore

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);
}
Also used : Mean(org.ojalgo.random.process.GaussianField.Mean) Collection(java.util.Collection) NumberContext(org.ojalgo.type.context.NumberContext) Normal(org.ojalgo.random.Normal) ComparableToDouble(org.ojalgo.type.keyvalue.ComparableToDouble) PrimitiveDenseStore(org.ojalgo.matrix.store.PrimitiveDenseStore) Test(org.junit.jupiter.api.Test)

Aggregations

PrimitiveDenseStore (org.ojalgo.matrix.store.PrimitiveDenseStore)72 Test (org.junit.jupiter.api.Test)37 Optimisation (org.ojalgo.optimisation.Optimisation)16 NumberContext (org.ojalgo.type.context.NumberContext)15 ExpressionsBasedModel (org.ojalgo.optimisation.ExpressionsBasedModel)12 ComparableToDouble (org.ojalgo.type.keyvalue.ComparableToDouble)7 Result (org.ojalgo.optimisation.Optimisation.Result)6 ComplexNumber (org.ojalgo.scalar.ComplexNumber)4 SimultaneousPrimitive (org.ojalgo.matrix.decomposition.HermitianEvD.SimultaneousPrimitive)3 PhysicalStore (org.ojalgo.matrix.store.PhysicalStore)3 Builder (org.ojalgo.optimisation.convex.ConvexSolver.Builder)3 IntRowColumn (org.ojalgo.access.Structure2D.IntRowColumn)2 ComplexDenseStore (org.ojalgo.matrix.store.ComplexDenseStore)2 LinearSolver (org.ojalgo.optimisation.linear.LinearSolver)2 Normal (org.ojalgo.random.Normal)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Disabled (org.junit.jupiter.api.Disabled)1 Tag (org.junit.jupiter.api.Tag)1 ProgrammingError (org.ojalgo.ProgrammingError)1