AttributeError: 'ArrayBox' object has no attribute 'exp'
See original GitHub issueHi everyone,
I’m implementing an alpha-divergence minimisation algorithm with a pretty simple loss function that I need to differentiate. The problem, it seems, is that the function contains exp and log, which should be totally fine.
Moreover, if I isolate the exponential or the logarithm function I can compute its gradient normally, so I guess the problem may be in the context of my loss function.
The code looks like this:
def wake_sleep(inputs, inputs_f, S, theta, alpha):
nn_params = [1e-1, [1, 10, 10, 1]]
z = [init_random_params(nn_params) for _ in range(S)]
init_theta = theta
def bb_alpha_energy(theta, t):
print(theta)
m_a, s_a, sigma = theta
a = np.random.normal(size=(S, S)) * s_a + m_a
m_qgp = 1. / S * np.sum([g_nn(inputs, z_i) for z_i in z], axis=0)
mc_q = []
for a_k in a:
m_k = []
for z_s, a_s in zip(z, a_k):
m_k.append((g_nn(inputs_f, z_s) - m_qgp) * a_s)
m = (1. / np.sqrt(S - 1) * np.sum(m_k, axis = 0))
mc_q.append(gaussian_pdf(inputs_f, m, sigma)**alpha)
mc_q = np.mean(mc_q, axis = 0)
alpha_energy = 1. / alpha * np.sum(np.log(mc_q)) - kl(m_a, s_a, 0., 1.)
return alpha_energy
grad_loss = grad(bb_alpha_energy)
opt_theta = adam(grad_loss, init_theta, step_size=0.01, num_iters=500)
return opt_theta
The failure occurs when the tracer goes through mc_q.append(gaussian_pdf(inputs_f, m, sigma)**alpha)
.
May it be because I’m mixing vector-output functions (such as gaussian_pdf
) with my scalar-output function? How should I go about this?
Thank you, Alex
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:13 (1 by maintainers)
Top Results From Across the Web
Examples of the supported features in Autograd
... f9(a): # Assume a is an array with 2 elements 2 b = np.array([1.0,2.0]) ----> 3 return a.dot(b) AttributeError: 'ArrayBox' object has...
Read more >Numpy AttributeError: 'float' object has no attribute 'exp'
Probably there's something wrong with the input values for X and/or T. The function from the question works ok: import numpy as np...
Read more >AttributeError: 'ArrayBox' object has no attribute 'exp' -
Hi everyone,. I'm implementing an alpha-divergence minimisation algorithm with a pretty simple loss function that I need to differentiate.
Read more >Autograd ArrayBox type intermediate output from optimizer
Hi not sure if this has been addressed before but when I try to run qml.GradientDescentOptimizer on a cost function with intermediate costs, ......
Read more >How to Fix: TypeError: 'numpy.float64' object is not callable
How to Fix: TypeError: 'numpy.float64' object is not callable ... How to Fix: 'numpy.ndarray' object has no attribute 'append'
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Are you using
import numpy as np
? If so change toimport autograd.numpy as np
.how about the log() the same issue.