Xfit

This library provides functions to perform fitting of 2D data to various functions. require.mx('mxjs/base/xdistributionfit.js');

StatusName
BestFitter BestFit.exp ( Table ↓Table, Function ↓read_FieldX, Function ↓read_FieldY, Function ↓optional_read_Filter )

Returns a bestfitter created by using a balanced exponential fit on the input data

BestFitter BestFit.exp_array ( Array ↓x_array, Array ↓y_array, Number ↓num_points )

Returns a bestfitter created by using a balanced exponential fit on the input data

BestFitter BestFit.expSimple ( Table ↓Table, Function ↓read_FieldX, Function ↓read_FieldY, Function ↓optional_read_Filter )

Returns a bestfitter created by using a simple exponential fit on the input data

BestFitter BestFit.expSimple_array ( Array ↓x_array, Array ↓y_array, Number ↓num_points )

Returns a bestfitter created by using a simple exponential fit on the input data

BestFitter BestFit.linear ( Table ↓Table, Function ↓read_FieldX, Function ↓read_FieldY, Function ↓optional_read_Filter )

Returns a bestfitter created by using a linear fit on the input data

BestFitter BestFit.linear_array ( Array ↓x_array, Array ↓y_array, Number ↓num_points )

Returns a bestfitter created by using a linear fit on the input data

BestFitter BestFit.log ( Table ↓Table, Function ↓read_FieldX, Function ↓read_FieldY, Function ↓optional_read_Filter )

Returns a bestfitter created by using a logarithmic fit on the input data

BestFitter BestFit.log_array ( Array ↓x_array, Array ↓y_array, Number ↓num_points )

Returns a bestfitter created by using a logarithmic fit on the input data

BestFitter BestFit.piecewiseLinear ( Table ↓Table, Function ↓read_FieldX, Function ↓read_FieldY, Function ↓optional_read_Filter )

Returns a piecewise linear interpolator on the input data. It returns fitted values as the linear interpolation between the closest data points in the set on either side of the input. If there are only points available on one side, it returns the value of the closest data point.

BestFitter BestFit.piecewiseLinear_array ( Array ↓x_array, Array ↓y_array, Number ↓num_points )

Returns a piecewise linear interpolator on the input data. It returns fitted values as the linear interpolation between the closest data points in the set on either side of the input. If there are only points available on one side, it returns the value of the closest data point.

BestFitter BestFit.polynomial ( Number ↓order, Table ↓Table, Function ↓read_FieldX, Function ↓read_FieldY, Function ↓optional_read_Filter )

Returns a bestfitter created by using a polynomial fit of the specified order on the input data

BestFitter BestFit.polynomial_array ( Number ↓order, Array ↓x_array, Array ↓y_array, Number ↓num_points )

Returns a bestfitter created by using a polynomial fit of the specified order on the input data

BestFitter BestFit.power ( Table ↓Table, Function ↓read_FieldX, Function ↓read_FieldY, Function ↓optional_read_Filter )

Returns a bestfitter created by using a power fit on the input data

BestFitter BestFit.power_array ( Array ↓x_array, Array ↓y_array, Number ↓num_points )

Returns a bestfitter created by using a power fit on the input data

Bestfitter Create.exp ( )

Creates a balanced exponential bestfitter.

Bestfitter Create.exponentialConstant ( )

Creates a fitter for exponential with constant

Bestfitter Create.expSimple ( )

Creates a simple exponential bestfitter. This variant is faster but is weighted towards values closer to zero.

Bestfitter Create.linear ( )

Creates a linear bestfitter

Bestfitter Create.log ( )

Creates a logarithmic (ln) bestfitter.

Bestfitter Create.piecewiseLinear ( )

Creates a piecewise linear interpolator

Bestfitter Create.polynomial ( Number order )

Creates a polynomial bestfitter for the specified order

Bestfitter Create.power ( )

Creates a power bestfitter

Number Measure.ks ( BestFitter ↓bestfitter, Table ↓Table, Function ↓read_FieldX, Function ↓read_FieldY, Function ↓optional_read_Filter )

Returns the Kolmogorov�Smirnov test result between the provided data points, and the fit from the provided bestfitter

Number Measure.ks_array ( BestFitter ↓bestfitter, Array ↓x_array, Array ↓y_array, Number ↓num_points )

Returns the Kolmogorov�Smirnov test result between the provided data points, and the fit from the provided bestfitter

Number Measure.rmse ( BestFitter ↓bestfitter, Table ↓Table, Function ↓read_FieldX, Function ↓read_FieldY, Function ↓optional_read_Filter )

Returns the root-mean-square-error result between the provided data points, and the fit from the provided bestfitter

Number Measure.rmse_array ( BestFitter ↓bestfitter, Array ↓x_array, Array ↓y_array, Number ↓num_points )

Returns the root-mean-square-error result between the provided data points, and the fit from the provided bestfitter

Number Measure.rsquare ( BestFitter ↓bestfitter, Table ↓Table, Function ↓read_FieldX, Function ↓read_FieldY, Function ↓optional_read_Filter )

Returns the R-square result between the provided data points, and the fit from the provided bestfitter

Number Measure.rsquare_array ( BestFitter ↓bestfitter, Array ↓x_array, Array ↓y_array, Number ↓num_points )

Returns the R-square result between the provided data points, and the fit from the provided bestfitter

Function Result.generateFunction ( BestFitter ↓bestfitter )

Returns a function f(x) that can be used to generate values for the best fitted equation.

Object Result.getCoefficients ( BestFitter ↓bestfitter )

Gets the coefficients for a particular bestfitter. The coefficients are specific to each bestfitter type.

Text Result.getEquation ( BestFitter ↓bestfitter )

Gets the textual representation of the equation for a particular bestfitter

BestFitter Result.loadFromJson ( Text ↓text )

Returns a bestfitter as loaded from the JSON text

Text Result.saveAsJson ( BestFitter ↓bestfitter )

Returns JSON text which contains the saved state of the bestfitter. This can be persisted to Table values or columns. It allows the Bestfitter to be saved and/or used in another calculation.

SetPoints.addPoint ( BestFitter ↓bestfitter, Number x, Number y )

Adds input for a bestfitter object from a data point (x, y)

SetPoints.fromArray ( BestFitter ↓bestfitter, Array ↓x_array, Array ↓y_array, Number ↓num_points )

Adds input for a bestfitter object from arrays

SetPoints.fromArray ( BestFitter ↓bestfitter, Table ↓Table, Function ↓read_FieldX, Function ↓read_FieldY, Function ↓read_Filter )

Adds input for a bestfitter object from data table columns. The filter is optional, providing it will use only data points that passed the filter.


Category: BestFit

These functions provide a BestFitter object based on input.

↑bestfitter = Lib.BestFit.exp ( ↓Table, ↓read_FieldX, ↓read_FieldY, ↓optional_read_Filter )

Returns a bestfitter created by using a balanced exponential fit on the input data

Parameters:
  • Table ↓Table - Table containing the input data
  • Function ↓read_FieldX - Table read function for the x of the data points.
  • Function ↓read_FieldY - Table read function for the y of the data points.
  • Function ↓optional_read_Filter - optional Table read function for the filter
Returns: BestFitter ↑bestfitter
↑bestfitter = Lib.BestFit.exp_array ( ↓x_array, ↓y_array, ↓num_points )

Returns a bestfitter created by using a balanced exponential fit on the input data

Parameters:
  • Array ↓x_array - array containing the x of the data points
  • Array ↓y_array - array containing the y of the data points
  • Number ↓num_points - the number of data points provided in the arrays above.
Returns: BestFitter ↑bestfitter
↑bestfitter = Lib.BestFit.expSimple ( ↓Table, ↓read_FieldX, ↓read_FieldY, ↓optional_read_Filter )

Returns a bestfitter created by using a simple exponential fit on the input data

Parameters:
  • Table ↓Table - Table containing the input data
  • Function ↓read_FieldX - Table read function for the x of the data points.
  • Function ↓read_FieldY - Table read function for the y of the data points.
  • Function ↓optional_read_Filter - optional Table read function for the filter
Returns: BestFitter ↑bestfitter
↑bestfitter = Lib.BestFit.expSimple_array ( ↓x_array, ↓y_array, ↓num_points )

Returns a bestfitter created by using a simple exponential fit on the input data

Parameters:
  • Array ↓x_array - array containing the x of the data points
  • Array ↓y_array - array containing the y of the data points
  • Number ↓num_points - the number of data points provided in the arrays above.
Returns: BestFitter ↑bestfitter
↑bestfitter = Lib.BestFit.linear ( ↓Table, ↓read_FieldX, ↓read_FieldY, ↓optional_read_Filter )

Returns a bestfitter created by using a linear fit on the input data

Parameters:
  • Table ↓Table - Table containing the input data
  • Function ↓read_FieldX - Table read function for the x of the data points.
  • Function ↓read_FieldY - Table read function for the y of the data points.
  • Function ↓optional_read_Filter - optional Table read function for the filter
