Class DataTransformHelper

java.lang.Object
net.simplace.sim.components.util.helper.DataTransformHelper

public class DataTransformHelper extends Object
Methods for interpolating and integrating piecewise linear functions WIKI_START Functions are given by arrays of x and y values. The class provides methods for - interpolating a value - calculating the integral of the function - rescales the function to have area of 1 WIKI_END
Author:
Gunther Krauss
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Calculates the linear regression of two variables.
    static double
    Integral(double[] xs, double[] ys)
    Calculates the area under the curve defined by arrays of x and y values
    static double
    IntegralFromTo(double t1, double t2, double[] xs, double[] ys)
    Calculates the area under the curve defined by arrays of x and y values between the points t1 and t2
    static double
    Interpolate(double x, double[] xs, double[] ys, boolean extrapolate)
    Linear interpolation of a piecewise linear curve
    static double[]
    NormalizeCurve(double[] xs, double[] ys)
    Normalizes the y-values of an x-y-curve so that the area under the curve is 1.
    static double[]
    NormalizeCurve(double[] xs, double[] ys, double area)
    Normalizes the y-values of an x-y-curve so that the area under the curve has given value.
    static double[]
    RescaleValues(double min, double max, double[] vs)
    Rescales an array of values proportionally from new mininimum to new maximum.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DataTransformHelper

      public DataTransformHelper()
  • Method Details

    • NormalizeCurve

      public static double[] NormalizeCurve(double[] xs, double[] ys)
      Normalizes the y-values of an x-y-curve so that the area under the curve is 1.
      Parameters:
      xs - the x values
      ys - the y values
      Returns:
      new y values
    • NormalizeCurve

      public static double[] NormalizeCurve(double[] xs, double[] ys, double area)
      Normalizes the y-values of an x-y-curve so that the area under the curve has given value.
      Parameters:
      xs - the x values
      ys - the y values
      area - the target area under the new curve
      Returns:
      new y values
    • RescaleValues

      public static double[] RescaleValues(double min, double max, double[] vs)
      Rescales an array of values proportionally from new mininimum to new maximum.
      Parameters:
      min - minimum value of the new array
      max - maximum value of the new array
      vs - values
      Returns:
      the rescaled values
    • Interpolate

      public static double Interpolate(double x, double[] xs, double[] ys, boolean extrapolate)
      Linear interpolation of a piecewise linear curve
      Parameters:
      x - position where the value should be interpolated
      xs - array of x values
      ys - array of corresponding y values
      extrapolate - if true then first or last y value is returned if x is out of range, if false 0 is returned
      Returns:
      the interpolated value
    • Integral

      public static double Integral(double[] xs, double[] ys)
      Calculates the area under the curve defined by arrays of x and y values
      Parameters:
      xs - the x values defining the curve
      ys - the y values defining the curve
      Returns:
      the area
    • IntegralFromTo

      public static double IntegralFromTo(double t1, double t2, double[] xs, double[] ys)
      Calculates the area under the curve defined by arrays of x and y values between the points t1 and t2
      Parameters:
      t1 - lower boundary of integration interval
      t2 - upper boundary of integration interval
      xs - the x values defining the curve
      ys - the y values defining the curve
      Returns:
      the area
    • CalculateRegression

      public static DataTransformHelper.RegressionValues CalculateRegression(Double[] x, Double[] y)
      Calculates the linear regression of two variables. Calculates the slope m and intercept b of the linear function by least squares estimation. The means of x and y as well as the coefficient of determination r squared are also calculated.
      Parameters:
      x -
      y -
      Returns:
      HashMap with the entries m, b, meanX, meanY, rSquared