Package smile.math

Class Scaler

java.lang.Object
smile.math.Scaler
All Implemented Interfaces:
Serializable, Function

public class Scaler extends Object implements Function
Affine transformation y = (x - offset) / scale.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Scaler(double scale, double offset, boolean clip)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    f(double x)
    Computes the value of the function at x.
    double
    inv(double x)
    Computes the value of the inverse function at x.
    static Scaler
    minmax(double[] data)
    Returns the scaler that map the values into the range [0, 1].
    static Scaler
    of(String scaler, double[] data)
    Returns the scaler.
    static Scaler
    standardizer(double[] data)
    Returns the standardize scaler to 0 mean and unit variance.
    static Scaler
    standardizer(double[] data, boolean robust)
    Returns the standardize scaler to 0 mean and unit variance.
    static Scaler
    winsor(double[] data)
    Returns the scaler that map the values into the range [0, 1].
    static Scaler
    winsor(double[] data, double lower, double upper)
    Returns the scaler that map the values into the range [0, 1].

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface smile.math.Function

    apply
  • Constructor Details

    • Scaler

      public Scaler(double scale, double offset, boolean clip)
      Constructor.
      Parameters:
      scale - the scaling factor.
      offset - the offset.
      clip - if true, clip the value in [0, 1].
  • Method Details

    • f

      public double f(double x)
      Description copied from interface: Function
      Computes the value of the function at x.
      Specified by:
      f in interface Function
      Parameters:
      x - a real number.
      Returns:
      the function value.
    • inv

      public double inv(double x)
      Description copied from interface: Function
      Computes the value of the inverse function at x.
      Specified by:
      inv in interface Function
      Parameters:
      x - a real number.
      Returns:
      the inverse function value.
    • minmax

      public static Scaler minmax(double[] data)
      Returns the scaler that map the values into the range [0, 1].
      Parameters:
      data - the training data.
      Returns:
      the scaler.
    • winsor

      public static Scaler winsor(double[] data)
      Returns the scaler that map the values into the range [0, 1]. The values greater than the 95% percentile are replaced with the upper limit, and those below the 5% percentile are replace with the lower limit.
      Parameters:
      data - the training data.
      Returns:
      the scaler.
    • winsor

      public static Scaler winsor(double[] data, double lower, double upper)
      Returns the scaler that map the values into the range [0, 1]. The values greater than the specified upper limit are replaced with the upper limit, and those below the lower limit are replace with the lower limit.
      Parameters:
      data - the training data.
      lower - the lower limit in terms of percentiles of the original distribution (e.g. 5th percentile).
      upper - the upper limit in terms of percentiles of the original distribution (e.g. 95th percentile).
      Returns:
      the scaler.
    • standardizer

      public static Scaler standardizer(double[] data)
      Returns the standardize scaler to 0 mean and unit variance.
      Parameters:
      data - The training data.
      Returns:
      the scaler.
    • standardizer

      public static Scaler standardizer(double[] data, boolean robust)
      Returns the standardize scaler to 0 mean and unit variance.
      Parameters:
      data - The training data.
      robust - If true, scale by subtracting the median and dividing by the IQR.
      Returns:
      the scaler.
    • of

      public static Scaler of(String scaler, double[] data)
      Returns the scaler. If the parameter scaler is null or empty, return null.
      Parameters:
      scaler - the scaling algorithm.
      data - the training data.
      Returns:
      the scaler.