当前位置: 首页>>代码示例>>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;未经允许,请勿转载。