gaussian_process.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:probabilistic_line_search 作者: ProbabilisticNumerics 项目源码 文件源码
def update(self):
    """Set up the Gram matrix and compute its LU decomposition to make the GP
    ready for inference (calls to ``.gp.mu(t)``, ``gp.V(t)``, etc...).

    Call this method after you have manipulated the GP by
       - ``gp.reset()`` ing,
       - adding observations with ``gp.add(t, f, df)``, or
       - adjusting the sigmas via ``gp.update_sigmas()``.
    and want to perform inference next."""

    if self.ready:
      return

    # Set up the kernel matrices.
    self.K = np.matrix(np.zeros([self.N, self.N]))
    self.Kd = np.matrix(np.zeros([self.N, self.N]))
    self.dKd = np.matrix(np.zeros([self.N, self.N]))    
    for i in range(self.N):
      for j in range(self.N):
        self.K[i, j] = self.k(self.ts[i], self.ts[j])
        self.Kd[i, j] = self.kd(self.ts[i], self.ts[j])
        self.dKd[i, j] = self.dkd(self.ts[i], self.ts[j])

    # Put together the Gram matrix
    S_f = np.matrix(np.diag(self.fvars))
    S_df = np.matrix(np.diag(self.dfvars))
    self.G = np.bmat([[self.K + S_f, self.Kd],
                      [self.Kd.T, self.dKd + S_df]])

    # Compute the LU decomposition of G and store it
    self.LU, self.LU_piv = linalg.lu_factor(self.G, check_finite=True)

    # Set ready switch to True
    self.ready = True

    # Pre-compute the regression weights used in mu
    self.w = self.solve_G(np.array(self.fs + self.dfs))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号