예제 #1
0
def predictE(atoms_train,
             atoms_predict,
             featureCalculator,
             feature_filename,
             eta=1):

    Etrain = np.array([a.get_potential_energy() for a in atoms_train])

    try:
        features = np.load(feature_filename + '.npy')
    except IOError:
        features = featureCalculator.get_featureMat(atoms_train,
                                                    show_progress=True)
        np.save(feature_filename, features)

    # Apply eta
    Nbins1 = featureCalculator.Nbins1
    Nbondtypes_2body = len(featureCalculator.bondtypes_2body)
    if featureCalculator.use_angular:
        features[:, Nbondtypes_2body * Nbins1:] *= eta

    # Set up KRR-model
    comparator = gaussComparator()
    krr = krr_class(comparator=comparator, featureCalculator=featureCalculator)

    # Perform training
    GSkwargs = {'reg': [1e-5], 'sigma': np.logspace(0, 2, 10)}
    FVU, params = krr.train(data_values=Etrain,
                            featureMat=features,
                            add_new_data=False,
                            k=5,
                            **GSkwargs)

    # Predict
    Npredict = len(atoms_predict)
    Epred = np.zeros(Npredict)
    Epred_error = np.zeros(Npredict)
    theta0 = np.zeros(Npredict)
    for i, a in enumerate(atoms_predict):
        Epred[i], Epred_error[i], theta0[i] = krr.predict_energy(
            atoms=a, return_error=True)

    return Epred, Epred_error, theta0
예제 #2
0
    Rc2 = 4
    Nbins2 = 30
    sigma2 = 0.2
    
    gamma = 1
    eta = 5
    use_angular = True
    """
    
    featureCalculator = Angular_Fingerprint(a, Rc1=Rc1, Rc2=Rc2, binwidth1=binwidth1, Nbins2=Nbins2, sigma1=sigma1, sigma2=sigma2, gamma=gamma, eta=eta, use_angular=use_angular)

    # Set up KRR-model
    comparator = gaussComparator(featureCalculator=featureCalculator)
    delta_function = deltaFunc(atoms=a, rcut=6)
    krr = krr_class(comparator=comparator,
                    featureCalculator=featureCalculator,
                    delta_function=delta_function)

    
    # Savefile setup
    savefiles_path = sys.argv[1]
    try:
        run_num = sys.argv[2]
    except IndexError:
        run_num = ''
    savefiles_namebase = savefiles_path + 'global' + run_num + '_' 

    try:
        start_pop_file = sys.argv[3]
        start_pop = read(start_pop_file, index=':')
    except IndexError: