本文整理匯總了Java中org.apache.commons.math3.stat.regression.SimpleRegression.predict方法的典型用法代碼示例。如果您正苦於以下問題:Java SimpleRegression.predict方法的具體用法?Java SimpleRegression.predict怎麽用?Java SimpleRegression.predict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.math3.stat.regression.SimpleRegression
的用法示例。
在下文中一共展示了SimpleRegression.predict方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
}
示例2: 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;
}
示例3: 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;
}
示例4: 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;
}
示例5: getRobustLoessParameterEstimates
import org.apache.commons.math3.stat.regression.SimpleRegression; //導入方法依賴的package包/類
/**
* Gets the robust loess parameter estimates.
*
* @param y the y array
* @return the robust loess parameter estimates
*/
public static double[] getRobustLoessParameterEstimates(final double... y) {
final int n = y.length;
final double[] x = new double[n];
for (int i = 0; i < n; i++) {
x[i] = i + 1;
}
final SimpleRegression tricubeRegression = createWeigthedLinearRegression(x,
y, getTricubeWeights(n));
final double[] residuals = new double[n];
for (int i = 0; i < n; i++) {
residuals[i] = y[i] - tricubeRegression.predict(x[i]);
}
final SimpleRegression tricubeBySqrRegression = createWeigthedLinearRegression(
x, y, getTricubeBisquareWeights(residuals));
final double[] estimates = tricubeBySqrRegression.regress()
.getParameterEstimates();
if (Double.isNaN(estimates[0]) || Double.isNaN(estimates[1])) {
return tricubeRegression.regress().getParameterEstimates();
}
return estimates;
}
示例6: createChart
import org.apache.commons.math3.stat.regression.SimpleRegression; //導入方法依賴的package包/類
private void createChart(SpotterResult result, String operation, NumericPairList<Long, Double> responseTimeSeries,
SimpleRegression regression) {
NumericPairList<Long, Double> linRegressionPoints = new NumericPairList<>();
NumericPairList<Long, Double> thresholdPoints = new NumericPairList<>();
long minTimestamp = responseTimeSeries.getKeyMin();
long maxTimestamp = responseTimeSeries.getKeyMax();
double intercept = regression.predict(minTimestamp);
linRegressionPoints.add(minTimestamp, intercept);
linRegressionPoints.add(maxTimestamp, regression.predict(maxTimestamp));
thresholdPoints.add(minTimestamp, intercept);
thresholdPoints.add(maxTimestamp, slopeThreshold * (double) (maxTimestamp - minTimestamp) + intercept);
AnalysisChartBuilder chartBuilder = AnalysisChartBuilder.getChartBuilder();
chartBuilder.startChart(operation, "Experiment Time [ms]", "Response Time [ms]");
// chartBuilder.addTimeSeries(responseTimeSeries, "Response Times");
chartBuilder.addTimeSeriesWithLine(thresholdPoints, "Threshold Slope");
chartBuilder.addTimeSeriesWithLine(linRegressionPoints, "Regression Slope");
mainDetectionController.getResultManager().storeImageChartResource(chartBuilder,
"Ramp Detection (Lin)", result);
}
示例7: drawNameRotated
import org.apache.commons.math3.stat.regression.SimpleRegression; //導入方法依賴的package包/類
/**
* Draws the given name at the centroid of the given plateCenters. The angle the name is
* drawn at is the least squares line through the plate centers. This does not break text
* into multiple lines.
*
* Side effect: This adds a new MapText to mapTexts.
*
* @param riseOffset The text will be raised (positive y) by this much distance above the centroid when
* drawn. The rotation will be applied to this location. If there is already a name drawn above the object,
* I try negating the riseOffset to draw the name below it. Positive y is down.
*/
public void drawNameRotated(BufferedImage map, Graphics2D g, String name, Set<Point> locations,
double riseOffset, boolean enableBoundsChecking, TextType type)
{
if (name.length() == 0)
return;
Point centroid = findCentroid(locations);
SimpleRegression regression = new SimpleRegression();
for (Point p : locations)
{
regression.addObservation(new double[]{p.x}, p.y);
}
double angle;
try
{
regression.regress();
// Find the angle to rotate the text to.
double y0 = regression.predict(0);
double y1 = regression.predict(1);
// Move the intercept to the origin.
y1 -= y0;
y0 = 0;
angle = Math.atan(y1/1.0);
}
catch(NoDataException e)
{
// This happens if the regression had only 2 or fewer points.
angle = 0;
}
MapText text = createMapText(name, centroid, angle, type);
if (drawNameRotated(map, g, riseOffset, enableBoundsChecking, text))
{
mapTexts.add(text);
}
}
示例8: addRegressionColumn
import org.apache.commons.math3.stat.regression.SimpleRegression; //導入方法依賴的package包/類
@Override
public Grid addRegressionColumn( int columnIndex, boolean addHeader )
{
verifyGridState();
SimpleRegression regression = new SimpleRegression();
List<Object> column = getColumn( columnIndex );
int index = 0;
for ( Object value : column )
{
// 0 omitted from regression
if ( value != null && !MathUtils.isEqual( Double.parseDouble( String.valueOf( value ) ), 0d ) )
{
regression.addData( index++, Double.parseDouble( String.valueOf( value ) ) );
}
}
List<Object> regressionColumn = new ArrayList<>();
for ( int i = 0; i < column.size(); i++ )
{
final double predicted = regression.predict( i );
// Enough values must exist for regression
if ( !Double.isNaN( predicted ) )
{
regressionColumn.add( Precision.round( predicted, 1 ) );
}
else
{
regressionColumn.add( null );
}
}
addColumn( regressionColumn );
if ( addHeader && columnIndex < headers.size() )
{
GridHeader header = headers.get( columnIndex );
if ( header != null )
{
GridHeader regressionHeader = new GridHeader( header.getName() + REGRESSION_SUFFIX,
header.getColumn() + REGRESSION_SUFFIX, header.getValueType(), header.getType(), header.isHidden(), header.isMeta() );
addHeader( regressionHeader );
}
}
return this;
}
示例9: addRegressionColumn
import org.apache.commons.math3.stat.regression.SimpleRegression; //導入方法依賴的package包/類
@Override
public Grid addRegressionColumn( int columnIndex, boolean addHeader )
{
verifyGridState();
SimpleRegression regression = new SimpleRegression();
List<Object> column = getColumn( columnIndex );
int index = 0;
for ( Object value : column )
{
// 0 omitted from regression
if ( value != null && !MathUtils.isEqual( Double.parseDouble( String.valueOf( value ) ), 0d ) )
{
regression.addData( index++, Double.parseDouble( String.valueOf( value ) ) );
}
}
List<Object> regressionColumn = new ArrayList<>();
for ( int i = 0; i < column.size(); i++ )
{
final double predicted = regression.predict( i );
// Enough values must exist for regression
if ( !Double.isNaN( predicted ) )
{
regressionColumn.add( getRounded( predicted, 1 ) );
}
else
{
regressionColumn.add( null );
}
}
addColumn( regressionColumn );
if ( addHeader && columnIndex < headers.size() )
{
GridHeader header = headers.get( columnIndex );
if ( header != null )
{
GridHeader regressionHeader = new GridHeader( header.getName() + REGRESSION_SUFFIX,
header.getColumn() + REGRESSION_SUFFIX, header.getType(), header.isHidden(), header.isMeta() );
addHeader( regressionHeader );
}
}
return this;
}
示例10: calcCalibratedCo2
import org.apache.commons.math3.stat.regression.SimpleRegression; //導入方法依賴的package包/類
/**
* <p>Calibrate a CO<sub>2</sub> measurement to the gas standards.</p>
*
* <p>The calibration is performed by retrieving the gas standard runs immediately before
* and after the measurement, which implicitly include the adjustment of the measured CO<sub>2</sub>
* in the gas standard run to the true value of the standard
* (see {@link GasStandardRuns#getStandardsRegression(DataSource, long, Calendar)}).
* If only one standard is available (e.g. at the beginning or end of a data file), the single
* available standard is used.
*
* The CO<sub>2</sub> value measured for the current record is adjusted to the linear progression between
* the two gas standard runs.
*
* @param driedCo2 The CO<sub>2</sub> value after drying
* @param time The time that the measurement was taken
* @param standardRuns The set of gas standard runs for the data file
* @param instrument The instrument from which the measurement was taken
* @return The calibrated CO<sub>2</sub> value
* @throws MissingParamException If any parameters are missing
* @throws DatabaseException If a database error occurs
* @throws RecordNotFoundException If any required database records are missing
* @see GasStandardRuns
*/
private double calcCalibratedCo2(double driedCo2, Calendar time, GasStandardRuns standardRuns, Instrument instrument) throws MissingParamException, DatabaseException, RecordNotFoundException {
SimpleRegression regression = standardRuns.getStandardsRegression(dataSource, instrument.getDatabaseId(), time);
return regression.predict(driedCo2);
}