Global

Members

(constant) DEFAULT_MAX_TIME_MS

Description:
  • Default maximum fitting time: one hour, expressed in milliseconds (Rust uses chrono::Duration::seconds(3600)).

Source:

Default maximum fitting time: one hour, expressed in milliseconds (Rust uses chrono::Duration::seconds(3600)).

(constant) Gaussian

Description:
  • Gaussian kernel — alias of SquaredExp (Rust pub type Gaussian = SquaredExp).

Source:

Gaussian kernel — alias of SquaredExp (Rust pub type Gaussian = SquaredExp).

Methods

addKernels(k1, k2) → {KernelSum}

Description:
  • Convenience constructor for k1 + k2 (Rust KernelArith Add operator).

Source:
Parameters:
Name Type Description
k1 object
k2 object
Returns:
Type
KernelSum

addRowsCholeskyCovMatrix(cholesky, allInputs, nbNewInputs, kernel, diagonalNoise)

Description:
  • Incrementally add the last nbNewInputs rows of allInputs to an existing Cholesky decomposition (in place), one row at a time. For each new row:

    • compute the new column (covariances with all rows up to and including itself, length col_index+1),
    • add noise² to the final (self) entry,
    • call cholesky.insertColumn(col_index, column).
Source:
Parameters:
Name Type Description
cholesky CholeskyDecomposition

updated in place

allInputs Array.<Array.<number>>

full input matrix (old rows then new rows)

nbNewInputs number

number of trailing rows to add

kernel
diagonalNoise number

the noise STANDARD DEVIATION

addToDiagonal(A, value) → {Array.<Array.<number>>}

Description:
  • Return a copy of A with value added to its diagonal (Aᵢᵢ += value). Does not mutate the input.

Source:
Parameters:
Name Type Description
A Array.<Array.<number>>
value number
Returns:
Type
Array.<Array.<number>>

addVec(a, b) → {Array.<number>}

Description:
  • Element-wise addition a + b.

Source:
Parameters:
Name Type Description
a Array.<number>
b Array.<number>
Returns:
Type
Array.<number>

assert(condition, message)

Source:
Parameters:
Name Type Description
condition boolean
message string

shown when the assertion fails

cholesky(A, epsilonopt) → {Array.<Array.<number>>}

Description:
  • Cholesky decomposition of a symmetric positive-definite matrix A(n×n), returning the lower-triangular factor L such that A = L·Lᵀ.

    Failure (non-positive-definite) behaviour:

    • epsilon === null → throw Error (matches Rust .expect() panic).
    • epsilon a finite positive number → mimic nalgebra Cholesky::new_with_substitute: whenever a diagonal pivot dⱼ ≤ 0, substitute epsilon for that pivot and keep going. If even the substitute fails to keep things real (cannot happen for epsilon > 0), throw.

    Reads only the lower triangle of A (the upper triangle is ignored), matching nalgebra's behaviour of using only the lower-triangular part.

Source:
Parameters:
Name Type Attributes Default Description
A Array.<Array.<number>>
epsilon number | null <optional>
null
Returns:

lower-triangular L

Type
Array.<Array.<number>>

choleskyInverse(L) → {Array.<Array.<number>>}

Description:
  • Compute A⁻¹ = (L·Lᵀ)⁻¹ from the lower-triangular Cholesky factor L, by solving A·X = I. Matches nalgebra Cholesky::inverse.

Source:
Parameters:
Name Type Description
L Array.<Array.<number>>

lower-triangular factor

Returns:

A⁻¹

Type
Array.<Array.<number>>

choleskySolve(L, B) → {Array.<number>|Array.<Array.<number>>}

Description:
  • Solve A·X = B given the lower-triangular Cholesky factor L (A = L·Lᵀ): first solve L·Y = B (forward), then Lᵀ·X = Y (back). Matches nalgebra Cholesky::solve.

Source:
Parameters:
Name Type Description
L Array.<Array.<number>>

