use of org.apache.commons.math.optimization.fitting.PolynomialFitter in project mzmine2 by mzmine.
the class RANSAC method fittPolinomialFunction.
private void fittPolinomialFunction(List<AlignStructMol> data, boolean linear) {
List<AlignStructMol> points = new ArrayList<AlignStructMol>();
int degree = 3;
if (linear) {
degree = 1;
}
PolynomialFitter fitter = new PolynomialFitter(degree, new GaussNewtonOptimizer(true));
for (int i = 0; i < data.size(); i++) {
AlignStructMol point = data.get(i);
if (point.ransacMaybeInLiers) {
points.add(point);
fitter.addObservedPoint(1, point.RT, point.RT2);
}
}
try {
PolynomialFunction function = fitter.fit();
for (AlignStructMol point : data) {
double y = point.RT2;
double bestY = function.value(point.RT);
if (Math.abs(y - bestY) < t) {
point.ransacAlsoInLiers = true;
AlsoNumber++;
} else {
point.ransacAlsoInLiers = false;
}
}
} catch (Exception ex) {
}
}
use of org.apache.commons.math.optimization.fitting.PolynomialFitter in project mzmine2 by mzmine.
the class RansacAlignerTask method getPolynomialFunction.
/**
* Return the corrected RT of the row
*
* @param row
* @param list
* @return
*/
private PolynomialFunction getPolynomialFunction(List<AlignStructMol> list) {
List<RTs> data = new ArrayList<RTs>();
for (AlignStructMol m : list) {
if (m.Aligned) {
data.add(new RTs(m.RT2, m.RT));
}
}
data = this.smooth(data);
Collections.sort(data, new RTs());
double[] xval = new double[data.size()];
double[] yval = new double[data.size()];
int i = 0;
for (RTs rt : data) {
xval[i] = rt.RT;
yval[i++] = rt.RT2;
}
PolynomialFitter fitter = new PolynomialFitter(3, new GaussNewtonOptimizer(true));
for (RTs rt : data) {
fitter.addObservedPoint(1, rt.RT, rt.RT2);
}
try {
return fitter.fit();
} catch (Exception ex) {
return null;
}
}
use of org.apache.commons.math.optimization.fitting.PolynomialFitter in project mzmine2 by mzmine.
the class AlignmentRansacPlot method getPolynomialFunction.
private PolynomialFunction getPolynomialFunction(Vector<AlignStructMol> list, boolean linear) {
List<RTs> data = new ArrayList<RTs>();
for (AlignStructMol m : list) {
if (m.Aligned) {
data.add(new RTs(m.RT2, m.RT));
}
}
data = this.smooth(data);
Collections.sort(data, new RTs());
double[] xval = new double[data.size()];
double[] yval = new double[data.size()];
int i = 0;
for (RTs rt : data) {
xval[i] = rt.RT;
yval[i++] = rt.RT2;
}
int degree = 2;
if (linear) {
degree = 1;
}
PolynomialFitter fitter = new PolynomialFitter(degree, new GaussNewtonOptimizer(true));
for (RTs rt : data) {
fitter.addObservedPoint(1, rt.RT, rt.RT2);
}
try {
return fitter.fit();
} catch (Exception ex) {
return null;
}
}
use of org.apache.commons.math.optimization.fitting.PolynomialFitter in project mzmine2 by mzmine.
the class RegressionInfo method getPolynomialFunction.
private PolynomialFunction getPolynomialFunction() {
Collections.sort(data, new RTs());
PolynomialFitter fitter = new PolynomialFitter(3, new GaussNewtonOptimizer(true));
for (RTs rt : data) {
fitter.addObservedPoint(1, rt.RT, rt.RT2);
}
try {
return fitter.fit();
} catch (Exception ex) {
return null;
}
}
Aggregations