示例#1
0
    def prior_sample(self, src_type, u=None):
        params = SrcParams(u=u)
        if src_type == 'star':
            # TODO SET a with atoken
            params.a = 0
            color   = self.star_flux_prior.rvs(size=1)[0]
            logprob = self.star_flux_prior.logpdf(color)
            params.fluxes = np.exp(self.star_flux_prior.to_fluxes(color))
            return params, logprob

        elif src_type == 'galaxy':
            params.a = 1
            color   = self.galaxy_flux_prior.rvs(size=1)[0]
            logprob = self.galaxy_flux_prior.logpdf(color)
            params.fluxes = np.exp(self.galaxy_flux_prior.to_fluxes(color))

            sample_ab = self.galaxy_ab_prior.rvs(size=1)[0,0]
            sample_ab = np.exp(sample_ab) / (1.+np.exp(sample_ab))

            params.shape  = np.array([np.random.random(),
                                      np.exp(self.galaxy_re_prior.rvs(size=1)[0,0]),
                                      np.random.random() * np.pi,
                                      sample_ab])

            logprob_re    = self.galaxy_re_prior.logpdf(params.sigma)
            logprob_ab    = self.galaxy_ab_prior.logpdf(params.rho)
            logprob_shape = -np.log(np.pi) + logprob_re + logprob_ab
            return params, logprob
示例#2
0
    def linear_propose_other_type(self):
        """ based on linear regression of fluxes and conditional distribution
        of galaxy shapes, propose parameters of the other type and report
        the log probability of generating that proposal

        Returns:
            - proposal params
            - log prob of proposal
            - log prob of implied reverse proposal
            - log determinant of the transformation |d(x',u')/d(x,u)|

        """
        params = SrcParams(u=self.params.u)
        if self.is_star():
            params.a = 1

            # fluxes
            residual = mvn.rvs(cov=star_mag_proposal.res_covariance)
            ll_prop_fluxes = mvn.logpdf(residual, mean=None, cov=star_mag_proposal.res_covariance)
            gal_mag = star_mag_proposal.predict(self.params.mags.reshape((1,-1))) + residual
            params.fluxes = du.mags2nanomaggies(gal_mag).flatten()

            # compute reverse ll
            res   = gal_mag_proposal.predict(gal_mag) - self.params.mags
            llrev = mvn.logpdf(res, mean=None, cov=gal_mag_proposal.res_covariance)

            # shape
            sample_re = star_rad_proposal.rvs(size=1)[0]
            ll_shape  = star_rad_proposal.logpdf(sample_re)
            params.shape = np.array([np.random.rand(),
                                     np.exp(sample_re),
                                     np.random.rand() * np.pi,
                                     np.random.rand()])
            _, logdet = np.linalg.slogdet(star_mag_proposal.coef_)
            return params, ll_prop_fluxes + ll_shape, llrev, logdet

        elif self.is_galaxy():
            params.a = 0
            # fluxes
            residual = mvn.rvs(cov=gal_mag_proposal.res_covariance)
            llprob   = mvn.logpdf(residual, mean=None, cov=gal_mag_proposal.res_covariance)
            star_mag = gal_mag_proposal.predict(self.params.mags.reshape((1, -1))) + residual
            params.fluxes = du.mags2nanomaggies(star_mag).flatten()

            res   = star_mag_proposal.predict(star_mag) - self.params.mags
            llrev = mvn.logpdf(res, mean=None, cov=star_mag_proposal.res_covariance)
            ll_re = star_rad_proposal.logpdf(np.log(self.params.sigma))

            _, logdet = np.linalg.slogdet(gal_mag_proposal.coef_)
            return params, llprob, llrev + ll_re, logdet