lower-triangular factor

B Array.<number> | Array.<Array.<number>>
Returns:
Type
Array.<number> | Array.<Array.<number>>

classifyFeature(feature, result)

Description:
  • 將單一 Feature 依幾何類型分類到結果物件中

Source:
Parameters:
Name Type Description
feature Object

輸入 GeoJSON Feature

result Object

輸入分類結果物件(包含 points、lines、polygons)

columnDot(A, B, c) → {number}

Description:
  • Dot product of column c of A with column c of B (both number[][]).

Source:
Parameters:
Name Type Description
A Array.<Array.<number>>
B Array.<Array.<number>>
c number
Returns:
Type
number

columnNormSquared(M, c) → {number}

Description:
  • Squared Euclidean norm of column c of matrix M (number[][]).

Source:
Parameters:
Name Type Description
M Array.<Array.<number>>
c number
Returns:
Type
number

createEmptyResult() → {Object}

Description:
  • 建立空的分類結果物件

Source:
Returns:

回傳包含 points、lines、polygons 三個空 FeatureCollection 的物件

Type
Object

diagonal(A) → {Array.<number>}

Description:
  • Diagonal of a square (or rectangular) matrix.

Source:
Parameters:
Name Type Description
A Array.<Array.<number>>
Returns:
Type
Array.<number>

dot(a, b) → {number}

Description:
  • Dot product Σ aᵢ·bᵢ.

Source:
Parameters:
Name Type Description
a Array.<number>
b Array.<number>
Returns:
Type
number

ensureRingClosed(ring) → {Array}

Description:
  • 修復 Polygon ring 閉合(首尾座標相同)

Source:
Parameters:
Name Type Description
ring Array

輸入 ring 座標陣列

Returns:

回傳已閉合的 ring 座標陣列

Type
Array

fitAmplitudeVar(outputs) → {number}

Description:
  • Best-guess amplitude = variance of the outputs.

    Matches nalgebra variance(): Σ(yᵢ − mean)² / N (divides by N, the sample count — NOT N−1). Confirmed from nalgebra 0.34.2 statistics.rs (PORT_SPEC §4.1).

Source:
Parameters:
Name Type Description
outputs Array.<number>
Returns:
Type
number

fitBandwidthMean(inputs) → {number}

Description:
  • Rough bandwidth estimate: mean Euclidean distance between distinct samples. Σ_{i<j} ‖xᵢ − xⱼ‖ / (n(n−1)/2)

Source:
Parameters:
Name Type Description
inputs Array.<Array.<number>>
Returns:
Type
number

fixCloseMultiPolygonCoords(coordinates) → {Array}

Description:
  • 修復 MultiPolygon 的所有 ring 閉合

Source:
Parameters:
Name Type Description
coordinates Array

MultiPolygon 的 coordinates(三維陣列)

Returns:

回傳已修復閉合的 coordinates

Type
Array

fixClosePolygonCoords(coordinates) → {Array}

Description:
  • 修復 Polygon 的所有 ring 閉合

Source:
Parameters:
Name Type Description
coordinates Array

Polygon 的 coordinates(二維陣列,每個元素為一個 ring)

Returns:

回傳已修復閉合的 coordinates

Type
Array

fromVector(v, single) → {number|Array.<number>}

Description:
  • Convert an internal result vector back to the user-facing output type.

    single Result Rust analogue (from_dvector)
    true v[0] (number) Vec<f64> impl: assert_eq!(nrows,1); v[0]
    false v.slice() Vec<Vec<f64>> impl: v.iter().cloned().collect()

    Note: predictCovariance always returns number[][] and must NOT call this function (PORT_SPEC §9, §6.7).

Source:
Parameters:
Name Type Description
v Array.<number>

internal result vector

single boolean

true if the original input was a single point

Returns:
Type
number | Array.<number>

gradientMarginalLikelihood(gp) → {Array.<number>}

