Skip to content

Numeric

General numerical programming utilities.

It can be imported as:

from covvfit import numeric

or

import covvfit

covvfit.numeric.some_function()

Optimization

covvfit.numeric.OptimizeMultiResult dataclass

Multi-start optimization result.

Parameters:

Name Type Description Default
x ndarray

array of shape (dim,) representing minimum found

required
fun float

value of the optimized function at x

required
best OptimizeResult

optimization result (for the best start, yielding x)

required
runs list

all the optimization results (for all starts)

required

covvfit.numeric.jax_multistart_minimize(loss_fn, theta0, n_starts=10, random_seed=42, maxiter=10000)

Multi-start gradient-based minimization.

Parameters:

Name Type Description Default
loss_fn

loss function to be optimized

required
theta0 ndarray

vector of shape (dim,) providing an example starting point

required
n_starts int

number of different starts

10
random_seed int

seed used to perturb theta0

42
maxiter int

maximum number of iterations per run

10000

Returns:

Type Description
result

OptimizeMultiResult with the optimization information

Matrix operations

covvfit.numeric.log_matrix(a, threshold=1e-07)

Takes the logarithm of the entries, in a numerically stable manner. I.e., replaces values smaller than threshold with minimum value for the provided data type.

Parameters:

Name Type Description Default
a Float[Array, '*shape']

matrix which entries should be logarithmied

required
threshold float

threshold used when to not calculate the logarithm

1e-07

Returns:

Type Description
log_a

matrix with logarithmied entries

covvfit.numeric.log1mexp(x)

Computes log(1 - exp(x)) in a numerically stable way.

Parameters:

Name Type Description Default
x Float[Array, '*shape']

array

required

Returns:

Type Description
log1mexp(x)

array of the same shape as x

covvfit.numeric.logsumexp_excluding_column(y, axis=-1)

Compute logsumexp across the given axis for each element, excluding the 'current' element at that axis index.

Parameters:

Name Type Description Default
y Float[Array, '*batch variants']

An array of shape [..., variants, ...].

required
axis int

The axis along which we exclude each index before computing logsumexp.

-1

Returns:

Type Description
Float[Array, '*batch variants']

An array of the same shape as y, whose element at index i along axis is the log-sum-exp of all other entries (j != i).