def _fastpredict(self, jw, iw, set_threading=False): """ jw : jwant iw : iwant """ mw = np.zeros_like(jw) vw = np.zeros_like(jw) for i, (jwant, iwant) in enumerate(zip(jw, iw)): if set_threading: covar = spear_threading(jwant, self.jd, iwant + 1, self.id + 1, **self.covparams) else: covar = spear(jwant, self.jd, iwant + 1, self.id + 1, **self.covparams) cplusninvdotcovar = chosolve_from_tri(self.U, covar.T, nugget=None, inplace=False) if set_threading: vw[i] = spear_threading(jwant, jwant, iwant + 1, iwant + 1, **self.covparams) else: vw[i] = spear(jwant, jwant, iwant + 1, iwant + 1, **self.covparams) mw[i] = np.dot(covar, self.cplusninvdoty) vw[i] = vw[i] - np.dot(covar, cplusninvdotcovar) return (mw, vw)
def _get_covmat(self, set_threading=False): if set_threading: self.cmatrix = spear_threading(self.jd, self.jd, self.id, self.id, **self.covparams) else: self.cmatrix = spear(self.jd, self.jd, self.id, self.id, **self.covparams) print("covariance matrix calculated")
def generate(self, zylclist, set_threading=False) : """ Presumably zylclist has our input j, and e, and the values in m should be the mean. Parameters ---------- zylclist: list of 3-list light curves Pre-simulated light curves in zylclist, with the values in m-column as the light curve mean, and those in e-column as the designated errorbar. Returns ------- zylclist_new: list of 3-list light curves Simulated light curves in zylclist. """ nlc_obs = len(zylclist) if nlc_obs != self.nlc_obs : raise RuntimeError("zylclist has unmatched nlc_obs with spearmode %s" % self.spearmode) jlist = [] mlist = [] elist = [] ilist = [] nptlist = [] npt = 0 for ilc, lclist in enumerate(zylclist): if (len(lclist) == 3): jsubarr, msubarr, esubarr = [np.array(l) for l in lclist] if (np.min(msubarr) != np.max(msubarr)) : print("WARNING: input zylclist has inequal m elements in light curve %d," + "please make sure the m elements are filled with the desired mean" + "of the mock light curves, now reset to zero"%ilc) msubarr = msubarr * 0.0 nptlc = len(jsubarr) # sort the date, safety p = jsubarr.argsort() jlist.append(jsubarr[p]) mlist.append(msubarr[p]) elist.append(esubarr[p]) ilist.append(np.zeros(nptlc, dtype="int")+ilc+1) # again, starting at 1. npt += nptlc nptlist.append(nptlc) # collapse the list to one array jarr, marr, earr, iarr = self._combineddataarr(npt, nptlist, jlist, mlist, elist, ilist) # get covariance function if set_threading : if self.spearmode == "Rmap" : cmatrix = spear_threading(jarr, jarr, iarr , iarr , self.sigma, self.tau, self.lags, self.wids, self.scales, set_pmap=False) elif self.spearmode == "Pmap" : cmatrix = spear_threading(jarr, jarr, iarr , iarr , self.sigma, self.tau, self.lags, self.wids, self.scales, set_pmap=True) elif self.spearmode == "SPmap" : cmatrix = spear_threading(jarr, jarr, iarr+1, iarr+1, self.sigma, self.tau, self.lags, self.wids, self.scales, set_pmap=True) else : if self.spearmode == "Rmap" : cmatrix = spear(jarr, jarr, iarr , iarr , self.sigma, self.tau, self.lags, self.wids, self.scales, set_pmap=False) elif self.spearmode == "Pmap" : cmatrix = spear(jarr, jarr, iarr , iarr , self.sigma, self.tau, self.lags, self.wids, self.scales, set_pmap=True) elif self.spearmode == "SPmap" : cmatrix = spear(jarr, jarr, iarr+1, iarr+1, self.sigma, self.tau, self.lags, self.wids, self.scales, set_pmap=True) # cholesky decomposed cmatrix to L, for which a C array is desired. L = np.empty(cmatrix.shape, order='C') L[:] = cholesky2(cmatrix) # XXX without the error report. # generate gaussian deviates y y = multivariate_normal(np.zeros(npt), np.identity(npt)) # get x = L * y + u, where u is the mean of the light curve(s) x = np.dot(L, y) + marr # generate errors # the way to get around peppering zeros is to generate deviates with unity std and multiply to earr. # XXX no covariance implemented here. e = earr * multivariate_normal(np.zeros(npt), np.identity(npt)) # add e m = x + e # unpack the data _jlist, _mlist, _elist = self._unpackdataarr(npt, nptlist, jarr, m, earr, iarr) zylclist_new = [] for ilc in xrange(self.nlc_obs) : zylclist_new.append([_jlist[ilc], _mlist[ilc], _elist[ilc]]) return(zylclist_new)