theano中 founction的用法

来源:互联网 发布:php常用全局变量 编辑:程序博客网 时间:2024/05/18 02:48

代码说明:

import theanoimport theano.tensor as Tprint 'theano.scan_module.until:'class GRU:    def __init__(self,word_dim):        self.word_dim = word_dim        self.theano = {}        self.__Thea_build__()    def __Thea_build__(self):        def prod_2(pre_value, max_value):            print "what-what"            return pre_value*2, theano.scan_module.until(pre_value*2 > max_value)        max_value = T.iscalar('max_value')        result, update = theano.scan(prod_2, outputs_info=T.constant(1.),                                     non_sequences=[max_value], n_steps=100)        self.prod_fn = theano.function([max_value], result, updates=update)mode = GRU(3)print "-----------------------------"for i in range(100,500,100):    print mode.prod_fn(i)


执行前需要先编译一下

输出:

[@104_27 theano_test]$ python theano_function.py
Using gpu device 0
theano.scan_module.until:
what-what
-----------------------------
[   2.    4.    8.   16.   32.   64.  128.]
[   2.    4.    8.   16.   32.   64.  128.  256.]
[   2.    4.    8.   16.   32.   64.  128.  256.  512.]
[   2.    4.    8.   16.   32.   64.  128.  256.  512.]



0 0
原创粉丝点击