Class Weighted_MeanArrayFunction
java.lang.Object
microsim.statistics.functions.AbstractFunction
microsim.statistics.weighted.functions.AbstractWeightedArrayFunction
microsim.statistics.weighted.functions.Weighted_MeanArrayFunction
- All Implemented Interfaces:
EventListener
,DoubleSource
,UpdatableSource
public class Weighted_MeanArrayFunction
extends AbstractWeightedArrayFunction
implements DoubleSource
This class computes the (weighted) average (mean) value of an array of values taken from a data source,
weighted by corresponding weights:
weighted mean = sum (values * weights) / sum (weights)
Note that the array of weights must have the same length as the array of values, otherwise an exception will be
thrown. The mean function return always double values, so it implements only the
DoubleSource
interface.-
Nested Class Summary
Nested classes/interfaces inherited from interface microsim.statistics.DoubleSource
DoubleSource.Variables
-
Field Summary
Fields inherited from class microsim.statistics.weighted.functions.AbstractWeightedArrayFunction
dblSource, intSource, lngSource, type, TYPE_DBL, TYPE_INT, TYPE_LNG
Fields inherited from class microsim.statistics.functions.AbstractFunction
timeChecker
-
Constructor Summary
ConstructorDescriptionWeighted_MeanArrayFunction
(@NonNull WeightedDoubleArraySource source) Create a mean function on a (weighted) double array source.Weighted_MeanArrayFunction
(@NonNull WeightedIntArraySource source) Create a mean function on an integer array source.Weighted_MeanArrayFunction
(@NonNull WeightedLongArraySource source) Create a mean function on a long array source. -
Method Summary
Modifier and TypeMethodDescriptionvoid
apply
(double @NonNull [] data, double @NonNull [] weights) Apply the function to the given array of double values.void
apply
(int @NonNull [] data, double @NonNull [] weights) Apply the function to the given array of integer values.void
apply
(long @NonNull [] data, double @NonNull [] weights) Apply the function to the given array of long values.double
getDoubleValue
(@NonNull Enum<?> variableID) Returns the double value corresponding to the given variableIDMethods inherited from class microsim.statistics.weighted.functions.AbstractWeightedArrayFunction
applyFunction
Methods inherited from class microsim.statistics.functions.AbstractFunction
isCheckingTime, onEvent, setCheckingTime, updateSource
-
Field Details
-
weightedMean
protected double weightedMean
-
-
Constructor Details
-
Weighted_MeanArrayFunction
Create a mean function on an integer array source.- Parameters:
source
- The data source.
-
Weighted_MeanArrayFunction
Create a mean function on a long array source.- Parameters:
source
- The data source.
-
Weighted_MeanArrayFunction
Create a mean function on a (weighted) double array source.- Parameters:
source
- The weighted data source.
-
-
Method Details
-
apply
public void apply(double @NonNull [] data, double @NonNull [] weights) Apply the function to the given array of double values.- Overrides:
apply
in classAbstractWeightedArrayFunction
- Parameters:
data
- A source array of values.weights
- An array of weights.
-
apply
public void apply(int @NonNull [] data, double @NonNull [] weights) Apply the function to the given array of integer values.- Overrides:
apply
in classAbstractWeightedArrayFunction
- Parameters:
data
- A source array of values.weights
- An array of weights.
-
apply
public void apply(long @NonNull [] data, double @NonNull [] weights) Apply the function to the given array of long values.- Overrides:
apply
in classAbstractWeightedArrayFunction
- Parameters:
data
- A source array of values.weights
- An array of weights.
-
getDoubleValue
Returns the double value corresponding to the given variableID- Specified by:
getDoubleValue
in interfaceDoubleSource
- Parameters:
variableID
- A unique identifier for a variable.- Returns:
- The current double value of the required variable.
-