Search in sources :

Example 66 with PrimitiveDenseStore

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

the class ExtremeElementsCase method testInvertSVD_7_307_1.

@Test
public void testInvertSVD_7_307_1() {
    final PrimitiveDenseStore tmpOriginal = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.6630365629391541, 0.5725332799439422, 0.6293312306387542, 0.3255116741968718, 0.16197060952553563, 0.38338065513999414, 0.45947212690705896 }, { 0.5725332799439422, 1.8635018216883505, 0.8196058776803916, 0.42392824070490653, 0.2109414837777316, 0.4992935723573937, 0.5983908592318098 }, { 0.6293312306387542, 0.8196058776803916, 1.949165198143842, 0.46598388385643336, 0.23186785507316293, 0.5488258051522601, 0.6577540014446122 }, { 0.3255116741968718, 0.42392824070490653, 0.46598388385643336, 1.4909407601202584, 0.11992999873960987, 0.283871509914158, 0.3402129050589385 }, { 0.16197060952553563, 0.2109414837777316, 0.23186785507316293, 0.11992999873960987, 1.2442860900574488, 0.14125097541024584, 0.16928576136879764 }, { 0.38338065513999414, 0.4992935723573937, 0.5488258051522601, 0.283871509914158, 0.14125097541024584, 1.5782194777321448, 0.4006954489432253 }, { 0.45947212690705896, 0.5983908592318098, 0.6577540014446122, 0.3402129050589385, 0.16928576136879764, 0.4006954489432253, 1.6929815829013701 } });
    tmpOriginal.modifyAll(PrimitiveFunction.MULTIPLY.second(PrimitiveFunction.POWER.invoke(PrimitiveMath.TEN, 307)));
    final SingularValueDecomposition.Primitive tmpAlgorithm = new SingularValueDecomposition.Primitive();
    final NumberContext tmpContext = NumberContext.getGeneral(1, Integer.MIN_VALUE);
    ExtremeElementsCase.performInvertTest(tmpOriginal, tmpAlgorithm, tmpContext);
}
Also used : SimultaneousPrimitive(org.ojalgo.matrix.decomposition.HermitianEvD.SimultaneousPrimitive) NumberContext(org.ojalgo.type.context.NumberContext) PrimitiveDenseStore(org.ojalgo.matrix.store.PrimitiveDenseStore) Test(org.junit.jupiter.api.Test)

Example 67 with PrimitiveDenseStore

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

the class ExtremeElementsCase method testInvertEvD_3_155_1.

@Test
public void testInvertEvD_3_155_1() {
    final PrimitiveDenseStore tmpOriginal = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.509726074514643, 0.6439543946598099, 1.2096354379603502 }, { 0.6439543946598099, 1.134228320145167, 0.8341376835908743 }, { 1.2096354379603502, 0.8341376835908743, 1.6999093634457072 } });
    tmpOriginal.modifyAll(PrimitiveFunction.MULTIPLY.second(PrimitiveFunction.POWER.invoke(PrimitiveMath.TEN, 155)));
    final SimultaneousPrimitive tmpAlgorithm = new HermitianEvD.SimultaneousPrimitive();
    final NumberContext tmpContext = NumberContext.getGeneral(1, Integer.MIN_VALUE);
    ExtremeElementsCase.performInvertTest(tmpOriginal, tmpAlgorithm, tmpContext);
}
Also used : NumberContext(org.ojalgo.type.context.NumberContext) PrimitiveDenseStore(org.ojalgo.matrix.store.PrimitiveDenseStore) SimultaneousPrimitive(org.ojalgo.matrix.decomposition.HermitianEvD.SimultaneousPrimitive) Test(org.junit.jupiter.api.Test)

Example 68 with PrimitiveDenseStore

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

the class ExtremeElementsCase method doTestInvert.

