本文整理汇总了Java中org.apache.commons.math3.fitting.PolynomialCurveFitter.create方法的典型用法代码示例。如果您正苦于以下问题:Java PolynomialCurveFitter.create方法的具体用法?Java PolynomialCurveFitter.create怎么用?Java PolynomialCurveFitter.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.fitting.PolynomialCurveFitter
的用法示例。
在下文中一共展示了PolynomialCurveFitter.create方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSlope
import org.apache.commons.math3.fitting.PolynomialCurveFitter; //导入方法依赖的package包/类
private double getSlope(Hashtable<Integer,Double> points)
{
WeightedObservedPoints obs=new WeightedObservedPoints();
Enumeration e=points.keys();
int key;
while (e.hasMoreElements())
{
key=(int)e.nextElement();
obs.add(key,points.get(key));
}
PolynomialCurveFitter fitter=PolynomialCurveFitter.create(1);
double[] coeff=fitter.fit(obs.toList());
BigDecimal bd = new BigDecimal(coeff[1]);
BigDecimal slope=bd.setScale(3,BigDecimal.ROUND_HALF_UP);
return slope.doubleValue()*10;
}
示例2: fit
import org.apache.commons.math3.fitting.PolynomialCurveFitter; //导入方法依赖的package包/类
public void fit(String path) throws IOException {
final WeightedObservedPoints obs = new WeightedObservedPoints();
try(BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(path))))) {
String line = br.readLine();
while (line != null) {
String[] point = line.split(" ");
double x = Double.parseDouble(point[0]);
double y = Double.parseDouble(point[1]);
obs.add(x, y);
line = br.readLine();
}
} catch (IOException e) {
throw e;
}
final PolynomialCurveFitter fitter = PolynomialCurveFitter.create(5);
final double[] coeff = fitter.fit(obs.toList());
StringBuilder res = new StringBuilder();
for (int i = coeff.length - 1; i >= 0; i--) {
res.append(coeff[i]).append(":");
}
System.out.println(res.substring(0, res.length() - 1));
}
示例3: process
import org.apache.commons.math3.fitting.PolynomialCurveFitter; //导入方法依赖的package包/类
/**
* TODO
*
* @return
*/
public double process() {
Collection<WeightedObservedPoint> points = new LinkedList<WeightedObservedPoint>();
// TODO We might need to change the behavior due to the fact that cell that are not in a track might still be in the metaXml file
for (MIFrame frame : forest.getMetaxml().getAllFrames()) {
// For the growth rate to be correct we need elapsed time in hours
double elapsedTime = frame.getElapsedTime() / 60;
double cellNumber = (double) frame.getAllCellsInFrame().size();
// The points are uniformly weighted
points.add(new WeightedObservedPoint(1d, elapsedTime, Math.log(cellNumber)));
}
final AbstractCurveFitter fitter = PolynomialCurveFitter.create(1);
double[] coeffs = fitter.fit(points);
growthRate = coeffs[1];
return growthRate;
}
示例4: processNew
import org.apache.commons.math3.fitting.PolynomialCurveFitter; //导入方法依赖的package包/类
/**
* TODO
*
* @return
*/
public double processNew() {
Collection<WeightedObservedPoint> points = new LinkedList<WeightedObservedPoint>();
// TODO We might need to change the behavior due to the fact that cell that are not in a track might still be in the metaXml file
for (MIFrame frame : forest.getMetaxml().getAllFrames()) {
// For the growth rate to be correct we need elapsed time in hours
double elapsedTime = frame.getElapsedTime() / 60;
double cellNumber = (double) frame.getAllCellsInFrame().size();
// The points are uniformly weighted
points.add(new WeightedObservedPoint(elapsedTime/forest.getMetaxml().getExperimentDuration(), elapsedTime, Math.log(cellNumber)));
}
final AbstractCurveFitter fitter = PolynomialCurveFitter.create(1);
double[] coeffs = fitter.fit(points);
factor = coeffs[0];
growthRate = coeffs[1];
return growthRate;
}
示例5: getStageEstimationFunction
import org.apache.commons.math3.fitting.PolynomialCurveFitter; //导入方法依赖的package包/类
public static PolynomialFunction getStageEstimationFunction(
List<Double> trainingSizes, List<Long> trainingDurations, int degree)
throws SmallDataException {
if (trainingSizes.size() <= degree)
throw new SmallDataException();
PolynomialCurveFitter fitter = PolynomialCurveFitter.create(degree);
List<WeightedObservedPoint> points = new ArrayList<>();
for (int i = 0; i < trainingSizes.size(); i++)
points.add(new WeightedObservedPoint(1, trainingSizes.get(i),
new Long(trainingDurations.get(i)).doubleValue()));
return new PolynomialFunction(fitter.fit(points));
}
示例6: detrend
import org.apache.commons.math3.fitting.PolynomialCurveFitter; //导入方法依赖的package包/类
public static void detrend(List<double[]> set, int detrendPolynomial) {
PolynomialCurveFitter p = PolynomialCurveFitter.create(detrendPolynomial);
WeightedObservedPoints wop = new WeightedObservedPoints();
for(int i = 0; i < set.size(); i++) {
wop.add(set.get(i)[0], set.get(i)[1]);
}
double[] coeff = p.fit(wop.toList());
for(int h = 0; h < set.size(); h++) {
double val = set.get(h)[0];
double off = 0;
for(int i = detrendPolynomial; i >= 0; i--) {
off += coeff[i] * Math.pow(val, i);
}
set.set(h, new double[]{set.get(h)[0], set.get(h)[1]-off});
}
}
示例7: isLinearCoeffDiff
import org.apache.commons.math3.fitting.PolynomialCurveFitter; //导入方法依赖的package包/类
private boolean isLinearCoeffDiff(double[] input, int centerIndex) {
double xStep = 2.0 / (input.length + 1);
WeightedObservedPoints firstHalf = new WeightedObservedPoints();
WeightedObservedPoints secondHalf = new WeightedObservedPoints();
for (int i = 0; i < input.length; i++) {
if (i <= centerIndex) {
firstHalf.add(i * xStep, input[i]);
}
if (i >= centerIndex) {
secondHalf.add((i - centerIndex) * xStep, input[i]);
}
}
PolynomialCurveFitter fitter = PolynomialCurveFitter.create(1);
double[] firstHalfCoeffs = fitter.fit(firstHalf.toList());
double[] secondHalfCoeffs = fitter.fit(secondHalf.toList());
double firstHalfCoeff = firstHalfCoeffs[1];
double secondHalfCoeff = secondHalfCoeffs[1];
return firstHalfCoeff * secondHalfCoeff < 0;
}
示例8: fitCurve
import org.apache.commons.math3.fitting.PolynomialCurveFitter; //导入方法依赖的package包/类
private double[] fitCurve(
final List<ValuePair<DoubleType, DoubleType>> pairs)
{
if (!allValuesFinite(pairs)) {
return new double[2];
}
final WeightedObservedPoints points = toWeightedObservedPoints(pairs);
final PolynomialCurveFitter curveFitter = PolynomialCurveFitter.create(1);
return curveFitter.fit(points.toList());
}
示例9: fitPolynomialToData
import org.apache.commons.math3.fitting.PolynomialCurveFitter; //导入方法依赖的package包/类
/**
* Get fitting coefficients for N degree polynomial.
* @param x
* @param y
* @param degree
* @param reverseCoefficients
* @return Fitting coefficients.
*/
public double[] fitPolynomialToData(double[] x, double[] y, int degree, boolean reverseCoefficients) {
WeightedObservedPoints obs = new WeightedObservedPoints();
for (int i = 0; i < x.length; i++) {
obs.add(1, x[i], y[i]);
}
PolynomialCurveFitter fitter = PolynomialCurveFitter.create(degree);
double[] coefficients = fitter.fit(obs.toList());
if (reverseCoefficients) {
return reverseDoublePrimitiveArray(coefficients);
} else {
return coefficients;
}
}
示例10: createFitter
import org.apache.commons.math3.fitting.PolynomialCurveFitter; //导入方法依赖的package包/类
@Override
protected AbstractCurveFitter createFitter() {
return PolynomialCurveFitter.create(degree);
}
示例11: estimateStageDuration
import org.apache.commons.math3.fitting.PolynomialCurveFitter; //导入方法依赖的package包/类
public static long estimateStageDuration(List<Double> trainingSizes,
List<Long> trainingDurations, double newSize, int degree) {
PolynomialCurveFitter fitter = PolynomialCurveFitter.create(degree);
List<WeightedObservedPoint> points = new ArrayList<>();
for (int i = 0; i < trainingSizes.size(); i++)
points.add(new WeightedObservedPoint(1, trainingSizes.get(i),
new Long(trainingDurations.get(i)).doubleValue()));
PolynomialFunction function = new PolynomialFunction(fitter.fit(points));
return new Double(function.value(newSize)).longValue();
}