Deeplearning.net etc. use Theano to define classes that have shared variables and expression symbols as class variables.
Let's check the behavior of this class.
Here, simply define a class with one shared variable and one expression symbol, and try to utilize the class variable.
python
import numpy as np
import theano
import theano.tensor as T
class simple(object):
def __init__(self, input):
self.vector = theano.shared(np.array([1, 2, 3], dtype="float64"))
self.formula = self.vector * input
x = T.iscalar('x')
s = simple(x)
func = theano.function(inputs=[x], outputs=s.formula)
func(5)
Output result
array([ 5., 10., 15.])
The behavior after defining the class is a little complicated, so let's summarize it.
Is it the point or the cause of complexity that the description in the class includes the expression symbol?
Expression symbols cannot be called directly to check their values.
It is also difficult to understand the behavior unless you make it a function and enter a concrete value.
You can use Theano's classes in this way.
Recommended Posts