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