Search in sources :

Example 36 with PrimitiveDenseStore

use of org.ojalgo.matrix.store.PrimitiveDenseStore in project ojAlgo by optimatika.

the class ExtremeElementsCase method testInvertSVD_6_307_2.

@Test
public void testInvertSVD_6_307_2() {
    final PrimitiveDenseStore tmpOriginal = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.7951923814808213, 0.659451350679988, 0.7107146253894259, 0.5763579411022435, 0.7199441830503458, 0.6356947473097578 }, { 0.659451350679988, 1.829297873115869, 0.7411968989569697, 0.6010777087922337, 0.7508223087524556, 0.6629594475153139 }, { 0.7107146253894259, 0.7411968989569697, 1.8937643794649044, 0.6478032355134435, 0.8091884190528792, 0.7144954285155056 }, { 0.5763579411022435, 0.6010777087922337, 0.6478032355134435, 1.7248031476721892, 0.6562158066095086, 0.5794240042274624 }, { 0.7199441830503458, 0.7508223087524556, 0.8091884190528792, 0.6562158066095086, 1.905371077260138, 0.7237740848430495 }, { 0.6356947473097578, 0.6629594475153139, 0.7144954285155056, 0.5794240042274624, 0.7237740848430495, 1.7994225826534653 } });
    tmpOriginal.modifyAll(PrimitiveFunction.MULTIPLY.second(PrimitiveFunction.POWER.invoke(PrimitiveMath.TEN, 307)));
    final RawSingularValue tmpAlgorithm = new RawSingularValue();
    final NumberContext tmpContext = NumberContext.getGeneral(2, Integer.MIN_VALUE);
    ExtremeElementsCase.performInvertTest(tmpOriginal, tmpAlgorithm, tmpContext);
}
Also used : NumberContext(org.ojalgo.type.context.NumberContext) PrimitiveDenseStore(org.ojalgo.matrix.store.PrimitiveDenseStore) Test(org.junit.jupiter.api.Test)

Example 37 with PrimitiveDenseStore

use of org.ojalgo.matrix.store.PrimitiveDenseStore in project ojAlgo by optimatika.

the class ExtremeElementsCase method getVerySmall.

static MatrixStore<Double> getVerySmall() {
    final long tmpDim = 5L;
    final PrimitiveDenseStore tmpRndm = PrimitiveDenseStore.FACTORY.makeZero(tmpDim, tmpDim);
    for (long j = 0L; j < tmpDim; j++) {
        for (long i = 0L; i < tmpDim; i++) {
            tmpRndm.set(i, j, Uniform.randomInteger(4));
        }
    }
    return tmpRndm.transpose().multiply(tmpRndm).multiply(1E-150);
}
Also used : PrimitiveDenseStore(org.ojalgo.matrix.store.PrimitiveDenseStore)

Example 38 with PrimitiveDenseStore

use of org.ojalgo.matrix.store.PrimitiveDenseStore in project ojAlgo by optimatika.

the class MarketShareCase method testSpecificBranch_37_8.

@Test
public void testSpecificBranch_37_8() {
    final PrimitiveDenseStore tmpAE = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0.87, 0.01, 0.6, 0.5, 0.85, 0.86, 0.09, 0.86, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 5.9, 5.7, 4.8, 2.8, 9.7, 5.8, 4.4, 3.7, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 1.9, 4.6, 3.1, 2.4, 8.5, 8.5, 7.4, 1.3, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.06, 0.26, 0.96, 0.31, 0.77, 0.1, 0.77, 0.71, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 3.8, 8.7, 1.5, 5.8, 7.9, 6.9, 3.7, 8.8, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 } });
    final PrimitiveDenseStore tmpBE = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 2.24 }, { 20.2 }, { 17.4 }, { 0.73 }, { 25.2 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 } });
    final PrimitiveDenseStore tmpC = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 } });
    final LinearSolver.Builder tmpBuilder = new LinearSolver.Builder(tmpC);
    tmpBuilder.equalities(tmpAE, tmpBE);
    final Optimisation.Options tmpOptions = new Optimisation.Options();
    // tmpOptions.debug_stream = BasicLogger.DEBUG;
    // tmpOptions.debug_solver = LinearSolver.class;
    // tmpOptions.validate = true;
    final LinearSolver tmpSolver = tmpBuilder.build(tmpOptions);
    final Optimisation.Result tmpResult = tmpSolver.solve();
    TestUtils.assertTrue(tmpResult.getState().isOptimal());
    for (int i = 0; i < tmpResult.size(); i++) {
        final double tmpValue = tmpResult.doubleValue(i);
        TestUtils.assertTrue(!tmpOptions.feasibility.isDifferent(0.0, tmpValue) || !tmpOptions.feasibility.isDifferent(1.0, tmpValue));
    }
}
Also used : Optimisation(org.ojalgo.optimisation.Optimisation) Result(org.ojalgo.optimisation.Optimisation.Result) LinearSolver(org.ojalgo.optimisation.linear.LinearSolver) PrimitiveDenseStore(org.ojalgo.matrix.store.PrimitiveDenseStore) Test(org.junit.jupiter.api.Test)

Example 39 with PrimitiveDenseStore

use of org.ojalgo.matrix.store.PrimitiveDenseStore in project ojAlgo by optimatika.

the class QuaternionTest method testRotationMatrixMathWorksExample.

@Test
public void testRotationMatrixMathWorksExample() {
    final double nmbr = 1.0 / Math.sqrt(2.0);
    final Quaternion rotQuat = Quaternion.of(nmbr, nmbr, 0.0, 0.0);
    final PrimitiveDenseStore expected = PrimitiveDenseStore.FACTORY.columns(new double[][] { { 1, 0, 0 }, { 0, 0, 1 }, { 0, -1, 0 } });
    final MatrixStore<Double> actual = rotQuat.toRotationMatrix();
    TestUtils.assertEquals(expected, actual);
}
Also used : PrimitiveDenseStore(org.ojalgo.matrix.store.PrimitiveDenseStore) Test(org.junit.jupiter.api.Test)

Example 40 with PrimitiveDenseStore

use of org.ojalgo.matrix.store.PrimitiveDenseStore in project ojAlgo by optimatika.

the class Expression method getAdjustedHessian.

public MatrixStore<Double> getAdjustedHessian() {
    final int tmpCountVariables = myModel.countVariables();
    final PrimitiveDenseStore retVal = PrimitiveDenseStore.FACTORY.makeZero(tmpCountVariables, tmpCountVariables);
    final BinaryFunction<Double> tmpBaseFunc = PrimitiveFunction.ADD;
    UnaryFunction<Double> tmpModFunc;
    for (final IntRowColumn tmpKey : this.getQuadraticKeySet()) {
        tmpModFunc = tmpBaseFunc.second(this.getAdjustedQuadraticFactor(tmpKey));
        retVal.modifyOne(tmpKey.row, tmpKey.column, tmpModFunc);
        retVal.modifyOne(tmpKey.column, tmpKey.row, tmpModFunc);
    }
    return retVal;
}
Also used : IntRowColumn(org.ojalgo.access.Structure2D.IntRowColumn) PrimitiveDenseStore(org.ojalgo.matrix.store.PrimitiveDenseStore)

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