# DistributionAggregateFunction (ARX Developer Documentation)

org.deidentifier.arx.framework.check.distribution

## Class DistributionAggregateFunction

- java.lang.Object
- - org.deidentifier.arx.framework.check.distribution.DistributionAggregateFunction

- All Implemented Interfaces:
    java.io.Serializable
  Direct Known Subclasses:
    DistributionAggregateFunction.DistributionAggregateFunctionArithmeticMean, DistributionAggregateFunction.DistributionAggregateFunctionGeneralization, DistributionAggregateFunction.DistributionAggregateFunctionGeometricMean, DistributionAggregateFunction.DistributionAggregateFunctionInterval, DistributionAggregateFunction.DistributionAggregateFunctionMedian, DistributionAggregateFunction.DistributionAggregateFunctionMode

      public abstract class DistributionAggregateFunction
      extends java.lang.Object
      implements java.io.Serializable

  This abstract class represents a function that aggregates values from a frequency distribution
  See Also:
    Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `DistributionAggregateFunction.DistributionAggregateFunctionArithmeticMean` This class calculates the arithmetic mean for a given distribution.
    `static class` | `DistributionAggregateFunction.DistributionAggregateFunctionGeneralization` This class generalizes the given distribution.
    `static class` | `DistributionAggregateFunction.DistributionAggregateFunctionGeometricMean` This class calculates the geometric mean for a given distribution.
    `static class` | `DistributionAggregateFunction.DistributionAggregateFunctionInterval` This class calculates the mode for a given distribution.
    `static class` | `DistributionAggregateFunction.DistributionAggregateFunctionMedian` This class calculates the median for a given distribution.
    `static class` | `DistributionAggregateFunction.DistributionAggregateFunctionMode` This class calculates the mode for a given distribution.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected java.lang.String[]` | `dictionary` Dictionary
    `protected int[][]` | `hierarchy` Hierarchy
    `protected boolean` | `ignoreMissingData` Whether or not null values should be ignored
    `protected DataType<?>` | `type` Type

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DistributionAggregateFunction(boolean ignoreMissingData, boolean typePreserving)` Instantiates a new function.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected <T> void` | `addAll(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics statistics, Distribution distribution, DataType.DataTypeWithRatioScale<T> type, double offset)` Adds all values from the distribution to the given descriptive statistics object
    `abstract <T> java.lang.String` | `aggregate(Distribution distribution)` This function returns an aggregate value.
    `abstract DistributionAggregateFunction` | `clone()` Clones this function
    `abstract <T> double` | `getError(Distribution distribution)` Returns the normalized error induced by aggregation.
    `<T> double` | `getInformationLoss(Distribution distribution)` This will return the normalized number of aggregated values in range [1/#distinct-values, 1].
    `protected <T> double[]` | `getMinMax(java.lang.String[] dictionary, DataType.DataTypeWithRatioScale<T> type)` Returns the minimum and maximum value
    `protected double` | `getNMSE(double min, double max, double[] values, double aggregate)` Calculates the mean square error after normalizing everything into [0,1]
    `void` | `initialize(java.lang.String[] dictionary, DataType<?> type, int[][] hierarchy)` Initializes the function
    `boolean` | `isTypePreserving()` Returns whether this is a type-preserving function

    - ### Methods inherited from class java.lang.Object

      `equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### ignoreMissingData

          protected boolean ignoreMissingData

      Whether or not null values should be ignored

    - #### dictionary

          protected transient java.lang.String[] dictionary

      Dictionary

    - #### type

          protected transient DataType<?> type

      Type

    - #### hierarchy

          protected transient int[][] hierarchy

      Hierarchy

  - ### Constructor Detail

    - #### DistributionAggregateFunction

          public DistributionAggregateFunction(boolean ignoreMissingData,
                                       boolean typePreserving)

      Instantiates a new function.
      Parameters:
        `ignoreMissingData` -
        `typePreserving` -

  - ### Method Detail

    - #### aggregate

          public abstract <T> java.lang.String aggregate(Distribution distribution)

      This function returns an aggregate value.
      Parameters:
        `distribution` -
        `dictionary` -
        `type` -
      Returns:
        the string

    - #### clone

          public abstract DistributionAggregateFunction clone()

      Clones this function
      Overrides:
        `clone` in class `java.lang.Object`

    - #### getError

          public abstract <T> double getError(Distribution distribution)

      Returns the normalized error induced by aggregation. In most cases this will be the mean squared error normalized into [0,1]. In case of generalization, it will return the normalized generalization level (also called generalization intensity). In case of intervals, it will return the normalized number of aggregated values.
      Parameters:
        `distribution` -
      Returns:

    - #### getInformationLoss

          public <T> double getInformationLoss(Distribution distribution)

      This will return the normalized number of aggregated values in range [1/#distinct-values, 1].
      Parameters:
        `distribution` -
      Returns:

    - #### initialize

          public void initialize(java.lang.String[] dictionary,
                        DataType<?> type,
                        int[][] hierarchy)

      Initializes the function
      Parameters:
        `dictionary` -
        `type` -
        `hierarchy` -

    - #### isTypePreserving

          public boolean isTypePreserving()

      Returns whether this is a type-preserving function
      Returns:

    - #### addAll

          protected <T> void addAll(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics statistics,
                        Distribution distribution,
                        DataType.DataTypeWithRatioScale<T> type,
                        double offset)

      Adds all values from the distribution to the given descriptive statistics object
      Parameters:
        `statistics` -
        `distribution` -
        `type` -
        `offset` - will be added to values

    - #### getMinMax

          protected <T> double[] getMinMax(java.lang.String[] dictionary,
                               DataType.DataTypeWithRatioScale<T> type)

      Returns the minimum and maximum value
      Parameters:
        `dictionary` -
        `type` -
      Returns:

    - #### getNMSE

          protected double getNMSE(double min,
                       double max,
                       double[] values,
                       double aggregate)

      Calculates the mean square error after normalizing everything into [0,1]
      Parameters:
        `min` -
        `max` -
        `values` -
        `aggregate` -
      Returns: