Funcs
Funcs : Funcs
Return constant for pi
Return the remainder or modulo of division
Return the smallest whole number greater than or equal to val
Return the largest whole number less than or equal to val
Returns the nearest whole number to val
Return e raised to val
Return natural logarithm to the base e of val
Return base 10 logarithm of val
Return val raised to the specified power
Return square root of val
Return random integer within given inclusive range
Bitwise not
Bitwise and
Bitwise or
Bitwise xor
Bitwise right shift
Bitwise left shift
Return the arc cosine
Return the arc sine
Return the arc tangent
Converts rectangular coordinates (x, y) to polar (r, theta)
Return the cosine of angle in radians
Return the hyperbolic cosine
Return sine of angle in radians
Return hyperbolic sine
Return tangent of angle in radians
Return hyperbolic tangent
Convert angle in radians to an angle in degrees
Convert angle in degrees to an angle in radians
Fold a sample of numbers into their standard average or arithmetic mean
Fold a sample of numbers into their median value which is the middle value of the sorted samples
Fold a sample of numbers into their RMSE (root mean square error)
Fold a sample of numbers into their MBE (mean bias error)
Fold a series of numbers into the standard deviation of a sample
Computes the pth quantile of a list of numbers, according to the specified interpolation method
Convert a general grid to an optimized matrix grid
Transpose the given matrix which is any value accepted by toMatrix
Return the determinant as a unitless Number for the given matrix which is any value accepted by toMatrix
Return the inverse of the given matrix which is any value accepted by toMatrix
Add two matrices together and return new matrix
Subtract two matrices and return new matrix
Multiply two matrices and return new matrix
Given a matrix of y coordinates and a matrix of multiple x coordinates compute the best fit multiple linear regression equation using the ordinary least squares method
Given a grid of x, y coordinates compute the best fit linear regression equation using the ordinary least squares method
() => Number
Return constant for pi: 3.141592653589793
(a: Number, b: Number) => Number
Return the remainder or modulo of division: a % b.
Result has same unit as a.
(val: Number) => Number
Return the smallest whole number greater than or equal to val.
Result has same unit as val.
(val: Number) => Number
Return the largest whole number less than or equal to val.
Result has same unit as val.
(val: Number) => Number
Returns the nearest whole number to val.
Result has same unit as val.
(val: Number) => Number
Return e raised to val.
(val: Number) => Number
Return natural logarithm to the base e of val.
(val: Number) => Number
Return base 10 logarithm of val.
(val: Number, exp: Number) => Number
Return val raised to the specified power.
(val: Number) => Number
Return square root of val.
(range: Obj?) => Number
Return random integer within given inclusive range. If range is null, then full range of representative integers is assumed.
Examples:
random() // random num with no range
random(0..100) // random num between 0 and 100
(a: Number) => Number
Bitwise not: ~a
(a: Number, b: Number) => Number
Bitwise and: a & b
(a: Number, b: Number) => Number
Bitwise or: a | b
(a: Number, b: Number) => Number
Bitwise xor: a ^ b
(a: Number, b: Number) => Number
Bitwise right shift: a >> b
(a: Number, b: Number) => Number
Bitwise left shift: a << b
(val: Number) => Number
Return the arc cosine.
(val: Number) => Number
Return the arc sine.
(val: Number) => Number
Return the arc tangent.
(y: Number, x: Number) => Number
Converts rectangular coordinates (x, y) to polar (r, theta).
(val: Number) => Number
Return the cosine of angle in radians.
(val: Number) => Number
Return the hyperbolic cosine.
(val: Number) => Number
Return sine of angle in radians.
(val: Number) => Number
Return hyperbolic sine.
(val: Number) => Number
Return tangent of angle in radians.
(val: Number) => Number
Return hyperbolic tangent.
(val: Number) => Number
Convert angle in radians to an angle in degrees.
(val: Number) => Number
Convert angle in degrees to an angle in radians.
(val: Obj?, acc: Obj?) => Obj? <foldOn:Number>
Fold a sample of numbers into their standard average or arithmetic mean. This function is the same as core::avg. Nulls values are ignored. Return null if no values.
Example:
[2, 4, 5, 3].fold(mean)
(val: Obj?, acc: Obj?) => Obj? <foldOn:Number>
Fold a sample of numbers into their median value which is the middle value of the sorted samples. If there are an even number of sample, then the median is the mean of the middle two. Null values are ignored. Return null if no values.
Example:
[2, 4, 5, 3, 1].fold(median)
(val: Obj?, acc: Obj?, nDegrees: Number) => Obj? <foldOn:Number>
Fold a sample of numbers into their RMSE (root mean square error). The RMSE function determines the RMSE between a sample set and its mean using the n-degrees of freedom RMSE:
RMBE = sqrt( Σ(xᵢ - median)² ) / (n - nDegrees)
Examples:
samples.fold(rootMeanSquareErr) // unbiased zero degrees of freedom
samples.fold(rootMeanSquareErr(_,_,1)) // 1 degree of freedom
(val: Obj?, acc: Obj?, nDegrees: Number) => Obj? <foldOn:Number>
Fold a sample of numbers into their MBE (mean bias error). The MBE function determines the MBE between a sample set and its mean:
MBE = Σ(xᵢ - median) / (n - nDegrees)
Examples:
samples.fold(meanBiasErr) // unbiased zero degrees of freedom
samples.fold(meanBiasErr(_,_,1)) // 1 degree of freedom
(val: Obj?, acc: Obj?) => Obj? <foldOn:Number>
Fold a series of numbers into the standard deviation of a sample:
s = sqrt(Σ (xᵢ - mean)² / (n-1))
Example:
[4, 2, 5, 8, 6].fold(standardDeviation)
(percent: Number, method: Str) => Obj?
Computes the pth quantile of a list of numbers, according to the specified interpolation method. The value p must be a number between 0.0 to 1.0.
- linear (default): Interpolates proportionally between the two closest values
- nearest: Rounds to the nearest data point
- lower: Rounds to the nearest lower data point
- higher: Rounds to the nearest higher data point
- midpoint: Averages two nearest values
Usage:
[1,2,3].fold(quantile(p, method))
Examples:
[10,10,10,25,100].fold(quantile(0.7 )) => 22 //default to linear
[10,10,10,25,100].fold(quantile(0.7, "nearest")) => 25
[10,10,10,25,100].fold(quantile(0.7, "lower")) => 10
[10,10,10,25,100].fold(quantile(0.7, "higher")) => 25
[10,10,10,25,100].fold(quantile(0.7, "linear")) => 22 //same as no arg
[10,10,10,25,100].fold(quantile(0.7, "midpoint")) => 17.5
Detailed Logic:
p: percentile (decimal 0-1)
n: list size
rank: p * (n-1) // this is the index of the percentile in your list
// if rank is an integer, return list[rank]
// if rank is not an integer, interpolate via one of the above methods (illustrated below in examples)
[1,2,3,4,5].percentile(0.5) => 3 // rank=2 is an int so we can index[2] directly
[10,10,10, 25, 100].percentile(0.7, method)
rank = (0.7 * 4) => 2.8
//adjust rank based on method
nearest = index[3] // => 25
lower = index[2] // => 10
higher = index[3] // => 25
//or interpolate for these methods
//takes the 2 closest indices and calculates midpoint
midpoint = (25-10)/2 + 10 // => 17.5
//takes the 2 closest indices and calculates weighted average
linear = (0.2 * 10) + (0.8 * 25) // => 22
(obj: Obj, opts: Dict) => Grid
Convert a general grid to an optimized matrix grid. Matrixs are two dimensional grids of Numbers. Columns are named "v0", "v1", "v2", etc. Grid meta is preserved, but not column meta. Numbers in the resulting matrix are unitless; any units passed in are stripped.
The following options are supported:
- nullVal (Number): replace null values in the grid with this value
- naVal (Number): replace NA values in the grid with this value
toMatrix(grid, {nullVal: 0, naVal: 0})
To create a sparse or initialized matrix you can pass a Dict with the the following tags (all required)
toMatrix({rows:10, cols: 1000, init: 0})
(m: Obj) => Grid
Transpose the given matrix which is any value accepted by toMatrix.
(m: Obj) => Number
Return the determinant as a unitless Number for the given matrix which is any value accepted by toMatrix. The matrix must be square.
(m: Obj) => Grid
Return the inverse of the given matrix which is any value accepted by toMatrix.
(a: Obj, b: Obj) => Grid
Add two matrices together and return new matrix. The parameters may be any value supported toMatrix. Matrices must have the same dimensions.
(a: Obj, b: Obj) => Grid
Subtract two matrices and return new matrix. The parameters may be any value supported toMatrix. Matrices must have the same dimensions.
(a: Obj, b: Obj) => Grid
Multiply two matrices and return new matrix. The parameters may
be any value supported toMatrix. Matrix a column count must match
matrix b row count.
(y: Obj, x: Obj) => Grid
Given a matrix of y coordinates and a matrix of multiple x coordinates
compute the best fit multiple linear regression equation using
the ordinary least squares method. Both y and x may be any value
accepted by toMatrix.
The resulting linear equation for r X coordinates is:
yᵢ = bias + b₁xᵢ₁ + b₂xᵢ₂ +...+ bᵣxᵢᵣ
The equation is returned as a grid. The grid meta:
bias: bias or zero coefficient which is independent of any of the x factorsr2: R² coefficient of determination as a number between 1.0 (perfect correlation) and 0.0 (no correlation)r: the square root of R², referred to as the correlation coefficientrowCount: the number of rows of data used in the correlation For each X factor there is a row with the following tags:b: the correlation coefficient for the given X factor
(grid: Grid, opts: Dict?) => Dict
Given a grid of x, y coordinates compute the best fit linear
regression equation using the ordinary least squares method.
The first column of the grid is used for x and the second
column is y. Any rows without a Number for both x and y
are skipped. Any special Numbers (infinity/NaN) are skipped.
Options:
x: column name to use for x if not first columny: column name to use for y if not second column
The resulting linear equation is:
yᵢ = mxᵢ + b
The equation is returned as a dictionary with these keys:
m: slope of the best fit regression lineb: intercept of the best fit regression liner2: R² coefficient of determination as a number between 1.0 (perfect correlation) and 0.0 (no correlation)xmin: minimum value of x variable in sample dataxmax: maximum value of x variable in sample dataymin: minimum value of y variable in sample dataymax: maximum value of y variable in sample data
Also see matrixFitLinearRegression to compute a multiple linear regression.
Example:
data: [{x:1, y:2},
{x:2, y:4},
{x:4, y:4},
{x:6, y:5}].toGrid
fitLinearRegression(data)
>>> {m:0.4915, b: 2.1525, r2: 0.7502}