Return a negative integer, zero, or a positive integer if this object is less than, equal to, or greater than the specified object:
this < that => <0
this == that => 0
this > that => >0
This method may also be accessed via the <
<=
<=>
>=
and >
shortcut operators. If not overridden the default
implementation compares the toStr
representations. Also see docLang.
Examples:
3.compare(8) => -1
8.compare(3) => 1
8.compare(8) => 0
3 <=> 8 => -1 // shortcut for 3.compare(8)
Compare this object to the specified for equality. This
method may be accessed via the == and != shortcut operators.
If not overridden the default implementation compares for
reference equality using the === operator. If this method
is overridden, then hash() must also be overridden such that
any two objects which return true for equals() must return
the same value for hash(). This method must accept null
and
return false.
Return a unique hashcode for this object. If a class overrides hash() then it must ensure if equals() returns true for any two objects then they have same hash code.
Get an immutable representation of this instance or throw NotImmutableErr if this object cannot be represented as an immutable:
Return a string representation of this object.
Trap a dynamic call for handling. Dynamic calls are invoked with the -> shortcut operator:
a->x a.trap("x", null)
a->x() a.trap("x", null)
a->x = b a.trap("x", [b])
a->x(b) a.trap("x", [b])
a->x(b, c) a.trap("x", [b, c])
The default implementation provided by Obj attempts to use reflection. If name maps to a method, it is invoked with the specified arguments. If name maps to a field and args.size is zero, get the field. If name maps to a field and args.size is one, set the field and return args[0]. Otherwise throw UnknownSlotErr.
This method called whenever an it-block is applied to an
object. The default implementation calls the function with this
,
and then returns this
.
Static
acosStatic
asinStatic
atanStatic
atan2Static
bitStatic
bitStatic
bitStatic
bitStatic
bitStatic
bitStatic
ceilStatic
cosStatic
coshStatic
echoWrite x.toStr
to standard output followed by newline. If x
is null then print "null". If no argument is provided then
print an empty line.
Optional
x: JsObjStatic
expStatic
fitGiven 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 columnThe 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 dataAlso 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}
Static
floorStatic
log10Static
logStatic
makeStatic
matrixAdd two matrices together and return new matrix. The parameters may be any value supported toMatrix. Matrices must have the same dimensions.
Static
matrixStatic
matrixGiven 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 factorStatic
matrixReturn the inverse of the given matrix which is any value accepted by toMatrix.
Static
matrixMultiply two matrices and return new matrix. The parameters
may be any value supported toMatrix.
Matrix a
column count must match matrix b
row count.
Static
matrixSubtract two matrices and return new matrix. The parameters may be any value supported toMatrix. Matrices must have the same dimensions.
Static
matrixTranspose the given matrix which is any value accepted by toMatrix.
Static
meanStatic
meanFold 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
Static
medianFold 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)
Static
piReturn constant for pi: 3.141592653589793
Static
powStatic
quantileComputes 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.
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
Optional
method: stringStatic
randomStatic
remainderStatic
rootFold 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
Static
roundStatic
sinStatic
sinhStatic
sqrtStatic
standardStatic
tanStatic
tanhStatic
toStatic
toConvert 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:
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})
Static
to
Axon functions for math