Search in sources :

Example 31 with NumberContext

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

the class EigenvalueTest method testRandomSymmetricValuesOnly.

@Test
public void testRandomSymmetricValuesOnly() {
    final NumberContext evaluationContext = NumberContext.getGeneral(MathContext.DECIMAL32);
    for (int dim = 1; dim < 10; dim++) {
        final PrimitiveDenseStore matrix = MatrixUtils.makeSPD(dim);
        for (final Eigenvalue<Double> decomp : MatrixDecompositionTests.getEigenvaluePrimitiveSymmetric()) {
            decomp.decompose(matrix);
            TestUtils.assertEquals(matrix, decomp, evaluationContext);
            final Array1D<ComplexNumber> expected = decomp.getEigenvalues();
            decomp.computeValuesOnly(matrix);
            final Array1D<ComplexNumber> actual = decomp.getEigenvalues();
            TestUtils.assertEquals(expected, actual, evaluationContext);
        }
    }
}
Also used : NumberContext(org.ojalgo.type.context.NumberContext) ComplexNumber(org.ojalgo.scalar.ComplexNumber) PrimitiveDenseStore(org.ojalgo.matrix.store.PrimitiveDenseStore) Test(org.junit.jupiter.api.Test)

Example 32 with NumberContext

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

the class ExtremeElementsCase method testInvertEvD_10_307_1.

@Test
public void testInvertEvD_10_307_1() {
    final PrimitiveDenseStore tmpOriginal = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.488828119167862, 0.42210916029401624, 0.3090339419657017, 0.31968488522727556, 0.32307269871880584, 0.46899580731023627, 0.12091920407255509, 0.03795763520492966, 0.17470282114825963, 0.3946701200769135 }, { 0.42210916029401624, 1.8635124366670595, 0.545906918558408, 0.5647217567560566, 0.570706312407284, 0.8284787565954789, 0.21360317145069477, 0.06705197344564522, 0.3086116630097931, 0.6971828004646068 }, { 0.3090339419657017, 0.545906918558408, 1.632193464017115, 0.41344326780911667, 0.417824671952357, 0.6065446573280001, 0.1563828419260192, 0.04908999287306165, 0.22594032001124298, 0.5104204536764679 }, { 0.31968488522727556, 0.5647217567560566, 0.41344326780911667, 1.6539821927009415, 0.43222511886101456, 0.6274493925480824, 0.16177262133291218, 0.05078189352797441, 0.23372741780909156, 0.528012240705021 }, { 0.32307269871880584, 0.570706312407284, 0.417824671952357, 0.43222511886101456, 1.660912672676802, 0.6340986950817811, 0.1634869828633994, 0.051320047166039655, 0.23620430969852588, 0.5336077726660703 }, { 0.46899580731023627, 0.8284787565954789, 0.6065446573280001, 0.6274493925480824, 0.6340986950817811, 1.959428864502749, 0.23732958500300408, 0.07449990991899043, 0.34289134104035285, 0.7746238203382216 }, { 0.12091920407255509, 0.21360317145069477, 0.1563828419260192, 0.16177262133291218, 0.1634869828633994, 0.23732958500300408, 1.2473654835536, 0.019207996469193075, 0.08840622324485663, 0.19971798116519177 }, { 0.03795763520492966, 0.06705197344564522, 0.04908999287306165, 0.05078189352797441, 0.051320047166039655, 0.07449990991899043, 0.019207996469193075, 1.0776502695252994, 0.027751515547194034, 0.06269328624082444 }, { 0.17470282114825963, 0.3086116630097931, 0.22594032001124298, 0.23372741780909156, 0.23620430969852588, 0.34289134104035285, 0.08840622324485663, 0.027751515547194034, 1.3573911039439759, 0.2885504830370714 }, { 0.3946701200769135, 0.6971828004646068, 0.5104204536764679, 0.528012240705021, 0.5336077726660703, 0.7746238203382216, 0.19971798116519177, 0.06269328624082444, 0.2885504830370714, 1.8073801497932753 } });
    tmpOriginal.modifyAll(PrimitiveFunction.MULTIPLY.second(PrimitiveFunction.POWER.invoke(PrimitiveMath.TEN, 307)));
    final RawEigenvalue.Symmetric tmpAlgorithm = new RawEigenvalue.Symmetric();
    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) Test(org.junit.jupiter.api.Test)

Example 33 with NumberContext

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

the class ExtremeElementsCase method testInvertTask_2_155_1.

@Test
public void testInvertTask_2_155_1() {
    final PrimitiveDenseStore tmpOriginal = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.7755876870972727, 0.5243083105843722 }, { 0.5243083105843722, 1.6760142267686806 } });
    tmpOriginal.modifyAll(PrimitiveFunction.MULTIPLY.second(PrimitiveFunction.POWER.invoke(PrimitiveMath.TEN, 155)));
    final InverterTask<Double> tmpAlgorithm = InverterTask.PRIMITIVE.make(tmpOriginal);
    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) Test(org.junit.jupiter.api.Test)

Example 34 with NumberContext

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

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

the class MarketShareCase method testMipButSomeConstainedToOptimatl.

@Test
public void testMipButSomeConstainedToOptimatl() {
    final ExpressionsBasedModel tmpModel = MarketShareCase.makeModel();
    // tmpModel.options.debug(IntegerSolver.class);
    // 37, 20
    final int tmpConstrLimit = 20;
    int tmpConstrCount = 0;
    for (final Variable tmpVariable : tmpModel.getVariables()) {
        final String tmpName = tmpVariable.getName();
        if (tmpConstrCount < tmpConstrLimit) {
            tmpVariable.level(SOLUTION.get(tmpName));
            tmpConstrCount++;
        }
    }
    final Result tmpResult = tmpModel.minimise();
    TestUtils.assertStateNotLessThanOptimal(tmpResult);
    TestUtils.assertTrue(tmpModel.validate(tmpModel.options.feasibility));
    TestUtils.assertTrue(tmpModel.validate(tmpResult, tmpModel.options.feasibility));
    TestUtils.assertEquals("OBJECTIVE_MIP", OBJECTIVE_MIP.doubleValue(), tmpResult.getValue(), tmpModel.options.feasibility);
    final NumberContext tmpContext = tmpModel.options.solution.newScale(13);
    for (final Variable tmpVariable : tmpModel.getVariables()) {
        final String tmpName = tmpVariable.getName();
        final double tmpExpected = SOLUTION.get(tmpName).doubleValue();
        final double tmpActual = tmpVariable.getValue().doubleValue();
        TestUtils.assertEquals(tmpName, tmpExpected, tmpActual, tmpContext);
    }
}
Also used : Variable(org.ojalgo.optimisation.Variable) NumberContext(org.ojalgo.type.context.NumberContext) ExpressionsBasedModel(org.ojalgo.optimisation.ExpressionsBasedModel) Result(org.ojalgo.optimisation.Optimisation.Result) Test(org.junit.jupiter.api.Test)

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