Hi,
I'm having trouble with a small modification of the getting started script, and would be grateful for any help. I'm using algopy 0.3.2, numpy 1.5.1, and python 2.7.2.
I'm trying to compute the gradient of f(x) = 2*x_1 + 2*x_2 which should be [2, 2] when x=[3,5].
Here's the code I'm running:
import numpy, algopy
from algopy import UTPM, exp
def eval_f(x):
y = numpy.array([2,2])
return algopy.sum(x * y)
cg = algopy.CGraph()
x = algopy.Function(numpy.array([1,2]))
y = eval_f(x)
cg.trace_off()
cg.independentFunctionList = [x]
cg.dependentFunctionList = [y]
print 'gradient =', cg.gradient(numpy.array([3.0,5.0]))
Unexpectedly, the output is:
gradient =
Traceback (most recent call last):
File "/home/lewfish/git/machine-learning/machine-learning/src/scratch.py", line 17, in <module>
print 'gradient =', cg.gradient(numpy.array([3.0,5.0]))
File "/usr/local/lib/python2.7/dist-packages/algopy/tracer/tracer.py", line 252, in gradient
self.pullback([ybar])
File "/usr/local/lib/python2.7/dist-packages/algopy/tracer/tracer.py", line 138, in pullback
f.xbar_from_x()
File "/usr/local/lib/python2.7/dist-packages/algopy/tracer/tracer.py", line 943, in xbar_from_x
self.xbar = self.func(*args)
File "/usr/local/lib/python2.7/dist-packages/algopy/utpm/utpm.py", line 287, in __mul__
x_data, y_data = UTPM._broadcast_arrays(self.data, rhs.data)
AttributeError: 'NoneType' object has no attribute 'data'
Strangely, when I modify the line
return algopy.sum(x * y)
to be
return algopy.sum(x + y) (i replaced the * with a +)
it returns the correct answer. I also get the same problem when dividing by y.
I'm not sure if this is a bug, or reflects a misuse of algopy.
Thanks,
Lewis