Skip to main content

Module stability_toolkit

Module stability_toolkit 

Source
Expand description

Extended numeric stability toolkit (gradients, error helpers, array-based activations)

§Numeric Stability Toolkit

Extended numeric stability utilities that complement the core stability module.

This module provides:

  • Error helpers: relative_error, absolute_error
  • Compensated summation: convenience wrapper around Kahan accumulation
  • Stable activations: softmax_array, sigmoid_array (ndarray-based)
  • Condition estimation: condition_number_1d for 1-D ratio analysis
  • Numerical differentiation: numerical_gradient with forward/backward/central modes
  • Gradient checking: check_gradient to compare analytical vs numerical gradients

Structs§

GradientCheckResult
Result of a gradient check.

Enums§

DifferenceMode
Mode of finite difference approximation.

Functions§

absolute_error
Absolute error between two values: |a - b|.
check_gradient
Check an analytical gradient against a numerical gradient.
compensated_sum
Compute a compensated (Kahan) sum of a slice.
compensated_sum_array
Compute a compensated (Neumaier) sum of an ndarray view.
condition_number_1d
Estimate a “condition number” for a 1-D array as max(|x|) / min_nonzero(|x|).
log_sum_exp_array
Numerically stable log-sum-exp for an ndarray 1-D array.
max_relative_error
Maximum relative error across all elements.
numerical_gradient
Compute the numerical gradient of a scalar function at point x.
pairwise_sum_array
Pairwise summation for an ndarray view.
relative_error
Relative error between computed and reference: |computed - reference| / |reference|.
relative_errors
Element-wise relative errors between two arrays. Returns Err if the arrays have different lengths.
sigmoid_array
Numerically stable sigmoid for an ndarray 1-D array.
softmax_array
Numerically stable softmax for an ndarray 1-D array.