本文整理汇总了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);
}
}