本文整理匯總了Java中org.apache.commons.math3.stat.regression.SimpleRegression.regress方法的典型用法代碼示例。如果您正苦於以下問題:Java SimpleRegression.regress方法的具體用法?Java SimpleRegression.regress怎麽用?Java SimpleRegression.regress使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.math3.stat.regression.SimpleRegression
的用法示例。
在下文中一共展示了SimpleRegression.regress方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
示例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: 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()};
}
示例4: calculateSlope
import org.apache.commons.math3.stat.regression.SimpleRegression; //導入方法依賴的package包/類
public double calculateSlope(int slopePos, int numSlices, double[] data) {
//calculate slope
SimpleRegression regression = new SimpleRegression();
for (int j = 0; j < numSlices; j++) {
regression.addData(j, data[(j + slopePos - numSlices / 2) % data.length]);
}
regression.regress();
return regression.getSlope();
}
示例5: 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);
}
}