cristal.christoffel module#

Christoffel Function and Growth Detector classes

class cristal.christoffel.BaggingDyCF(n_values, n_estimators=10, **dycf_kwargs)#

Bases: DyCF

Bagging DyCF model.

n_estimators#

The number of DyCF models in the ensemble.

Type:

int

models#

The list of DyCF models in the ensemble.

Type:

list[DyCF]

d#

The dimension of the input data. 0 if not fitted.

Type:

int

__init__(n_values, n_estimators=10, **dycf_kwargs)#

Initialize the BaggingDyCF model.

Parameters:
  • n_values (int | list[int]) – The degree of the polynomial basis or a list of degrees for the DyCF models. If a single integer is provided, it will be used for all models. If a list is provided, its length should match n_estimators, and each model will have a different degree.

  • n_estimators (int, optional) – The number of DyCF models in the ensemble (default is 10).

  • dycf_kwargs (dict, optional) – Additional keyword arguments to pass to the DyCF constructor.

fit(x, n_samples=None)#

Generate n_estimators DyCF models and fit them on the data.

Parameters:
  • x (np.ndarray (N, d)) – The input data to fit the models on.

  • n_samples (int | None, optional) – The number of samples to use for fitting each model. If None or greater than N, all samples are used, by default None.

Returns:

The fitted BaggingDyCF instance.

Return type:

BaggingDyCF

is_fitted()#

Checks if the model is fitted.

Returns:

True if the model is fitted, False otherwise.

Return type:

bool

load_model(model_dict)#

Loads the BaggingDyCF model from a dictionary.

Parameters:

model_dict (dict) –

The dictionary containing the BaggingDyCF model parameters returned by save_model():
  • ”n_values”: list[int], the degrees of the polynomial basis for each DyCF model.

  • ”n_estimators”: int, the number of DyCF models in the ensemble.

  • ”d”: int, the dimension of the input data.

  • ”regularization”: str, the regularization method used.

  • ”C”: float | int, the constant factor used in the regularization.

  • ”regularizer”: float | int | None, the regularization factor.

  • ”models”: list[dict], the saved DyCF models.

Returns:

The loaded BaggingDyCF model with updated parameters.

Return type:

BaggingDyCF

method_name()#

Returns the name of the method.

Return type:

str

Returns:

The name of the method.

Return type:

str

save_model()#

Saves the BaggingDyCF model as a dictionary.

Returns:

The BaggingDyCF model represented as a dictionary, with keys:
  • ”n_values”: list[int], the degrees of the polynomial basis for each DyCF model.

  • ”n_estimators”: int, the number of DyCF models in the ensemble.

  • ”d”: int, the dimension of the input data.

  • ”regularization”: str, the regularization method used.

  • ”C”: float | int, the constant factor used in the regularization.

  • ”regularizer”: float | int | None, the regularization factor.

  • ”models”: list[dict], the saved DyCF models.

Return type:

dict

score_samples(x)#

Computes the outlier scores for the samples in x.

Parameters:

x (np.ndarray (L, d)) – The input data to compute the scores.

Returns:

The outlier scores for each sample.

Return type:

np.ndarray (L,)

update(x, sym=True)#

Update the current model with instances in x.

Parameters:
  • x (np.ndarray (N', d)) – The input data to update the model.

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

Returns:

The updated DyCF instance.

Return type:

DyCF

class cristal.christoffel.DyCF(n, regularization=IMPLEMENTED_REGULARIZATION_OPTIONS.VU_C, C=1, polynomial_basis=IMPLEMENTED_POLYNOMIAL_BASIS.MONOMIALS, inv_opt=IMPLEMENTED_INVERSION_OPTIONS.FPD_INV, incr_opt=IMPLEMENTED_INCREMENTERS_OPTIONS.INVERSE)#

Bases: BaseDetector

Dynamical Christoffel Function

n#

The degree of polynomials, usually set between 2 and 8.

Type:

int

regularization#

The regularization method to use for the score.

Type:

IMPLEMENTED_REGULARIZATION_OPTIONS

C#

The constant factor used in the “vu_C” or “constant” regularization.

Type:

float | int

moments_matrix#

The moments matrix object.

Type:

MomentsMatrix

d#

The dimension of the input data. 0 if not fitted.

Type:

int

regularizer#

The regularization factor computed based on the degree and dimension. None if not fitted.

Type:

float | int | None

__init__(n, regularization=IMPLEMENTED_REGULARIZATION_OPTIONS.VU_C, C=1, polynomial_basis=IMPLEMENTED_POLYNOMIAL_BASIS.MONOMIALS, inv_opt=IMPLEMENTED_INVERSION_OPTIONS.FPD_INV, incr_opt=IMPLEMENTED_INCREMENTERS_OPTIONS.INVERSE)#

Initialize the DyCF model.

Parameters:
decision_function(x)#

Computes the decision function for the samples in x.

Parameters:

x (np.ndarray (L, d)) – The input data to compute the decision function.

Returns:

The decision function values for each sample.

Return type:

np.ndarray (L,)

eval_update(x)#

Evaluates the model on the samples in x and updates it with inliers. This method iterates over each sample in x.

Parameters:

x (np.ndarray (L, d)) – The input data to evaluate and update the model.

Returns:

The decision function values for each sample.

Return type:

np.ndarray (L,)

fit(x)#

Generates a model that fit dataset x.

Parameters:

x (np.ndarray (N, d)) – The input data to fit the model.

Returns:

The fitted model.

Return type:

Self

is_fitted()#

Checks if the model is fitted.

Returns:

True if the model is fitted, False otherwise.

Return type:

bool

load_model(model_dict)#

Loads the DyCF model from a dictionary.

Parameters:

model_dict (dict) –

The dictionary containing the DyCF parameters returned by save_model():
  • ”n”: int, the degree of the polynomial basis.

  • ”regularization”: str, the regularization method used.

  • ”C”: float | int, the constant factor used in the regularization.

  • ”moments_matrix”: dict, the saved moments matrix.

  • ”d”: int, the dimension of the input data.

  • ”regularizer”: float | int | None, the regularization factor.

Returns:

The loaded DyCF instance with updated parameters.

Return type:

DyCF

method_name()#

Returns the name of the method.

Return type:

str

Returns:

The name of the method.

Return type:

str

predict(x)#

Predicts the outlier labels for the samples in x.

Parameters:

x (np.ndarray (L, d)) – The input data to predict the labels.

Returns:

The predicted labels for each sample.

Return type:

np.ndarray (L,)

predict_update(x)#

Predict the model on the samples in x and updates it with inliers.

Parameters:

x (np.ndarray (L, d)) – The input data to evaluate and update the model.

Returns:

The predicted labels for each sample.

Return type:

np.ndarray (L,)

save_model()#

Saves the DyCF model as a dictionary.

Returns:

The DyCF model represented as a dictionary, with keys:
  • ”n”: int, the degree of the polynomial basis.

  • ”regularization”: str, the regularization method used.

  • ”C”: float | int, the constant factor used in the regularization.

  • ”moments_matrix”: dict, the saved moments matrix.

  • ”d”: int, the dimension of the input data.

  • ”regularizer”: float | int | None, the regularization factor.

Return type:

dict

score_samples(x)#

Computes the outlier scores for the samples in x.

Parameters:

x (np.ndarray (L, d)) – The input data to compute the scores.

Returns:

The outlier scores for each sample.

Return type:

np.ndarray (L,)

update(x, sym=True)#

Update the current model with instances in x.

Parameters:
  • x (np.ndarray (N', d)) – The input data to update the model.

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

Returns:

The updated DyCF instance.

Return type:

DyCF

class cristal.christoffel.DyCG(degrees=array([2, 8]), **dycf_kwargs)#

Bases: BaseDetector

Dynamical Christoffel Growth

degrees#

The degrees of at least two DyCF models inside (default is np.array([2, 8]))

Type:

ndarray, optional

models#

The list of DyCF models with different degrees n.

Type:

list[DyCF]

d#

The dimension of the input data. 0 if not fitted.

Type:

int

__init__(degrees=array([2, 8]), **dycf_kwargs)#

Initialize the DyCG model.

Parameters:
  • degrees (np.ndarray, optional) – The degrees of at least two DyCF models inside (default is np.array([2, 8]))

  • dycf_kwargs (dict, optional) – Additional keyword arguments to pass to the DyCF constructor (other than n).

decision_function(x)#

Computes the decision function for the samples in x.

Parameters:

x (np.ndarray (L, d)) – The input data to compute the decision function.

Returns:

The decision function values for each sample.

Return type:

np.ndarray (L,)

eval_update(x)#

Evaluates the model on the samples in x and updates it with inliers. This method iterates over each sample in x.

Parameters:

x (np.ndarray (L, d)) – The input data to evaluate and update the model.

Returns:

The decision function values for each sample.

Return type:

np.ndarray (L,)

fit(x)#

Generates a model that fit dataset x.

Parameters:

x (np.ndarray (N, d)) – The input data to fit the model.

Returns:

The fitted model.

Return type:

Self

is_fitted()#

Checks if the model is fitted.

Returns:

True if the model is fitted, False otherwise.

Return type:

bool

load_model(model_dict)#

Loads the DyCG model from a dictionary.

Parameters:

model_dict (dict) –

The dictionary containing the DyCG model parameters returned by save_model():
  • ”degrees”: list[int], the degrees of the polynomial basis.

  • ”d”: int, the dimension of the input data.

  • ”models”: list[dict], the saved DyCF models.

Returns:

The loaded DyCG model with updated parameters.

Return type:

DyCG

method_name()#

Returns the name of the method.

Return type:

str

Returns:

The name of the method.

Return type:

str

predict(x)#

Predicts the outlier labels for the samples in x.

Parameters:

x (np.ndarray (L, d)) – The input data to predict the labels.

Returns:

The predicted labels for each sample.

Return type:

np.ndarray (L,)

predict_update(x)#

Predict the model on the samples in x and updates it with inliers.

Parameters:

x (np.ndarray (L, d)) – The input data to evaluate and update the model.

Returns:

The predicted labels for each sample.

Return type:

np.ndarray (L,)

save_model()#

Saves the DyCG model as a dictionary.

Returns:

The DyCG model represented as a dictionary, with keys:
  • ”degrees”: list[int], the degrees of the polynomial basis.

  • ”d”: int, the dimension of the input data.

  • ”models”: list[dict], the saved DyCF models.

Return type:

dict

score_samples(x)#

Computes the outlier scores for the samples in x.

Parameters:

x (np.ndarray (L, d)) – The input data to compute the scores.

Returns:

The outlier scores for each sample.

Return type:

np.ndarray (L,)

update(x)#

Updates the current model with instances in x.

Parameters:

x (np.ndarray (N', d)) – The input data to update the model.

Returns:

The updated model.

Return type:

Self