Numeric
General numerical programming utilities.
It can be imported as:
or
Optimization
covvfit.numeric.OptimizeMultiResult
dataclass
Multi-start optimization result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
ndarray |
array of shape |
required |
fun |
float |
value of the optimized function at |
required |
best |
OptimizeResult |
optimization result (for the best start, yielding |
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 |
required |
n_starts |
int |
number of different starts |
10 |
random_seed |
int |
seed used to perturb |
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 |
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 |