pyvallocation.utils.validation module

pyvallocation.utils.validation.check_non_negativity(array, tolerance=1e-09)[source]

Check if all elements in the array are non-negative within a tolerance.

Parameters:
  • array – Array to test.

  • tolerance – Allowed negative tolerance.

Returns:

boolTrue if all entries are non-negative within tolerance.

Parameters:
  • array (numpy.ndarray)

  • tolerance (float)

Return type:

bool

pyvallocation.utils.validation.check_weights_sum_to_one(weights, tolerance=1e-06)[source]

Check if weights sum approximately to one within a tolerance.

Parameters:
  • weights – Weight vector.

  • tolerance – Absolute tolerance around 1.0.

Returns:

boolTrue if weights sum to one within tolerance.

Parameters:
  • weights (numpy.ndarray)

  • tolerance (float)

Return type:

bool

pyvallocation.utils.validation.ensure_psd_matrix(matrix, jitter=1e-08)[source]

Ensure a matrix is PSD by adding jitter to the diagonal if necessary.

Parameters:
  • matrix – Square matrix to regularize.

  • jitter – Diagonal jitter added when PSD fails.

Returns:

np.ndarray – PSD-adjusted matrix.

Parameters:
  • matrix (numpy.ndarray)

  • jitter (float)

Return type:

numpy.ndarray

pyvallocation.utils.validation.is_psd(matrix, tolerance=1e-08)[source]

Check if a matrix is positive semi-definite (PSD) within a tolerance.

Parameters:
  • matrix – Square matrix to test.

  • tolerance – Numerical tolerance for symmetry and eigenvalues.

Returns:

boolTrue if the matrix is PSD.

Parameters:
  • matrix (numpy.ndarray)

  • tolerance (float)

Return type:

bool