Class SemiVariance
- All Implemented Interfaces:
Serializable,UnivariateStatistic,MathArrays.Function
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] invalid input: '<' 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.
- Since:
- 2.1
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe direction of the semivariance - either upside or downside. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SemiVariance.DirectionThe DOWNSIDE Direction is used to specify that the observations below the cutoff point will be used to calculate SemiVariancestatic final SemiVariance.DirectionThe UPSIDE Direction is used to specify that the observations above the cutoff point will be used to calculate SemiVariance. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a SemiVariance with default (true)biasCorrectedproperty and default (Downside)varianceDirectionproperty.SemiVariance(boolean biasCorrected) Constructs a SemiVariance with the specifiedbiasCorrectedproperty and default (Downside)varianceDirectionproperty.SemiVariance(boolean corrected, SemiVariance.Direction direction) Constructs a SemiVariance with the specifiedisBiasCorrectedproperty and the specifiedDirectionproperty.SemiVariance(SemiVariance original) Copy constructor, creates a newSemiVarianceidentical to theoriginalSemiVariance(SemiVariance.Direction direction) Constructs a SemiVariance with the specifiedDirectionproperty and default (true)biasCorrectedproperty -
Method Summary
Modifier and TypeMethodDescriptioncopy()Returns a copy of the statistic with the same internal state.static voidcopy(SemiVariance source, SemiVariance dest) Copies source to dest.doubleevaluate(double[] values, double cutoff) Returns theSemiVarianceof the designated values against the cutoff, using instance properties variancDirection and biasCorrection.doubleevaluate(double[] values, double cutoff, SemiVariance.Direction direction) Returns theSemiVarianceof the designated values against the cutoff in the given direction, using the current value of the biasCorrection instance property.doubleevaluate(double[] values, double cutoff, SemiVariance.Direction direction, boolean corrected, int start, int length) Returns theSemiVarianceof the designated values against the cutoff in the given direction with the provided bias correction.doubleevaluate(double[] values, int start, int length) Returns theSemiVarianceof the designated values against the mean, using instance properties varianceDirection and biasCorrection.doubleevaluate(double[] values, SemiVariance.Direction direction) This method calculatesSemiVariancefor the entire array against the mean, using the current value of the biasCorrection instance property.Returns the varianceDirection property.booleanReturns true iff biasCorrected property is set to true.voidsetBiasCorrected(boolean biasCorrected) Sets the biasCorrected property.voidsetVarianceDirection(SemiVariance.Direction varianceDirection) Sets the variance direction
-
Field Details
-
UPSIDE_VARIANCE
The UPSIDE Direction is used to specify that the observations above the cutoff point will be used to calculate SemiVariance. -
DOWNSIDE_VARIANCE
The DOWNSIDE Direction is used to specify that the observations below the cutoff point will be used to calculate SemiVariance
-
-
Constructor Details
-
SemiVariance
public SemiVariance()Constructs a SemiVariance with default (true)biasCorrectedproperty and default (Downside)varianceDirectionproperty. -
SemiVariance
public SemiVariance(boolean biasCorrected) Constructs a SemiVariance with the specifiedbiasCorrectedproperty and default (Downside)varianceDirectionproperty.- Parameters:
biasCorrected- setting for bias correction - true means bias will be corrected and is equivalent to using the argumentless constructor
-
SemiVariance
Constructs a SemiVariance with the specifiedDirectionproperty and default (true)biasCorrectedproperty- Parameters:
direction- setting for the direction of the SemiVariance to calculate
-
SemiVariance
Constructs a SemiVariance with the specifiedisBiasCorrectedproperty and the specifiedDirectionproperty.- Parameters:
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 calculate
-
SemiVariance
Copy constructor, creates a newSemiVarianceidentical to theoriginal- Parameters:
original- theSemiVarianceinstance to copy- Throws:
NullArgumentException- if original is null
-
-
Method Details
-
copy
Returns a copy of the statistic with the same internal state.- Specified by:
copyin interfaceUnivariateStatistic- Specified by:
copyin classAbstractUnivariateStatistic- Returns:
- a copy of the statistic
-
copy
Copies source to dest.Neither source nor dest can be null.
- Parameters:
source- SemiVariance to copydest- SemiVariance to copy to- Throws:
NullArgumentException- if either source or dest is null
-
evaluate
Returns the
SemiVarianceof the designated values against the mean, using instance properties varianceDirection and biasCorrection.Returns
NaNif the array is empty and throwsIllegalArgumentExceptionif the array is null.- Specified by:
evaluatein interfaceMathArrays.Function- Specified by:
evaluatein interfaceUnivariateStatistic- Specified by:
evaluatein classAbstractUnivariateStatistic- Parameters:
values- the input arraystart- index of the first array element to includelength- the number of elements to include- Returns:
- the SemiVariance
- Throws:
MathIllegalArgumentException- if the parameters are not valid
-
evaluate
public double evaluate(double[] values, SemiVariance.Direction direction) throws MathIllegalArgumentException This method calculatesSemiVariancefor the entire array against the mean, using the current value of the biasCorrection instance property.- Parameters:
values- the input arraydirection- theSemiVariance.Directionof the semivariance- Returns:
- the SemiVariance
- Throws:
MathIllegalArgumentException- if values is null
-
evaluate
Returns the
SemiVarianceof the designated values against the cutoff, using instance properties variancDirection and biasCorrection.Returns
NaNif the array is empty and throwsMathIllegalArgumentExceptionif the array is null.- Parameters:
values- the input arraycutoff- the reference point- Returns:
- the SemiVariance
- Throws:
MathIllegalArgumentException- if values is null
-
evaluate
public double evaluate(double[] values, double cutoff, SemiVariance.Direction direction) throws MathIllegalArgumentException Returns the
SemiVarianceof the designated values against the cutoff in the given direction, using the current value of the biasCorrection instance property.Returns
NaNif the array is empty and throwsMathIllegalArgumentExceptionif the array is null.- Parameters:
values- the input arraycutoff- the reference pointdirection- theSemiVariance.Directionof the semivariance- Returns:
- the SemiVariance
- Throws:
MathIllegalArgumentException- if values is null
-
evaluate
public double evaluate(double[] values, double cutoff, SemiVariance.Direction direction, boolean corrected, int start, int length) throws MathIllegalArgumentException Returns the
SemiVarianceof the designated values against the cutoff in the given direction with the provided bias correction.Returns
NaNif the array is empty and throwsIllegalArgumentExceptionif the array is null.- Parameters:
values- the input arraycutoff- the reference pointdirection- theSemiVariance.Directionof the semivariancecorrected- the BiasCorrection flagstart- index of the first array element to includelength- the number of elements to include- Returns:
- the SemiVariance
- Throws:
MathIllegalArgumentException- if the parameters are not valid
-
isBiasCorrected
public boolean isBiasCorrected()Returns true iff biasCorrected property is set to true.- Returns:
- the value of biasCorrected.
-
setBiasCorrected
public void setBiasCorrected(boolean biasCorrected) Sets the biasCorrected property.- Parameters:
biasCorrected- new biasCorrected property value
-
getVarianceDirection
Returns the varianceDirection property.- Returns:
- the varianceDirection
-
setVarianceDirection
Sets the variance direction- Parameters:
varianceDirection- the direction of the semivariance
-