Discussion:
[theano-users] theano.scan: ValueError: length not known & Question regarding sequences and previous values
b***@gmail.com
2017-07-22 04:51:37 UTC
Permalink
Hi everybody,
I am trying to approximate a function that consist of multiple overlapping
Gaussian kernels. The calculation should be done in the scan function that
iterates over the Gaussian kernels. At this point I got stuck with two
problems.

1. I have tried to calculate the sum of all kernels for each input by using
the previous result. However, the return value is not the sum of all
kernels for a given input but something else. I was not able to figure it
out yet. See attached file scan_sum_kernel.py

2. I would like to define the input vector and the kernel parameters
(height, mean, variance) as NumPy arrays. Therefore, I added the ‘givens’
parameter to the function. However, this leads to the Value Error: "length
not known: <TensorType(int64, vector)> [id A]" See attached file
scan_shared_variable.py

Any hint and advice how to go on and what to try next is much appreciated!
Below the code that is working so far:
x = np.arange(start=1,stop=100,step=1)
xs = T.dscalar('xs')
height = T.dvector('height')
mean = T.dvector('mean')
variance = T.dvector('variance')
bias = T.dvector('bias')

def gaussian(height, mean, variance, bias, x):
return (height * \
T.exp(-(T.sqr( x-mean) / \
(2*variance)))) + bias

gaus_dist, updates = theano.scan(
fn=gaussian,
sequences=[height, mean, variance, bias],
non_sequences=[xs]
)

get_gaus = theano.function(inputs=[xs, height, mean, variance, bias],
outputs=gaus_dist)

gaus3 = np.array([])
for xs in x:
gaus1 = get_gaus(xs, [2,10,11], [10,35,64], [2,12,22], [2, 3, 4])
gaus2=0
for gaus_tmp in gaus1:
gaus2=gaus2+gaus_tmp
gaus3 = np.append(gaus3,gaus2)

%matplotlib inline
plt.plot(gaus3)
--
---
You received this message because you are subscribed to the Google Groups "theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to theano-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...