當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。