Returns: BestFitter ↑bestfitter
↑bestfitter = Lib.BestFit.linear_array ( ↓x_array, ↓y_array, ↓num_points )

Returns a bestfitter created by using a linear fit on the input data

Parameters:
  • Array ↓x_array - array containing the x of the data points
  • Array ↓y_array - array containing the y of the data points
  • Number ↓num_points - the number of data points provided in the arrays above.
Returns: BestFitter ↑bestfitter
↑bestfitter = Lib.BestFit.log ( ↓Table, ↓read_FieldX, ↓read_FieldY, ↓optional_read_Filter )

Returns a bestfitter created by using a logarithmic fit on the input data

Parameters:
  • Table ↓Table - Table containing the input data
  • Function ↓read_FieldX - Table read function for the x of the data points.
  • Function ↓read_FieldY - Table read function for the y of the data points.
  • Function ↓optional_read_Filter - optional Table read function for the filter
Returns: BestFitter ↑bestfitter
↑bestfitter = Lib.BestFit.log_array ( ↓x_array, ↓y_array, ↓num_points )

Returns a bestfitter created by using a logarithmic fit on the input data

Parameters:
  • Array ↓x_array - array containing the x of the data points
  • Array ↓y_array - array containing the y of the data points
  • Number ↓num_points - the number of data points provided in the arrays above.
Returns: BestFitter ↑bestfitter
↑interpolator = Lib.BestFit.piecewiseLinear ( ↓Table, ↓read_FieldX, ↓read_FieldY, ↓optional_read_Filter )

Returns a piecewise linear interpolator on the input data. It returns fitted values as the linear interpolation between the closest data points in the set on either side of the input. If there are only points available on one side, it returns the value of the closest data point.

Parameters:
  • Table ↓Table - Table containing the input data
  • Function ↓read_FieldX - Table read function for the x of the data points.
  • Function ↓read_FieldY - Table read function for the y of the data points.
  • Function ↓optional_read_Filter - optional Table read function for the filter
Returns: BestFitter ↑interpolator
↑interpolator = Lib.BestFit.piecewiseLinear_array ( ↓x_array, ↓y_array, ↓num_points )

Returns a piecewise linear interpolator on the input data. It returns fitted values as the linear interpolation between the closest data points in the set on either side of the input. If there are only points available on one side, it returns the value of the closest data point.

Parameters:
  • Array ↓x_array - array containing the x of the data points
  • Array ↓y_array - array containing the y of the data points
  • Number ↓num_points - the number of data points provided in the arrays above.
Returns: BestFitter ↑interpolator
↑bestfitter = Lib.BestFit.polynomial ( ↓order, ↓Table, ↓read_FieldX, ↓read_FieldY, ↓optional_read_Filter )

Returns a bestfitter created by using a polynomial fit of the specified order on the input data

Parameters:
  • Number ↓order - order of the polynomial fit
  • Table ↓Table - Table containing the input data
  • Function ↓read_FieldX - Table read function for the x of the data points.
  • Function ↓read_FieldY - Table read function for the y of the data points.
  • Function ↓optional_read_Filter - optional Table read function for the filter
Returns: BestFitter ↑bestfitter
↑bestfitter = Lib.BestFit.polynomial_array ( ↓order, ↓x_array, ↓y_array, ↓num_points )

Returns a bestfitter created by using a polynomial fit of the specified order on the input data

Parameters:
  • Number ↓order - order of the polynomial fit
  • Array ↓x_array - array containing the x of the data points
  • Array ↓y_array - array containing the y of the data points
  • Number ↓num_points - the number of data points provided in the arrays above.
Returns: BestFitter ↑bestfitter
↑bestfitter = Lib.BestFit.power ( ↓Table, ↓read_FieldX, ↓read_FieldY, ↓optional_read_Filter )

Returns a bestfitter created by using a power fit on the input data

Parameters:
  • Table ↓Table - Table containing the input data
  • Function ↓read_FieldX - Table read function for the x of the data points.
  • Function ↓read_FieldY - Table read function for the y of the data points.
  • Function ↓optional_read_Filter - optional Table read function for the filter
Returns: BestFitter ↑bestfitter
↑bestfitter = Lib.BestFit.power_array ( ↓x_array, ↓y_array, ↓num_points )

Returns a bestfitter created by using a power fit on the input data

Parameters:
  • Array ↓x_array - array containing the x of the data points
  • Array ↓y_array - array containing the y of the data points
  • Number ↓num_points - the number of data points provided in the arrays above.
Returns: BestFitter ↑bestfitter

