Thank you for your help. But I guess my question is creating a random
shared variable with the shape of a "tensor".
something like:
def generate_(x):
x_shape = x.shape
rng = RandomStreams()
random_tensor = rng.normal(x_shape)
>> return theano.shared(random_tensor, dtype=floatX)
But in line >> you cannot do it. Because theano.shared needs a value not
symbolic tensor.
On Monday, February 27, 2017 at 4:27:57 AM UTC-8, Kiuhnm Mnhuik wrote:
>
> import theano
> import theano.tensor as T
> import numpy as np
> from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams
>
> floatX = theano.config.floatX
>
> srng = RandomStreams()
>
> x = T.matrix()
> random_shared = theano.shared(np.empty((0, 0), dtype=floatX))
>
> f = theano.function([x], updates=[(random_shared, srng.normal(x.shape))])
>
> print(random_shared.get_value())
> f(np.ones((4, 5), dtype=floatX))
> print(random_shared.get_value())
>
>
> On Monday, February 27, 2017 at 9:47:12 AM UTC+1, Asghar Inanlou Asl wrote:
>>
>> Yes, but that does not create a shared variable.
>>
>> On Sunday, February 26, 2017 at 4:05:40 AM UTC-8, Kiuhnm Mnhuik wrote:
>>>
>>> You can generate random tensors in Theano:
>>>
>>> from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams
>>>
>>> srng = RandomStreams() # change the seed if you want
>>>
>>> .
>>> .
>>> .
>>>
>>> R1 = srng.normal(shape)
>>> R2 = srng.normal(shape)
>>> .
>>> .
>>> .
>>>
>>>
>>>
>>> On Saturday, February 25, 2017 at 12:49:18 PM UTC+1, Asghar Inanlou Asl
>>> wrote:
>>>>
>>>> Hi all,
>>>> I need to make a shared variable and randomly initialize it. Obviously,
>>>> the way to do it is to use numpy to generate a random matrix and then
>>>> change it to shared variable via theano.shared()
>>>> However, I cannot do it because the size of the random matrix is partly
>>>> coming from a TensorVariable so numpy gets stuck in it.
>>>> To be particular, I have a function which multiplies the input tensor
>>>> in a random matrix (think about what a fully connected layer does). But
>>>> the
>>>> point is the shape of the tensor might be changing. And it needs to be a
>>>> shared variable to that I can use it as one of the parameters of my
>>>> updates.
>>>> Any comments?
>>>> Thanks!
>>>>
>>>
--
---
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 [email protected].
For more options, visit https://groups.google.com/d/optout.