asaplib.fit package

Submodules

asaplib.fit.base module

Base class for regressions

class asaplib.fit.base.RegressorBase[source]

Bases: sklearn.base.BaseEstimator, sklearn.base.RegressorMixin

Base class for regressions contains generic methods for computing errors

fit(X, y)[source]

method specific

fit_predict(X, y, X_test)[source]

Train the ridge regression model with the design matrix and trainLabel. :param X: :type X: array-like, shape=[n_descriptors, n_samples] :param Input points.: :param y: :type y: array-like, shape=[n_samples] :param Input points.: :param X_test: :type X_test: array-like, shape=[n_descriptors, n_test_samples] :param Input points.:

fit_predict_error(X, y, X_test, y_test)[source]

Train the ridge regression model with the design matrix and trainLabel. and does prediction on test samples, and compute the error :param X: :type X: array-like, shape=[n_descriptors, n_samples] :param Input points.: :param y: :type y: array-like, shape=[n_samples] :param Input points.: :param X_test: :type X_test: array-like, shape=[n_descriptors, n_test_samples] :param Input points.:

get_name()[source]
get_params(deep=True)[source]

Get parameters for this estimator.

Parameters

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns

params – Parameter names mapped to their values.

Return type

mapping of string to any

get_train_test_error(X_train, y_train, X_test, y_test, verbose=True, return_pred=True)[source]

train the model, and get the test error

loads(state)[source]
pack()[source]
predict(X, y)[source]

method specific

predict_error(X, y)[source]

compute the score of the predictions compared with the true values :param X: :type X: array-like, shape=[n_descriptors, n_samples] :param Input points.: :param y: :type y: array-like, shape=[n_samples] :param Input points.:

set_params(deep=True)[source]

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters

**params (dict) – Estimator parameters.

Returns

self – Estimator instance.

Return type

object

unpack(state)[source]

asaplib.fit.getscore module

Functions for assessing the quality of the fits

class asaplib.fit.getscore.LC_SCOREBOARD(train_sizes)[source]

Bases: object

add_score(Ntrain, score)[source]
dump_all()[source]
fetch(sc_name='RMSE')[source]
fetch_all()[source]
plot_learning_curve(sc_name='RMSE')[source]

plot the learning curve

asaplib.fit.getscore.get_mae(ypred, y)[source]
asaplib.fit.getscore.get_r2(y_pred, y)[source]
asaplib.fit.getscore.get_rmse(ypred, y)[source]
asaplib.fit.getscore.get_score(ypred, y)[source]
asaplib.fit.getscore.get_spearman(ypred, y)[source]
asaplib.fit.getscore.get_sup(ypred, y)[source]

asaplib.fit.krr module

NOTE: These methods operate directly on the kernel matrix!!! some functions are adapted from Felix Musil’s ml_tools

class asaplib.fit.krr.KRR(jitter)[source]

Bases: asaplib.fit.base.RegressorBase

fit(kernel, y, kNM=[])[source]

Train the krr model with trainKernel and trainLabel.

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns

params – Parameter names mapped to their values.

Return type

mapping of string to any

loads(state)[source]
pack()[source]
predict(kernel)[source]

kernel.shape is expected as (nPred, nTrain)

predict_uncertainty(k, delta)[source]

k.shape is expected as (nPred, nTrain), delta is the variance of y

set_params(params, deep=True)[source]

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters

**params (dict) – Estimator parameters.

Returns

self – Estimator instance.

Return type

object

unpack(state)[source]
class asaplib.fit.krr.KRRFastCV(jitter, delta, cv)[source]

Bases: asaplib.fit.base.RegressorBase

taken from: An, S., Liu, W., & Venkatesh, S. (2007). Fast cross-validation algorithms for least squares support vector machine and kernel ridge regression. Pattern Recognition, 40(8), 2154-2162. https://doi.org/10.1016/j.patcog.2006.12.015

fit(kernel, y, kNM=[])[source]

Fast cv scheme. Destroy kernel.

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns

params – Parameter names mapped to their values.

Return type

mapping of string to any

loads(state)[source]
pack()[source]
predict(kernel=None)[source]

method specific

set_params(params, deep=True)[source]

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters

**params (dict) – Estimator parameters.

Returns

self – Estimator instance.

Return type

object

unpack(state)[source]
class asaplib.fit.krr.KRRSparse(jitter, delta, sigma)[source]

Bases: asaplib.fit.base.RegressorBase

fit(kMM, y, kNM)[source]

N train structures, M sparsified representative structures

fit_predict(kMM, kNM, y, kNM_test)[source]

Train the ridge regression model with the design matrix and trainLabel. :param X: :type X: array-like, shape=[n_descriptors, n_samples] :param Input points.: :param y: :type y: array-like, shape=[n_samples] :param Input points.: :param X_test: :type X_test: array-like, shape=[n_descriptors, n_test_samples] :param Input points.:

fit_predict_error(kMM, kNM, y, kNM_test, y_test)[source]

Train the ridge regression model with the design matrix and trainLabel. and does prediction on test samples, and compute the error :param X: :type X: array-like, shape=[n_descriptors, n_samples] :param Input points.: :param y: :type y: array-like, shape=[n_samples] :param Input points.: :param X_test: :type X_test: array-like, shape=[n_descriptors, n_test_samples] :param Input points.:

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns

params – Parameter names mapped to their values.

Return type

mapping of string to any

loads(state)[source]
pack()[source]
predict(kNM)[source]

kNM: the kernel matrix between the representative and the new structures with shape (N,M)

set_params(params, deep=True)[source]

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters

**params (dict) – Estimator parameters.

Returns

self – Estimator instance.

Return type

object

unpack(state)[source]

asaplib.fit.ridgeregression module

class asaplib.fit.ridgeregression.RidgeRegression(jitter)[source]

Bases: asaplib.fit.base.RegressorBase

fit(X, y)[source]

Train the ridge regression model with the design matrix and trainLabel. :param X: :type X: array-like, shape=[n_descriptors, n_samples] :param Input points.: :param y: :type y: array-like, shape=[n_samples] :param Input points.:

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns

params – Parameter names mapped to their values.

Return type

mapping of string to any

loads(state)[source]
pack()[source]
predict(X)[source]

desc.shape is expected as [n_descriptors, n_samples]

set_params(params, deep=True)[source]

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters

**params (dict) – Estimator parameters.

Returns

self – Estimator instance.

Return type

object

unpack(state)[source]

asaplib.fit.sparse_krr_wrapper module

Tools for performing sparse kernel ridge regression of design matrices using sparse KRR NOTE: this class operate directly on design matrices. for methods handingly kmatrix, see ./krr.py

class asaplib.fit.sparse_krr_wrapper.SPARSE_KRR_Wrapper(kernel, krr_obj, sparse_mode='fps', n_sparse=None)[source]

Bases: asaplib.fit.base.RegressorBase

fit(X, y)[source]

Train the krr model with the design matrix and trainLabel. :param X: :type X: array-like, shape=[n_descriptors, n_samples] :param Input points.: :param y: :type y: array-like, shape=[n_samples] :param Input points.:

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns

params – Parameter names mapped to their values.

Return type

mapping of string to any

loads(state)[source]
pack()[source]
predict(X)[source]

desc.shape is expected as [n_descriptors, n_samples]

set_params(params, deep=True)[source]

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters

**params (dict) – Estimator parameters.

Returns

self – Estimator instance.

Return type

object

unpack(state)[source]

Module contents