Theanoをつかってみた
最近Deep learningがちょっと気になってきたのでネットで調べて見たらどうやらTheanoとかいうやつが良い?らしい。
調べてみた。
DeepLearning - Theano の 基本メモ - Qiita
Theano 入門
個人的にはDeep learningの数学的背景も知りたいので、Theanoでいいかーでのんびりやってみることにする。
インストールは割愛。(だって他の人が色々書いてるし・・・)
とりあえず、コードちょっと書いてみる。
import theano.tensor as T import theano x = T.dscalar() func = 1/(1+T.log(x)) valFunc = theano.function([x], func) print valFunc(2)
なんか、tensorっていうのが重要っぽい。
funcは実際に数値計算されるわけではなく、実際に値を代入できる形にするのがfunction([x], func)というわけ。
[x]で束縛変数を指定してやるって感じかな。ん、ということは・・・
import theano.tensor as T import theano x = T.dscalar() y = T.dscalar() func = (1+T.log(y))/(1+T.log(x)) valFunc = theano.function([x], func) print valFunc(2)
とやってみたら、
Traceback (most recent call last): File "test.py", line 12, in <module> valFunc = theano.function([x], func) File "/usr/local/lib/python2.7/dist-packages/theano/compile/function.py", line 223, in function profile=profile) File "/usr/local/lib/python2.7/dist-packages/theano/compile/pfunc.py", line 512, in pfunc on_unused_input=on_unused_input) File "/usr/local/lib/python2.7/dist-packages/theano/compile/function_module.py", line 1311, in orig_function on_unused_input=on_unused_input).create( File "/usr/local/lib/python2.7/dist-packages/theano/compile/function_module.py", line 1007, in __init__ fgraph, additional_outputs = std_fgraph(inputs, outputs, accept_inplace) File "/usr/local/lib/python2.7/dist-packages/theano/compile/function_module.py", line 132, in std_fgraph fgraph = gof.fg.FunctionGraph(orig_inputs, orig_outputs) File "/usr/local/lib/python2.7/dist-packages/theano/gof/fg.py", line 128, in __init__ self.__import_r__(outputs, reason="init") File "/usr/local/lib/python2.7/dist-packages/theano/gof/fg.py", line 250, in __import_r__ self.__import__(apply_node, reason=reason) File "/usr/local/lib/python2.7/dist-packages/theano/gof/fg.py", line 344, in __import__ r) theano.gof.fg.MissingInputError: ('An input of the graph, used to compute Elemwise{log,no_inplace}(<TensorType(float64, scalar)>), was not provided and not given a value', <TensorType(float64, scalar)>)
と言われた。どうやら評価可能なvalFuncにする際に自由変数が残ってないか判断するみたい。