Utilities (bellman_filter_dfsv.utils)

This module provides utility functions for analysis and JAX helpers.

Analysis (bellman_filter_dfsv.utils.analysis)

Analysis utilities for DFSV models.

Provides accuracy metrics for comparing true and estimated values.

bellman_filter_dfsv.utils.analysis.calculate_accuracy(true_values, estimated_values)[source]

Calculate RMSE and correlation between true and estimated values.

Parameters:
  • true_values – Ground truth array (T, K) or (T,).

  • estimated_values – Estimated array (T, K) or (T,).

Returns:

Tuple of (rmse, correlation), each np.ndarray of shape (K,).

JAX Helpers (bellman_filter_dfsv.utils.jax_helpers)

Helper functions for JAX operations, particularly for safe probability distributions.

bellman_filter_dfsv.utils.jax_helpers.safe_inverse_gamma_logpdf(x: Array, alpha: float, beta: float) Array[source]

Computes the log probability density function of the Inverse-Gamma distribution with safety checks for the input x.

Parameters:
  • x – The value(s) at which to evaluate the log PDF (must be positive).

  • alpha – The shape parameter (must be positive).

  • beta – The scale parameter (must be positive).

Returns:

The log PDF value(s), replacing NaN/Inf with a large negative number.

bellman_filter_dfsv.utils.jax_helpers.safe_norm_logpdf(x: Array, loc: float | Array, scale: float | Array) Array[source]

Computes the log probability density function of the Normal distribution with safety checks for the scale parameter.

Parameters:
  • x – The value(s) at which to evaluate the log PDF.

  • loc – The mean of the distribution.

  • scale – The standard deviation of the distribution.

Returns:

The log PDF value(s), replacing NaN/Inf with a large negative number.