matchcake.ml package¶
Subpackages¶
- matchcake.ml.kernels package
- Submodules
- matchcake.ml.kernels.fermionic_pqc_kernel module
FermionicPQCKernelFermionicPQCKernel.__init__()FermionicPQCKernel.ansatz()FermionicPQCKernel.available_entangling_mthFermionicPQCKernel.circuit()FermionicPQCKernel.data_scalingFermionicPQCKernel.depthFermionicPQCKernel.initialize_parameters()FermionicPQCKernel.rotationsFermionicPQCKernel.set_predict_request()FermionicPQCKernel.set_transform_request()
StateVectorFermionicPQCKernel
- matchcake.ml.kernels.kernel_utils module
GramMatrixKernelGramMatrixKernel.__init__()GramMatrixKernel.close()GramMatrixKernel.dtypeGramMatrixKernel.fill_diagonal()GramMatrixKernel.is_squareGramMatrixKernel.make_batches_indexes_generator()GramMatrixKernel.mirror()GramMatrixKernel.shapeGramMatrixKernel.sizeGramMatrixKernel.symmetrize()GramMatrixKernel.tril_reflect()GramMatrixKernel.triu_reflect()
mrot_zz_template()
- matchcake.ml.kernels.ml_kernel module
MLKernelMLKernel.__init__()MLKernel.batch_distance()MLKernel.batch_distance_in_sequence()MLKernel.cast_tensor_to_interface()MLKernel.compute_gram_matrix()MLKernel.fit()MLKernel.fit_transform()MLKernel.get_batch_size_for()MLKernel.gram_diagonal_fill()MLKernel.initialize_parameters()MLKernel.make_batches_generator()MLKernel.pairwise_distances()MLKernel.pairwise_distances_in_batch()MLKernel.pairwise_distances_in_sequence()MLKernel.parametersMLKernel.pre_initialize()MLKernel.predict()MLKernel.set_predict_request()MLKernel.set_transform_request()MLKernel.single_distance()MLKernel.sizeMLKernel.transform()
- matchcake.ml.kernels.nif_kernel module
NIFKernelNIFKernel.UNPICKLABLE_ATTRIBUTESNIFKernel.__init__()NIFKernel.batch_distance()NIFKernel.cast_tensor_to_interface()NIFKernel.circuit()NIFKernel.compile_qnode()NIFKernel.draw()NIFKernel.draw_mpl()NIFKernel.fit()NIFKernel.get_n_ops()NIFKernel.get_n_params()NIFKernel.initialize_parameters()NIFKernel.n_opsNIFKernel.n_paramsNIFKernel.pre_initialize()NIFKernel.qnodeNIFKernel.set_predict_request()NIFKernel.set_transform_request()NIFKernel.single_distance()NIFKernel.tapeNIFKernel.wires
- Module contents
- matchcake.ml.optimizer_strategies package
- Submodules
- matchcake.ml.optimizer_strategies.adam_strategy module
- matchcake.ml.optimizer_strategies.adamw_strategy module
- matchcake.ml.optimizer_strategies.genetic_strategy module
- matchcake.ml.optimizer_strategies.optimizer_strategy module
OptimizerStrategyOptimizerStrategy.NAMEOptimizerStrategy.OPTIONAL_HYPERPARAMETERSOptimizerStrategy.REQUIRES_GRADOptimizerStrategy.REQUIRES_HYPERPARAMETERSOptimizerStrategy.__init__()OptimizerStrategy.check_required_hyperparameters()OptimizerStrategy.jac()OptimizerStrategy.optimize()OptimizerStrategy.params_vectorOptimizerStrategy.set_optional_hyperparameters()OptimizerStrategy.set_parameters()OptimizerStrategy.step()OptimizerStrategy.vector_to_parameters()
ScipyOptimizerStrategy
- matchcake.ml.optimizer_strategies.random_strategy module
- matchcake.ml.optimizer_strategies.scipy_strategies module
- matchcake.ml.optimizer_strategies.simulated_annealing_strategy module
SimulatedAnnealingStrategySimulatedAnnealingStrategy.DEFAULT_TEMPERATURESimulatedAnnealingStrategy.NAMESimulatedAnnealingStrategy.OPTIONAL_HYPERPARAMETERSSimulatedAnnealingStrategy.REQUIRES_HYPERPARAMETERSSimulatedAnnealingStrategy.__init__()SimulatedAnnealingStrategy.optimize()SimulatedAnnealingStrategy.set_parameters()SimulatedAnnealingStrategy.step()
- Module contents
- matchcake.ml.parameters_initialisation_strategies package
- Submodules
- matchcake.ml.parameters_initialisation_strategies.linear_strategy module
- matchcake.ml.parameters_initialisation_strategies.parameters_initialisation_strategy module
ParametersInitialisationStrategyParametersInitialisationStrategy.NAMEParametersInitialisationStrategy.OPTIONAL_HYPERPARAMETERSParametersInitialisationStrategy.REQUIRES_HYPERPARAMETERSParametersInitialisationStrategy.__init__()ParametersInitialisationStrategy.add_parameters_to_memory()ParametersInitialisationStrategy.check_required_hyperparameters()ParametersInitialisationStrategy.get_next_parameters()ParametersInitialisationStrategy.initialise_parameters()ParametersInitialisationStrategy.set_optional_hyperparameters()
- matchcake.ml.parameters_initialisation_strategies.random_strategy module
- Module contents
- matchcake.ml.torch_models package
Submodules¶
matchcake.ml.std_estimator module¶
- class matchcake.ml.std_estimator.StdEstimator(**kwargs)¶
Bases:
BaseEstimator- UNPICKLABLE_ATTRIBUTES = []¶
- __init__(**kwargs) None¶
- check_is_fitted()¶
- fit(X, y=None, **kwargs) StdEstimator¶
Fit the model with the given data.
- Parameters:
X – The input data.
y – The target values.
kwargs – Additional arguments.
- Keyword Arguments:
check_X_y – Whether to check the input data and target values. Default is True.
- Returns:
The fitted model.
- property is_fitted¶
- classmethod load(filepath) StdEstimator¶
Load a model from a saved file. If the extension of the file is not specified, this method will try to load the model from the file with the “.joblib” extension. If the file does not exist, it will try to load the model from the file with the “.pkl” extension. Otherwise, it will try without any extension.
- Parameters:
filepath (str) – The path to the saved model.
- Returns:
The loaded model.
- Return type:
- save(filepath) StdEstimator¶
Save the model to a joblib file. If the given filepath does not end with “.joblib”, it will be appended.
- Parameters:
filepath (str) – The path to save the model.
- Returns:
The model instance.
- Return type:
self.__class__
matchcake.ml.svm module¶
- class matchcake.ml.svm.FixedSizeSVC(kernel_cls: Type[MLKernel] | str, kernel_kwargs: dict | None = None, max_gram_size: int | None = inf, cache_size: int = 1024, random_state: int = 0, **kwargs)¶
Bases:
StdEstimator- __init__(kernel_cls: Type[MLKernel] | str, kernel_kwargs: dict | None = None, max_gram_size: int | None = inf, cache_size: int = 1024, random_state: int = 0, **kwargs) None¶
- fit(X, y=None, **kwargs)¶
Fit the model with the given data.
- Parameters:
X – The input data.
y – The target values.
kwargs – Additional arguments.
- Keyword Arguments:
check_X_y – Whether to check the input data and target values. Default is True.
- Returns:
The fitted model.
- get_gram_matrices(X, **kwargs)¶
- get_gram_matrices_from_memory(X, **kwargs)¶
- get_gram_matrix(X)¶
- get_is_in_memory(X)¶
- get_pairwise_distances(x0, x1)¶
- get_pairwise_distances_matrices(x0, x1, **kwargs)¶
- property kernel¶
- property kernel_n_ops¶
- property kernel_n_params¶
- property kernel_size¶
- property n_features¶
- property n_kernels¶
- predict(X, **kwargs)¶
Predict the labels of the input data of shape (n_samples, n_features).
- Parameters:
X (np.ndarray or array-like) – The input data of shape (n_samples, n_features).
kwargs – Additional keyword arguments.
- Keyword Arguments:
cache – If True, the computed gram matrices will be stored in memory. Default is False.
- Returns:
The predicted labels of the input data.
- Return type:
np.ndarray of shape (n_samples,)
- push_to_memory(X, gram_matrices)¶
- score(X, y, **kwargs)¶
- split_data(x, y=None)¶
- class matchcake.ml.svm.SimpleSVC(kernel_cls: Type[MLKernel], kernel_kwargs: dict | None = None, cache_size: int = 1024, random_state: int = 0, **kwargs)¶
Bases:
StdEstimator- __init__(kernel_cls: Type[MLKernel], kernel_kwargs: dict | None = None, cache_size: int = 1024, random_state: int = 0, **kwargs) None¶
- fit(X, y=None, train_gram_matrix=None, **kwargs)¶
Fit the model to the input data of shape (n_samples, n_features). This process involves building the kernel object, computing the gram matrix, and fitting the SVM model. If the train_gram_matrix is provided, the kernel object will not be built and the gram matrix will be used directly.
- Parameters:
X – The input data of shape (n_samples, n_features).
y – The target labels of shape (n_samples,).
train_gram_matrix – The precomputed gram matrix of shape (n_samples, n_samples). This input is optional and is used to avoid recomputing the gram matrix.
kwargs – Additional keyword arguments to be passed to the kernel object and the compute_gram_matrix method.
- Returns:
The fitted model.
- get_gram_matrix_from_memory(X, **kwargs)¶
- get_is_in_memory(X)¶
- predict(X, **kwargs)¶
Predict the labels of the input data of shape (n_samples, n_features).
- Parameters:
X (np.ndarray or array-like) – The input data of shape (n_samples, n_features).
kwargs – Additional keyword arguments.
- Keyword Arguments:
cache – If True, the computed gram matrices will be stored in memory. Default is False.
- Returns:
The predicted labels of the input data.
- Return type:
np.ndarray of shape (n_samples,)
- push_to_memory(X, gram_matrix)¶
- score(X, y, **kwargs)¶
Get the accuracy of the model on the input data.
- Parameters:
X – The input data of shape (n_samples, n_features).
y – The target labels of shape (n_samples,).
kwargs – Additional keyword arguments to be passed to the predict method.
- Returns:
The accuracy of the model on the input data.
- set_fit_request(*, train_gram_matrix: bool | None | str = '$UNCHANGED$') SimpleSVC¶
Request metadata passed to the
fitmethod.Note that this method is only relevant if
enable_metadata_routing=True(seesklearn.set_config()). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline. Otherwise it has no effect.- Parameters:
train_gram_matrix (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
train_gram_matrixparameter infit.- Returns:
self – The updated object.
- Return type:
object
- property train_gram_matrix¶
matchcake.ml.visualisation module¶
- class matchcake.ml.visualisation.ClassificationVisualizer(*, x: ndarray | None = None, x_reduced: ndarray | None = None, x_mesh: ndarray | None = None, reducer: Any | None = None, transform: Callable | None = None, inverse_transform: Callable | None = None, n_pts: int = 1000, seed: int | None = 0, **kwargs)¶
Bases:
Visualizer- __init__(*, x: ndarray | None = None, x_reduced: ndarray | None = None, x_mesh: ndarray | None = None, reducer: Any | None = None, transform: Callable | None = None, inverse_transform: Callable | None = None, n_pts: int = 1000, seed: int | None = 0, **kwargs)¶
- compute_x_mesh(**kwargs)¶
- compute_x_reduced(**kwargs)¶
- gather_transforms(**kwargs)¶
If a transform and an inverse_transform functions are given, they will be returned. Otherwise, the transform and inverse_transform will be inferred from the given reducer. If the reducer is None, then it will be initialized as a PCA with 2 components.
- plot_2d_decision_boundaries(*, y: ndarray | None = None, model: Any | None = None, y_pred: ndarray | None = None, **kwargs)¶
- class matchcake.ml.visualisation.Visualizer¶
Bases:
object