Description:
  • Computes the gradient of the marginal likelihood for the current value of each parameter. The produced vector contains the gradient per kernel parameter followed by the gradient for the noise parameter.

    Per-parameter formula (optimizer.rs:24): ½ ( alphaᵀ · dp · alpha − trace(K⁻¹ · dp) ) where K = cov(train, train) alpha = K⁻¹ · output dp = ∂K/∂parameter

    Noise gradient (gradient(K, noise) = 2·noise·Id): noise · ( alpha·alpha − trace(K⁻¹) )

Source:
Parameters:
Name Type Description
gp object

GaussianProcess (see module note)

Returns:

length = kernel.nbParameters() + 1 (last entry = noise)

Type
Array.<number>

hypot(a, b) → {number}

Description:
  • Numerically stable sqrt(a² + b²) (matches Rust f64::hypot).

Source:
Parameters:
Name Type Description
a number
b number
Returns:
Type
number

identity(n) → {Array.<Array.<number>>}

Description:
  • n×n identity matrix.

Source:
Parameters:
Name Type Description
n number
Returns:
Type
Array.<Array.<number>>

isSingle(input) → {boolean}

Description:
  • Detect whether input represents a single multidimensional point.

    Rules (mirrors Rust trait dispatch):

    • number[] (all elements are numbers) → true (single point, like Vec<f64>)
    • number[][] (first element is an array) → false (multiple points, like Vec<Vec<f64>>)

    An empty array is treated as multi-point (falsy single, matches the assert_ne!(nb_rows, 0) guard in the Rust Vec<Vec<f64>> impl — empty inputs are rejected upstream anyway).

Source:
Parameters:
Name Type Description
input Array.<number> | Array.<Array.<number>>
Returns:
Type
boolean

lstsqSolve(A, b) → {Array.<number>}

Description:
  • Least-squares solve of min ‖A·x − b‖ (used by LinearPrior.fit). A may be non-square (m×n). Implemented via the normal equations (AᵀA)·x = Aᵀb solved by Cholesky; falls back to a regularized solve if AᵀA is (numerically) singular, approximating SVD-with-threshold-0 well enough for the LinearPrior integration tests.

    Rust uses SVD solve (threshold 0); PORT_SPEC §12.12 permits the normal- equations approximation here.

Source:
Parameters:
Name Type Description
A Array.<Array.<number>>

(m×n)

b Array.<number>

(m)

Returns:

(n)

Type
Array.<number>

makeCholeskyCovMatrix(inputs, kernel, diagonalNoise, epsilonopt) → {CholeskyDecomposition}

Description:
  • Covariance matrix of inputs with diagonal noise², returned as its CholeskyDecomposition.

    cov[i][j] = kernel.kernel(inputs[i], inputs[j]) cov[i][i] += diagonalNoise² (note: the SQUARE of the noise)

    epsilon is forwarded to the Cholesky (null → throw on failure; positive → substitute mode).

Source:
Parameters:
Name Type Attributes Default Description
inputs Array.<Array.<number>>
kernel
diagonalNoise number

the noise STANDARD DEVIATION

epsilon number | null <optional>
null
Returns:
Type
CholeskyDecomposition

makeCovarianceMatrix(m1, m2, kernel) → {Array.<Array.<number>>}

Description:
  • Covariance matrix between rows of m1 and rows of m2 using kernel. out[r][c] = kernel.kernel(m1[r], m2[c]). Shape (m1.length × m2.length).

Source:
Parameters:
Name Type Description
m1 Array.<Array.<number>>
m2 Array.<Array.<number>>
kernel
Returns:
Type
Array.<Array.<number>>

makeGp() → {GaussianProcess}

Description:
  • Helper: build the same simple 1-D GP used by every Rust test (integration.rs::make_gp).

Source:
Returns:
Type
GaussianProcess

makeGradientCovarianceMatrices(inputs, kernel) → {Array.<Array.<Array.<number>>>}

