本文整理匯總了Java中org.apache.commons.math3.stat.regression.SimpleRegression類的典型用法代碼示例。如果您正苦於以下問題:Java SimpleRegression類的具體用法?Java SimpleRegression怎麽用?Java SimpleRegression使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SimpleRegression類屬於org.apache.commons.math3.stat.regression包,在下文中一共展示了SimpleRegression類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: calculareTrend
import org.apache.commons.math3.stat.regression.SimpleRegression; //導入依賴的package包/類
private List<List<Object>> calculareTrend(List<List<Object>> measurements) {
SimpleRegression regression = new SimpleRegression(true);
Long firstX = null;
Long lastX = null;
for(int i = 0; i < measurements.size(); i++) {
List<Object> measurement = measurements.get(i);
Long x = (Long) measurement.get(0);
BigDecimal y = (BigDecimal) measurement.get(1);
regression.addData(x.doubleValue(), y.doubleValue());
if (i == 0) {
firstX = x;
} else if (i + 1 == measurements.size()) {
lastX = x;
}
}
double slope = regression.getSlope();
if (Double.isNaN(slope)) {
return new ArrayList<>();
} else {
List<Object> start = Lists.newArrayList(firstX, regression.predict(firstX));
List<Object> end = Lists.newArrayList(lastX, regression.predict(lastX));
return Lists.newArrayList(start, end);
}
}
示例2: LinearFunctionFitter
import org.apache.commons.math3.stat.regression.SimpleRegression; //導入依賴的package包/類
public LinearFunctionFitter(List<DelayPoint> delayPoints) {
if (delayPoints.size() < 2) {
throw new Error("cannot fit linear function with just one data point");
}
apacheSimpleRegression = new SimpleRegression();
for (DelayPoint p : delayPoints) {
apacheSimpleRegression.addData(p.getX(), p.getY());
}
if (delayPoints.size() == 2) {
DelayPoint center = DelayPoint.centerBetween(delayPoints.get(0), delayPoints.get(1));
apacheSimpleRegression.addData(center.getX(), center.getY());
}
apacheSimpleRegression.regress();
}
示例3: calculateLinearRegressionOn4Observations
import org.apache.commons.math3.stat.regression.SimpleRegression; //導入依賴的package包/類
@Test
public void calculateLinearRegressionOn4Observations() {
SimpleLinearRegressionIndicator reg = new SimpleLinearRegressionIndicator(closePrice, 4);
assertDecimalEquals(reg.getValue(1), 20);
assertDecimalEquals(reg.getValue(2), 30);
SimpleRegression origReg = buildSimpleRegression(10, 20, 30, 40);
assertDecimalEquals(reg.getValue(3), 40);
assertDecimalEquals(reg.getValue(3), origReg.predict(3));
origReg = buildSimpleRegression(30, 40, 30, 40);
assertDecimalEquals(reg.getValue(5), origReg.predict(3));
origReg = buildSimpleRegression(30, 20, 30, 50);
assertDecimalEquals(reg.getValue(9), origReg.predict(3));
}
示例4: makePrediction
import org.apache.commons.math3.stat.regression.SimpleRegression; //導入依賴的package包/類
private void makePrediction(List<GlucoseData> trendList) {
if (trendList.size() == 0) {
return;
}
regression = new SimpleRegression();
for (int i = 0; i < trendList.size(); i++) {
regression.addData(i, (trendList.get(i)).getGlucoseLevelRaw());
}
int glucoseLevelRaw =
(int) regression.predict(regression.getN() - 1 + PREDICTION_TIME);
glucoseSlopeRaw = regression.getSlope();
confidenceInterval = regression.getSlopeConfidenceInterval();
int ageInSensorMinutes =
trendList.get(trendList.size() - 1).getAgeInSensorMinutes() + PREDICTION_TIME;
glucoseData = new GlucoseData(trendList.get(0).getSensor(), ageInSensorMinutes, trendList.get(0).getTimezoneOffsetInMinutes(), glucoseLevelRaw, true);
}
示例5: updateStageRelation
import org.apache.commons.math3.stat.regression.SimpleRegression; //導入依賴的package包/類
private void updateStageRelation() {
//updates slope and offset parameters for the two stages
if (rpm_.getSize() > 1){ //need at least two points for linear fit
//Least Squares regression
SimpleRegression sr = new SimpleRegression();
int np = rpm_.getSize();
for (int n=0; n<np; n++) {
ReferencePoint RP = rpm_.getReferencePoint(n);
sr.addData(RP.stage1Position, RP.stage2Position);
}
try {
mmc_.setProperty(multiStageName_, "Scaling-2", sr.getSlope());
mmc_.setProperty(multiStageName_, "TranslationUm-2", sr.getIntercept());
} catch (Exception ex) {
logger_.logError(ex, "LightSheetControl: Error when setting scaling and translation");
}
}
}
示例6: getPairs
import org.apache.commons.math3.stat.regression.SimpleRegression; //導入依賴的package包/類
public List<double[]> getPairs(BufferedImage bi1, BufferedImage bi2, int u, int v, int s, int n) throws IOException {
List<double[]> pairList = new ArrayList<>(bi1.getWidth()*bi1.getHeight());
Raster r1 = bi1.getRaster().createTranslatedChild(0,0);
Raster r2 = bi2.getRaster().createTranslatedChild(0,0);
if (r1.getNumBands()>1) throw new IllegalArgumentException("only 1-banded rasters allowed here");
if (r2.getNumBands()>1) throw new IllegalArgumentException("only 1-banded rasters allowed here");
SimpleRegression reg = new SimpleRegression(true);
int minX = u<0?u*-1:0;
int minY = v<0?v*-1:0;
int maxX = u>0?bi1.getWidth()-u: bi1.getWidth();
int maxY = v>0?bi1.getHeight()-v: bi1.getHeight();
for (int x=minX; x<maxX; x++) {
for (int y=minY; y<maxY; y++) {
double d1 = r1.getSampleDouble(x+u,y+v,0);
if (d1> intensityThreshold) {
double d2 = r2.getSampleDouble(x, y, 0);
double[] pair = new double[]{d2,d1};
pairList.add(pair);
}
}
}
return pairList;
}
示例7: getSlope
import org.apache.commons.math3.stat.regression.SimpleRegression; //導入依賴的package包/類
public double getSlope(BufferedImage bi1, BufferedImage bi2, int u, int v, int s, int n) throws IOException {
Raster r1 = bi1.getRaster().createTranslatedChild(0,0);
Raster r2 = bi2.getRaster().createTranslatedChild(0,0);
if (r1.getNumBands()>1) throw new IllegalArgumentException("only 1-banded rasters allowed here");
if (r2.getNumBands()>1) throw new IllegalArgumentException("only 1-banded rasters allowed here");
SimpleRegression reg = new SimpleRegression(true);
int minX = u<0?u*-1:0;
int minY = v<0?v*-1:0;
int maxX = u>0?bi1.getWidth()-u: bi1.getWidth();
int maxY = v>0?bi1.getHeight()-v: bi1.getHeight();
for (int x=minX; x<maxX; x++) {
for (int y=minY; y<maxY; y++) {
double d1 = r1.getSampleDouble(x+u,y+v,0);
if (d1> intensityThreshold) {
double d2 = r2.getSampleDouble(x, y, 0);
reg.addData(d2, d1);
}
}
}
double slope = reg.getSlope();
double intercept = reg.getIntercept();
logger.info("i,j: "+s+","+n+": "+ "slope: "+slope+" ; intercept: "+intercept);
return slope;
}
示例8: removeTrend
import org.apache.commons.math3.stat.regression.SimpleRegression; //導入依賴的package包/類
/**
* Enfernt den Trend von einer Zeitreihe
* und speichert diese beiden in ein Objekt der @{@link TrendRemovedTimeSeries}-Klasse.
*
* @param timeSeriesWithTrend Zeitreihe von dem der Trend entfernt wird.
* @return Ein Objekt, welche die trendbereinigte Zeitreihe und den Trend enthält.
*/
public static TrendRemovedTimeSeries removeTrend(final double[] timeSeriesWithTrend) {
final double[] timeSeriesWithoutTrend = new double[timeSeriesWithTrend.length];
//Ermittle den Trend der Zeitreihe
final SimpleRegression regression = getRegression(timeSeriesWithTrend);
final double slope = regression.getSlope();
//Entferne den Trend
for (int i = 0; i < timeSeriesWithTrend.length; i++) {
final double trend = i * slope;
timeSeriesWithoutTrend[i] = timeSeriesWithTrend[i] - trend;
}
//Kapsele den Trend und die Zeitreihe in ein Objekt und gebe es aus
return new TrendRemovedTimeSeries(timeSeriesWithoutTrend, slope);
}
示例9: getRobustLoessParameterEstimates
import org.apache.commons.math3.stat.regression.SimpleRegression; //導入依賴的package包/類
/**
* Gets the robust loess parameter estimates.
*
* @param y the y
* @return the robust loess parameter estimates
*/
public static double[] getRobustLoessParameterEstimates(final double[] y) {
int n = y.length;
double[] x = new double[n];
for (int i = 0; i < n; i++) {
x[i] = i + 1;
}
SimpleRegression tricubeRegression = createWeigthedLinearRegression(x,
y, getTricubeWeigts(n));
double[] residuals = new double[n];
for (int i = 0; i < n; i++) {
residuals[i] = y[i] - tricubeRegression.predict(x[i]);
}
SimpleRegression tricubeBySquareRegression = createWeigthedLinearRegression(
x, y, getTricubeBisquareWeigts(residuals));
double[] estimates = tricubeBySquareRegression.regress()
.getParameterEstimates();
if (estimates[0] == Double.NaN || estimates[1] == Double.NaN) {
return tricubeRegression.regress().getParameterEstimates();
}
return estimates;
}
示例10: process
import org.apache.commons.math3.stat.regression.SimpleRegression; //導入依賴的package包/類
@Override
public Data process(Data item) {
// TODO Auto-generated method stub
Utils.mapContainsKeys(item, key);
double[] data = (double[]) item.get(key);
double[] slope = new double[data.length];
double[] intercept = new double[data.length];
for (int i = 1; i < data.length; i++) {
SimpleRegression regression = new SimpleRegression();
for (int j = 0; j < width; j++) {
regression.addData(j, data[(i + j) % data.length]);
}
regression.regress();
slope[(i + (width / 2)) % data.length] = scale * regression.getSlope();
intercept[(i + (width / 2)) % data.length] = regression.getIntercept();
}
item.put(slopeKey, slope);
item.put(interceptKey, intercept);
return item;
}
示例11: getPredictionData
import org.apache.commons.math3.stat.regression.SimpleRegression; //導入依賴的package包/類
@NonNull
private static PredictionData getPredictionData(int attempt, String tagId, ArrayList<GlucoseData> trendList) {
PredictionData predictedGlucose = new PredictionData();
SimpleRegression regression = new SimpleRegression();
for (int i = 0; i < trendList.size(); i++) {
regression.addData(trendList.size() - i, (trendList.get(i)).glucoseLevel);
}
predictedGlucose.glucoseLevel = (int)regression.predict(15 + PREDICTION_TIME);
predictedGlucose.trend = regression.getSlope();
predictedGlucose.confidence = regression.getSlopeConfidenceInterval();
predictedGlucose.errorCode = PredictionData.Result.OK;
predictedGlucose.realDate = trendList.get(0).realDate;
predictedGlucose.sensorId = tagId;
predictedGlucose.attempt = attempt;
predictedGlucose.sensorTime = trendList.get(0).sensorTime;
return predictedGlucose;
}
示例12: doAnalysis
import org.apache.commons.math3.stat.regression.SimpleRegression; //導入依賴的package包/類
@Override
protected double doAnalysis(final ThroughputHistory history) {
final SimpleRegression regression = new SimpleRegression();
for (int i = 1; i <= this.window; i++) {
final double xaxis = history.getTimestampOfEntry(i);
final double yaxis = history.getThroughputOfEntry(i);
regression.addData(xaxis, yaxis);
}
final double currentTime = history.getTimestampOfEntry(0);
double prediction = regression.predict(currentTime);
if (Double.isNaN(prediction)
|| prediction < 0
|| Double.isInfinite(prediction)) {
prediction = 0;
}
return prediction;
}
示例13: calculateElongationRate
import org.apache.commons.math3.stat.regression.SimpleRegression; //導入依賴的package包/類
/**
* TODO Documentation
*
* @param cells
* @return
*/
private Double calculateElongationRate(List<Cell> cells) {
Double lengths[] = new Double[cells.size()];
Double time[] = new Double[cells.size()];
int i=0;
SimpleRegression regression = new SimpleRegression();
for(Cell c:cells) {
lengths[i] = c.getLength();
time[i] = c.getMIFrameObject().getElapsedTime();
regression.addData(time[i], lengths[i]);
i++;
}
return regression.getSlope();
}
示例14: getStandardsRegression
import org.apache.commons.math3.stat.regression.SimpleRegression; //導入依賴的package包/類
/**
* Retrieve the linear regression to be used to calibrate a measurement against the gas standard
* runs.
*
* <p>
* Calibrating a measurement against gas standards is a two dimensional process.
* First, the gas standards of each type are examined individually, and the standard value for each
* type is calculated as a linear interpolation of the standard runs immediately preceding and
* following the measurement. This gives the value of the standards that would be measured at that time.
*
* Plotting the measured values against the known true concentrations of the gas standards gives what
* is close to a linear relationship between a measured value and its true value. This can be expressed
* as a linear regression, which can then be used to calculate the true value of a measurement.
* </p>
* @param dataSource A data source
* @param instrumentId The database ID of the instrument
* @param time The time of the measurement being calibrated
* @return The regression that can be used to calculate the true value of a measurement
* @throws MissingParamException If any parameters are missing
* @throws DatabaseException If a database error occurs
* @throws RecordNotFoundException If any required database records are missing
*/
public SimpleRegression getStandardsRegression(DataSource dataSource, long instrumentId, Calendar time) throws MissingParamException, DatabaseException, RecordNotFoundException {
SimpleRegression result = new SimpleRegression(true);
StandardStub actualStandard = GasStandardDB.getStandardBefore(dataSource, instrumentId, time);
Map<String, StandardConcentration> actualConcentrations = GasStandardDB.getConcentrationsMap(dataSource, actualStandard);
for (String runType : groupedStandardMeans.keySet()) {
// The gas standard as measured either side of the 'real' CO2 measurement
double measuredStandard = getInterpolatedCo2(runType, time);
if (measuredStandard != RawDataDB.MISSING_VALUE) {
// The actual concentration of the gas standard
double actualConcentration = actualConcentrations.get(runType).getConcentration();
result.addData(measuredStandard, actualConcentration);
}
}
return result;
}
示例15: ApacheRegression
import org.apache.commons.math3.stat.regression.SimpleRegression; //導入依賴的package包/類
public static double[] ApacheRegression(double[][] x, double[] y) {
if (x.length < 2) {
// Tools.warning("******************************************************");
// Tools.warning("******************************************************");
// Tools.warning("******************************************************");
// Tools.warning("Trying to run regression with " + x.length + " points.");
// Tools.warning("******************************************************");
// Tools.warning("******************************************************");
// Tools.warning("******************************************************");
exit("Trying to run regression with " + x.length + " points.");
}
if (Tools.loggerIsOn()) {
Tools.writeLog("Regression");
Tools.writeLog("\tx\ty");
for (int i = 0; i < x.length; i++) {
Tools.writeLog("\t" + x[i][0] + "\t" + y[i]);
}
}
SimpleRegression reg = new SimpleRegression(true);
reg.addObservations(x, y);
RegressionResults regRes = reg.regress();
double[] regResValues = regRes.getParameterEstimates();
double intercept = regResValues[0];
double slope = regResValues[1];
return new double[]{intercept, slope, regRes.getRSquared()};
}