The TransportMap support team will be happy to help you out with questions ranging from theory on transport maps, to the installation and usage of the software TransportMaps.

I got an error "log_pdf() got an unexpected keyword argument 'cache'" when I ran the tutorial

0 votes

I ran the "Laplace approximation" in tutorial but I I got an error "log_pdf() got an unexpected keyword argument 'cache'".
asked Aug 1, 2018 in usage by Aaron (12 points)

1 Answer

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) = 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 =
        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 =
        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,


answered Aug 1, 2018 by dabi (267 points)
selected Mar 9 by dabi
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)


Thanks, I understand. Do you have some ideas for the other error?
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.
Thank you for your help. It works now.