Search in sources :

Example 66 with NumberContext

use of org.ojalgo.type.context.NumberContext in project ojAlgo by optimatika.

the class ExtremeElementsCase method doTestSolve.

static void doTestSolve(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 tmpBody = MatrixUtils.makeSPD(dim);
                final PrimitiveDenseStore tmpRHS = PrimitiveDenseStore.FACTORY.makeFilled(dim, 1, new Uniform());
                if (DEBUG) {
                    BasicLogger.debug("Scale exp={} => factor={} and context={}", exp, tmpScale, tmpContext);
                    BasicLogger.debug("Body (unscaled) {}", tmpBody.toString());
                    BasicLogger.debug("RHS (unscaled) {}", tmpRHS.toString());
                }
                final UnaryFunction<Double> tmpModifier = PrimitiveFunction.MULTIPLY.second(tmpScale);
                tmpBody.modifyAll(tmpModifier);
                tmpRHS.modifyAll(tmpModifier);
                ExtremeElementsCase.performSolveTest(tmpBody, tmpRHS, SolverTask.PRIMITIVE.make(tmpBody, tmpRHS), 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.performSolveTest(tmpBody, tmpRHS, (SolverTask<Double>) tmpDecomp, tmpContext);
                    }
                }
            }
        }
    }
}
Also used : NumberContext(org.ojalgo.type.context.NumberContext) Uniform(org.ojalgo.random.Uniform) PrimitiveDenseStore(org.ojalgo.matrix.store.PrimitiveDenseStore)

Example 67 with NumberContext

use of org.ojalgo.type.context.NumberContext in project ojAlgo by optimatika.

the class ExtremeElementsCase method testSolveLU_1_16_1.

@Test
public void testSolveLU_1_16_1() {
    final PrimitiveDenseStore tmpBody = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.7259687987824925 } });
    final PrimitiveDenseStore tmpRHS = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0.6533251061005759 } });
    final UnaryFunction<Double> tmpSecond = PrimitiveFunction.MULTIPLY.second(PrimitiveFunction.POWER.invoke(PrimitiveMath.TEN, -16));
    tmpBody.modifyAll(tmpSecond);
    tmpRHS.modifyAll(tmpSecond);
    final SolverTask<Double> tmpAlgorithm = new LUDecomposition.Primitive();
    final NumberContext tmpContext = NumberContext.getGeneral(1, Integer.MIN_VALUE);
    ExtremeElementsCase.performSolveTest(tmpBody, tmpRHS, 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 68 with NumberContext

use of org.ojalgo.type.context.NumberContext 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 69 with NumberContext

use of org.ojalgo.type.context.NumberContext 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 70 with NumberContext

use of org.ojalgo.type.context.NumberContext 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)

Aggregations

NumberContext (org.ojalgo.type.context.NumberContext)91 Test (org.junit.jupiter.api.Test)63 ComplexNumber (org.ojalgo.scalar.ComplexNumber)16 PrimitiveDenseStore (org.ojalgo.matrix.store.PrimitiveDenseStore)15 BigDecimal (java.math.BigDecimal)14 BasicMatrix (org.ojalgo.matrix.BasicMatrix)13 BeforeEach (org.junit.jupiter.api.BeforeEach)12 Result (org.ojalgo.optimisation.Optimisation.Result)12 ExpressionsBasedModel (org.ojalgo.optimisation.ExpressionsBasedModel)9 Expression (org.ojalgo.optimisation.Expression)8 Variable (org.ojalgo.optimisation.Variable)8 PrimitiveMatrix (org.ojalgo.matrix.PrimitiveMatrix)6 Optimisation (org.ojalgo.optimisation.Optimisation)6 Uniform (org.ojalgo.random.Uniform)4 BigArray (org.ojalgo.array.BigArray)3 SimultaneousPrimitive (org.ojalgo.matrix.decomposition.HermitianEvD.SimultaneousPrimitive)3 MatrixStore (org.ojalgo.matrix.store.MatrixStore)3 Tag (org.junit.jupiter.api.Tag)2 RationalMatrix (org.ojalgo.matrix.RationalMatrix)2 Solver (org.ojalgo.matrix.decomposition.MatrixDecomposition.Solver)2