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);
}
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());
}
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.");
}
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);
}
Aggregations