Category: Create

These functions create bestfitter data objects.

↑bestfitter = Lib.Create.exp ( )

Creates a balanced exponential bestfitter.

Parameters:
Returns: Bestfitter ↑bestfitter
↑bestfitter = Lib.Create.exponentialConstant ( )

Creates a fitter for exponential with constant

Parameters:
Returns: Bestfitter ↑bestfitter
↑bestfitter = Lib.Create.expSimple ( )

Creates a simple exponential bestfitter. This variant is faster but is weighted towards values closer to zero.

Parameters:
Returns: Bestfitter ↑bestfitter
↑bestfitter = Lib.Create.linear ( )

Creates a linear bestfitter

Parameters:
Returns: Bestfitter ↑bestfitter
↑bestfitter = Lib.Create.log ( )

Creates a logarithmic (ln) bestfitter.

Parameters:
Returns: Bestfitter ↑bestfitter
↑bestfitter = Lib.Create.piecewiseLinear ( )

Creates a piecewise linear interpolator

Parameters:
Returns: Bestfitter ↑bestfitter
↑bestfitter = Lib.Create.polynomial ( order )

Creates a polynomial bestfitter for the specified order

Parameters:
  • Number order - of polynomial fitting
Returns: Bestfitter ↑bestfitter
↑bestfitter = Lib.Create.power ( )

Creates a power bestfitter

Parameters:
Returns: Bestfitter ↑bestfitter

Category: Measure

These functions compute a measure of goodness of fit given the original input points (or an alternative sample set) and the BestFitter object.

↑ks = Lib.Measure.ks ( ↓bestfitter, ↓Table, ↓read_FieldX, ↓read_FieldY, ↓optional_read_Filter )

Returns the Kolmogorov�Smirnov test result between the provided data points, and the fit from the provided bestfitter

Parameters:
  • BestFitter ↓bestfitter - bestfitter object to compare against
  • Table ↓Table - Table containing the data points
  • Function ↓read_FieldX - Table read function for the x of the data points.
  • Function ↓read_FieldY - Table read function for the y of the data points.
  • Function ↓optional_read_Filter - optional Table read function for the filter
Returns: Number ↑ks - - the Kolmogorov�Smirnov test result
↑ks = Lib.Measure.ks_array ( ↓bestfitter, ↓x_array, ↓y_array, ↓num_points )

Returns the Kolmogorov�Smirnov test result between the provided data points, and the fit from the provided bestfitter

Parameters:
  • BestFitter ↓bestfitter - bestfitter object to compare against
  • Array ↓x_array - array containing the x of the data points
  • Array ↓y_array - array containing the y of the data points
  • Number ↓num_points - the number of data points provided in the arrays above.
Returns: Number ↑ks - - the Kolmogorov�Smirnov test result
↑rmse = Lib.Measure.rmse ( ↓bestfitter, ↓Table, ↓read_FieldX, ↓read_FieldY, ↓optional_read_Filter )

Returns the root-mean-square-error result between the provided data points, and the fit from the provided bestfitter

Parameters:
  • BestFitter ↓bestfitter - bestfitter object to compare against
  • Table ↓Table - Table containing the data points
  • Function ↓read_FieldX - Table read function for the x of the data points.
  • Function ↓read_FieldY - Table read function for the y of the data points.
  • Function ↓optional_read_Filter - optional Table read function for the filter
Returns: Number ↑rmse - - the root-mean-square-error result
↑rmse = Lib.Measure.rmse_array ( ↓bestfitter, ↓x_array, ↓y_array, ↓num_points )

Returns the root-mean-square-error result between the provided data points, and the fit from the provided bestfitter

Parameters:
  • BestFitter ↓bestfitter - bestfitter object to compare against
  • Array ↓x_array - array containing the x of the data points
  • Array ↓y_array - array containing the y of the data points
  • Number ↓num_points - the number of data points provided in the arrays above.
Returns: Number ↑rmse - - the root-mean-square-error result
↑rsquare = Lib.Measure.rsquare ( ↓bestfitter, ↓Table, ↓read_FieldX, ↓read_FieldY, ↓optional_read_Filter )

Returns the R-square result between the provided data points, and the fit from the provided bestfitter

Parameters:
  • BestFitter ↓bestfitter - bestfitter object to compare against
  • Table ↓Table - Table containing the data points
  • Function ↓read_FieldX - Table read function for the x of the data points.
  • Function ↓read_FieldY - Table read function for the y of the data points.
  • Function ↓optional_read_Filter - optional Table read function for the filter
