NDWasmOptimize

Namespace

NDWasmOptimize

Description:
  • Namespace for Optimization functions using Go WASM.

Source:

Methods

(static) linearRegression(x, y) → {Object}

Description:
  • Fits a simple linear regression model: Y = alpha + beta*X.

Source:
Parameters:
Name Type Description
x NDArray

The independent variable (1D NDArray of float64).

y NDArray

The dependent variable (1D NDArray of float64).

Throws:

If WASM runtime is not loaded or inputs are invalid.

Type
Error
Returns:
  • An object containing the intercept (alpha) and slope (beta) of the fitted line.
Type
Object

(static) linprog(c, G, h, A, b, bounds) → {Object}

Description:
  • Provides Optimization capabilities by wrapping Go WASM functions. minimize cᵀ * x s.t G * x <= h A * x = b lower <= x <= upper

Source:
Parameters:
Name Type Description
c NDArray

Coefficient vector for the objective function (1D NDArray of float64).

G NDArray | null

Coefficient matrix for inequality constraints (2D NDArray of float64).

h NDArray | null

Right-hand side vector for inequality constraints (1D NDArray of float64).

A NDArray | null

Coefficient matrix for equality constraints (2D NDArray of float64).

b NDArray | null

Right-hand side vector for equality constraints (1D NDArray of float64).

bounds Array

Optional variable bounds as an array of [lower, upper] pairs. Use null for unbounded. [0, null] for all for default.

Throws:

If WASM runtime is not loaded or inputs are invalid.

Type
Error
Returns:
  • The optimization result.
Type
Object

(static) minimize(func, x0, optionsopt) → {Object}

Description:
  • Finds the minimum of a scalar function of one or more variables using an L-BFGS optimizer.

Source:
Parameters:
Name Type Attributes Description
func function

The objective function to be minimized. It must take a 1D Float64Array x (current point) and return a single number (the function value at x).

x0 NDArray

The initial guess for the optimization (1D NDArray of float64).

options Object <optional>

Optional parameters.

Properties
Name Type Attributes Description
grad function <optional>

The gradient of the objective function. Must take x (a 1D Float64Array) and write the result into the second argument grad_out (a 1D Float64Array). This function should not return a value.

Returns:

The optimization result.

Type
Object

(static) ode15s(odefun, tspan, y0, options)

Source:
Parameters:
Name Type Description
odefun function

(t, y, f_out, m_out)

tspan Array | NDArray

[t0, tfinal]

y0 Array | NDArray

Initial state

options Object

{absTol, relTol, initialStep, hasM, jac}

Properties
Name Type Description
jac: number

(t, y, f, index_out, val_out) => returns nnz (number of non-zeros) - index_out: NDArray of int32 with shape [max_nnz, 2] - val_out: NDArray of float64 with shape [max_nnz]

hasM boolean

Whether the ODE function uses the mass matrix M (i.e. M*dy/dt = f(t,y))

absTol number

Absolute tolerance for ODE solver

relTol number

Relative tolerance for ODE solver

maxStep number

Maximum number of steps for ODE solver

maxTime number

Maximum time for ODE solver in milliseconds

(static) ode45(odefun, tspan, y0, options)

Source:
Parameters:
Name Type Description
odefun function

(t, y, f_out, m_out)

tspan Array | NDArray

[t0, tfinal]

y0 Array | NDArray

Initial state

options Object

{absTol, relTol, initialStep, hasM, jac}

Properties
Name Type Description
jac: number

(t, y, f, index_out, val_out) => returns nnz (number of non-zeros) - index_out: NDArray of int32 with shape [max_nnz, 2] - val_out: NDArray of float64 with shape [max_nnz]

hasM boolean

Whether the ODE function uses the mass matrix M (i.e. M*dy/dt = f(t,y))

absTol number

Absolute tolerance for ODE solver

relTol number

Relative tolerance for ODE solver

maxStep number

Maximum number of steps for ODE solver

maxTime number

Maximum time for ODE solver in milliseconds

(static) odeSolve(odefun, tspan, y0, options)

Source:
Parameters:
Name Type Description
odefun function

(t, y, f_out, m_out)

tspan Array | NDArray

[t0, tfinal]

y0 Array | NDArray

Initial state

options Object

{absTol, relTol, initialStep, method: 'ode45'|'ode15s', hasM, jac}

Properties
Name Type Description
jac: number

(t, y, f, index_out, val_out) => returns nnz (number of non-zeros) - index_out: NDArray of int32 with shape [max_nnz, 2] - val_out: NDArray of float64 with shape [max_nnz]

hasM boolean

Whether the ODE function uses the mass matrix M (i.e. M*dy/dt = f(t,y))

absTol number

Absolute tolerance for ODE solver

relTol number

Relative tolerance for ODE solver

maxStep number

Maximum number of steps for ODE solver

maxTime number

Maximum time for ODE solver in milliseconds

(static) pdepe(m, pdefun, icfun, bcfun, xmesh, tspan, options) → {NDArray|null}

Description:
  • Solve 1D Parabolic and Elliptic PDEs using the method of lines with an underlying ODE15s integrator.

Source:
Parameters:
Name Type Description
m number

Symmetry parameter: 0 (slab), 1 (cylinder), 2 (sphere)

pdefun function

(x, t, u, dudx, c_out, f_out, s_out)

icfun function

(x) => returns initial conditions as Array or NDArray

bcfun function

(xl, ul, xr, ur, t, pl_out, ql_out, pr_out, qr_out)

xmesh Array | NDArray

Spatial grid points [x0, ..., xN]

tspan Array | NDArray

Time output points [t0, ..., tM]

options Object

{absTol: 1e-5, relTol: 1e-4}

Properties
Name Type Description
absTol number

Absolute tolerance for ODE solver

relTol number

Relative tolerance for ODE solver

maxStep number

Maximum number of steps for ODE solver

maxTime number

Maximum time for ODE solver in milliseconds

estimateError boolean

Whether to return an error estimate

estimatedError boolean

The returned error estimate (if options.estimateError is true) will be a 2D tensor of shape [length(xmesh), dim] containing the estimated local truncation error at each point in space.

Returns:

3D Tensor of shape [length(tspan), length(xmesh), dim]

Type
NDArray | null

(static) polyfit(x, y, degree) → {Float64Array}

Description:
  • Fits a polynomial of the specified degree to a set of 2D points using least squares. Model: Y = c0 + c1X + c2X^2 + ... + cd*X^d

Source:
Parameters:
Name Type Description
x NDArray

The independent variable (1D NDArray of float64).

y NDArray

The dependent variable (1D NDArray of float64).

degree number

The degree of the polynomial to fit (non-negative integer).

Throws:

If WASM runtime is not loaded, inputs are invalid, or degree is negative.

Type
Error
Returns:
  • An array of coefficients in ascending order of degree [c0, c1, ..., cd].
Type
Float64Array