import numpy as np
from matplotlib import pyplot as plt
from itertools import product
def kernel(x, xd): # カーネル関数
K = np.zeros([len(x), len(xd)])
for i, j in product(range(len(x)), range(len(xd))):
K[i][j] = theta[0]*np.exp(-1*(x[i] - xd[j])**2 /theta[1])+(theta[2]*int(x[i]==xd[j]))
return K
K = kernel(X_smpl, X_smpl)
W = np.dot(np.linalg.inv(K), Y_smpl) # パラメータ
k = kernel(X_est, X_smpl)
mu = np.dot(k, W) # 平均値
KK = np.dot(k, np.linalg.inv(K))
for i in range(len(X_est)):
std[i] = np.sqrt(theta[0] + theta[2] - np.dot(KK[i], k[i].T)) # 標準偏差