theano tutorial(一)
2016-04-18 12:05
429 查看
#coding=utf-8 """shared 使用共享变量 shared函数创建共享变量 可以被多个函数共享 share函数可以用于符号表达式(例如=datrices返回的对象) alue可以通过.get_value和.set_value获得和修改 updates function.updates 其参数(shared-variable, new expression)是一个字典 key:shared-variable,values:new expression 每次run function的时候都用new expression来替换shared-variable """ import theano import theano.tensor as T from theano import shared from theano import function state=shared(0) inc=T.iscalar('inc') accumulator=function([inc],state,updates=[(state,state+inc)]) print(state.get_value()) accumulator(1) print(state.get_value()) accumulator(300) print(state.get_value()) # 0 # 1 # 301 #可以充值state:.set_values() state.set_value(-1) accumulator(3) print(state.get_value()) #2 #可以定义多个方法使用同一个shared变量,这些函数都可以更新value decrementor=function([inc],state,updates=[(state,state-inc)]) decrementor(2) print(state.get_value()) #0 """ 使用updates有时是为了更快的使用一些内置的算法(eg.low-rank matrix updates) 和更好的控制内存的分配(gpu) """ #givens:当使用了shared变量定义来一个表达式,但不使用他的值, # dtype:一个用来描述数组中元素类型的对象,可以通过创造或指定dtype使用标准Python类型。另外NumPy提供它自己的数据类型 fn_of_state=state*2+inc foo=T.scalar(dtype=state.dtype)<pre code_snippet_id="1651439" snippet_file_name="blog_20160418_1_3329301" name="code" class="python">#givens允许你用一个不同的表达式将公式里面相同shape和dtype的那部分给替换掉 skip_shared=function([inc,foo],fn_of_state,givens=[(state,foo)])skip_shared(1, 3)print(state.get_value())
相关文章推荐
- Python学习十一——theano库符号求导示例代码
- ubuntu theano 安装成功,windows theano安装失败
- Theano 模块 基础知识篇
- Windows7+Anaconda+Theano+Pylearn2深度学习环境搭建
- deep learning 个人理解及其实现工具
- unbutu12.04 64bit系统 安装theano+cuda5.5,并运行deeplearningtutorial里面的代码
- 深度学习笔记:windows10+visual studio 2013+cuda7.5+theano+lasagne环境配置
- 利用Theano实现简单手写识别
- Windows安装Theano
- Windows8.1下安装theano和CUDA
- Windows 7 64位 安装配置Theano 配置GPU
- theano的配置过程
- Win7 中安装Theano及配置CUDA以搭建GPU加速环境
- debian下安装Theano(附pydot问题解决方法)
- Theano(1):windows、linux下安装深度学习库Theano
- Theano(3):Theano【数据类型】与【代码初尝试】
- Theano(6):Theano条件语句,IfElse vs Switch
- Theano(7):Theano循环语句,Scan
- Windows server 2012 下theano安装并配置GPU
- Deeplearning学习之Theano(1)--保存参数