/** * Guesses the parameters based on the specified observed points. * * @param points Observed points, sorted. * @return the guessed parameters (normalization factor, mean and * sigma). */ private double[] basicGuess(WeightedObservedPoint[] points) { final int maxYIdx = findMaxY(points); final double n = points[maxYIdx].getY(); final double m = points[maxYIdx].getX(); double fwhmApprox; try { final double halfY = n + ((m - n) / 2); final double fwhmX1 = interpolateXAtY(points, maxYIdx, -1, halfY); final double fwhmX2 = interpolateXAtY(points, maxYIdx, 1, halfY); fwhmApprox = fwhmX2 - fwhmX1; } catch (OutOfRangeException e) { // TODO: Exceptions should not be used for flow control. fwhmApprox = points[points.length - 1].getX() - points[0].getX(); } final double s = fwhmApprox / (2 * Math.sqrt(2 * Math.log(2))); return new double[] { n, m, s }; }
final WeightedObservedPoint p1 = points[i]; final WeightedObservedPoint p2 = points[i + idxStep]; if (isBetween(y, p1.getY(), p2.getY())) { if (idxStep < 0) { return new WeightedObservedPoint[] { p2, p1 };
= getInterpolationPointsForY(points, startIdx, idxStep, y); final WeightedObservedPoint p1 = twoPoints[0]; final WeightedObservedPoint p2 = twoPoints[1];
= getInterpolationPointsForY(points, startIdx, idxStep, y); final WeightedObservedPoint p1 = twoPoints[0]; final WeightedObservedPoint p2 = twoPoints[1];
final WeightedObservedPoint p1 = points[i]; final WeightedObservedPoint p2 = points[i + idxStep]; if (isBetween(y, p1.getY(), p2.getY())) { if (idxStep < 0) { return new WeightedObservedPoint[] { p2, p1 };
/** * Guesses the parameters based on the specified observed points. * * @param points Observed points, sorted. * @return the guessed parameters (normalization factor, mean and * sigma). */ private double[] basicGuess(WeightedObservedPoint[] points) { final int maxYIdx = findMaxY(points); final double n = points[maxYIdx].getY(); final double m = points[maxYIdx].getX(); double fwhmApprox; try { final double halfY = n + ((m - n) / 2); final double fwhmX1 = interpolateXAtY(points, maxYIdx, -1, halfY); final double fwhmX2 = interpolateXAtY(points, maxYIdx, 1, halfY); fwhmApprox = fwhmX2 - fwhmX1; } catch (OutOfRangeException e) { // TODO: Exceptions should not be used for flow control. fwhmApprox = points[points.length - 1].getX() - points[0].getX(); } final double s = fwhmApprox / (2 * FastMath.sqrt(2 * FastMath.log(2))); return new double[] { n, m, s }; }
/** * Constructs instance with the specified observed points. * * @param observations Observed points from which to guess the * parameters of the Gaussian. * @throws NullArgumentException if {@code observations} is * {@code null}. * @throws NumberIsTooSmallException if there are less than 3 * observations. */ public ParameterGuesser(WeightedObservedPoint[] observations) { if (observations == null) { throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } if (observations.length < 3) { throw new NumberIsTooSmallException(observations.length, 3, true); } final WeightedObservedPoint[] sorted = sortObservations(observations); final double[] params = basicGuess(sorted); norm = params[0]; mean = params[1]; sigma = params[2]; }
/** * Constructs instance with the specified observed points. * * @param observations Observed points from which to guess the * parameters of the Gaussian. * @throws NullArgumentException if {@code observations} is * {@code null}. * @throws NumberIsTooSmallException if there are less than 3 * observations. */ public ParameterGuesser(WeightedObservedPoint[] observations) { if (observations == null) { throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } if (observations.length < 3) { throw new NumberIsTooSmallException(observations.length, 3, true); } final WeightedObservedPoint[] sorted = sortObservations(observations); final double[] params = basicGuess(sorted); norm = params[0]; mean = params[1]; sigma = params[2]; }
/** * Fits a Gaussian function to the observed points. * * @return the parameters of the Gaussian function that best fits the * observed points (in the same order as above). */ public double[] fit() { final double[] guess = (new ParameterGuesser(getObservations())).guess(); return fit(guess); }
/** * Fits a Gaussian function to the observed points. * * @return the parameters of the Gaussian function that best fits the * observed points (in the same order as above). */ public double[] fit() { final double[] guess = (new ParameterGuesser(getObservations())).guess(); return fit(guess); }
final WeightedObservedPoint p1 = points[i]; final WeightedObservedPoint p2 = points[i + idxStep]; if (isBetween(y, p1.getY(), p2.getY())) { if (idxStep < 0) { return new WeightedObservedPoint[] { p2, p1 };
= getInterpolationPointsForY(points, startIdx, idxStep, y); final WeightedObservedPoint p1 = twoPoints[0]; final WeightedObservedPoint p2 = twoPoints[1];
/** * Constructs instance with the specified observed points. * * @param observations Observed points from which to guess the * parameters of the Gaussian. * @throws NullArgumentException if {@code observations} is * {@code null}. * @throws NumberIsTooSmallException if there are less than 3 * observations. */ public ParameterGuesser(WeightedObservedPoint[] observations) { if (observations == null) { throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } if (observations.length < 3) { throw new NumberIsTooSmallException(observations.length, 3, true); } final WeightedObservedPoint[] sorted = sortObservations(observations); final double[] params = basicGuess(sorted); norm = params[0]; mean = params[1]; sigma = params[2]; }
/** * Guesses the parameters based on the specified observed points. * * @param points Observed points, sorted. * @return the guessed parameters (normalization factor, mean and * sigma). */ private double[] basicGuess(WeightedObservedPoint[] points) { final int maxYIdx = findMaxY(points); final double n = points[maxYIdx].getY(); final double m = points[maxYIdx].getX(); double fwhmApprox; try { final double halfY = n + ((m - n) / 2); final double fwhmX1 = interpolateXAtY(points, maxYIdx, -1, halfY); final double fwhmX2 = interpolateXAtY(points, maxYIdx, 1, halfY); fwhmApprox = fwhmX2 - fwhmX1; } catch (OutOfRangeException e) { // TODO: Exceptions should not be used for flow control. fwhmApprox = points[points.length - 1].getX() - points[0].getX(); } final double s = fwhmApprox / (2 * FastMath.sqrt(2 * FastMath.log(2))); return new double[] { n, m, s }; }
/** * Fits a Gaussian function to the observed points. * * @return the parameters of the Gaussian function that best fits the * observed points (in the same order as above). */ public double[] fit() { final double[] guess = (new ParameterGuesser(getObservations())).guess(); return fit(guess); }