mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-27 14:25:16 +02:00
[parameterized] merge in jacobian for priors?
This commit is contained in:
parent
ff558ff57c
commit
208a025751
2 changed files with 10 additions and 11 deletions
|
|
@ -109,7 +109,7 @@ class ParameterIndexOperations(object):
|
||||||
try:
|
try:
|
||||||
return self._properties.itervalues()
|
return self._properties.itervalues()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
#Changed this from itervalues to values for Py3 compatibility. It didn't break the test suite.
|
#Changed this from itervalues to values for Py3 compatibility. It didn't break the test suite.
|
||||||
return self._properties.values()
|
return self._properties.values()
|
||||||
|
|
||||||
def indices(self):
|
def indices(self):
|
||||||
|
|
|
||||||
|
|
@ -433,35 +433,34 @@ class Indexable(Nameable, Updateable):
|
||||||
if self.priors.size == 0:
|
if self.priors.size == 0:
|
||||||
return 0.
|
return 0.
|
||||||
x = self.param_array
|
x = self.param_array
|
||||||
#evaluate the prior log densities
|
#evaluate the prior log densities
|
||||||
log_p = reduce(lambda a, b: a + b, (p.lnpdf(x[ind]).sum() for p, ind in self.priors.items()), 0)
|
log_p = reduce(lambda a, b: a + b, (p.lnpdf(x[ind]).sum() for p, ind in self.priors.items()), 0)
|
||||||
|
|
||||||
#account for the transformation by evaluating the log Jacobian (where things are transformed)
|
#account for the transformation by evaluating the log Jacobian (where things are transformed)
|
||||||
log_j = 0.
|
log_j = 0.
|
||||||
priored_indexes = np.hstack([i for p, i in self.priors.items()])
|
priored_indexes = np.hstack([i for p, i in self.priors.items()])
|
||||||
for c,j in self.constraints.items():
|
for c,j in self.constraints.items():
|
||||||
if c is 'fixed':continue
|
if c is 'fixed':continue
|
||||||
for jj in j:
|
for jj in j:
|
||||||
if jj in priored_indexes:
|
if jj in priored_indexes:
|
||||||
log_j += c.log_jacobian(x[jj])
|
log_j += c.log_jacobian(x[jj])
|
||||||
return log_p + log_j
|
return log_p + log_j
|
||||||
|
|
||||||
|
|
||||||
def _log_prior_gradients(self):
|
def _log_prior_gradients(self):
|
||||||
"""evaluate the gradients of the priors"""
|
"""evaluate the gradients of the priors"""
|
||||||
if self.priors.size == 0:
|
if self.priors.size == 0:
|
||||||
return 0.
|
return 0.
|
||||||
x = self.param_array
|
x = self.param_array
|
||||||
ret = np.zeros(x.size)
|
ret = np.zeros(x.size)
|
||||||
#compute derivate of prior density
|
#compute derivate of prior density
|
||||||
[np.put(ret, ind, p.lnpdf_grad(x[ind])) for p, ind in self.priors.items()]
|
[np.put(ret, ind, p.lnpdf_grad(x[ind])) for p, ind in self.priors.items()]
|
||||||
#add in jacobian derivatives if transformed
|
#add in jacobian derivatives if transformed
|
||||||
priored_indexes = np.hstack([i for p, i in self.priors.items()])
|
priored_indexes = np.hstack([i for p, i in self.priors.items()])
|
||||||
for c,j in self.constraints.items():
|
for c,j in self.constraints.items():
|
||||||
for jj in j:
|
for jj in j:
|
||||||
if jj in priored_indexes:
|
if jj in priored_indexes:
|
||||||
ret[jj] += c.log_jacobian_grad(x[jj])
|
ret[jj] += c.log_jacobian_grad(x[jj])
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
#===========================================================================
|
#===========================================================================
|
||||||
# Tie parameters together
|
# Tie parameters together
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue