本文整理匯總了Java中org.apache.commons.math3.stat.regression.SimpleRegression.getIntercept方法的典型用法代碼示例。如果您正苦於以下問題:Java SimpleRegression.getIntercept方法的具體用法?Java SimpleRegression.getIntercept怎麽用?Java SimpleRegression.getIntercept使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.math3.stat.regression.SimpleRegression
的用法示例。
在下文中一共展示了SimpleRegression.getIntercept方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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());
});
}
示例4: 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;
}
示例5: 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();
}
示例6: 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.getIntercept();
}
示例7: 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.getIntercept();
checkArgument(Double.isFinite(expected) && expected != 0., "Expected result is trivial");
testAggregation(expected, createDoublesBlock(y), createDoublesBlock(x));
}
示例8: testRegression
import org.apache.commons.math3.stat.regression.SimpleRegression; //導入方法依賴的package包/類
@Test
public void testRegression() {
SimpleRegression regression = new SimpleRegression();
regression.addData(0.0, 1.0);
regression.addData(1.0, 2.5);
regression.addData(2.0, 3.0);
double slope = regression.getSlope();
double intercept = regression.getIntercept();
long n = regression.getN();
double err = regression.getMeanSquareError();
}
示例9: regress
import org.apache.commons.math3.stat.regression.SimpleRegression; //導入方法依賴的package包/類
private Line regress(Set<Line> things, LinearForm lfDir) {
SimpleRegression fit = new SimpleRegression();
// regression isn't happy on lines with infinite slope: so swap params!
boolean flip = Math.abs ( lfDir.x ) > Math.abs (lfDir.y);
for (Line l : things)
if (flip) {
fit.addData(l.start.y, l.start.x);
fit.addData(l.end.y, l.end.x);
}
else {
fit.addData(l.start.x, l.start.y);
fit.addData(l.end.x, l.end.y);
}
double intercept = fit.getIntercept(), slope = fit.getSlope();
if (Double.isNaN(intercept))
return null;
LinearForm lf;
if (flip)
lf = new LinearForm( 1, -slope );
else
lf = new LinearForm( -slope, 1 );
if ( lf.unitVector().angle(lfDir.unitVector())> Math.PI / 2) {
lf.x = -lf.x; // if regression is pointing wrong way, flip
lf.y = -lf.y;
}
if (flip)
lf.findC( intercept, 0 );
else
lf.findC( 0, intercept );
double[] minMax = things.stream()
.map(x -> new double[] { lf.findPParam(x.start), lf.findPParam(x.end) })
.collect(new InAxDoubleArray());
// Line line = new Line(lfDir, r.min, r.max);
return new Line(lf, minMax[0], minMax[1]); // do regression
}