theano tutorial(三)
来源:互联网 发布:js数组从小到大排序 编辑:程序博客网 时间:2024/04/26 01:09
theano的图结构,参见这篇文章ycheng_sjtu: Theano学习笔记(三)——图结构
#coding=utf-8"""在theano graphs之间复制随机状态1.在两个图之间可以转换随机发生器的所有状态,(eg.用第一个graph里面发生器的状态去初始化第二个发生器里面图)2.theano.tensor.shared_randomstreams.RandomStreams和theano.sandbox.rng_mrg.MRG_RandomStreams3.每当从RandomStreams获得一个随机变量,就在state_updates list里面加入一个元组,元组的第一个element是一个shared变量,代表于这个特定变量的随机数所联系发生器的状态,第二个代表了相对于这个随机数产生过程的那个theano graph(即RandomFunction{Uniform,0})"""from __future__ import print_functionimport theanoimport numpyimport theano.tensor as Tfrom theano.sandbox.rng_mrg import MRG_RandomStreamsfrom theano.tensor.shared_randomstreams import RandomStreamsclass Graph(): def __init__(self, seed=123): self.rng = RandomStreams(seed) self.y = self.rng.uniform(size=(1,))g1=Graph(seed=123)f1=theano.function([],g1.y)g2=Graph(seed=987)f2=theano.function([],g2.y)print(f1())print(f2())def copy_random_state(g1, g2): #isinstance(sinstance(object, class_or_type_or_tuple) #Return whether an object is an instance of a class or of a subclass thereof.With a type as second argument, return whether that is the object's type. if isinstance(g1.rng, MRG_RandomStreams): g2.rng.rstate = g1.rng.rstate #其实上面的代码没看太明白,但是其实注销来结果好像也是对的 for (su1, su2) in zip(g1.rng.state_updates, g2.rng.state_updates): su2[0].set_value(su1[0].get_value())copy_random_state(g1, g2)print(f1())print(f2())
0 0
- theano tutorial(三)
- theano tutorial -- 用theano实现逻辑回归LR(三)theano实现LR算法
- Theano Tutorial文档翻译(三) - 基础张量功能
- theano tutorial(一)
- theano tutorial(六)Loop
- theano tutorial(一)
- 深度学习Theano教程Theano tutorial
- theano tutorial(七)稀疏矩阵
- theano tutorial(八)Shape Information
- theano tutorial(十)Graph Structures
- Theano学习三----Theano function
- theano tutorial学习笔记(一)
- theano tutorial(四) logistic regression 练习
- theano tutorial(五)计算偏导数
- theano tutorial(六)IfElse vs Switch
- Theano Tutorial文档翻译(一):词汇
- Theano Tutorial文档翻译(二):代数
- Theano Tutorial文档翻译(六) - 条件
- JAVA多线程--基本特性
- 版本更新的Service
- 使用JMeter创建数据库(Mysql)测试
- 如何禁用easyui中linkbutton的click事件
- ubuntu 安装 opencv
- theano tutorial(三)
- MATLAB“figure”使用详解!
- Linux内存管理之二 内存节点和内存分区
- linux下iconv()函数的用法
- webuploader 手动提交问题
- Handler、Loop、MessageQueue的关系
- GlobalAlloc、GlobalLock和GlobalUnLock详解
- cocos2d-x 3.0 在C++中调用lua函数
- 阅读论文:Distributed GraphLab