theano tutorial(一)
来源:互联网 发布:软件测试数据库笔试题 编辑:程序博客网 时间:2024/04/26 06:09
#coding=utf-8"""shared使用共享变量shared函数创建共享变量可以被多个函数共享share函数可以用于符号表达式(例如=datrices返回的对象)alue可以通过.get_value和.set_value获得和修改updatesfunction.updates 其参数(shared-variable, new expression)是一个字典key:shared-variable,values:new expression每次run function的时候都用new expression来替换shared-variable"""import theanoimport theano.tensor as Tfrom theano import sharedfrom theano import functionstate=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变量,这些函数都可以更新valuedecrementor=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+incfoo=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())
0 0
- theano tutorial(一)
- theano tutorial(一)
- theano tutorial学习笔记(一)
- Theano Tutorial文档翻译(一):词汇
- theano tutorial -- 用theano实现逻辑回归LR(一)theano基础知识
- theano tutorial(三)
- theano tutorial(六)Loop
- 深度学习Theano教程Theano tutorial
- theano tutorial(七)稀疏矩阵
- theano tutorial(八)Shape Information
- theano tutorial(十)Graph Structures
- theano tutorial(四) logistic regression 练习
- theano tutorial(五)计算偏导数
- theano tutorial(六)IfElse vs Switch
- Theano Tutorial文档翻译(二):代数
- Theano Tutorial文档翻译(六) - 条件
- Theano Tutorial文档翻译(七) - 循环
- theano tutorial -- 用theano实现逻辑回归LR(三)theano实现LR算法
- Google地图百度地图GPS经纬度偏移转换(JAVA)
- iOS 计算文件夹中包含所有文件的大小
- C#学习-string
- 疫苗:Java HashMap的死循环
- 新建工作站点
- theano tutorial(一)
- Android程序中访问sdcard
- POJ 3767 I Wanna Go Home(Dijkstra)
- java.io.filenotfoundexception: ... .jar
- oracle 手工建库
- 各种view
- WebSocket connection to 'ws://.../sockjs/pushWords/635/78epgvv8/websocket'
- PAM登录代码
- CocoaPods安装和使用教程