static void doTestInvert(final boolean large) {
    for (int precision = 1; precision <= 16; precision++) {
        final NumberContext tmpContext = NumberContext.getGeneral(precision, Integer.MIN_VALUE);
        for (int dim = 1; dim <= 10; dim++) {
            // exp = 308 could potentially create numbers that are 2E308 which is larger than Double.MAX_VALUE
            for (int exp = 0; exp < 308; exp++) {
                final double tmpScale = PrimitiveFunction.POWER.invoke(PrimitiveMath.TEN, large ? exp : -exp);
                final PrimitiveDenseStore tmpOriginal = MatrixUtils.makeSPD(dim);
                if (DEBUG) {
                    BasicLogger.debug("Scale exp={} => factor={} and context={}", exp, tmpScale, tmpContext);
                    BasicLogger.debug("Original (unscaled) {}", tmpOriginal.toString());
                }
                tmpOriginal.modifyAll(PrimitiveFunction.MULTIPLY.second(tmpScale));
                ExtremeElementsCase.performInvertTest(tmpOriginal, InverterTask.PRIMITIVE.make(tmpOriginal), tmpContext);
                final List<MatrixDecomposition<Double>> tmpAllDecomps = MatrixDecompositionTests.getAllPrimitive();
                for (final MatrixDecomposition<Double> tmpDecomp : tmpAllDecomps) {
                    if (DEBUG) {
                        BasicLogger.debug("{} at dim={} for scale={}", tmpDecomp.getClass(), dim, tmpScale);
                    }
                    if (tmpDecomp instanceof MatrixDecomposition.Solver) {
                        ExtremeElementsCase.performInvertTest(tmpOriginal, (InverterTask<Double>) tmpDecomp, tmpContext);
                    }
                }
            }
        }
    }
}
Also used : NumberContext(org.ojalgo.type.context.NumberContext) PrimitiveDenseStore(org.ojalgo.matrix.store.PrimitiveDenseStore)

Example 69 with PrimitiveDenseStore

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

the class MarketShareCase method testSpecificBranch_20_25.

@Test
@Disabled("Underscored before JUnit 5")
public void testSpecificBranch_20_25() {
    final PrimitiveDenseStore tmpAE = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0.88, 0.59, 1.0, 0.16, 0.7, 0.7, 0.12, 0.66, 0.85, 0.68, 0.97, 0.33, 0.87, 0.01, 0.6, 0.5, 0.85, 0.09, 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, 0.0, 0.0 }, { 3.0, 0.7, 3.6, 7.3, 1.9, 1.5, 8.1, 5.5, 3.2, 5.3, 4.3, 2.1, 5.9, 5.7, 4.8, 2.8, 9.7, 4.4, 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, 0.0, 0.0 }, { 7.5, 9.6, 0.7, 5.4, 3.8, 0.0, 8.7, 0.2, 7.6, 6.3, 9.4, 5.5, 1.9, 4.6, 3.1, 2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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, 0.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, 0.0, 0.0, 0.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, 0.0, 0.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, 0.0, 0.0, 0.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, 0.0, 0.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, 0.0, 0.0, 0.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, 0.0, 0.0, 0.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[][] { { 4.49 }, { 18.5 }, { 41.5 }, { 3.44 }, { 33.2 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 1.0 }, { 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 }, { 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 }, { 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(LinearSolver.class);
    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) Disabled(org.junit.jupiter.api.Disabled)

Example 70 with PrimitiveDenseStore

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

the class MatrixUtils method getComplexImaginary.

/**
 * Extracts the imaginary part of the ComplexNumber elements to a new primitive double valued matrix.
 */
public static PrimitiveDenseStore getComplexImaginary(final Access2D<ComplexNumber> arg) {
    final long tmpRows = arg.countRows();
    final long tmpColumns = arg.countColumns();
    final PrimitiveDenseStore retVal = PrimitiveDenseStore.FACTORY.makeZero(tmpRows, tmpColumns);
    MatrixUtils.copyComplexImaginary(arg, retVal);
    return retVal;
}
Also used : 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