Search in sources :

Example 1 with QRDecomposition

use of org.apache.ignite.ml.math.decompositions.QRDecomposition in project ignite by apache.

the class OLSMultipleLinearRegression method newSampleData.

/**
     * {@inheritDoc}
     * <p>This implementation computes and caches the QR decomposition of the X matrix.</p>
     */
@Override
public void newSampleData(double[] data, int nobs, int nvars, Matrix like) {
    super.newSampleData(data, nobs, nvars, like);
    qr = new QRDecomposition(getX(), threshold);
}
Also used : QRDecomposition(org.apache.ignite.ml.math.decompositions.QRDecomposition)

Example 2 with QRDecomposition

use of org.apache.ignite.ml.math.decompositions.QRDecomposition in project ignite by apache.

the class OLSMultipleLinearRegression method newXSampleData.

/**
     * {@inheritDoc}
     * <p>This implementation computes and caches the QR decomposition of the X matrix
     * once it is successfully loaded.</p>
     */
@Override
protected void newXSampleData(Matrix x) {
    super.newXSampleData(x);
    qr = new QRDecomposition(getX());
}
Also used : QRDecomposition(org.apache.ignite.ml.math.decompositions.QRDecomposition)

Example 3 with QRDecomposition

use of org.apache.ignite.ml.math.decompositions.QRDecomposition in project ignite by apache.

the class QRDecompositionExample method main.

/**
 * Executes example.
 *
 * @param args Command line arguments, none required.
 */
public static void main(String[] args) {
    System.out.println(">>> QR decomposition example started.");
    Matrix m = new DenseLocalOnHeapMatrix(new double[][] { { 2.0d, -1.0d, 0.0d }, { -1.0d, 2.0d, -1.0d }, { 0.0d, -1.0d, 2.0d } });
    System.out.println("\n>>> Input matrix:");
    Tracer.showAscii(m);
    QRDecomposition dec = new QRDecomposition(m);
    System.out.println("\n>>> Value for full rank in decomposition: [" + dec.hasFullRank() + "].");
    Matrix q = dec.getQ();
    Matrix r = dec.getR();
    System.out.println("\n>>> Orthogonal matrix Q:");
    Tracer.showAscii(q);
    System.out.println("\n>>> Upper triangular matrix R:");
    Tracer.showAscii(r);
    Matrix qSafeCp = safeCopy(q);
    Matrix identity = qSafeCp.times(qSafeCp.transpose());
    System.out.println("\n>>> Identity matrix obtained from Q:");
    Tracer.showAscii(identity);
    Matrix recomposed = qSafeCp.times(r);
    System.out.println("\n>>> Recomposed input matrix:");
    Tracer.showAscii(recomposed);
    Matrix sol = dec.solve(new DenseLocalOnHeapMatrix(3, 10));
    System.out.println("\n>>> Solved matrix:");
    Tracer.showAscii(sol);
    dec.destroy();
    System.out.println("\n>>> QR decomposition example completed.");
}
Also used : QRDecomposition(org.apache.ignite.ml.math.decompositions.QRDecomposition) Matrix(org.apache.ignite.ml.math.Matrix) DenseLocalOnHeapMatrix(org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix) DenseLocalOnHeapMatrix(org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix)

Example 4 with QRDecomposition

use of org.apache.ignite.ml.math.decompositions.QRDecomposition in project ignite by apache.

the class LinearRegressionQRTrainer method train.

/**
 * {@inheritDoc}
 */
@Override
public LinearRegressionModel train(Matrix data) {
    Vector groundTruth = extractGroundTruth(data);
    Matrix inputs = extractInputs(data);
    QRDecomposition decomposition = new QRDecomposition(inputs);
    QRDSolver solver = new QRDSolver(decomposition.getQ(), decomposition.getR());
    Vector variables = solver.solve(groundTruth);
    Vector weights = variables.viewPart(1, variables.size() - 1);
    double intercept = variables.get(0);
    return new LinearRegressionModel(weights, intercept);
}
Also used : QRDecomposition(org.apache.ignite.ml.math.decompositions.QRDecomposition) Matrix(org.apache.ignite.ml.math.Matrix) QRDSolver(org.apache.ignite.ml.math.decompositions.QRDSolver) FunctionVector(org.apache.ignite.ml.math.impls.vector.FunctionVector) Vector(org.apache.ignite.ml.math.Vector)

Aggregations

QRDecomposition (org.apache.ignite.ml.math.decompositions.QRDecomposition)4 Matrix (org.apache.ignite.ml.math.Matrix)2 Vector (org.apache.ignite.ml.math.Vector)1 QRDSolver (org.apache.ignite.ml.math.decompositions.QRDSolver)1 DenseLocalOnHeapMatrix (org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix)1 FunctionVector (org.apache.ignite.ml.math.impls.vector.FunctionVector)1