コード例 #1
0
 def sample_pp_post_pred(self, nsamp, input_list, full_cov=False, nloop=None):
   """ Sample from posterior predictive of PP.
       Inputs:
         input_list - list of np arrays size=(-1,)
       Returns:
         list (len input_list) of np arrays (size=(nsamp,1))."""
   if self.modelp.model_str=='optfixedsig' or self.modelp.model_str=='opt' or \
     self.modelp.model_str=='optmatern32':
     nloop = 1
     sampids = [0]
   elif self.modelp.model_str=='samp' or \
     self.modelp.model_str=='sampmatern32':
     if nloop is None: nloop=nsamp
     nsamp = int(nsamp/nloop)
     sampids = np.random.randint(len(self.sample_list), size=(nloop,))
   ppred_list = []
   for i in range(nloop):
     samp = self.sample_list[sampids[i]]
     postmu, postcov = self.gp_post(self.data.X, self.data.y,
       np.stack(input_list), samp.ls, samp.alpha, samp.sigma, full_cov)
     if full_cov:
       ppred_list.extend(list(sample_mvn(postmu, postcov, nsamp)))
     else:
       ppred_list.extend(list(np.random.normal(postmu.reshape(-1,),
         postcov.reshape(-1,), size=(nsamp, len(input_list)))))
   return self.get_reverse_transform(list(np.stack(ppred_list).T), ppred_list,
     input_list)
コード例 #2
0
 def sample_pp_pred(self, nsamp, input_list, lv=None):
     """ Sample from predictive of PP for parameter lv.
     Returns: list (len input_list) of np arrays (size (nsamp,1))."""
     if lv is None:
         lv = self.sample_list[0]
     postmu, postcov = self.gp_post(self.data.X, self.data.y, input_list,
                                    lv.ls, lv.alpha, lv.sigma)
     pred_list = list(sample_mvn(
         postmu, postcov, 1))  ###TODO: sample from this mean nsamp times
     return list(np.stack(pred_list).T), pred_list
コード例 #3
0
ファイル: pp_gp_stan_distmat.py プロジェクト: auroua/NPENASv1
 def sample_pp_pred(self, nsamp, input_list, lv=None):
   """ Sample from predictive of PP for parameter lv.
       Returns: list (len input_list) of np arrays (size (nsamp,1))."""
   x_pred = np.stack(input_list)
   if lv is None:
     if self.modelp.model_str=='optfixedsig' or self.modelp.model_str=='opt' \
       or self.modelp.model_str=='fixedparam':
       lv = self.sample_list[0]
     elif self.modelp.model_str=='samp' or \
       self.modelp.model_str=='sampfixedsig':
       lv = self.sample_list[np.random.randint(len(self.sample_list))]
   postmu, postcov = self.gp_post(self.data.X, self.data.y, x_pred, lv.ls,
     lv.alpha, lv.sigma)
   pred_list = list(sample_mvn(postmu, postcov, 1)) ###TODO: sample from this mean nsamp times
   return list(np.stack(pred_list).T), pred_list
コード例 #4
0
 def sample_pp_post_pred(self, nsamp, input_list, full_cov=False):
     """ Sample from posterior predictive of PP.
     Inputs:
       input_list - list of np arrays size=(-1,)
     Returns:
       list (len input_list) of np arrays (size=(nsamp,1))."""
     samp = self.sample_list[0]
     postmu, postcov = self.gp_post(self.data.X, self.data.y, input_list,
                                    samp.ls, samp.alpha, samp.sigma,
                                    full_cov)
     if full_cov:
         ppred_list = list(sample_mvn(postmu, postcov, nsamp))
     else:
         ppred_list = list(
             np.random.normal(postmu.reshape(-1, ),
                              postcov.reshape(-1, ),
                              size=(nsamp, len(input_list))))
     return list(np.stack(ppred_list).T), ppred_list