Returns: Number ↑rsquare - - the R-square result
↑rsquare = Lib.Measure.rsquare_array ( ↓bestfitter, ↓x_array, ↓y_array, ↓num_points )

Returns the R-square result between the provided data points, and the fit from the provided bestfitter

Parameters:
  • BestFitter ↓bestfitter - bestfitter object to compare against
  • Array ↓x_array - array containing the x of the data points
  • Array ↓y_array - array containing the y of the data points
  • Number ↓num_points - the number of data points provided in the arrays above.
Returns: Number ↑rsquare - - the R-square result

Category: Result

These functions extract output from a bestfitter object after input has been specified.

↑function = Lib.Result.generateFunction ( ↓bestfitter )

Returns a function f(x) that can be used to generate values for the best fitted equation.

Parameters: Returns: Function ↑function - this function takes a single numeric input x, and returns the fitted value for x.
↑coefficients = Lib.Result.getCoefficients ( ↓bestfitter )

Gets the coefficients for a particular bestfitter. The coefficients are specific to each bestfitter type.

Parameters: Returns: Object ↑coefficients
↑equation = Lib.Result.getEquation ( ↓bestfitter )

Gets the textual representation of the equation for a particular bestfitter

Parameters: Returns: Text ↑equation
↑bestfitter = Lib.Result.loadFromJson ( ↓text )

Returns a bestfitter as loaded from the JSON text

Parameters: Returns: BestFitter ↑bestfitter
↑text = Lib.Result.saveAsJson ( ↓bestfitter )

Returns JSON text which contains the saved state of the bestfitter. This can be persisted to Table values or columns. It allows the Bestfitter to be saved and/or used in another calculation.

Parameters: Returns: Text ↑text

Category: SetPoints

These functions provide data to a bestfitter object.

Lib.SetPoints.addPoint ( ↓bestfitter, x, y )

Adds input for a bestfitter object from a data point (x, y)

Parameters:
Lib.SetPoints.fromArray ( ↓bestfitter, ↓x_array, ↓y_array, ↓num_points )

Adds input for a bestfitter object from arrays

Parameters:
  • BestFitter ↓bestfitter - - the Bestfitter to add data points to
  • Array ↓x_array - - input array containing x of data points
  • Array ↓y_array - - input array containing y of data points
  • Number ↓num_points - - number of data points (size of the x, y arrays)
Lib.SetPoints.fromArray ( ↓bestfitter, ↓Table, ↓read_FieldX, ↓read_FieldY, ↓read_Filter )

Adds input for a bestfitter object from data table columns. The filter is optional, providing it will use only data points that passed the filter.

Parameters:
  • BestFitter ↓bestfitter - - the Bestfitter to add data points to
  • Table ↓Table - - input Table containing data points
  • Function ↓read_FieldX - - input Table read Function containing x of data points
  • Function ↓read_FieldY - - input Table read Function containing y of data points
  • Function ↓read_Filter - - optional input Table read Function containing filter

Class: BestFitter

A BestFitter object contains the calculated coefficients from a data set and can compute the fitted value for input.

StatusName
addPoint ( Number x, Number y )

Adds the data point (x, y) provided, and recomputes the fit

Function generateFunction ( )

Generates a function f(x) that will compute the fitted value for any input x. The function once generated is standalone from the BestFitter (function will not change if you provide additional data points to this BestFitter that changes the coefficients)

Number generator ( Number x )

Computes the fitted value for a specified input x

Object getCoefficients ( )

Returns an object containing the coefficients for this bestfitter. How the coefficients are stored or specified is specific to the BestFitter type.

Text getEquation ( )

Gets a textual representation of the fitted equation.

BestFitter.addPoint ( x, y )

Adds the data point (x, y) provided, and recomputes the fit

Parameters:
BestFitter.generateFunction ( )

Generates a function f(x) that will compute the fitted value for any input x. The function once generated is standalone from the BestFitter (function will not change if you provide additional data points to this BestFitter that changes the coefficients)

Parameters:
Returns: Function function - - a function f(x) that will compute the fitted value for input x.
BestFitter.generator ( x )

Computes the fitted value for a specified input x

Parameters: Returns: Number y - fitted value for x
BestFitter.getCoefficients ( )

Returns an object containing the coefficients for this bestfitter. How the coefficients are stored or specified is specific to the BestFitter type.

Parameters:
Returns: Object coefficients - - coefficients object. How the coefficients are stored or specified is specific to the BestFitter type.
BestFitter.getEquation ( )

Gets a textual representation of the fitted equation.

Parameters:
Returns: Text equation - - textual representation of the fitted equation