Discussion:
[theano-users] How create activation function from scratch in python
Bruno Messias
2017-07-05 15:53:22 UTC
Permalink
For didactic reasons, I am trying to implement a "activation" function


a, x, y = T.matrices("a", 'x','y')
b = T.scalars("b")
def custom(val):

T.log(val)


z_switch = T.switch(T.gt(a,b), T.true_div(T.add(T.pow(x, qEff),0), 2),
T.log(y))

f_switch = theano.function([a, b, x, y], z_switch,
mode=theano.Mode(linker='vm'))
return f_switch(val, 0, val, val)

Then I get the following error

Expected an array-like object, but found a Variable: maybe you are trying to call a function on a (possibly shared) variable instead of a numeric array?

Repeating> this is only for didactic purposes. There are any good tutorial about this?
--
---
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.
Bruno Messias
2017-07-05 16:33:31 UTC
Permalink
I' need call "custom" function with a given variable x, such that

type(x)<class 'theano.tensor.var.TensorVariable'>
Post by Bruno Messias
For didactic reasons, I am trying to implement a "activation" function
a, x, y = T.matrices("a", 'x','y')
b = T.scalars("b")
T.log(val)
z_switch = T.switch(T.gt(a,b), T.true_div(T.add(T.pow(x, qEff),0), 2),
T.log(y))
f_switch = theano.function([a, b, x, y], z_switch,
mode=theano.Mode(linker='vm'))
return f_switch(val, 0, val, val)
Then I get the following error
Expected an array-like object, but found a Variable: maybe you are trying to call a function on a (possibly shared) variable instead of a numeric array?
Repeating> this is only for didactic purposes. There are any good tutorial about this?
--
---
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.
Frédéric Bastien
2017-07-05 22:02:40 UTC
Permalink
Give the full error message. Without our I can't help.

Fred
Post by Bruno Messias
I' need call "custom" function with a given variable x, such that
type(x)<class 'theano.tensor.var.TensorVariable'>
Post by Bruno Messias
For didactic reasons, I am trying to implement a "activation" function
a, x, y = T.matrices("a", 'x','y')
b = T.scalars("b")
T.log(val)
z_switch = T.switch(T.gt(a,b), T.true_div(T.add(T.pow(x, qEff),0),
2), T.log(y))
f_switch = theano.function([a, b, x, y], z_switch,
mode=theano.Mode(linker='vm'))
return f_switch(val, 0, val, val)
Then I get the following error
Expected an array-like object, but found a Variable: maybe you are trying to call a function on a (possibly shared) variable instead of a numeric array?
Repeating> this is only for didactic purposes. There are any good tutorial about this?
--
---
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
For more options, visit https://groups.google.com/d/optout.
--
---
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.
Jesse Livezey
2017-07-07 20:52:36 UTC
Permalink
Here you're treating val like it is a symbolic theano variable
T.log(val)

But here you're treating it like a numpy array and passing it into a
compiled theano function
return f_switch(val, 0, val, val)

Maybe you're intending to just return the function f_switch and then call
it with values?
Post by Frédéric Bastien
Give the full error message. Without our I can't help.
Fred
Post by Bruno Messias
I' need call "custom" function with a given variable x, such that
type(x)<class 'theano.tensor.var.TensorVariable'>
Post by Bruno Messias
For didactic reasons, I am trying to implement a "activation" function
a, x, y = T.matrices("a", 'x','y')
b = T.scalars("b")
T.log(val)
z_switch = T.switch(T.gt(a,b), T.true_div(T.add(T.pow(x, qEff),0),
2), T.log(y))
f_switch = theano.function([a, b, x, y], z_switch,
mode=theano.Mode(linker='vm'))
return f_switch(val, 0, val, val)
Then I get the following error
Expected an array-like object, but found a Variable: maybe you are trying to call a function on a (possibly shared) variable instead of a numeric array?
Repeating> this is only for didactic purposes. There are any good tutorial about this?
--
---
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
For more options, visit https://groups.google.com/d/optout.
--
---
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...