Class 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.
  • Field Details

    • weightedMean

      protected double weightedMean
  • Constructor Details

    • Weighted_MeanArrayFunction

      public Weighted_MeanArrayFunction(@NonNull @NonNull WeightedIntArraySource source)
      Create a mean function on an integer array source.
      Parameters:
      source - The data source.
    • Weighted_MeanArrayFunction

      public Weighted_MeanArrayFunction(@NonNull @NonNull WeightedLongArraySource source)
      Create a mean function on a long array source.
      Parameters:
      source - The data source.
    • Weighted_MeanArrayFunction

      public Weighted_MeanArrayFunction(@NonNull @NonNull WeightedDoubleArraySource source)
      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 class AbstractWeightedArrayFunction
      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 class AbstractWeightedArrayFunction
      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 class AbstractWeightedArrayFunction
      Parameters:
      data - A source array of values.
      weights - An array of weights.
    • getDoubleValue

      public double getDoubleValue(@NonNull @NonNull Enum<?> variableID)
      Returns the double value corresponding to the given variableID
      Specified by:
      getDoubleValue in interface DoubleSource
      Parameters:
      variableID - A unique identifier for a variable.
      Returns:
      The current double value of the required variable.