The penalties_cmhn submodule#

This module contains penalties used during training for regularization.

mhn.training.penalties_cmhn.build_regularized_gradient_func(gradient_and_score_function: ~typing.Callable, penalty_derivative: ~typing.Callable = <function l1_>) Callable#

Wraps a gradient-and-score function to include regularization gradient.

Parameters:
  • gradient_and_score_function (Callable) – Function that computes gradient and score.

  • penalty_derivative (Callable, optional) – Regularization penalty derivative function. Defaults to l1_.

Returns:

Regularized gradient function.

Return type:

Callable

mhn.training.penalties_cmhn.build_regularized_score_func(gradient_and_score_function: ~typing.Callable, penalty_function: ~typing.Callable = <function l1>) Callable#

Wraps a gradient-and-score function to include regularization.

Parameters:
  • gradient_and_score_function (Callable) – Function that computes gradient and score.

  • penalty_function (Callable, optional) – Regularization penalty function. Defaults to l1.

Returns:

Regularized score function.

Return type:

Callable

mhn.training.penalties_cmhn.l1(theta: ndarray, eps: float = 1e-05) float#

Computes the L1 penalty. Base rates are not penalized.

Parameters:
  • theta (np.ndarray) – Input array representing model parameters.

  • eps (float, optional) – Small value to avoid division by zero. Defaults to 1e-05.

Returns:

Computed L1 penalty.

Return type:

float

mhn.training.penalties_cmhn.l1_(theta: ndarray, eps: float = 1e-05) ndarray#

Computes the derivative of the L1 penalty.

Parameters:
  • theta (np.ndarray) – Input array representing model parameters.

  • eps (float, optional) – Small value to avoid division by zero. Defaults to 1e-05.

Returns:

Gradient of the L1 penalty with respect to theta.

Return type:

np.ndarray

mhn.training.penalties_cmhn.l2(theta: ndarray) float#

Computes the L2 penalty. Base rates are not penalized.

Parameters:

theta (np.ndarray) – Input array representing model parameters.

Returns:

Computed L2 penalty.

Return type:

float

mhn.training.penalties_cmhn.l2_(theta: ndarray) ndarray#

Computes the derivative of the L2 penalty.

Parameters:

theta (np.ndarray) – Input array representing model parameters.

Returns:

Gradient of the L2 penalty with respect to theta.

Return type:

np.ndarray

mhn.training.penalties_cmhn.sym_sparse(theta: ndarray, eps: float = 1e-05) float#

Computes a penalty that induces sparsity and soft symmetry.

Parameters:
  • theta (np.ndarray) – Input array representing model parameters.

  • eps (float, optional) – Small value to avoid division by zero. Defaults to 1e-05.

Returns:

Computed penalty.

Return type:

float

mhn.training.penalties_cmhn.sym_sparse_deriv(theta: ndarray, eps: float = 1e-05) ndarray#

Computes the derivative of the sparsity and symmetry penalty.

Parameters:
  • theta (np.ndarray) – Input array representing parameters.

  • eps (float, optional) – Small value to avoid division by zero. Defaults to 1e-05.

Returns:

Gradient of the sym_sparse penalty.

Return type:

np.ndarray