Example usage for org.apache.commons.math.stat.regression OLSMultipleLinearRegression newSampleData

List of usage examples for org.apache.commons.math.stat.regression OLSMultipleLinearRegression newSampleData

Introduction

In this page you can find the example usage for org.apache.commons.math.stat.regression OLSMultipleLinearRegression newSampleData.

Prototype

@Override
public void newSampleData(double[] data, int nobs, int nvars) 

Source Link

Document

This implementation computes and caches the QR decomposition of the X matrix.

Usage

From source file:com.ibm.streamsx.transportation.sfpark.ParkingFill.java

public ParkingFill aggregate(Iterable<ParkingOccupancy> items) {

    Mean mean = new Mean();

    int count = 0;
    for (ParkingOccupancy occupancy : items) {
        ospid = occupancy.getOspid();//from   w  w w  .j a v  a  2 s . co m
        // maintain the last values, as that's all
        // that matters for parking now!
        occ = occupancy.getOcc();
        oper = occupancy.getOper();
        setTs(occupancy.getTs());
        if (oper == 0)
            continue;
        count++;
        double fill = ((double) occ) / ((double) oper);
        mean.increment(fill);
    }

    if (ospid == null || oper == 0) {
        return null;
    }

    if (count > 5) {
        double[] values = new double[count * 2];
        int i = 0;
        for (ParkingOccupancy occupancy : items) {
            int occl = occupancy.getOcc();
            int operl = occupancy.getOper();
            long tsl = occupancy.getTs();
            if (operl == 0)
                continue;

            // y, then x
            // spaces (y) vs time (x)
            values[i++] = occl;
            values[i++] = tsl;
        }

        OLSMultipleLinearRegression ols = new OLSMultipleLinearRegression();
        ols.newSampleData(values, count, 1);

        double[] coe = ols.estimateRegressionParameters();
        if (coe.length >= 2)
            setTrend(coe[1] * 1000.0 * 60.0); // cars per minute
    }

    fill = (int) (mean.getResult() * 100.0);
    if (fill > 100)
        fill = 100;
    else if (fill < 0)
        fill = 0;

    return this;
}