Search in sources :

Example 1 with PolynomialFitter

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) {
    }
}
Also used : PolynomialFitter(org.apache.commons.math.optimization.fitting.PolynomialFitter) GaussNewtonOptimizer(org.apache.commons.math.optimization.general.GaussNewtonOptimizer) ArrayList(java.util.ArrayList) PolynomialFunction(org.apache.commons.math.analysis.polynomials.PolynomialFunction)

Example 2 with PolynomialFitter

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;
    }
}
Also used : PolynomialFitter(org.apache.commons.math.optimization.fitting.PolynomialFitter) GaussNewtonOptimizer(org.apache.commons.math.optimization.general.GaussNewtonOptimizer) ArrayList(java.util.ArrayList) DataPoint(net.sf.mzmine.datamodel.DataPoint)

Example 3 with PolynomialFitter

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;
    }
}
Also used : PolynomialFitter(org.apache.commons.math.optimization.fitting.PolynomialFitter) GaussNewtonOptimizer(org.apache.commons.math.optimization.general.GaussNewtonOptimizer) ArrayList(java.util.ArrayList)

Example 4 with PolynomialFitter

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;
    }
}
Also used : RTs(net.sf.mzmine.modules.peaklistmethods.alignment.ransac.RTs) PolynomialFitter(org.apache.commons.math.optimization.fitting.PolynomialFitter) GaussNewtonOptimizer(org.apache.commons.math.optimization.general.GaussNewtonOptimizer)

Aggregations

PolynomialFitter (org.apache.commons.math.optimization.fitting.PolynomialFitter)4 GaussNewtonOptimizer (org.apache.commons.math.optimization.general.GaussNewtonOptimizer)4 ArrayList (java.util.ArrayList)3 DataPoint (net.sf.mzmine.datamodel.DataPoint)1 RTs (net.sf.mzmine.modules.peaklistmethods.alignment.ransac.RTs)1 PolynomialFunction (org.apache.commons.math.analysis.polynomials.PolynomialFunction)1