Hi,

I ran the "Laplace approximation" in tutorial but I I got an error "log_pdf() got an unexpected keyword argument 'cache'".

- All categories
- theory (2)
- installation (2)
- usage (8)

0 votes

Best answer

It appears to be a leftover bug in the documentation. Thanks for point it out.

The functions log_pdf, grad_x_log_pdf and hess_x_log_pdf now can take additional arguments and the Gumbel example provided in the tutorial is still coding an old interface. The correct code for the definition of the GumbelDistribution is as follows.

```
class GumbelDistribution(DIST.Distribution):
def __init__(self, mu, beta):
super(GumbelDistribution,self).__init__(1)
self.mu = mu
self.beta = beta
self.dist = stats.gumbel_r(loc=mu, scale=beta)
def pdf(self, x, params=None, *args, **kwargs):
return self.dist.pdf(x).flatten()
def log_pdf(self, x, params=None, *args, **kwargs):
return self.dist.logpdf(x).flatten()
def grad_x_log_pdf(self, x, params=None, *args, **kwargs):
m = self.mu
b = self.beta
z = (x-m)/b
return (np.exp(-z)-1.)/b
def hess_x_log_pdf(self, x, params=None, *args, **kwargs):
m = self.mu
b = self.beta
z = (x-m)/b
return (-np.exp(-z)/b**2.)[:,:,np.newaxis]
```

I'm in the process of updating the tutorial in any place where this bug appear.

Thanks again,

Daniele

Besides，I add ‘self.dim = kl’ in the class you give me. Since when I run the code without this sentence, there is an error ‘EllipticPDEDistribution’ object has no attribute ‘_dim’. I am not sure if this is right.

On the init error you are right. One way to do the same thing you did is to do the following.

```
def __init__(self, n, kl):
self.M = self.matern(n)
a, e = np.linalg.eig(M)
self.A = e[:,0:kl]
self.T = np.diag(a[0:kl])
super(EllipticPDEDistribution, self).__init__(kl)
```

The problem is that log_pdf allows you to do everything vectorized, i.e. it takes x to be a 2d array of m points in d dimensions (in your case d=kl=1). So, when solvepde is called the argument k is 2d array of dimension m x n. For each row of this array you should call solvepde which I guess it is not vectorized. This is why you see the error. A for loop over the m rows of k should do the trick.

...