Description:
  • For each kernel hyper-parameter, build the (symmetric) gradient matrix ∂K/∂param. Returns number[][][] of length kernel.nbParameters().

    mats[p][r][c] = mats[p][c][r] = kernel.gradient(inputs[r], inputs[c])[p]

Source:
Parameters:
Name Type Description
inputs Array.<Array.<number>>
kernel
Returns:
Type
Array.<Array.<Array.<number>>>

matMul(A, B) → {Array.<Array.<number>>}

Description:
  • Matrix product A(m×k) · B(k×n) → (m×n).

Source:
Parameters:
Name Type Description
A Array.<Array.<number>>
B Array.<Array.<number>>
Returns:
Type
Array.<Array.<number>>

matSub(A, B) → {Array.<Array.<number>>}

Description:
  • Element-wise matrix subtraction A − B.

Source:
Parameters:
Name Type Description
A Array.<Array.<number>>
B Array.<Array.<number>>
Returns:
Type
Array.<Array.<number>>

matTransposeVec(A, x) → {Array.<number>}

Description:
  • Transposed matrix-vector product Aᵀ(n×m) · x(m) → number. Equivalent to transpose(A)·x without materializing the transpose.

Source:
Parameters:
Name Type Description
A Array.<Array.<number>>

(m×n)

x Array.<number>

(m)

Returns:

(n)

Type
Array.<number>

matVec(A, x) → {Array.<number>}

Description:
  • Matrix-vector product A(m×n) · x(n) → number.

Source:
Parameters:
Name Type Description
A Array.<Array.<number>>
x Array.<number>
Returns:
Type
Array.<number>

mulKernels(k1, k2) → {KernelProd}

Description:
  • Convenience constructor for k1 · k2 (Rust KernelArith Mul operator).

Source:
Parameters:
Name Type Description
k1 object
k2 object
Returns:
Type
KernelProd

mulberry32(seed)

Description:
  • Seedable 32-bit PRNG (mulberry32).

    Returns a closure () => number ∈ [0, 1) that advances the PRNG state on each call. Pass the returned function as the rng argument to standardNormal and MultivariateNormal.sample.

    Example: const rng = mulberry32(42); rng(); // reproducible pseudo-random number

Source:
Parameters:
Name Type Description
seed number

32-bit unsigned integer seed

Returns:

norm(a) → {number}

Description:
  • Euclidean norm sqrt(Σ aᵢ²).

Source:
Parameters:
Name Type Description
a Array.<number>
Returns:
Type
number

normSquared(a) → {number}

Description:
  • Squared Euclidean norm Σ aᵢ².

Source:
Parameters:
Name Type Description
a Array.<number>
Returns:
Type
number

optimizeParameters(gp, maxIter, convergenceFraction, maxTime)

Description:
  • Fit parameters using the ADAM gradient-ascent algorithm.

    Runs for at most maxIter iterations. Stops early if every component of the update step delta is ≤ convergenceFraction in magnitude (no significant progress), or if the runtime exceeds maxTime (milliseconds).

    The noise parameter is fitted in log-scale, since its magnitude matters more than its precise value.

    ADAM constants (optimizer.rs:79): beta1=0.9, beta2=0.999, epsilon=1e-8, learningRate=0.1.

Source:
Parameters:
Name Type Description
gp object
maxIter number
convergenceFraction number
maxTime number

milliseconds

procSpecPolygon(polygonsFC) → {Object}

Description:
  • 處理特殊 Polygon 數據,讓 MapLibre GL JS 可正確渲染

    此函數的設計目的是處理 splitGeoJSON 回傳的 polygons FeatureCollection 中, 含有「多層套疊 ring」的 Polygon / MultiPolygon 數據。

    Leaflet 利用 SVG 的 evenodd fill rule 可直接繪製多層套疊的 ring, 但 MapLibre GL JS 僅依賴 winding order(外環 CCW、洞環 CW)來決定填色/挖洞。 因此,必須將多層套疊結構轉換為符合 RFC 7946 的標準 MultiPolygon 格式。

    處理邏輯:

    1. 遍歷所有 Feature
    2. 對於 Polygon 類型:
      • ring 數量 <= 2 時,使用 flattenMultiPolygon 修正 winding order
      • ring 數量 > 2 時(可能為多層套疊),使用 flattenMultiPolygon 搭配 supposeType='ringStrings' 模式,透過 XOR 運算將套疊結構轉為標準 MultiPolygon
    3. 對於 MultiPolygon 類型:
      • 將每個子 polygon 各自透過 flattenMultiPolygon 處理後合併
    4. 處理完畢後,若 MultiPolygon 只含一個 polygon,降級為 Polygon 類型
    5. 深拷貝輸出,不汙染原始資料
    6. 保留所有 properties
Source:
Example
// 三層套疊 Polygon
let input = {
    type: 'FeatureCollection',
    features: [{
        type: 'Feature',
        properties: { name: '三層' },
        geometry: {
            type: 'Polygon',
            coordinates: [
                [[0, 0], [20, 0], [20, 20], [0, 20], [0, 0]],
                [[4, 4], [16, 4], [16, 16], [4, 16], [4, 4]],
                [[8, 8], [12, 8], [12, 12], [8, 12], [8, 8]],
            ],
        },
    }],
}
let result = procSpecPolygon(input)
console.log(result.features[0].geometry.type) // 'MultiPolygon'
Parameters:
Name Type Description
polygonsFC Object | null

輸入 polygons FeatureCollection(來自 splitGeoJSON 的 polygons 欄位)

Returns:

回傳處理後的 FeatureCollection

Type
Object

processPolygonCoords(coordinates) → {Object}

Description:
  • 處理單一 Polygon 的 coordinates

Source:
Parameters:
Name Type Description
coordinates Array

Polygon 的 coordinates(二維陣列,每個元素為一個 ring)

Returns:

回傳 GeoJSON Geometry 物件(Polygon 或 MultiPolygon)

Type
Object

scaleVec(a, s) → {Array.<number>}

Description:
  • Scalar multiplication s·a.

Source:
Parameters:
Name Type Description
a Array.<number>
s number
Returns:
Type
Array.<number>

scaledGradientMarginalLikelihood(gp)

Description:
  • Returns [scale, gradients]: the optimal scale for the kernel+noise (used to optimize the noise) plus the gradient per kernel parameter (NOT including the noise gradient).

    Per-parameter formula (optimizer.rs:150): ½ ( alphaᵀ · dp · alpha / scale − trace(K⁻¹ · dp) ) scale = outputᵀ · K⁻¹ · output / n NOTE: the data-fit term is divided by scale, unlike the unscaled gradient.

Source:
Parameters:
Name Type Description
gp object
Returns:

scaledOptimizeParameters(gp, maxIter, convergenceFraction, maxTime)

Description:
  • Fit parameters using ADAM gradient ascent; additionally, at each step the kernel and noise are rescaled by the optimal magnitude scale.

    Runs for at most maxIter iterations. Stops early on no significant progress (all deltaconvergenceFraction) or if the runtime exceeds maxTime (milliseconds).

    ADAM constants identical to optimizeParameters.

Source:
Parameters:
Name Type Description
gp object
maxIter number
convergenceFraction number
maxTime number

milliseconds

solveLowerTri(L, B) → {Array.<number>|Array.<Array.<number>>}

Description:
  • Solve L·X = B where L is lower-triangular (forward substitution). B may be a vector (number[]) → solves one RHS, or a matrix (number[][]) → solves column by column (each column is one RHS), returning the same shape. Matches nalgebra solve_lower_triangular.

Source:
Parameters:
Name Type Description
L Array.<Array.<number>>

lower-triangular

B Array.<number> | Array.<Array.<number>>
Returns:
Type
Array.<number> | Array.<Array.<number>>

solveLowerTriVec(L, b) → {Array.<number>}

