precision = 0.00001 i = 0 steps = 0 diff = 100 maxstep = 1000 while (abs(diff) > precision and steps < maxstep): GoodDir = True div = 2**i step = inistep / div while (GoodDir): steps += 1 lambd = lambd + step * (-1)**i if lambd <= 0: lambd = step * 1.1 KRR = KernelRidgeRegression(type="linear") KRR.set_var(c1=-10**10, lambd=lambd) KRR.fit(X, Y) KRR.predict(Xv, Yv) out2 = KRR.rmse diff = prev - out2 if diff < 0: GoodDir = False prev = out2 output.append([lambd, out2]) print(str(lambd) + ", " + str(out2) + "\n", flush=True) i += 1 with open(folder + "MINI_other_LIN_faulty", 'wb') as file: pickle.dump([output], file) c1_list = list(frange(-20, -5, 2))
#%% 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)