@haxall/haxall
    Preparing search index...

    Class MathFuncs

    Axon functions for math

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    type$: Type

    Methods

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

      Parameters

      Returns number

    • 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.

      Parameters

      Returns boolean

    • 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.

      Returns number

    • Return if this Obj is immutable and safe to share between threads:

      • an instance of a const class
      • the result of toImmutable on List, Map, or Buf
      • a Func object may or may not be immutable - see sys::Func.
      • other instances are assumed mutable and return false

      Returns boolean

    • Get an immutable representation of this instance or throw NotImmutableErr if this object cannot be represented as an immutable:

      • if type is const, return this
      • if already an immutable List, Map, Buf, or Func return this
      • if a List, then attempt to perform a deep clone by calling toImmutable on all items
      • if a Map, then attempt to perform a deep clone by calling toImmutable on all values (keys are already immutable)
      • some Funcs can be made immutable - see sys::Func
      • if a Buf create immutable copy, see sys::Buf
      • any other object throws NotImmutableErr

      Returns Readonly<this>

    • Return a string representation of this object.

      Returns string

    • 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.

      Parameters

      Returns JsObj

    • Get the Type instance which represents this object's class. Also seeType.of or Pod.of.

      Returns Type

    • This method called whenever an it-block is applied to an object. The default implementation calls the function with this, and then returns this.

      Parameters

      • f: (arg0: this) => void

      Returns this

    • Return the arc cosine.

      Parameters

      Returns Number

    • Return the arc sine.

      Parameters

      Returns Number

    • Return the arc tangent.

      Parameters

      Returns Number

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

      Parameters

      Returns Number

    • Bitwise not: ~a

      Parameters

      Returns Number

    • Bitwise left shift: a << b

      Parameters

      Returns Number

    • Bitwise right shift: a >> b

      Parameters

      Returns Number

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

      Parameters

      Returns Number

    • Return the cosine of angle in radians.

      Parameters

      Returns Number

    • Return the hyperbolic cosine.

      Parameters

      Returns Number

    • Write 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.

      Parameters

      Returns void

    • Return e raised to val.

      Parameters

      Returns Number

    • 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}

      Parameters

      Returns Dict

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

      Parameters

      Returns Number

    • Return base 10 logarithm of val.

      Parameters

      Returns Number

    • Return natural logarithm to the base e of val.

      Parameters

      Returns Number

    • Parameters

      • ...args: unknown[]

      Returns MathFuncs

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

      Parameters

      Returns MatrixGrid

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

      Parameters

      Returns Number

    • 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 + bxᵢ₁ + bxᵢ₂ +...+ 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

      Parameters

      Returns Grid

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

      Parameters

      Returns MatrixGrid

    • 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.

      Parameters

      Returns MatrixGrid

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

      Parameters

      Returns MatrixGrid

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

      Parameters

      Returns MatrixGrid

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

      Parameters

      Returns JsObj

    • 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

      Parameters

      Returns JsObj

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

      Parameters

      Returns JsObj

    • Return constant for pi: 3.141592653589793

      Returns Number

    • Return val raised to the specified power.

      Parameters

      Returns Number

    • 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

      Parameters

      • percent: Number
      • Optionalmethod: string

      Returns JsObj

    • 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

      Parameters

      Returns Number

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

      Parameters

      Returns 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

      Parameters

      Returns JsObj

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

      Parameters

      Returns Number

    • Return sine of angle in radians.

      Parameters

      Returns Number

    • Return hyperbolic sine.

      Parameters

      Returns Number

    • Return square root of val.

      Parameters

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

      Parameters

      Returns JsObj

    • Return tangent of angle in radians.

      Parameters

      Returns Number

    • Return hyperbolic tangent.

      Parameters

      Returns Number

    • Convert angle in radians to an angle in degrees.

      Parameters

      Returns Number

    • 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})
      

      Parameters

      Returns MatrixGrid

    • Convert angle in degrees to an angle in radians.

      Parameters

      Returns Number