Description:
  • Forward substitution for a single RHS vector: solve L·x = b.

Source:
Parameters:
Name Type Description
L Array.<Array.<number>>

lower-triangular

b Array.<number>
Returns:
Type
Array.<number>

solveUpperTri(U, B) → {Array.<number>|Array.<Array.<number>>}

Description:
  • Solve U·X = B where U is upper-triangular (back substitution). In friedrich the upper-triangular system is U = Lᵀ. B may be number[] or number[][] (column-wise), returning the same shape.

Source:
Parameters:
Name Type Description
U Array.<Array.<number>>

upper-triangular

B Array.<number> | Array.<Array.<number>>
Returns:
Type
Array.<number> | Array.<Array.<number>>

solveUpperTriVec(U, b) → {Array.<number>}

Description:
  • Back substitution for a single RHS vector: solve U·x = b.

Source:
Parameters:
Name Type Description
U Array.<Array.<number>>

upper-triangular

b Array.<number>
Returns:
Type
Array.<number>

splitAndProcGeoJSON(geoIn) → {Object}

Description:
  • 將任意 GeoJSON 資料拆分為依幾何類型分類的多個 FeatureCollection, 並對其中的 Polygon 數據進行特殊處理(多層套疊 ring 轉換為標準 MultiPolygon)

    此函數結合了 splitGeoJSON 與 procSpecPolygon 的功能:

    1. splitGeoJSON:將混合幾何類型的 GeoJSON 拆分為 points / lines / polygons
    2. procSpecPolygon:將 polygons 中含有多層套疊 ring 的 Polygon/MultiPolygon 轉換為符合 RFC 7946 規範的標準格式,確保 winding order 正確

    此函數設計為方便日後 MapLibre GL JS 渲染使用的一站式前處理函數。

Source:
Example
let input = {
    type: 'FeatureCollection',
    features: [
        { type: 'Feature', properties: { name: 'pt' }, geometry: { type: 'Point', coordinates: [121, 25] } },
        { type: 'Feature', properties: { name: 'ls' }, geometry: { type: 'LineString', coordinates: [[121, 25], [122, 26]] } },
        {
            type: 'Feature',
            properties: { name: '三層' },
            geometry: {
                type: 'Polygon',
                coordinates: [
                    [[0, 0], [20, 0], [20, 20], [0, 20], [0, 0]],
                    [[4, 4], [16, 4], [16, 16], [4, 16], [4, 4]],
                    [[8, 8], [12, 8], [12, 12], [8, 12], [8, 8]],
                ],
            },
        },
    ],
}
let result = splitAndProcGeoJSON(input)
console.log(result.points.features.length)   // 1
console.log(result.lines.features.length)    // 1
console.log(result.polygons.features.length) // 1(polygon 已被處理為 MultiPolygon)
Parameters:
Name Type Description
geoIn Object | String | null

輸入 GeoJSON 資料,可為 FeatureCollection、Feature、裸 Geometry 物件或 JSON 字串

Returns:

回傳分類結果物件,結構為 { points: FeatureCollection, lines: FeatureCollection, polygons: FeatureCollection }

Type
Object

splitGeoJSON(geoIn) → {Object}

Description:
  • 將 GeoJSON 資料拆分成依幾何類型分類的多個 FeatureCollection

    此函數的設計目的是針對 MapLibre GL JS 的 layer type 限制, 將混合不同幾何類型的 GeoJSON 資料預先拆分成:

    • points:包含 Point / MultiPoint 的 FeatureCollection
    • lines:包含 LineString / MultiLineString 的 FeatureCollection
    • polygons:包含 Polygon / MultiPolygon 的 FeatureCollection

    額外處理:

    1. GeometryCollection 會被遞迴拆解成獨立的 Feature,properties 繼承父 Feature
    2. Polygon / MultiPolygon 的 ring 自動修復閉合(首尾座標相同)
    3. 支援多種輸入格式:FeatureCollection、Feature、裸 Geometry、JSON 字串
    4. 深拷貝輸出,不汙染原始資料
    5. 空輸入 / 無效輸入回傳空的分類結果
