Package cnuphys.splot.fit
Class FitUtilities
java.lang.Object
cnuphys.splot.fit.FitUtilities
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
fitAltPoly
(Fit fit) An alternate polynomial fit with errorsstatic void
Erf fit with errorsstatic void
Ercf fit with errorsstatic void
fitGaussians
(Fit fit) A Gaussian fit with errorsstatic void
fitGaussPlusPoly
(Fit fit) A Gaussian and polynomial fit with errorsstatic void
A Polynomial fit with errorsstatic void
fitStraightLine
(Fit fit) A Straight line fit with errors in yprotected static void
fixNullSig
(Fit fit) This deals with missing or bad error data.static double[]
getWeightedXAverage
(double[] x, double[] y) Get a weighted x meanstatic Integer[]
indexSort
(double[] val) Index sort of an arraystatic boolean
isSorted
(double[] val) Checks whether an array is sorted in ascending orderstatic double[]
muSigma
(double[] v) Another stats convenience methodstatic void
parallelSort
(double[]... da) Sort a set of parallel arrays.static double
standardDev
(double[] x) Compute the "standard" standard deviation (divide variance by N) using an accurate one-pass method.static double[]
stats
(double[] v) Get the mean, min and max of an array.
-
Constructor Details
-
FitUtilities
public FitUtilities()
-
-
Method Details
-
fitStraightLine
A Straight line fit with errors in y- Parameters:
_x
- the x data_y
- the y datasigma
- the errors on the y data
-
fitPoly
A Polynomial fit with errors- Parameters:
fit
- the fit data
-
fitAltPoly
An alternate polynomial fit with errors- Parameters:
fit
- the fit data
-
fitErf
Erf fit with errors- Parameters:
fit
- the fit data- Throws:
IllegalArgumentException
-
fitErfc
Ercf fit with errors- Parameters:
fit
- the fit data- Throws:
IllegalArgumentException
-
fitGaussians
A Gaussian fit with errors- Parameters:
fit
- the fit data- Throws:
IllegalArgumentException
-
fitGaussPlusPoly
A Gaussian and polynomial fit with errors- Parameters:
fit
- the fit data- Throws:
IllegalArgumentException
-
isSorted
public static boolean isSorted(double[] val) Checks whether an array is sorted in ascending order- Parameters:
val
- the array to check- Returns:
true
if the array is sorted
-
indexSort
Index sort of an array- Parameters:
val
- the array to sort- Returns:
- the sorted index array
-
parallelSort
public static void parallelSort(double[]... da) Sort a set of parallel arrays. The first one is the one that will end up sorted. Does nothing if the first array is sorted.- Parameters:
da
- a set of arrays
-
standardDev
public static double standardDev(double[] x) Compute the "standard" standard deviation (divide variance by N) using an accurate one-pass method.- Parameters:
x
- the data- Returns:
- the standard deviation
-
stats
public static double[] stats(double[] v) Get the mean, min and max of an array.- Parameters:
v
- the array- Returns:
- a double[3] containing, in order, the mean, min and max
-
muSigma
public static double[] muSigma(double[] v) Another stats convenience method- Parameters:
v
- the input array- Returns:
- a double[4] containing, in order, the mean, min, max, and standard deviation
-
getWeightedXAverage
public static double[] getWeightedXAverage(double[] x, double[] y) Get a weighted x mean- Parameters:
x
- the x valuesy
- the x values- Returns:
- the weighted x mean
-
fixNullSig
This deals with missing or bad error data. If the sigma array is null, it creates a new array and assigns a value of 1 to each error. It does the same if the sigma array has all zero values. The real troubling case is when sigma has some zero values. This will cause many fits to fail. So in that case it repleaces all zero values with the mean value. At that point the fit should be considered suspect.- Parameters:
sig
- the sigma array, which might be nulln
- the length of the array, if it has to be created
-