Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log prior computation #617

Open
befelix opened this issue Mar 27, 2018 · 4 comments
Open

Log prior computation #617

befelix opened this issue Mar 27, 2018 · 4 comments

Comments

@befelix
Copy link

befelix commented Mar 27, 2018

I was going through the GPy code and found some part that seems wrong to me (or that I don't understand) in the computation of the log prior.

The first part of the code computes the log prior probabilities, which makes perfect sense. The second part starting in line 57 supposedly adds some correction terms for the constraints, but I don't understand where they come from. Why would the transformed parameter space matter, when the prior is defined on the untransformed space and param_array returns the untransformed parameters?

Thanks for your help.

@befelix
Copy link
Author

befelix commented Mar 27, 2018

Here's roughly what I would have expected:

def log_prior(self):
    """evaluate the prior"""
    if self.priors.size == 0:
        return 0.
    x = self.param_array
    #evaluate the prior log densities
    return sum(p.lnpdf(x[ind]).sum() for p, ind in self.priors.items())

def _log_prior_gradients(self):
    """evaluate the gradients of the priors"""
    if self.priors.size == 0:
        return 0.
    x = self.param_array
    ret = np.zeros(x.size)
    
    #compute derivate of prior density
    for p, ind in self.priors.items():
        np.put(ret, ind, p.lnpdf_grad(x[ind]))
        
    # Transform gradients to unconstrained space
    for c, idx in self.constraints.items():
        if isinstance(c, Transformation):
            ret[idx] = c.gradfactor(x[idx], ret[idx])
    return ret

@mzwiessele
Copy link
Member

@jameshensman do you recall why this was necessary?

@mzwiessele
Copy link
Member

@jameshensman ping

@JasperKirton
Copy link

bumping this, can result in some strange transformations of the log prior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants