bioneuralnet.network.pysmccnet.math_helpers

Functions

binary_search(argu, sumabs)

Finds penalty parameter such that L1 norm of normalized argument equals sumabs.

l2n(vec)

Computes the L2 norm of a vector; returns 0.05 if norm is zero.

r_scale(x)

Numpy scaling using sample standard deviation.

r_scale_torch(x)

Pytorch scaling using sample standard deviation.

r_vec_mult_sum(v1, v2)

Computes element-wise multiplication and sum with vector recycling.

soft(x, d)

Applies soft thresholding to input x with threshold d.

Finds penalty parameter such that L1 norm of normalized argument equals sumabs.

Parameters:
  • argu (np.ndarray | list) – Input vector.

  • sumabs (float) – Target L1 sum constraint.

Returns:

The computed penalty parameter (lambda).

Return type:

float

bioneuralnet.network.pysmccnet.math_helpers.l2n(vec: ndarray | list) float[source]

Computes the L2 norm of a vector; returns 0.05 if norm is zero.

Parameters:

vec (np.ndarray | list) – Input vector.

Returns:

The L2 norm or 0.05 if zero.

Return type:

float

bioneuralnet.network.pysmccnet.math_helpers.r_scale(x: ndarray | list) ndarray[source]

Numpy scaling using sample standard deviation.

Parameters:

x (np.ndarray | list) – Input data matrix.

Returns:

Scaled data where each column has mean 0 and sample std 1.

Return type:

np.ndarray

bioneuralnet.network.pysmccnet.math_helpers.r_scale_torch(x: torch.Tensor | ndarray | list) torch.Tensor[source]

Pytorch scaling using sample standard deviation.

Parameters:

x (torch.Tensor | np.ndarray | list) – Input data; converted to float32 tensor if not already.

Returns:

Centered and scaled data tensor.

Return type:

torch.Tensor

bioneuralnet.network.pysmccnet.math_helpers.r_vec_mult_sum(v1: torch.Tensor | ndarray | list, v2: torch.Tensor | ndarray | list) float[source]

Computes element-wise multiplication and sum with vector recycling.

Parameters:
Returns:

Sum of element-wise product after recycling to matching lengths.

Return type:

float

bioneuralnet.network.pysmccnet.math_helpers.soft(x: ndarray | list | float, d: float) ndarray | float[source]

Applies soft thresholding to input x with threshold d.

Parameters:
  • x (np.ndarray | list | float) – Input data.

  • d (float) – Threshold value.

Returns:

Thresholded output; sign(x) * max(0, abs(x) - d).

Return type:

np.ndarray | float