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


Java SimpleRegression.addData方法代码示例

本文整理汇总了Java中org.apache.commons.math3.stat.regression.SimpleRegression.addData方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleRegression.addData方法的具体用法?Java SimpleRegression.addData怎么用?Java SimpleRegression.addData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math3.stat.regression.SimpleRegression的用法示例。


在下文中一共展示了SimpleRegression.addData方法的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: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: fitLineToDataFor2D

import org.apache.commons.math3.stat.regression.SimpleRegression; //导入方法依赖的package包/类
public McLeanRegressionLineInterface fitLineToDataFor2D(String x, String y, String x1SigmaAbs, String y1SigmaAbs, String rhos) {
    double[] xDouble = toDouble(x);
    double[] yDouble = toDouble(y);
    double[] x1SigmaAbsDouble = toDouble(x1SigmaAbs);
    double[] y1SigmaAbsDouble = toDouble(y1SigmaAbs);
    double[] rhosDouble = toDouble(rhos);

    double[][] xy = new double[x.length()][2];

    for(int i = 0; i < xDouble.length; i++) {
        xy[i][0] = xDouble[i];
        xy[i][1] = yDouble[i];
    }

    try {
        mcLeanRegressionLine = mcLeanRegression.fitLineToDataFor2D(xDouble, yDouble, x1SigmaAbsDouble, y1SigmaAbsDouble, rhosDouble);
    } catch (Exception e) {
        // in the case that an uncertainty is not provided, the try block fails and we do an ordinary least squares (OLS)
        SimpleRegression regression = new SimpleRegression();
        regression.addData(xy);

        mcLeanRegressionLine = new McLeanOrdinaryLeastSquaresRegressionLine(regression);
    }

    return mcLeanRegressionLine;
}
 
开发者ID:CIRDLES,项目名称:Topsoil,代码行数:27,代码来源:Regression.java

示例14: Graph

import org.apache.commons.math3.stat.regression.SimpleRegression; //导入方法依赖的package包/类
public Graph(boolean simple) {
	setDefaultCloseOperation(EXIT_ON_CLOSE);
	setSize(1200, 1200);

	for (int i = 0; i < Pitch.pitches.getItemCount(); i++) {
		pitch[i] = Double.valueOf(Pitch.pitches.getItem(i));
		time[i] = Double.valueOf(Pitch.time.getItem(i));
	}

	for (int w = 0; w < pitch.length; w++) {
		dataFull.add(time[w], pitch[w]);
	}

	for (int i = 0; i < Pitch.pitches.getItemCount() / 8; i++) {
		SimpleRegression Regression = new SimpleRegression();
		double x = 0;
		for (int s = 0; s < 8; s++) {
			position++;
			try {
				Regression.addData(time[position], pitch[position]);
				x = x + time[position];
			} catch (Exception e) {
				/* silence... */}
		}
		double average = x / 8;
		data.add(average, Regression.predict(average));
	}

	XYPlot plot = new XYPlot(data);
	XYPlot plotFull = new XYPlot(dataFull);
	LineRenderer lines = new DefaultLineRenderer2D();

	if (simple) {
		getContentPane().add(new InteractivePanel(plot));
		plot.setLineRenderers(data, lines);
	} else {
		getContentPane().add(new InteractivePanel(plotFull));
		plotFull.setLineRenderers(dataFull, lines);
	}
}
 
开发者ID:Scoutdrago3,项目名称:MusicToGraph,代码行数:41,代码来源:Graph.java

示例15: start

import org.apache.commons.math3.stat.regression.SimpleRegression; //导入方法依赖的package包/类
@Override
    public void start(Stage stage) {

//Belgium	1950	8639369
//Belgium	1960	9118700
//Belgium	1970	9637800
//Belgium	1980	9846800
//Belgium	1990	9969310
//Belgium	2000	10263618
        double[][] input = {
            {1950, 8639369},
            {1960, 9118700},
            {1970, 9637800},
            {1980, 9846800},
            {1990, 9969310},
            {2000, 10263618}};
        double[] predictionYears = {1950, 1960, 1970, 1980, 1990, 2000, 2010, 2020, 2030, 2040};

        NumberFormat yearFormat = NumberFormat.getNumberInstance();
        yearFormat.setMaximumFractionDigits(0);
        yearFormat.setGroupingUsed(false);
        NumberFormat populationFormat = NumberFormat.getNumberInstance();
        populationFormat.setMaximumFractionDigits(0);
        
        SimpleRegression regression = new SimpleRegression();
        regression.addData(input);
        projectedSeries.setName("Projected");
        for (int i = 0; i < predictionYears.length; i++) {
            out.println(yearFormat.format(predictionYears[i]) + "-"
                    + populationFormat.format(regression.predict(predictionYears[i])));
            addDataItem(projectedSeries, predictionYears[i],
                    regression.predict(predictionYears[i]));
        }

        displayAttribute("Slope",regression.getSlope());
        displayAttribute("Intercept", regression.getIntercept());
        displayAttribute("InterceptStdEr", regression.getInterceptStdErr());
        displayAttribute("MeanSquareError", regression.getMeanSquareError());
        displayAttribute("N", + regression.getN());
        displayAttribute("R", + regression.getR());
        displayAttribute("RSquare", regression.getRSquare());

        //Create index chart
        stage.setTitle("Simple Linear Regression");
        xAxis.setTickLabelFormatter(new StringConverter<Number>() {
            @Override
            public String toString(Number object) {
                return (object.intValue()) + "";
            }

            @Override
            public Number fromString(String string) {
                return 0;
            }
        });

        final LineChart<Number, Number> lineChart
                = new LineChart<>(xAxis, yAxis);
        lineChart.setTitle("Belgium Population");
        yAxis.setLabel("Population");

        originalSeries.setName("Actual");
        addDataItem(originalSeries, 1950, 8639369);
        addDataItem(originalSeries, 1960, 9118700);
        addDataItem(originalSeries, 1970, 9637800);
        addDataItem(originalSeries, 1980, 9846800);
        addDataItem(originalSeries, 1990, 9969310);
        addDataItem(originalSeries, 2000, 10263618);

        Scene scene = new Scene(lineChart, 800, 600);
        lineChart.getData().addAll(originalSeries, projectedSeries);
        stage.setScene(scene);
        stage.show();
    }
 
开发者ID:PacktPublishing,项目名称:Java-Data-Science-Made-Easy,代码行数:75,代码来源:MainApp - Simple Regression.java


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