def _do_selection(self, psr, priorfn, basisfn, coefficients, selection): sel = selection(psr) self._keys = list(sorted(sel.masks.keys())) self._masks = [sel.masks[key] for key in self._keys] self._prior, self._bases = {}, {} self._params, self._coefficients = {}, {} for key, mask in zip(self._keys, self._masks): pnames = [psr.name, name, key] pname = '_'.join([n for n in pnames if n]) self._prior[key] = priorfn(pname, psr=psr) self._bases[key] = basisfn(pname, psr=psr) for par in itertools.chain(self._prior[key]._params.values(), self._bases[key]._params.values()): self._params[par.name] = par if coefficients and pyv3: # we can only create GPCoefficients parameters if the basis # can be constructed with default arguments # (and does not change size) self._construct_basis() for key in self._keys: pname = '_'.join([n for n in [psr.name, name, key] if n]) chain = itertools.chain(self._prior[key]._params.values(), self._bases[key]._params.values()) priorargs = { par.name: self._params[par.name] for par in chain } logprior = parameter.Function( functools.partial(self._get_coefficient_logprior, key), **priorargs) size = self._slices[key].stop - self._slices[key].start cpar = parameter.GPCoefficients(logprior=logprior, size=size)(pname + '_coefficients') self._coefficients[key] = cpar self._params[cpar.name] = cpar
def __init__(self, psr): super(BasisCommonGP, self).__init__(psr) self.name = self.psrname + "_" + self.signal_id pname = "_".join([psr.name, name]) self._bases = basisFunction(pname, psr=psr) self._params, self._coefficients = {}, {} for par in itertools.chain(self._prior._params.values(), self._orf._params.values(), self._bases._params.values()): self._params[par.name] = par rand_state = np.int(np.abs(np.sum(psr.pos)) * 10000) ra = uniform.rvs(loc=0, scale=2 * np.pi, random_state=rand_state) dec = cosine.rvs(loc=0, scale=0.5, random_state=rand_state + 11) newpos = np.array(SkyCoord(ra=ra*u.rad, \ dec=dec*u.rad).cartesian.xyz) self._psrpos = psr.pos self._psrpos_scrambled = newpos if coefficients: self._construct_basis() # if we're given an instantiated coefficient vector # that's what we will use if isinstance(coefficients, parameter.Parameter): self._coefficients[""] = coefficients self._params[coefficients.name] = coefficients return chain = itertools.chain(self._prior._params.values(), self._orf._params.values(), self._bases._params.values()) priorargs = {par.name: self._params[par.name] for par in chain} logprior = parameter.Function(self._get_coefficient_logprior, **priorargs) size = self._basis.shape[1] cpar = parameter.GPCoefficients( logprior=logprior, size=size)(pname + "_coefficients") self._coefficients[""] = cpar self._params[cpar.name] = cpar
def __init__(self, psr): super(BasisCommonGP, self).__init__(psr) self.name = self.psrname + '_' + self.signal_id pname = '_'.join([psr.name, name]) self._bases = basisFunction(pname, psr=psr) self._params, self._coefficients = {}, {} for par in itertools.chain(self._prior._params.values(), self._orf._params.values(), self._bases._params.values()): self._params[par.name] = par self._psrpos = psr.pos if coefficients and pyv3: self._construct_basis() # if we're given an instantiated coefficient vector # that's what we will use if isinstance(coefficients, parameter.Parameter): self._coefficients[''] = coefficients self._params[coefficients.name] = coefficients return chain = itertools.chain(self._prior._params.values(), self._orf._params.values(), self._bases._params.values()) priorargs = {par.name: self._params[par.name] for par in chain} logprior = parameter.Function(self._get_coefficient_logprior, **priorargs) size = self._basis.shape[1] cpar = parameter.GPCoefficients( logprior=logprior, size=size)(pname + '_coefficients') self._coefficients[''] = cpar self._params[cpar.name] = cpar