Class DataTransformHelper
java.lang.Object
net.simplace.sim.components.util.helper.DataTransformHelper
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCalculateRegression(Double[] x, Double[] y) Calculates the linear regression of two variables.static doubleIntegral(double[] xs, double[] ys) Calculates the area under the curve defined by arrays of x and y valuesstatic doubleIntegralFromTo(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 t2static doubleInterpolate(double x, double[] xs, double[] ys, boolean extrapolate) Linear interpolation of a piecewise linear curvestatic 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.
-
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 valuesys- 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 valuesys- the y valuesarea- 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 arraymax- maximum value of the new arrayvs- 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 interpolatedxs- array of x valuesys- array of corresponding y valuesextrapolate- 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 curveys- 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 intervalt2- upper boundary of integration intervalxs- the x values defining the curveys- the y values defining the curve- Returns:
- the area
-
CalculateRegression
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
-