public class SemiVariance extends AbstractUnivariateStatistic implements java.io.Serializable
Computes the semivariance of a set of values with respect to a given cutoff value.
We define the downside semivariance of a set of values x
against the cutoff value cutoff
to be
Σ (x[i] - target)2 / df
where the sum is taken over all i
such that x[i] < cutoff
and df
is the length of x
(non-bias-corrected) or
one less than this number (bias corrected). The upside semivariance
is defined similarly, with the sum taken over values of x
that
exceed the cutoff value.
The cutoff value defaults to the mean, bias correction defaults to true
and the "variance direction" (upside or downside) defaults to downside. The variance direction
and bias correction may be set using property setters or their values can provided as
parameters to evaluate(double[], double, Direction, boolean, int, int)
.
If the input array is null, evaluate
methods throw
IllegalArgumentException.
If the array has length 1, 0
is returned, regardless of the value of the cutoff.
Note that this class is not intended to be threadsafe. If multiple threads access an instance of this class concurrently, and one or more of these threads invoke property setters, external synchronization must be provided to ensure correct results.
Modifier and Type | Class and Description |
---|---|
static class |
SemiVariance.Direction
The direction of the semivariance - either upside or downside.
|
Modifier and Type | Field and Description |
---|---|
static SemiVariance.Direction |
DOWNSIDE_VARIANCE
The DOWNSIDE Direction is used to specify that the observations below
the cutoff point will be used to calculate SemiVariance
|
static SemiVariance.Direction |
UPSIDE_VARIANCE
The UPSIDE Direction is used to specify that the observations above the
cutoff point will be used to calculate SemiVariance.
|
Constructor and Description |
---|
SemiVariance()
Constructs a SemiVariance with default (true)
biasCorrected
property and default (Downside) varianceDirection property. |
SemiVariance(boolean biasCorrected)
Constructs a SemiVariance with the specified
biasCorrected
property and default (Downside) varianceDirection property. |
SemiVariance(boolean corrected,
SemiVariance.Direction direction)
Constructs a SemiVariance with the specified
isBiasCorrected
property and the specified Direction property. |
SemiVariance(SemiVariance.Direction direction)
Constructs a SemiVariance with the specified
Direction property
and default (true) biasCorrected property |
SemiVariance(SemiVariance original)
Copy constructor, creates a new
SemiVariance identical
to the original |
Modifier and Type | Method and Description |
---|---|
SemiVariance |
copy()
Returns a copy of the statistic with the same internal state.
|
static void |
copy(SemiVariance source,
SemiVariance dest)
Copies source to dest.
|
double |
evaluate(double[] values)
This method calculates
SemiVariance for the entire array against the mean, using
instance properties varianceDirection and biasCorrection. |
double |
evaluate(double[] values,
double cutoff)
Returns the
SemiVariance of the designated values against the cutoff, using
instance properties variancDirection and biasCorrection. |
double |
evaluate(double[] values,
double cutoff,
SemiVariance.Direction direction)
Returns the
SemiVariance of the designated values against the cutoff in the
given direction, using the current value of the biasCorrection instance property. |
double |
evaluate(double[] values,
double cutoff,
SemiVariance.Direction direction,
boolean corrected,
int start,
int length)
Returns the
SemiVariance of the designated values against the cutoff
in the given direction with the provided bias correction. |
double |
evaluate(double[] values,
int start,
int length)
Returns the
SemiVariance of the designated values against the mean, using
instance properties varianceDirection and biasCorrection. |
double |
evaluate(double[] values,
SemiVariance.Direction direction)
This method calculates
SemiVariance for the entire array against the mean, using
the current value of the biasCorrection instance property. |
SemiVariance.Direction |
getVarianceDirection()
Returns the varianceDirection property.
|
boolean |
isBiasCorrected()
Returns true iff biasCorrected property is set to true.
|
void |
setBiasCorrected(boolean biasCorrected)
Sets the biasCorrected property.
|
void |
setVarianceDirection(SemiVariance.Direction varianceDirection)
Sets the variance direction
|
evaluate, getData, setData, setData
public static final SemiVariance.Direction UPSIDE_VARIANCE
public static final SemiVariance.Direction DOWNSIDE_VARIANCE
public SemiVariance()
biasCorrected
property and default (Downside) varianceDirection
property.public SemiVariance(boolean biasCorrected)
biasCorrected
property and default (Downside) varianceDirection
property.biasCorrected
- setting for bias correction - true means
bias will be corrected and is equivalent to using the argumentless
constructorpublic SemiVariance(SemiVariance.Direction direction)
Direction
property
and default (true) biasCorrected
propertydirection
- setting for the direction of the SemiVariance
to calculatepublic SemiVariance(boolean corrected, SemiVariance.Direction direction)
isBiasCorrected
property and the specified Direction
property.corrected
- setting for bias correction - true means
bias will be corrected and is equivalent to using the argumentless
constructordirection
- setting for the direction of the SemiVariance
to calculatepublic SemiVariance(SemiVariance original)
SemiVariance
identical
to the original
original
- the SemiVariance
instance to copypublic SemiVariance copy()
copy
in interface UnivariateStatistic
copy
in class AbstractUnivariateStatistic
public static void copy(SemiVariance source, SemiVariance dest)
Neither source nor dest can be null.
source
- SemiVariance to copydest
- SemiVariance to copy tojava.lang.NullPointerException
- if either source or dest is nullpublic double evaluate(double[] values)
SemiVariance
for the entire array against the mean, using
instance properties varianceDirection and biasCorrection.evaluate
in interface UnivariateStatistic
evaluate
in class AbstractUnivariateStatistic
values
- the input arrayjava.lang.IllegalArgumentException
- if values is nullpublic double evaluate(double[] values, int start, int length)
Returns the SemiVariance
of the designated values against the mean, using
instance properties varianceDirection and biasCorrection.
Returns NaN
if the array is empty and throws
IllegalArgumentException
if the array is null.
evaluate
in interface UnivariateStatistic
evaluate
in class AbstractUnivariateStatistic
values
- the input arraystart
- index of the first array element to includelength
- the number of elements to includejava.lang.IllegalArgumentException
- if the parameters are not validpublic double evaluate(double[] values, SemiVariance.Direction direction)
SemiVariance
for the entire array against the mean, using
the current value of the biasCorrection instance property.values
- the input arraydirection
- the SemiVariance.Direction
of the semivariancejava.lang.IllegalArgumentException
- if values is nullpublic double evaluate(double[] values, double cutoff)
Returns the SemiVariance
of the designated values against the cutoff, using
instance properties variancDirection and biasCorrection.
Returns NaN
if the array is empty and throws
IllegalArgumentException
if the array is null.
values
- the input arraycutoff
- the reference pointjava.lang.IllegalArgumentException
- if values is nullpublic double evaluate(double[] values, double cutoff, SemiVariance.Direction direction)
Returns the SemiVariance
of the designated values against the cutoff in the
given direction, using the current value of the biasCorrection instance property.
Returns NaN
if the array is empty and throws
IllegalArgumentException
if the array is null.
values
- the input arraycutoff
- the reference pointdirection
- the SemiVariance.Direction
of the semivariancejava.lang.IllegalArgumentException
- if values is nullpublic double evaluate(double[] values, double cutoff, SemiVariance.Direction direction, boolean corrected, int start, int length)
Returns the SemiVariance
of the designated values against the cutoff
in the given direction with the provided bias correction.
Returns NaN
if the array is empty and throws
IllegalArgumentException
if the array is null.
values
- the input arraycutoff
- the reference pointdirection
- the SemiVariance.Direction
of the semivariancecorrected
- the BiasCorrection flagstart
- index of the first array element to includelength
- the number of elements to includejava.lang.IllegalArgumentException
- if the parameters are not validpublic boolean isBiasCorrected()
public void setBiasCorrected(boolean biasCorrected)
biasCorrected
- new biasCorrected property valuepublic SemiVariance.Direction getVarianceDirection()
public void setVarianceDirection(SemiVariance.Direction varianceDirection)
varianceDirection
- the direction of the semivarianceCopyright © 2010 - 2020 Adobe. All Rights Reserved