Search in sources :

Example 1 with RecoverableCondition

use of org.ojalgo.RecoverableCondition in project ojAlgo by optimatika.

the class BasicParser method parse.

/**
 * @param reader The CSV data reader
 * @param consumer The results consumer
 */
default void parse(final Reader reader, final Consumer<T> consumer) {
    String tmpLine = null;
    T tmpItem = null;
    try (final BufferedReader tmpBufferedReader = new BufferedReader(reader)) {
        while ((tmpLine = tmpBufferedReader.readLine()) != null) {
            try {
                if ((tmpLine.length() > 0) && !tmpLine.startsWith("#") && ((tmpItem = this.parse(tmpLine)) != null)) {
                    consumer.accept(tmpItem);
                }
            } catch (final RecoverableCondition xcptn) {
            // Skip this line and try the next
            }
        }
    } catch (final IOException exception) {
        exception.printStackTrace();
    }
}
Also used : RecoverableCondition(org.ojalgo.RecoverableCondition) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 2 with RecoverableCondition

use of org.ojalgo.RecoverableCondition in project ojAlgo by optimatika.

the class DecompositionProblems method testP20160419.

/**
 * A user reported problems related to calculating the pseudoinverse for large (2000x2000) matrices.
 */
@Test
@Tag("slow")
public void testP20160419() {
    final PrimitiveDenseStore tmpOrg = PrimitiveDenseStore.FACTORY.makeFilled(2000, 2000, new Normal());
    final SingularValue<Double> tmpRaw = new RawSingularValue();
    try {
        final MatrixStore<Double> tmpInv = tmpRaw.invert(tmpOrg);
        TestUtils.assertEquals(tmpOrg, tmpOrg.multiply(tmpInv).multiply(tmpOrg), NumberContext.getGeneral(6, 6));
    } catch (final RecoverableCondition exception) {
        exception.printStackTrace();
    }
}
Also used : RecoverableCondition(org.ojalgo.RecoverableCondition) Normal(org.ojalgo.random.Normal) PrimitiveDenseStore(org.ojalgo.matrix.store.PrimitiveDenseStore) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Example 3 with RecoverableCondition

use of org.ojalgo.RecoverableCondition in project ojAlgo by optimatika.

the class DecompositionProblems method testP20160510InvertLargeMatrix.

/**
 * A user discovered that some large (relatively uniform) matrices causes the algorithm to never finsh
 * https://github.com/optimatika/ojAlgo/issues/22
 */
@Test
@Tag("slow")
public void testP20160510InvertLargeMatrix() {
    final double[][] data = new double[3000][3000];
    for (int i = 0; i < data.length; i++) {
        for (int j = 0; j < data.length; j++) {
            data[i][j] = 0.9;
        }
    }
    data[0][1] = 1.01;
    final PrimitiveMatrix input = PrimitiveMatrix.FACTORY.rows(data);
    try {
        // final SingularValue<Double> svd = SingularValue.make(input);
        final SingularValue<Double> svd = new SingularValueDecomposition.Primitive();
        svd.invert(input);
    } catch (final RecoverableCondition exception) {
        // TODO Auto-generated catch block
        exception.printStackTrace();
    }
// The issue:can't  be reached here!!!
}
Also used : RecoverableCondition(org.ojalgo.RecoverableCondition) PrimitiveMatrix(org.ojalgo.matrix.PrimitiveMatrix) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Example 4 with RecoverableCondition

use of org.ojalgo.RecoverableCondition in project ojAlgo by optimatika.

the class DesignCase method testSolveIdentity.

@Test
public void testSolveIdentity() {
    final Access2D<?> tmpIdentity = MatrixStore.PRIMITIVE.makeIdentity(9).get();
    final Access2D<?> tmpRandom = PrimitiveDenseStore.FACTORY.makeFilled(9, 1, new Uniform());
    final List<MatrixDecomposition<Double>> tmpAllDecomps = MatrixDecompositionTests.getAllPrimitive();
    for (final MatrixDecomposition<Double> tmpDecomp : tmpAllDecomps) {
        if (tmpDecomp instanceof SolverTask) {
            final SolverTask<Double> tmpSolverTask = (SolverTask<Double>) tmpDecomp;
            try {
                TestUtils.assertEquals(tmpDecomp.getClass().toString(), tmpRandom, tmpSolverTask.solve(tmpIdentity, tmpRandom));
            } catch (final RecoverableCondition xcptn) {
                TestUtils.fail(tmpDecomp.getClass().toString() + " " + xcptn.getMessage());
            }
        }
    }
}
Also used : RecoverableCondition(org.ojalgo.RecoverableCondition) SolverTask(org.ojalgo.matrix.task.SolverTask) Uniform(org.ojalgo.random.Uniform) Test(org.junit.jupiter.api.Test)

Aggregations

RecoverableCondition (org.ojalgo.RecoverableCondition)4 Test (org.junit.jupiter.api.Test)3 Tag (org.junit.jupiter.api.Tag)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 PrimitiveMatrix (org.ojalgo.matrix.PrimitiveMatrix)1 PrimitiveDenseStore (org.ojalgo.matrix.store.PrimitiveDenseStore)1 SolverTask (org.ojalgo.matrix.task.SolverTask)1 Normal (org.ojalgo.random.Normal)1 Uniform (org.ojalgo.random.Uniform)1