public class LinearProfileStats extends ContextCommand implements ShollStats
org.apache.commons.math3
package.Modifier and Type | Field and Description |
---|---|
protected double[] |
fCounts |
protected double[] |
inputCounts |
protected double[] |
inputRadii |
protected Logger |
logger |
protected int |
nPoints |
protected ShollPlot |
plot |
protected Profile |
profile |
protected static double |
UNASSIGNED_VALUE |
ANNULUS, AREA, GUESS_SLOG, LOG_LOG, PERIMETER, S_SHELL, SEMI_LOG, SURFACE, VOLUME
Constructor and Description |
---|
LinearProfileStats(Profile profile)
Instantiates the Linear Profile Statistics.
|
Modifier and Type | Method and Description |
---|---|
protected void |
debug(Object msg) |
int |
findBestFit(int fromDegree,
int toDegree,
double minRSquared,
double pvalue)
Computes the 'best fit' polynomial between a specified range of degrees for
this profile and keeps the fit in memory.
|
int |
findBestFit(int fromDegree,
int toDegree,
PrefService prefService)
Runs
findBestFit(int, int, double, double) using the preferences
specified by the user using the ShollAnalysisPrefsCmd command. |
void |
fitPolynomial(int degree)
Fits sampled data to a polynomial function and keeps the fit in memory.
|
protected double |
getAdjustedRSquaredOfFit(int p) |
ShollPoint |
getCenteredMaximum() |
ShollPoint |
getCenteredMaximum(boolean fittedData)
Returns the average coordinates of all maxima.
|
ShollPoint |
getCentroid() |
ShollPoint |
getCentroid(boolean fittedData)
Retrieves the centroid from all pairs of data (radius, inters.
|
double |
getEnclosingRadius(boolean fittedData,
double cutoff)
Returns the largest radius associated with at least the number of
specified counts.
|
double |
getEnclosingRadius(double cutoff) |
double[] |
getFitYvalues()
Returns the ordinates of the sampled linear plot of fitted data.
|
double[] |
getFitYvalues(boolean asCumulativeFrequencies) |
protected int |
getIndex(double[] array,
double value) |
int |
getIndexOfInters(boolean fittedData,
double inters)
Returns the closest index of the intersections data associated with the
specified value
|
int |
getIndexOfRadius(double radius)
Returns the closest index of sampled distances associated with the
specified value
|
int |
getIntersectingRadii() |
int |
getIntersectingRadii(boolean fittedData)
Returns the number of intersecting radii.
|
double |
getKStestOfFit()
Returns the two-sample Kolmogorov-Smirnov (K-S) test between the polynomial
fit and sampled intersections as a measurement of goodness of fit.
|
double |
getKurtosis() |
double |
getKurtosis(boolean fittedData)
Calculates the kurtosis.
|
double |
getMax() |
double |
getMax(boolean fittedData)
Returns the largest value of intersection count.
|
int |
getMaxEvaluations()
Gets the function evaluation limit for solvers
|
ArrayList<ShollPoint> |
getMaxima() |
ArrayList<ShollPoint> |
getMaxima(boolean fittedData)
Returns a list of all the points in the linear Sholl profile associated
with the highest intersections count
|
double |
getMean() |
double |
getMean(boolean fittedData)
Calculates the arithmetic mean.
|
double |
getMeanValueOfPolynomialFit(double lowerBound,
double upperBound)
Calculates the mean value of polynomial fit using the default integration
method (Simpson's).
|
double |
getMeanValueOfPolynomialFit(String integrator,
double lowerBound,
double upperBound)
Gets the mean value of polynomial fit.
|
double |
getMedian() |
double |
getMedian(boolean fittedData)
Calculates the median.
|
double |
getMin() |
double |
getMin(boolean fittedData)
Returns the lowest value of intersection count.
|
int |
getN() |
ShollPlot |
getPlot(boolean cumulativeFrequencies) |
ShollPoint |
getPolygonCentroid() |
ShollPoint |
getPolygonCentroid(boolean fittedData)
Calculates the centroid from all (radius, inters.
|
PolynomialFunction |
getPolynomial()
Gets the polynomial function.
|
String |
getPolynomialAsString()
Returns a string describing the polynomial fit
|
int |
getPolynomialDegree()
Returns the degree of the polynomial.
|
Set<ShollPoint> |
getPolynomialMaxima(double lowerBound,
double upperBound,
double initialGuess)
Calculates local maxima (critical points at which the derivative of the
polynomial is zero) within the specified interval.
|
double |
getPrimaryBranches() |
double |
getPrimaryBranches(boolean fittedData)
Returns intersection counts at the smallest radius (inferred no.
|
Profile |
getProfile() |
double |
getRamificationIndex() |
double |
getRamificationIndex(boolean fittedData)
Calculates the ramification index (the highest intersections count divided by
the n.
|
double |
getRSquaredOfFit() |
double |
getRSquaredOfFit(boolean adjusted)
Returns RSquared of the polynomial fit.
|
double |
getSkewness() |
double |
getSkewness(boolean fittedData)
Calculates the skewness.
|
double |
getSum() |
double |
getSum(boolean fittedData)
Calculates the sum.
|
double |
getSumSq() |
double |
getSumSq(boolean fittedData)
Calculates the sum of the squared values.
|
double |
getVariance() |
double |
getVariance(boolean fittedData)
Calculates the variance.
|
double[] |
getXvalues()
Returns the abscissae of the sampled linear plot for sampled data.
|
double[] |
getYvalues()
Returns the ordinates of the sampled linear plot of sampled data.
|
double[] |
getYvalues(boolean asCumulativeFrequencies) |
boolean |
isPrimaryBranchesInferred()
Checks whether the number of primary branches is being inferred from the
number of intersections at starting radius or if it has been set explicitly.
|
void |
run() |
void |
setContext(Context context) |
void |
setDebug(boolean debug) |
void |
setLogger(Logger logger) |
void |
setLogger(Logger logger,
boolean debug) |
void |
setMaxEvaluations(int maxEval)
Sets the the function evaluation limit for solvers.
|
void |
setPrimaryBranches(int nBranches)
Sets the number of primary branches associated with this profile, used to
calculate ramification indices.
|
protected void |
validateFit() |
boolean |
validFit()
Checks if valid fitted data exists.
|
cancel, getCancelReason, isCanceled
context, getContext
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getFitYvalues, getN, getProfile, getYvalues
protected static final double UNASSIGNED_VALUE
protected final double[] inputRadii
protected final double[] inputCounts
protected final Profile profile
protected int nPoints
protected double[] fCounts
protected ShollPlot plot
protected Logger logger
public LinearProfileStats(Profile profile)
profile
- the profile to be analyzedpublic ShollPoint getCentroid(boolean fittedData)
fittedData
- If true
, calculation is performed on polynomial fitted
values, otherwise from sampled datapublic ShollPoint getCentroid()
getCentroid(false)
public ShollPoint getPolygonCentroid(boolean fittedData)
fittedData
- If true
, calculation is performed on polynomial fitted
values, otherwise from sampled datapublic ShollPoint getPolygonCentroid()
getPolygonCentroid(false)
public double getEnclosingRadius(boolean fittedData, double cutoff)
fittedData
- If true
, calculation is performed on polynomial fitted
values, otherwise from sampled datacutoff
- the cutoff for intersection countspublic double getEnclosingRadius(double cutoff)
cutoff
- the cutoff for intersection countsgetEnclosingRadius(false, cutoff)
public int getIntersectingRadii(boolean fittedData)
fittedData
- If true
, calculation is performed on polynomial fitted
values, otherwise from sampled datapublic int getIntersectingRadii()
getIntersectingRadii(false)
public double getKurtosis(boolean fittedData)
fittedData
- If true
, calculation is performed on polynomial fitted
values, otherwise from sampled datapublic double getKurtosis()
getKurtosis(false)
public ArrayList<ShollPoint> getMaxima(boolean fittedData)
fittedData
- If true
, calculation is performed on polynomial fitted
values, otherwise from sampled datapublic ArrayList<ShollPoint> getMaxima()
getMaxima(false)
public ShollPoint getCenteredMaximum(boolean fittedData)
fittedData
- If true
, calculation is performed on polynomial fitted
values, otherwise from sampled datapublic ShollPoint getCenteredMaximum()
getCenteredMaximum(false)
public double getMean(boolean fittedData)
fittedData
- If true
, calculation is performed on polynomial fitted
values, otherwise from sampled datapublic double getMean()
getMean(false)
public int getIndexOfRadius(double radius)
radius
- the query valuepublic int getIndexOfInters(boolean fittedData, double inters)
fittedData
- If true
, calculation is performed on polynomial fitted
values, otherwise from sampled datainters
- the query valuepublic void fitPolynomial(int degree)
degree
- Degree of the polynomial to be fittedNullArgumentException
- if the computed polynomial coefficients were
nullNoDataException
- if the computed polynomial coefficients were
emptyConvergenceException
- if optimization failedpublic int findBestFit(int fromDegree, int toDegree, double minRSquared, double pvalue)
Note that in some edge cases specified constrains may be bypassed: E.g., If the profile is constant, a constant function is fitted. If the profile contains only two data points, a linear function is fitted
fromDegree
- the lowest degree to be considered. Will be set to
(getN()
-1) if higher than (getN()
-1).toDegree
- the highest degree to be considered. Will be set to
(getN()
-1) if higher than (getN()
-1)minRSquared
- the lowest value for adjusted RSquared. Only fits
associated with an equal or higher value will be
consideredpvalue
- the two-sample Kolmogorov-Smirnov (K-S) test statistic
(p-value) used to discard 'unsuitable fits'. It is used to
evaluate the null hypothesis that profiled data and
polynomial fit represent samples drawn from the same
probability distribution. Set it to -1 to skip K-S
testing.public int findBestFit(int fromDegree, int toDegree, PrefService prefService)
findBestFit(int, int, double, double)
using the preferences
specified by the user using the ShollAnalysisPrefsCmd
command.fromDegree
- the lowest degree to be considered. See
findBestFit(int, int, double, double)
toDegree
- the highest degree to be considered. See
findBestFit(int, int, double, double)
prefService
- the PrefService
used to read preferencesfindBestFit(int, int, double, double)
public double[] getXvalues()
getXvalues
in interface ShollStats
public double[] getYvalues()
getYvalues
in interface ShollStats
public double[] getFitYvalues()
getFitYvalues
in interface ShollStats
NullPointerException
- if fitPolynomial(int)
has not been calledpublic PolynomialFunction getPolynomial()
NullPointerException
- if fitPolynomial(int)
has not been calledpublic int getPolynomialDegree()
NullPointerException
- if fitPolynomial(int)
has not been calledpublic String getPolynomialAsString()
NullPointerException
- if fitPolynomial(int)
has not been calledpublic Set<ShollPoint> getPolynomialMaxima(double lowerBound, double upperBound, double initialGuess)
lowerBound
- the lower bound of the intervalupperBound
- the upper bound of the intervalinitialGuess
- initial guess for a solution (solver's starting point)TooManyEvaluationsException
- if the maximum number of evaluations is exceeded when solving
for one of the rootsNullPointerException
- if fitPolynomial(int)
has not been calledpublic int getMaxEvaluations()
public void setMaxEvaluations(int maxEval)
maxEval
- the new maximum of evaluationspublic double getRSquaredOfFit(boolean adjusted)
adjusted
- if true
returns adjusted RSquared, i.e., adjusted for
the number of terms of the polynomial modelNullPointerException
- if fitPolynomial(int)
has not been calledpublic double getMeanValueOfPolynomialFit(String integrator, double lowerBound, double upperBound)
integrator
- the integration method to retrieve the integral of the
polynomial fit. Either "Simpson" (the default), or "Romberg"
(case insensitive)lowerBound
- the lower bound (smallest radius) for the intervalupperBound
- the upper bound (largest radius) for the intervalMathIllegalArgumentException
- if bounds do not satisfy the integrator requirementsTooManyEvaluationsException
- if the maximum number of function evaluations is exceeded by
the integratorMaxCountExceededException
- if the maximum iteration count is exceeded by the integratorNullPointerException
- if fitPolynomial(int)
has not been calledpublic double getMeanValueOfPolynomialFit(double lowerBound, double upperBound)
lowerBound
- the lower bound (smallest radius) for the intervalupperBound
- the upper bound (largest radius) for the intervalDouble.NaN
if
calculation failed.NullPointerException
- if fitPolynomial(int)
has not been calledpublic double getMedian(boolean fittedData)
fittedData
- If true
, calculation is performed on polynomial fitted
values, otherwise from sampled datapublic double getMedian()
getMedian(false)
public void setPrimaryBranches(int nBranches)
nBranches
- the new primary branchesgetPrimaryBranches(boolean)
,
getRamificationIndex(boolean)
public boolean isPrimaryBranchesInferred()
setPrimaryBranches(int)
public double getPrimaryBranches(boolean fittedData)
setPrimaryBranches(int)
.fittedData
- If true
, and setPrimaryBranches(int)
has
not been called, calculation is performed on polynomial
fitted values, otherwise from sampled data. It is ignored
if the number of primary branches has been successfully
specified by calling setPrimaryBranches(int)
getRamificationIndex(boolean)
public double getPrimaryBranches()
getPrimaryBranches(false)
getRamificationIndex()
public double getRamificationIndex(boolean fittedData)
fittedData
- If true
, calculation is performed on polynomial
fitted values, otherwise from sampled datasetPrimaryBranches(int)
public double getRamificationIndex()
getRamificationIndex(false)
public double getMax(boolean fittedData)
fittedData
- If true
, calculation is performed on polynomial fitted
values, otherwise from sampled datapublic double getMax()
getMax(false)
public double getMin(boolean fittedData)
fittedData
- If true
, calculation is performed on polynomial fitted
values, otherwise from sampled datapublic double getMin()
getMin(false)
public double getSkewness(boolean fittedData)
fittedData
- If true
, calculation is performed on polynomial fitted
values, otherwise from sampled datapublic double getSkewness()
getSkewness(false)
public double getSum(boolean fittedData)
fittedData
- If true
, calculation is performed on polynomial fitted
values, otherwise from sampled datapublic double getSum()
getSum(false)
public double getSumSq(boolean fittedData)
fittedData
- If true
, calculation is performed on polynomial fitted
values, otherwise from sampled datapublic double getSumSq()
getSumSq(false)
public double getVariance(boolean fittedData)
fittedData
- If true
, calculation is performed on polynomial fitted
values, otherwise from sampled datapublic double getVariance()
getVariance(false)
public boolean validFit()
validFit
in interface ShollStats
true
if polynomial fitted data existspublic double getKStestOfFit()
NullPointerException
- if curve fitting has not been performedInsufficientDataException
- if sampled data contains fewer than two
data pointspublic double getRSquaredOfFit()
public ShollPlot getPlot(boolean cumulativeFrequencies)
protected double getAdjustedRSquaredOfFit(int p)
protected int getIndex(double[] array, double value)
protected void validateFit()
protected void debug(Object msg)
public void setLogger(Logger logger)
public void setLogger(Logger logger, boolean debug)
public void setDebug(boolean debug)
public void setContext(Context context)
setContext
in interface Contextual
public double[] getYvalues(boolean asCumulativeFrequencies)
getYvalues
in interface ShollStats
public int getN()
getN
in interface ShollStats
public double[] getFitYvalues(boolean asCumulativeFrequencies)
getFitYvalues
in interface ShollStats
public Profile getProfile()
getProfile
in interface ShollStats
Copyright © 2015–2021 Fiji. All rights reserved.