gt:         return new StandardDeviationFunction();
context: /*
   * =================================================
   * Copyright 2011 tagtraum industries incorporated
   * All rights reserved.
   * =================================================
   */
  package com.tagtraum.jipes.math;
  
  /**
   * Common map functions.
   *
   * @author <a href="mailto:hs@tagtraum.com">Hendrik Schreiber</a>
   * @see MapFunction
   */
  public final class MapFunctions {
  
      private MapFunctions() {}
  
      /**
       * @see <a href="http://www.mathworks.com/help/toolbox/signal/xcorr.html">Matlab&trade; function <code>xcorr</code></a>
       */
      public static final MapFunction<float[]> AUTO_CORRELATION = new MapFunction<float[]>() {
          public float[] map(final float[] samples) {
              return Floats.autoCorrelation(samples);
          }
  
          @Override
          public String toString() {
              return "AUTO_CORRELATION";
          }
      };
  
      /**
       * Auto correlation function normalized with the first coefficient (global maximum).
       * I.e. all values are between 0 and 1.
       *
       * @see <a href="http://www.mathworks.com/help/toolbox/signal/xcorr.html">Matlab&trade; function <code>xcorr(..., 'coeff')</code></a>
       */
      public static final MapFunction<float[]> AUTO_CORRELATION_COEFF = new MapFunction<float[]>() {
          public float[] map(final float[] samples) {
              final float[] floats = Floats.autoCorrelation(samples);
              final float zeroLag = floats[0];
              for (int i=0; i<floats.length; i++) {
                  floats[i] = floats[i]/zeroLag;
              }
              return floats;
          }
  
          @Override
          public String toString() {
              return "AUTO_CORRELATION_COEFF";
          }
      };
  
      /**
       * Auto correlation function normalized with the number of samples, i.e. <code>biased(t) = r(t)/N</code>.
       *
       * @see <a href="http://www.mathworks.com/help/toolbox/signal/xcorr.html">Matlab&trade; function <code>xcorr(..., 'biased')</code></a>
       */
      public static final MapFunction<float[]> AUTO_CORRELATION_BIASED = new MapFunction<float[]>() {
          public float[] map(final float[] samples) {
              final float[] floats = Floats.autoCorrelation(samples);
              final float samplesLength = samples.length;
              for (int i=0; i<floats.length; i++) {
                  floats[i] = floats[i]/samplesLength;
              }
              return floats;
          }
  
          @Override
          public String toString() {
              return "AUTO_CORRELATION_BIASED";
          }
      };
  
      /**
       * Auto correlation function normalized with the number of samples minus abs(t),
       * i.e. <code>unbiased(t) = r(t)/(N-|t|)</code>
       *
       * @see <a href="http://www.mathworks.com/help/toolbox/signal/xcorr.html">Matlab&trade; function <code>xcorr(..., 'unbiased')</code></a>
       */
      public static final MapFunction<float[]> AUTO_CORRELATION_UNBIASED = new MapFunction<float[]>() {
          public float[] map(final float[] samples) {
              final float[] floats = Floats.autoCorrelation(samples);
              final float samplesLength = samples.length;
              for (int i=0; i<floats.length; i++) {
                  floats[i] = floats[i]/(samplesLength-i);
              }
              return floats;
          }
  
          @Override
          public String toString() {
              return "AUTO_CORRELATION_UNBIASED";
          }
      };
  
      /**
       * Removes sign.
       *
       * @return array with absolute values
       */
      public static MapFunction<float[]> createAbsFunction() {
          return new AbsFunction();
      }
  
      /**
       * Squares all values.
       *
       * @return arrays of squared values
       */
      public static MapFunction<float[]> createSquareFunction() {
          return new SquareFunction();
      }
  
      /**
       * Divides all values by the Euclidean norm of the the given buffer.
       * @return normalization
       */
      public static MapFunction<float[]> createEuclideanNormalization() {
          return new FloatNormalization() {
              public double getDivisor(final float[] buffer) {
                  return Floats.euclideanNorm(buffer);
              }
  
              @Override
              public String toString() {
                  return "EUCLIDEAN_NORMALIZATION";
              }
          };
      }
  
      /**
       * Divides all values by the max value in the given buffer.
       * @return normalization
       */
      public static MapFunction<float[]> createDivByMaxNormalization() {
          return new FloatNormalization() {
              public double getDivisor(final float[] buffer) {
                  return Floats.max(buffer);
              }
  
              @Override
              public String toString() {
                  return "DIV_BY_MAX_NORMALIZATION";
              }
          };
      }
  
      /**
       * Assumes that all values are signed 16bit values and divides them by {@link Short#MAX_VALUE}+1 in
       * order to map them to a range of -1 to 1.
       * @return normalization
       */
      public static MapFunction<float[]> createShortToOneNormalization() {
          return new ShortToOneNormalization();
      }
  
      /**
       * Reverses the order of the elements in <em>each</em> array.
       *
       * @return array with reversed order
       */
      public static MapFunction<float[]> createReverseFunction() {
          return new ReverseFunction();
      }
  
      /**
       * Creates wrap function.
       *
       * @param length length
       * @return wrap function
       */
      public static MapFunction<float[]> createWrapFunction(final int length) {
          return new WrapFunction(length);
      }
  
      /**
       * Creates a linear interpolation function.
       *
       * @param shift shift amount between -1 and 1
       * @param indicesPerOneShift number of indices the values need to be shifted, when the (normalized) shift is 1.
       * @return linear interpolation function
       */
      public static MapFunction<float[]> createInterpolateFunction(final float shift, final int indicesPerOneShift) {
          return new InterpolateFunction(shift, indicesPerOneShift);
      }
  
      /**
       * Maps consecutive samples to their temporal centroid.
       * This can e.g. be used in a {@link com.tagtraum.jipes.universal.Mapping}.
       *
       * @return mean function
       */
      public static StatefulMapFunction<Float> createTemporalCentroidFunction() {
          return new TemporalCentroidFunction();
      }
  
      /**
       * Maps consecutive samples to their variance.
       * This can e.g. be used in a {@link com.tagtraum.jipes.universal.Mapping}.
       *
       * @return variance function
       */
      public static StatefulMapFunction<Float> createVarianceFunction() {
          return new VarianceFunction();
      }
  
      /**
       * Maps consecutive samples to their standard deviation.
       * This can e.g. be used in a {@link com.tagtraum.jipes.universal.Mapping}.
       *
       * @return standard deviation function
       */
      public static StatefulMapFunction<Float> createStandardDeviationFunction() {
  