当前位置: 首页>>代码示例>>Java>>正文


Java SimpleRegression类代码示例

本文整理汇总了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);
	}
}
 
开发者ID:xabgesagtx,项目名称:fat-lining,代码行数:25,代码来源:ChartFactory.java

示例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();
}
 
开发者ID:hpiasg,项目名称:asgdrivestrength,代码行数:17,代码来源:LinearFunctionFitter.java

示例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));
}
 
开发者ID:ta4j,项目名称:ta4j,代码行数:18,代码来源:SimpleLinearRegressionIndicatorTest.java

示例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);
}
 
开发者ID:DorianScholz,项目名称:OpenLibre,代码行数:17,代码来源:PredictionData.java

示例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");
        }
    }           
}
 
开发者ID:kthorn,项目名称:AZ100LightSheet,代码行数:19,代码来源:LightSheetControlForm.java

示例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;
}
 
开发者ID:mstritt,项目名称:orbit-image-analysis,代码行数:25,代码来源:Calibration.java

示例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;
}
 
开发者ID:mstritt,项目名称:orbit-image-analysis,代码行数:27,代码来源:Calibration.java

示例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);
}
 
开发者ID:DHBW-Karlsruhe,项目名称:businesshorizon2,代码行数:23,代码来源:TrendRemover.java

示例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;
}
 
开发者ID:gmartinezramirez,项目名称:Fog-Computing-Mobile-Architecture,代码行数:29,代码来源:MathUtil.java

示例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;
}
 
开发者ID:fact-project,项目名称:fact-tools,代码行数:26,代码来源:MovingLinearFit.java

示例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;
}
 
开发者ID:pimpimmi,项目名称:LibreAlarm,代码行数:18,代码来源:AlgorithmUtil.java

示例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;
}
 
开发者ID:teetime-framework,项目名称:TeeTime,代码行数:23,代码来源:RegressionAlgorithm.java

示例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();
}
 
开发者ID:modsim,项目名称:vizardous,代码行数:23,代码来源:CellElongationRateSistesCorrelation.java

示例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;
}
 
开发者ID:BjerknesClimateDataCentre,项目名称:QuinCe,代码行数:45,代码来源:GasStandardRuns.java

示例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()};
    }
 
开发者ID:pierpal,项目名称:IBDMUT,代码行数:27,代码来源:Tools.java


注:本文中的org.apache.commons.math3.stat.regression.SimpleRegression类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。