當前位置: 首頁>>代碼示例>>Java>>正文


Java SimpleRegression.getSlope方法代碼示例

本文整理匯總了Java中org.apache.commons.math3.stat.regression.SimpleRegression.getSlope方法的典型用法代碼示例。如果您正苦於以下問題:Java SimpleRegression.getSlope方法的具體用法?Java SimpleRegression.getSlope怎麽用?Java SimpleRegression.getSlope使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.math3.stat.regression.SimpleRegression的用法示例。


在下文中一共展示了SimpleRegression.getSlope方法的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);
	}
}
 
開發者ID:xabgesagtx,項目名稱:fat-lining,代碼行數:25,代碼來源:ChartFactory.java

示例2: 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);
}
 
開發者ID:DorianScholz,項目名稱:OpenLibre,代碼行數:17,代碼來源:PredictionData.java

示例3: 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;
}
 
開發者ID:mstritt,項目名稱:orbit-image-analysis,代碼行數:27,代碼來源:Calibration.java

示例4: 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);
}
 
開發者ID:DHBW-Karlsruhe,項目名稱:businesshorizon2,代碼行數:23,代碼來源:TrendRemover.java

示例5: 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;
}
 
開發者ID:fact-project,項目名稱:fact-tools,代碼行數:26,代碼來源:MovingLinearFit.java

示例6: 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;
}
 
開發者ID:pimpimmi,項目名稱:LibreAlarm,代碼行數:18,代碼來源:AlgorithmUtil.java

示例7: 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();
}
 
開發者ID:modsim,項目名稱:vizardous,代碼行數:23,代碼來源:CellElongationRateSistesCorrelation.java

示例8: computeBufferSizeTrend

import org.apache.commons.math3.stat.regression.SimpleRegression; //導入方法依賴的package包/類
public void computeBufferSizeTrend() {
  for (InstanceMetrics instanceMetrics : componentMetrics.getMetrics().values()) {
    Map<Instant, Double> bufferMetrics
        = instanceMetrics.getMetrics().get(METRIC_BUFFER_SIZE.text());
    if (bufferMetrics == null || bufferMetrics.size() < 3) {
      // missing of insufficient data for creating a trend line
      continue;
    }

    SimpleRegression simpleRegression = new SimpleRegression(true);
    for (Instant timestamp : bufferMetrics.keySet()) {
      simpleRegression.addData(timestamp.getEpochSecond(), bufferMetrics.get(timestamp));
    }

    double slope = simpleRegression.getSlope();
    instanceMetrics.addMetric(METRIC_WAIT_Q_GROWTH_RATE.text(), slope);

    if (maxBufferChangeRate < slope) {
      maxBufferChangeRate = slope;
    }
  }
}
 
開發者ID:twitter,項目名稱:heron,代碼行數:23,代碼來源:ComponentMetricsHelper.java

示例9: dataRegressionSlope

import org.apache.commons.math3.stat.regression.SimpleRegression; //導入方法依賴的package包/類
private double dataRegressionSlope(Double[] extrems) {

		List<double[]> regInput = new ArrayList<double[]>();
		int j = 0;
		for (int i = 0; i < extrems.length; i++) {
			if (extrems[i] != 0d) {
				regInput.add(new double[]{j,extrems[i]});
			}
			j++;
		}
		SimpleRegression regression = new SimpleRegression();
		regression.addData(regInput.toArray(new double[0][]));
		double slope = regression.getSlope();

		return slope;

	}
 
開發者ID:premiummarkets,項目名稱:pm,代碼行數:18,代碼來源:HighLowSolver.java

示例10: assertResultsMatch

import org.apache.commons.math3.stat.regression.SimpleRegression; //導入方法依賴的package包/類
/**
 * Checks that the Morpheus OLS model yields the same results as Apache Math
 * @param frame      the data for regression
 * @param actual    the Morpheus results
 * @param expected  the Apache results
 */
