SkySpark by SkyFoundry

ext math

acos

acos(val)

Return the arc cosine.

asin

asin(val)

Return the arc sine.

atan

atan(val)

Return the arc tangent.

atan2

atan2(y, x)

Converts rectangular coordinates (x, y) to polar (r, theta).

bitAnd

bitAnd(a, b)

Bitwise and: a & b

bitNot

bitNot(a)

Bitwise not: ~a

bitOr

bitOr(a, b)

Bitwise or: a | b

bitShiftl

bitShiftl(a, b)

Bitwise left shift: a << b

bitShiftr

bitShiftr(a, b)

Bitwise right shift: a >> b

bitXor

bitXor(a, b)

Bitwise xor: a ^ b

ceil

ceil(val)

Return the smallest whole number greater than or equal to val. Result has same unit as val.

cos

cos(val)

Return the cosine of angle in radians.

cosh

cosh(val)

Return the hyperbolic cosine.

exp

exp(val)

Return e raised to val.

fitLinearRegression

fitLinearRegression(grid, opts: null)

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 column
  • y: 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 line
  • b: intercept of the best fit regression line
  • r2: 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 data
  • xmax: maximum value of x variable in sample data
  • ymin: minimum value of y variable in sample data
  • ymax: 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}
floor

floor(val)

Return the largest whole number less than or equal to val. Result has same unit as val.

log10

log10(val)

Return base 10 logarithm of val.

logE

logE(val)

Return natural logarithm to the base e of val.

matrixAdd

matrixAdd(a, b)

Add two matrices together and return new matrix. The parameters may be any value supported toMatrix. Matrices must have the same dimensions.

matrixDeterminant

matrixDeterminant(m)

Return the determinant as a unitless Number for the given matrix which is any value accepted by toMatrix. The matrix must be square.

matrixFitLinearRegression

matrixFitLinearRegression(y, x)

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 factors
  • r2: 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 coefficient
  • rowCount: 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
matrixInverse

matrixInverse(m)

Return the inverse of the given matrix which is any value accepted by toMatrix.

matrixMult

matrixMult(a, b)

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.

matrixSub

matrixSub(a, b)

Subtract two matrices and return new matrix. The parameters may be any value supported toMatrix. Matrices must have the same dimensions.

matrixTranspose

matrixTranspose(m)

Transpose the given matrix which is any value accepted by toMatrix.

mean

mean(val, acc)

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)
meanBiasErr

meanBiasErr(val, acc, nDegrees: 0)

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
median

median(val, acc)

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)
pi

pi()

Return constant for pi: 3.141592653589793

pow

pow(val, exp)

Return val raised to the specified power.

random

random(range: null)

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
remainder

remainder(a, b)

Return the remainder or modulo of division: a % b. Result has same unit as a.

rootMeanSquareErr

rootMeanSquareErr(val, acc, nDegrees: 0)

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
round

round(val)

Returns the nearest whole number to val. Result has same unit as val.

sin

sin(val)

Return sine of angle in radians.

sinh

sinh(val)

Return hyperbolic sine.

sqrt

sqrt(val)

Return square root of val.

standardDeviation

standardDeviation(val, acc)

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)
tan

tan(val)

Return tangent of angle in radians.

tanh

tanh(val)

Return hyperbolic tangent.

toDegrees

toDegrees(val)

Convert angle in radians to an angle in degrees.

toMatrix

toMatrix(obj)

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.

toRadians

toRadians(val)

Convert angle in degrees to an angle in radians.