Search in sources :

Example 1 with OLSMultipleLinearRegression

use of org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression in project cruise-control by linkedin.

the class LinearRegressionModelParameters method modelState.

public synchronized LinearRegressionModelState modelState() {
    Map<Integer, Double> detailCompleteness = new HashMap<>();
    for (Map.Entry<Integer, AtomicInteger> entry : INDICES.entrySet()) {
        detailCompleteness.put(entry.getKey(), Math.min((double) entry.getValue().get() / NUM_OBSERVATIONS_PER_UTIL_BUCKET, 1.0));
    }
    Map<Integer, Integer> usedLeaderToFollowerRatio = new HashMap<>();
    Map<Integer, Integer> usedLeaderBytesInToBytesOutRatio = new HashMap<>();
    Map<ModelCoefficient, Double> coefficientFromAvailableData = new HashMap<>(_coefficients);
    OLSMultipleLinearRegression regression = new OLSMultipleLinearRegression();
    regression.setNoIntercept(true);
    boolean ignoreLeaderBytesOutRate = !isLeaderBytesInAndOutRatioDiverseEnough();
    double[][] sampleBytesRateData = aggregateSampleBytesRateData(ignoreLeaderBytesOutRate);
    int leaderBytesInIndex = 0;
    int leaderBytesOutIndex = 1;
    int followerBytesInIndex = ignoreLeaderBytesOutRate ? 1 : 2;
    for (int i = 0; i < sampleBytesRateData.length; i++) {
        int leaderToFollowerRatio = sampleBytesRateData[i][followerBytesInIndex] == 0.0 ? 10000000 : (int) ((sampleBytesRateData[i][leaderBytesInIndex] / sampleBytesRateData[i][followerBytesInIndex]) * 10);
        int count = usedLeaderToFollowerRatio.getOrDefault(leaderToFollowerRatio, 0);
        usedLeaderToFollowerRatio.put(leaderToFollowerRatio, count + 1);
        if (!ignoreLeaderBytesOutRate) {
            int leaderBytesInToBytesOutRatio = sampleBytesRateData[i][leaderBytesOutIndex] == 0.0 ? 10000000 : (int) ((sampleBytesRateData[i][leaderBytesInIndex] / sampleBytesRateData[i][leaderBytesOutIndex]) * 10);
            count = usedLeaderBytesInToBytesOutRatio.getOrDefault(leaderBytesInToBytesOutRatio, 0);
            usedLeaderBytesInToBytesOutRatio.put(leaderBytesInToBytesOutRatio, count + 1);
        }
    }
    regression.newSampleData(aggregateSampleCpuUtilData(), sampleBytesRateData);
    double[] parameters = regression.estimateRegressionParameters();
    coefficientFromAvailableData.put(ModelCoefficient.LEADER_BYTES_IN, parameters[leaderBytesInIndex]);
    if (ignoreLeaderBytesOutRate) {
        coefficientFromAvailableData.put(ModelCoefficient.FOLLOWER_BYTES_IN, parameters[followerBytesInIndex]);
    } else {
        coefficientFromAvailableData.put(ModelCoefficient.LEADER_BYTES_OUT, parameters[leaderBytesOutIndex]);
        coefficientFromAvailableData.put(ModelCoefficient.FOLLOWER_BYTES_IN, parameters[followerBytesInIndex]);
    }
    return new LinearRegressionModelState(detailCompleteness, coefficientFromAvailableData, OBSERVED_LEADER_TO_FOLLOWER_BYTES_RATIO, OBSERVED_LEADER_BYTES_IN_TO_BYTES_OUT_RATIO, usedLeaderToFollowerRatio, usedLeaderBytesInToBytesOutRatio, CPU_UTIL_ESTIMATION_ERROR_STATS);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) OLSMultipleLinearRegression(org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) Map(java.util.Map)

Example 2 with OLSMultipleLinearRegression

use of org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression in project cloudsim-plus by manoelcampos.

the class MathUtil method createLinearRegression.

public static OLSMultipleLinearRegression createLinearRegression(final double[][] x, final double[] y) {
    final OLSMultipleLinearRegression regression = new OLSMultipleLinearRegression();
    regression.newSampleData(y, x);
    return regression;
}
Also used : OLSMultipleLinearRegression(org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression)

Example 3 with OLSMultipleLinearRegression

use of org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression in project cruise-control by linkedin.

the class LinearRegressionModelParameters method updateModelCoefficient.

/**
 * Trigger the calculation of the model parameters.
 * @return true if the parameters are generated, otherwise false;
 */
public synchronized boolean updateModelCoefficient() {
    if (validBuckets().size() < MIN_CPU_UTIL_OBSERVATION_BUCKETS) {
        return false;
    }
    try {
        OLSMultipleLinearRegression regression = new OLSMultipleLinearRegression();
        regression.setNoIntercept(true);
        boolean ignoreLeaderBytesOut = !isLeaderBytesInAndOutRatioDiverseEnough();
        regression.newSampleData(aggregateSampleCpuUtilData(), aggregateSampleBytesRateData(ignoreLeaderBytesOut));
        double[] parameters = regression.estimateRegressionParameters();
        int leaderBytesInIndex = 0;
        int leaderBytesOutIndex = 1;
        int followerBytesInIndex = ignoreLeaderBytesOut ? 1 : 2;
        _coefficients.put(ModelCoefficient.LEADER_BYTES_IN, parameters[leaderBytesInIndex]);
        if (!ignoreLeaderBytesOut) {
            _coefficients.put(ModelCoefficient.LEADER_BYTES_OUT, parameters[leaderBytesOutIndex]);
        }
        _coefficients.put(ModelCoefficient.FOLLOWER_BYTES_IN, parameters[followerBytesInIndex]);
        LOG.info("Coefficient generated: leader_bytes_in: {}, leader_bytes_out: {}, follower_bytes_in: {}", _coefficients.get(ModelCoefficient.LEADER_BYTES_IN), _coefficients.get(ModelCoefficient.LEADER_BYTES_OUT), _coefficients.get(ModelCoefficient.FOLLOWER_BYTES_IN));
        return true;
    } catch (Exception e) {
        LOG.warn("received exception {}", e);
    }
    return false;
}
Also used : OLSMultipleLinearRegression(org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression)

Example 4 with OLSMultipleLinearRegression

use of org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression in project tetrad by cmu-phil.

the class Lofs2 method resolveOneEdgeMaxR3.

private double resolveOneEdgeMaxR3(double[] x, double[] y) {
    TetradLogger.getInstance().log("info", "\nEDGE " + x + " --- " + y);
    OLSMultipleLinearRegression regression = new OLSMultipleLinearRegression();
    double[][] _x = new double[1][];
    _x[0] = x;
    double[][] _y = new double[1][];
    _y[0] = y;
    regression.newSampleData(x, transpose(_y));
    double[] rXY = regression.estimateResiduals();
    regression.newSampleData(y, transpose(_x));
    double[] rYX = regression.estimateResiduals();
    double xPlus = new AndersonDarlingTest(rXY).getASquared();
    double xMinus = new AndersonDarlingTest(x).getASquared();
    double yPlus = new AndersonDarlingTest(rYX).getASquared();
    double yMinus = new AndersonDarlingTest(y).getASquared();
    double deltaX = xPlus - xMinus;
    double deltaY = yPlus - yMinus;
    return deltaX - deltaY;
}
Also used : OLSMultipleLinearRegression(org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression)

Aggregations

OLSMultipleLinearRegression (org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression)4 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1