private <R> void assertResultsMatch(DataFrame<String,String> frame, DataFrameLeastSquares<String,String> actual, SimpleRegression expected) {

    final double tss1 = actual.getTotalSumOfSquares();
    final double tss2 = expected.getTotalSumSquares();
    final double threshold = ((tss1 + tss2) / 2d) * 0.00001d;

    Assert.assertEquals(actual.getTotalSumOfSquares(), expected.getTotalSumSquares(), threshold, "Total sum of squares matches");
    Assert.assertEquals(actual.getRSquared(), expected.getRSquare(), 0.0000001, "R^2 values match");

    final double beta1 = actual.getBetaValue("X", Field.PARAMETER);
    final double beta2 = expected.getSlope();
    Assert.assertEquals(beta1, beta2, 0.000001, "Beta parameters match");

    final double intercept = expected.getIntercept();
    final double interceptStdError = expected.getInterceptStdErr();
    Assert.assertEquals(actual.getInterceptValue(Field.PARAMETER), intercept,  0.0000001, "The intercepts match");
    Assert.assertEquals(actual.getInterceptValue(Field.STD_ERROR), interceptStdError, 0.000000001, "The intercept std errors match");

    final double betaStdErr1 = actual.getBetaValue("X", Field.STD_ERROR);
    final double betaStdErr2 = expected.getSlopeStdErr();
    Assert.assertEquals(betaStdErr1, betaStdErr2, 0.00000001, "Beta Standard errors match");

    final DataFrame<String,String> residuals = actual.getResiduals();
    Assert.assertEquals(residuals.rows().count(), frame.rows().count(), "There are expected number of residuals");
    residuals.rows().forEach(row -> {
        final double x = frame.data().getDouble(row.ordinal(), "X");
        final double y = frame.data().getDouble(row.ordinal(), "Y");
        final double residual = row.getDouble(0);
        final double expect = y - expected.predict(x);
        Assert.assertEquals(residual, expect, 0.0000001, "Residual matches for x=" + x + " at row index " + row.ordinal());
    });
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:39,代碼來源:OLSTests.java

示例11: calculateSlope

import org.apache.commons.math3.stat.regression.SimpleRegression; //導入方法依賴的package包/類
public double calculateSlope(int slopePos, int numSlices, double[] data) {
    //calculate slope
    SimpleRegression regression = new SimpleRegression();

    for (int j = 0; j < numSlices; j++) {
        regression.addData(j, data[(j + slopePos - numSlices / 2) % data.length]);
    }
    regression.regress();

    return regression.getSlope();

}
 
開發者ID:fact-project,項目名稱:fact-tools,代碼行數:13,代碼來源:FindMaxSlope.java

示例12: solve

import org.apache.commons.math3.stat.regression.SimpleRegression; //導入方法依賴的package包/類
/**
 * Directly solve the linear problem, using the {@link SimpleRegression}
 * class.
 */
public double[] solve() {
    final SimpleRegression regress = new SimpleRegression(true);
    for (double[] d : points) {
        regress.addData(d[0], d[1]);
    }

    final double[] result = { regress.getSlope(), regress.getIntercept() };
    return result;
}
 
開發者ID:Quanticol,項目名稱:CARMA,代碼行數:14,代碼來源:StraightLineProblem.java

示例13: McLeanOrdinaryLeastSquaresRegressionLine

import org.apache.commons.math3.stat.regression.SimpleRegression; //導入方法依賴的package包/類
public McLeanOrdinaryLeastSquaresRegressionLine(SimpleRegression regression) {
    this.regression = regression;

    a = new double[2][1];
    a[1][0] = regression.getIntercept();

    v = new double[2][1];
    v[1][0] = regression.getSlope();
}
 
開發者ID:CIRDLES,項目名稱:ET_Redux,代碼行數:10,代碼來源:McLeanRegressionLineFit.java

示例14: getExpectedValue

import org.apache.commons.math3.stat.regression.SimpleRegression; //導入方法依賴的package包/類
@Override
public Object getExpectedValue(int start, int length)
{
    if (length <= 1) {
        return null;
    }
    SimpleRegression regression = new SimpleRegression();
    for (int i = start; i < start + length; i++) {
        regression.addData(i + 2, i);
    }
    return regression.getSlope();
}
 
開發者ID:y-lan,項目名稱:presto,代碼行數:13,代碼來源:TestRegrSlopeAggregation.java

示例15: testNonTrivialAggregation

import org.apache.commons.math3.stat.regression.SimpleRegression; //導入方法依賴的package包/類
private void testNonTrivialAggregation(Double[] y, Double[] x)
{
    SimpleRegression regression = new SimpleRegression();
    for (int i = 0; i < x.length; i++) {
        regression.addData(x[i], y[i]);
    }
    double expected = regression.getSlope();
    checkArgument(Double.isFinite(expected) && expected != 0.0, "Expected result is trivial");
    testAggregation(expected, createDoublesBlock(y), createDoublesBlock(x));
}
 
開發者ID:y-lan,項目名稱:presto,代碼行數:11,代碼來源:TestRegrSlopeAggregation.java


注:本文中的org.apache.commons.math3.stat.regression.SimpleRegression.getSlope方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。