Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 4
0
lam_list = [10**n for n in range(-3, 5)]

c_list = [10**n for n in range(-3, 7)]
x = [-10**n for n in range(-1, 7)]
x.reverse()
c_list = x + c_list

if method == 'linear':
    out_matrix_lin = np.zeros((len(c_list), len(lam_list)))
    for c in range(len(c_list)):
        for l in range(len(lam_list)):
            print(f'c={c_list[c]}, lambda={lam_list[l]}', flush=True)

            KRR = KernelRidgeRegression(type="linear")
            KRR.set_var(c1=c_list[c], lambd=lam_list[l])
            KRR.fit(X, Y, "error")
            out = KRR.rmse
            print(out, flush=True)

            out_matrix_lin[c, l] = out

    with open(folder + "out_matrix_lin_fixed_faulty_matrix", 'wb') as file:
        pickle.dump([lam_list, c_list, out_matrix_lin], file)

lam_list = [10**n for n in range(-3, 3)]

c1_list = [10**n for n in range(-3, 3)]

c2_list = [10**n for n in range(-2, 3)]
x = [-10**n for n in range(-2, 3)]
elif Feature == "GP":
    largeFeatureMatrixValidate = advanced_large_matrix(
        path, featureMatrixFileValidate, atomicSymbolsListFileValidate)

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",
Ejemplo n.º 6
0
    inistep = 1
    i = 0
    maxstep = 250
    precision = 0.0001
    steps = 0
    diff = 100
    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", 'wb') as file:
        pickle.dump([output], file)

c1_list = list(frange(-20, -5, 2))