Exemplo n.º 1
0
    def test_load(self):
        """Function to test loading a pre-generated model."""
        train_features, train_targets, test_features, test_targets = get_data()

        self.make_test(train_features, train_targets, test_features,
                       test_targets)

        new_gp = io.read(filename='test-model', ext='pkl')

        pred = new_gp.predict(test_fp=test_features,
                              test_target=test_targets,
                              get_validation_error=True,
                              get_training_error=True)

        self.assertTrue(
            np.allclose(pred['validation_error']['rmse_all'],
                        self.original['validation_error']['rmse_all']))

        gp = io.read(filename='test-model', ext='hdf5')

        pred = gp.predict(test_fp=test_features,
                          test_target=test_targets,
                          get_validation_error=True,
                          get_training_error=True)

        self.assertTrue(
            np.allclose(pred['validation_error']['rmse_all'],
                        self.original['validation_error']['rmse_all']))

        os.remove('{}/test-model.pkl'.format(wkdir))
        os.remove('{}/test-model.hdf5'.format(wkdir))
Exemplo n.º 2
0
import numpy as np

from sklearn.impute import SimpleImputer

import ase.atoms

from catlearn.fingerprint.adsorbate_prep import autogen_info
from catlearn.fingerprint.setup import FeatureGenerator, default_fingerprinters
from catlearn.regression.gpfunctions import io as gp_io

model_fname = 'apps/catlearn/models/metals_catlearn_gp'
clean_index_name = 'apps/catlearn/train_data/metals_clean_index.npy'
clean_mean = 'apps/catlearn/train_data/metals_clean_feature_mean.npy'

# Load pickled Gaussian process regression model.
gp = gp_io.read(model_fname)


def predict_catkit_demo(images):
    """Return a prediction of adsorption energies for structures generated with
    CatKitDemo.

    Parameters
    ----------
    images : list
        List of atoms objects representing adsorbate-surface structures.
    model : str
        Path and filename of Catlearn model pickle.
    """
    model_ref = {'H': 'H2', 'O': 'H2O, H2', 'C': 'CH4, H2'}
def _get_model():
    """Load the generated model."""
    model = gp_io.read('apps/catlearn/models/catapp_catlearn_gp')
    return model