Example usage for org.apache.commons.math.linear MatrixUtils createColumnRealMatrix

List of usage examples for org.apache.commons.math.linear MatrixUtils createColumnRealMatrix

Introduction

In this page you can find the example usage for org.apache.commons.math.linear MatrixUtils createColumnRealMatrix.

Prototype

public static RealMatrix createColumnRealMatrix(double[] columnData) 

Source Link

Document

Creates a column RealMatrix using the data from the input array.

Usage

From source file:dfs.OLSTrendLine.java

@Override
public void setValues(double[] y, double[] x) {
    if (x.length != y.length) {
        throw new IllegalArgumentException(
                String.format("The numbers of y and x values must be equal (%d != %d)", y.length, x.length));
    }/*from w w w. jav  a 2  s . com*/
    double[][] xData = new double[x.length][];
    for (int i = 0; i < x.length; i++) {
        // the implementation determines how to produce a vector of predictors from a single x
        xData[i] = xVector(x[i]);
    }
    if (logY()) { // in some models we are predicting ln y, so we replace each y with ln y
        y = Arrays.copyOf(y, y.length); // user might not be finished with the array we were given
        for (int i = 0; i < x.length; i++) {
            y[i] = Math.log(y[i]);
        }
    }
    OLSMultipleLinearRegression ols = new OLSMultipleLinearRegression();
    ols.setNoIntercept(true); // let the implementation include a constant in xVector if desired
    ols.newSampleData(y, xData); // provide the data to the model
    coef = MatrixUtils.createColumnRealMatrix(ols.estimateRegressionParameters()); // get our coefs
}

From source file:org.apache.flink.statistics.regression.OLSTrendLine.java

@Override
public void setValues(double[] y, double[] x) {
    if (x.length != y.length) {
        throw new IllegalArgumentException(
                String.format("The numbers of y and x values must be equal (%d != %d)", y.length, x.length));
    }//from   www .  ja va2  s  .  c om
    double[][] xData = new double[x.length][];
    for (int i = 0; i < x.length; i++) {
        // the implementation determines how to produce a vector of
        // predictors from a single x
        xData[i] = xVector(x[i]);
    }
    if (logY()) { // in some models we are predicting ln y, so we replace
                  // each y with ln y
        y = Arrays.copyOf(y, y.length); // user might not be finished with
        // the array we were given
        for (int i = 0; i < x.length; i++) {
            y[i] = Math.log(y[i]);
        }
    }
    OLSMultipleLinearRegression ols = new OLSMultipleLinearRegression();

    ols.newSampleData(y, xData); // provide the data to the model
    coef = MatrixUtils.createColumnRealMatrix(ols.estimateRegressionParameters()); // get our coefs
}