コード例 #1
0
 def func(a,*args):
     if a[1]<=0:
         return 10000
     KRR=KernelRidgeRegression(type="laplace")
     KRR.set_var(sigma=a[0], lambd=a[1])
     KRR.fit(X,Y, "error")
     out1=KRR.rmse
     KRR.predict(Xv,Yv)
     out2=KRR.rmse
     print(str(a[1])+", "+str(a[0])+", "+str(out1)+", "+str(out2)+"\n", flush=True)
     return out2
コード例 #2
0
 def func(a,*args):
     if a[1]<=0:
         return 10000
     KRR=KernelRidgeRegression(type="laplace")
     KRR.set_var(sigma=a[0], lambd=a[1])
     KRR.fit(X,Y, "error")
     out1=KRR.rmse
     KRR.predict(Xv,Yv)
     out2=KRR.rmse
     with open(folder+filename, "a") as myfile:
         myfile.write(str(size)+", "+str(out1)+", "+str(out2)+"\n")
     return out2
コード例 #3
0
 def func(a, *args):
     if a[3]<=0:
         return 10000
     try:
         KRR=KernelRidgeRegression(type="poly")
         KRR.set_var(c1=a[0],c2=a[1],d=a[2], lambd=a[3])
         KRR.fit(X,Y, "error")
         out1=KRR.rmse
         KRR.predict(Xv,Yv)
         out2=KRR.rmse
         print(str(a[3])+", "+str(a[0])+", "+str(a[1])+", "+str(a[2])+", "+str(out1)+", "+str(out2)+"\n", flush=True)
     except numpy.linalg.linalg.LinAlgError:
         out1=10**9
         out2=10**9
     return out2
コード例 #4
0
with open(path + energiesFileValidate, "rb") as pickleFile:
    energiesValidate = pickle.load(pickleFile)

largeFeatureMatrixValidate.shape = (largeFeatureMatrixValidate.shape[0], -1)

Xv = largeFeatureMatrixValidate
Yv = np.array(energiesValidate)

if method == 'linear':
    folder = folder + "lin/"
    KRR = KernelRidgeRegression(type="linear")
    KRR.set_var(c1=Args, lambd=lambd)
    KRR.fit(X, Y, "error")
    out1 = KRR.rmse
    KRR.predict(Xv, Yv)
    out2 = KRR.rmse
    print("\nTrain: " + str(out1) + " Validation: " + str(out2) + "\n",
          flush=True)
elif method == 'polynomial':
    try:
        KRR = KernelRidgeRegression(type="poly")
        KRR.set_var(c1=c1_list[c1], c2=c2_list[c2], d=d_list[d], lambd=lambd)
        KRR.fit(X, Y, "error")
        out1 = KRR.rmse
        KRR.predict(Xv, Yv)
        out2 = KRR.rmse
        print("\nTrain: " + str(out1) + " Validation: " + str(out2) + "\n",
              flush=True)
    except numpy.linalg.linalg.LinAlgError:
        out1 = -1
コード例 #5
0
#%% Load validation data
featureMatrixFileValidate = "validate_featureMatrix.npy"
atomicSymbolsListFileValidate = "validate_pickledAtomicSymbolsList.txt"
energiesFileValidate = "validate_pickledEnergies.txt"

largeFeatureMatrixValidate, mappedAtomicNumberValidate = simpleLargeMatrix(path,featureMatrixFileValidate, atomicSymbolsListFileValidate)


with open(path+energiesFileValidate, "rb") as pickleFile:
    energiesValidate = pickle.load(pickleFile)

#Flatten description
largeFeatureMatrixValidate.shape = (largeFeatureMatrixValidate.shape[0], -1)

X_v = largeFeatureMatrixValidate
Y_v = np.array(energiesValidate)



import time
start=time.time()
KRR=KernelRidgeRegression(type="laplace")
KRR.fit(X,Y)
Y_predict_val=KRR.predict(X_v,Y_v)
print(KRR.rmse)
rmse_class=np.sqrt(np.mean(np.square(Y_predict_val-Y_v)))
print(rmse_class)
end=time.time()
print(end-start)