use of org.apache.commons.math3.fitting.GaussianCurveFitter in project GDSC-SMLM by aherbert.
the class FIRE method fitGaussian.
/**
* Fit gaussian.
*
* @param x
* the x
* @param y
* the y
* @return new double[] { norm, mean, sigma }
*/
private double[] fitGaussian(float[] x, float[] y) {
WeightedObservedPoints obs = new WeightedObservedPoints();
for (int i = 0; i < x.length; i++) obs.add(x[i], y[i]);
Collection<WeightedObservedPoint> observations = obs.toList();
GaussianCurveFitter fitter = GaussianCurveFitter.create().withMaxIterations(2000);
GaussianCurveFitter.ParameterGuesser guess = new GaussianCurveFitter.ParameterGuesser(observations);
double[] initialGuess = null;
try {
initialGuess = guess.guess();
return fitter.withStartPoint(initialGuess).fit(observations);
} catch (TooManyEvaluationsException e) {
// Use the initial estimate
return initialGuess;
} catch (Exception e) {
// Just in case there is another exception type, or the initial estimate failed
return null;
}
}
use of org.apache.commons.math3.fitting.GaussianCurveFitter in project GDSC-SMLM by aherbert.
the class PCPALMMolecules method fitGaussian.
private double[] fitGaussian(float[] x, float[] y) {
WeightedObservedPoints obs = new WeightedObservedPoints();
for (int i = 0; i < x.length; i++) obs.add(x[i], y[i]);
Collection<WeightedObservedPoint> observations = obs.toList();
GaussianCurveFitter fitter = GaussianCurveFitter.create().withMaxIterations(2000);
GaussianCurveFitter.ParameterGuesser guess = new GaussianCurveFitter.ParameterGuesser(observations);
double[] initialGuess = null;
try {
initialGuess = guess.guess();
return fitter.withStartPoint(initialGuess).fit(observations);
} catch (TooManyEvaluationsException e) {
// Use the initial estimate
return initialGuess;
} catch (Exception e) {
// Just in case there is another exception type, or the initial estimate failed
return null;
}
}
Aggregations