Source:
Example
// 混合類型 FeatureCollection
let input = {
    type: 'FeatureCollection',
    features: [
        { type: 'Feature', properties: { name: 'pt' }, geometry: { type: 'Point', coordinates: [121, 25] } },
        { type: 'Feature', properties: { name: 'ls' }, geometry: { type: 'LineString', coordinates: [[121, 25], [122, 26]] } },
        { type: 'Feature', properties: { name: 'pg' }, geometry: { type: 'Polygon', coordinates: [[[0, 0], [4, 0], [4, 4], [0, 4], [0, 0]]] } },
    ],
}
let result = splitGeoJSON(input)
console.log(result.points.features.length)   // 1
console.log(result.lines.features.length)    // 1
console.log(result.polygons.features.length) // 1
Parameters:
Name Type Description
geoIn Object | String | null

輸入 GeoJSON 資料,可為 FeatureCollection、Feature、裸 Geometry 物件或 JSON 字串

Returns:

回傳分類結果物件,結構為 { points: FeatureCollection, lines: FeatureCollection, polygons: FeatureCollection }

Type
Object

standardNormal(rng) → {number}

Description:
  • Draw one standard-normal sample N(0,1) using the Box-Muller transform.

    Consumes two uniform draws from rng; retries if the first draw is exactly 0 (to avoid log(0) → -Infinity).

    Note: this uses only the cosine branch of Box-Muller (the sine branch is discarded), matching the PORT_SPEC §3 canonical implementation. Statistical correctness is maintained; the sine branch would give equally valid samples but is not required.

Source:
Parameters:
Name Type Description
rng
Returns:
Type
number

subVec(a, b) → {Array.<number>}

Description:
  • Element-wise subtraction a − b.

Source:
Parameters:
Name Type Description
a Array.<number>
b Array.<number>
Returns:
Type
Array.<number>

toMatrix(input) → {Array.<Array.<number>>}

Description:
  • Normalise any recognised input form to number[][] (one row per sample).

    JS input Rust analogue Result
    [a, b, c] Vec<f64> [[a, b, c]] (1×d)
    [[a,b],[c,d],…] Vec<Vec<f64>> unchanged

    Matches Input::to_dmatrix (both impls):

    • Vec<f64>DMatrix::from_row_slice(1, m.len(), m) — wraps in 1 row.
    • Vec<Vec<f64>>DMatrix::from_fn(nb_rows, nb_cols, |r,c| m[r][c]) — direct.
Source:
Parameters:
Name Type Description
input Array.<number> | Array.<Array.<number>>
Returns:
Type
Array.<Array.<number>>

toVector(output) → {Array.<number>}

Description:
  • Normalise a training-output value to number[].

    JS output Rust analogue Result
    number f64 [v]
    number[] Vec<f64> unchanged

    Matches Input::to_dvector:

    • Vec<f64> impl: DVector::from_element(1, *v) — wraps scalar in 1-element vector.
    • Vec<Vec<f64>> impl: DVector::from_column_slice(v) — direct slice.
Source:
Parameters:
Name Type Description
output number | Array.<number>
Returns:
Type
Array.<number>

trace(A) → {number}

Description:
  • Trace Σ Aᵢᵢ (also used as generic diagonal sum, e.g. trace(A⁻¹)).

Source:
Parameters:
Name Type Description
A Array.<Array.<number>>
Returns:
Type
number

transpose(A) → {Array.<Array.<number>>}

Description:
  • Transpose of A.

Source:
Parameters:
Name Type Description
A Array.<Array.<number>>
Returns:
Type
Array.<Array.<number>>

zeros(m, n) → {Array.<Array.<number>>}

Description:
  • m×n zero matrix.

Source:
Parameters:
Name Type Description
m number
n number
Returns:
Type
Array.<Array.<number>>