示例#1
0
def test_fit_1():
    """
    This function tests the first way of preparing for fitting the neural network: 
    Compounds are created from xyz files and the energies are stored in the estimator.
    The fit method is called with the indices of the molecules we want to fit.
    """

    test_dir = os.path.dirname(os.path.realpath(__file__))

    filenames = glob.glob(test_dir + "/CN_isobutane/*.xyz")
    energies = np.loadtxt(test_dir + '/CN_isobutane/prop_kjmol_training.txt',
                          usecols=[1])
    filenames.sort()

    available_representations = [
        'sorted_coulomb_matrix', 'unsorted_coulomb_matrix', 'bag_of_bonds',
        'slatm'
    ]

    for rep in available_representations:
        estimator = MRMP(representation=rep)
        estimator.generate_compounds(filenames[:100])
        estimator.set_properties(energies[:100])
        estimator.generate_representation()

        idx = np.arange(0, 100)
        estimator.fit(idx)
示例#2
0
文件: MRMP_1.py 项目: charnley/qml
                      '/../test/CN_isobutane/prop_kjmol_training.txt',
                      usecols=[1])
filenames.sort()

## ------------- ** Setting up the estimator ** ---------------

estimator = MRMP(representation='slatm',
                 representation_params={
                     'slatm_dgrid2': 0.06,
                     'slatm_dgrid1': 0.06
                 })

estimator.generate_compounds(filenames[:100])
estimator.set_properties(energies[:100])

estimator.generate_representation()

##  ------------- ** Fitting to the data ** ---------------

idx = np.arange(0, 100)

estimator.fit(idx)

##  ------------- ** Predicting and scoring ** ---------------

score = estimator.score(idx)

print("The mean absolute error is %s kJ/mol." % (str(-score)))

energies_predict = estimator.predict(idx)