cristal.helper_classes.moment_matrix module#

MomentsMatrix class for computing and storing moments matrix and its inverse.

class cristal.helper_classes.moment_matrix.MomentsMatrix(n, polynomial_basis=IMPLEMENTED_POLYNOMIAL_BASIS.MONOMIALS, inv_opt=IMPLEMENTED_INVERSION_OPTIONS.INV, incr_opt=IMPLEMENTED_INCREMENTERS_OPTIONS.INVERSE)#

Bases: object

Class for computing and storing moments matrix and its inverse.

n#

The degree of the polynomial basis.

Type:

int

polynomial_basis#

The polynomial basis to use.

Type:

str

inv_opt#

The inversion option to use.

Type:

str

incr_opt#

The incrementation option to use.

Type:

str

polynomial_func#

The function to apply the polynomial combinations.

Type:

Callable(np.ndarray, np.ndarray) -> np.ndarray

inv_class#

The class to use for inverting the moments matrix.

Type:

BaseInverter

incr_class#

The class to use for incrementing the inverse moments matrix.

Type:

BaseIncrementer

monomials_matrix#

The monomials matrix used for computing the moments matrix. None if not fitted.

Type:

np.ndarray | None

moments_matrix#

The moments matrix. None if not fitted.

Type:

np.ndarray | None

inverse_moments_matrix#

The inverse moments matrix. None if not fitted.

Type:

np.ndarray | None

N#

The number of points integrated in the moments matrix.

Type:

int

__init__(n, polynomial_basis=IMPLEMENTED_POLYNOMIAL_BASIS.MONOMIALS, inv_opt=IMPLEMENTED_INVERSION_OPTIONS.INV, incr_opt=IMPLEMENTED_INCREMENTERS_OPTIONS.INVERSE)#

Initialize the MomentsMatrix.

Parameters:
  • n (int) – The degree of the polynomial basis.

  • polynomial_basis (IMPLEMENTED_POLYNOMIAL_BASIS, optional) – The polynomial basis to use, by default IMPLEMENTED_POLYNOMIAL_BASIS.MONOMIALS

  • inv_opt (IMPLEMENTED_INVERSION_OPTIONS, optional) – The inversion option to use, by default IMPLEMENTED_INVERSION_OPTIONS.INV

  • incr_opt (IMPLEMENTED_INCREMENTERS_OPTIONS, optional) – The incrementation option to use, by default IMPLEMENTED_INCREMENTERS_OPTIONS.INVERSE

copy()#

Create a copy of the MomentsMatrix instance.

Return type:

Self

Returns:

A copy of the MomentsMatrix instance.

Return type:

Self

fit(x)#

Construct the moments matrix and its inverse from the input data.

Return type:

Self

Parameters:

x (np.ndarray (N, d)) – The input data.

Returns:

The fitted MomentsMatrix instance.

Return type:

Self

is_fitted()#

Check if the MomentsMatrix is fitted.

Return type:

bool

Returns:

True if the MomentsMatrix is fitted, False otherwise.

Return type:

bool

load_model(model_dict)#

Load the model parameters from a dictionary.

Return type:

Self

Parameters:

model_dict (dict) – The dictionary containing the model parameters, with keys: - “n”: int, the degree of the polynomial basis - “polynomial_basis”: str, the polynomial basis used - “inv_opt”: str, the inversion option used - “incr_opt”: str, the incrementation option used - “monomials_matrix”: list[list[float]] | None, the monomials matrix - “moments_matrix”: list[list[float]] | None, the moments matrix - “inverse_moments_matrix”: list[list[float]] | None, the inverse moments matrix - “N”: int, the number of points integrated in the moments matrix

Returns:

The updated MomentsMatrix instance.

Return type:

Self

save_model()#

Save the MomentsMatrix model as a dictionary.

Return type:

dict[str, Any]

Returns:

The MomentsMatrix model represented as a dictionary, with keys: - “n”: int, the degree of the polynomial basis - “polynomial_basis”: str, the polynomial basis used - “inv_opt”: str, the inversion option used - “incr_opt”: str, the incrementation option used - “monomials_matrix”: list[list[float]] | None, the monomials matrix - “moments_matrix”: list[list[float]] | None, the moments matrix - “inverse_moments_matrix”: list[list[float]] | None, the inverse moments matrix - “N”: int, the number of points integrated in the moments matrix

Return type:

dict

score_samples(x)#

Compute the score for each sample in the input data.

Return type:

ndarray

Parameters:

x (np.ndarray (L, d)) – The input data.

Returns:

The scores for each sample.

Return type:

np.ndarray (L,)

update(x, sym=True)#

Update the inverse of the moments matrix with new data.

Return type:

MomentsMatrix

Parameters:
  • x (np.ndarray (N', d)) – The new input data.

  • sym (bool, optional) – Whether the inverse of the moments matrix should be considered as symmetric, by default True

Returns:

The updated MomentsMatrix instance.

Return type:

MomentsMatrix