首页 > 其他 > 详细

theano入门教程1.4

时间:2014-06-11 13:23:47      阅读:708      评论:0      收藏:0      [点我收藏+]

使用共享变量


# -*- coding: utf-8 -*-

"""

Created on Wed Jun  4 23:28:21 2014


@author: wencc

"""


from theano import shared

from theano import function

import theano.tensor as T


if __name__ == ‘__main__‘:

state = shared(0)

inc = T.iscalar(‘inc‘)

accumulator = function([inc], state, updates=[(state, state+inc)])

print state.get_value()

print accumulator(1)

print state.get_value()

print accumulator(20)

print state.get_value()

fn_of_state = state*2 + inc

foo = T.scalar(dtype=state.dtype)

skip_shared = function([inc, foo], fn_of_state, givens=[(state, foo)])

skip_shared(1, 3)

state.get_value()



shared函数构造共享变量,共享变量的get_value,set_value函数用来查看和设置共享变量的值

function函数中的updates参数用来更新共享变量,它是一个list,list中的每一项用map(共享变量,共享变量的新值表达式)的形式来表示。









theano入门教程1.4,布布扣,bubuko.com

theano入门教程1.4

原文:http://www.cnblogs.com/fireae/p/3772511.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!