Example usage for org.apache.commons.math.optimization.fitting PolynomialFitter PolynomialFitter

List of usage examples for org.apache.commons.math.optimization.fitting PolynomialFitter PolynomialFitter

Introduction

In this page you can find the example usage for org.apache.commons.math.optimization.fitting PolynomialFitter PolynomialFitter.

Prototype

public PolynomialFitter(int degree, final DifferentiableMultivariateVectorialOptimizer optimizer) 

Source Link

Document

Simple constructor.

Usage

From source file:net.sf.mzmine.modules.peaklistmethods.gapfilling.peakfinder.RegressionInfo.java

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);
    }//from w  ww.jav  a 2 s. c o m
    try {
        return fitter.fit();

    } catch (Exception ex) {
        return null;
    }
}

From source file:guineu.modules.filter.Alignment.RANSAC.AlignmentRansacPlot.java

private PolynomialFunction getPolynomialFunction(List<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));
        }//from   w  ww  .ja  v  a2 s  .com
    }

    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 (OptimizationException ex) {
        return null;
    }
}

From source file:net.sf.mzmine.modules.peaklistmethods.alignment.ransac.AlignmentRansacPlot.java

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));
        }/*from  www .j a  va 2s .  c  o  m*/
    }

    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;
    }
}

From source file:io.github.msdk.features.ransacaligner.RANSAC.java

private void fittPolinomialFunction(List<AlignStructMol> data, boolean linear) {
    List<AlignStructMol> points = new ArrayList<AlignStructMol>();

    int degree = 3;
    if (linear) {
        degree = 1;// w ww  . j a va2 s  . c o  m
    }

    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) {
    }
}

From source file:guineu.modules.filter.Alignment.RANSACGCGC.AlignmentGCGCRansacPlot.java

private PolynomialFunction getPolynomialFunction(List<AlignGCGCStructMol> list, boolean linear) {
    List<GCGCRTs> data = new ArrayList<GCGCRTs>();
    for (AlignGCGCStructMol m : list) {
        if (m.Aligned) {
            data.add(new GCGCRTs(m.RT2, m.RT));
        }//from   ww w .ja  v a 2s  . c om
    }

    data = this.smooth(data);
    Collections.sort(data, new GCGCRTs());

    double[] xval = new double[data.size()];
    double[] yval = new double[data.size()];
    int i = 0;

    for (GCGCRTs 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 (GCGCRTs rt : data) {
        fitter.addObservedPoint(1, rt.RT, rt.RT2);
    }
    try {
        return fitter.fit();

    } catch (OptimizationException ex) {
        return null;
    }
}

From source file:guineu.modules.filter.Alignment.RANSAC.RANSAC.java

private void fittPolinomialFunction(List<AlignStructMol> data) {
    List<AlignStructMol> points = new ArrayList<AlignStructMol>();

    PolynomialFitter fitter = new PolynomialFitter(3, new GaussNewtonOptimizer(true));
    for (int i = 0; i < data.size(); i++) {
        AlignStructMol point = data.get(i);
        if (point.ransacMaybeInLiers) {
            points.add(point);/*from www  .  j  a va  2  s  .c o m*/
            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) {
    }
}

From source file:guineu.modules.filter.Alignment.RANSACGCGC.RANSACGCGC.java

private void fittPolinomialFunction(List<AlignGCGCStructMol> data) {
    List<AlignGCGCStructMol> points = new ArrayList<AlignGCGCStructMol>();

    PolynomialFitter fitter = new PolynomialFitter(3, new GaussNewtonOptimizer(true));
    for (int i = 0; i < data.size(); i++) {
        AlignGCGCStructMol point = data.get(i);
        if (point.ransacMaybeInLiers) {
            points.add(point);/*from w  w  w  .  j  a  v a 2s.c  om*/
            fitter.addObservedPoint(1, point.RT, point.RT2);
        }
    }
    try {
        PolynomialFunction function = fitter.fit();
        for (AlignGCGCStructMol 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) {
    }
}

From source file:guineu.modules.filter.Alignment.RANSAC.RansacAlignerTask.java

/**
 * Returns the corrected RT of the row/* w ww  .j a  va 2s  .  com*/
 *
 * @param row
 * @param list
 * @return
 */
private PolynomialFunction getPolynomialFunction(List<AlignStructMol> list, Range RTrange) {
    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, RTrange);
    Collections.sort(data, new RTs());

    try {
        PolynomialFitter fitter = new PolynomialFitter(3, new GaussNewtonOptimizer(true));
        for (RTs rt : data) {
            fitter.addObservedPoint(1, rt.RT, rt.RT2);
        }

        return fitter.fit();
    } catch (Exception ex) {
        return null;
    }
}

From source file:guineu.modules.filter.Alignment.RANSACGCGC.RansacGCGCAlignerTask.java

/**
 * Returns the corrected RT of the row/*  w  w  w . ja  v a 2s. com*/
 *
 * @param row
 * @param list
 * @return
 */
private PolynomialFunction getPolynomialFunction(List<AlignGCGCStructMol> list, Range RTrange) {
    List<GCGCRTs> data = new ArrayList<GCGCRTs>();
    for (AlignGCGCStructMol m : list) {
        if (m.Aligned) {
            data.add(new GCGCRTs(m.RT2, m.RT));
        }
    }

    data = this.smooth(data, RTrange);
    Collections.sort(data, new GCGCRTs());

    try {
        PolynomialFitter fitter = new PolynomialFitter(3, new GaussNewtonOptimizer(true));
        for (GCGCRTs rt : data) {
            fitter.addObservedPoint(1, rt.RT, rt.RT2);
        }

        return fitter.fit();
    } catch (Exception ex) {
        return null;
    }
}

From source file:io.github.msdk.features.ransacaligner.RansacAlignerMethod.java

/**
 * Return the corrected RT of the row/*from  w w w  .j av  a 2s .co m*/
 * 
 * @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;
    }
}