theano tutorial(三)
2016-04-18 17:16
381 查看
theano的图结构,参见这篇文章ycheng_sjtu: Theano学习笔记(三)——图结构
#coding=utf-8 """ 在theano graphs之间复制随机状态 1.在两个图之间可以转换随机发生器的所有状态,(eg.用第一个graph里面发生器的状态去初始化第二个发生器里面图) 2.theano.tensor.shared_randomstreams.RandomStreams和theano.sandbox.rng_mrg.MRG_RandomStreams 3.每当从RandomStreams获得一个随机变量,就在state_updates list里面加入一个元组,元组的第一个element是一个shared变量,代表于这个特定变量的随机数所联系发生器的状态,第二个代表了相对于这个随机数产生过程的那个theano graph(即RandomFunction{Uniform,0}) """ from __future__ import print_function import theano import numpy import theano.tensor as T from theano.sandbox.rng_mrg import MRG_RandomStreams from theano.tensor.shared_randomstreams import RandomStreams class 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())
相关文章推荐
- Web开发之一:Web UI技术综述
- easyUI实现动态增加表头
- git代码库回滚
- 微信公众号开发之JSSDK:记config:invalid signature 的错误排查
- WebView loadUrl,loadData,loadDataBase
- UVA_624_CD
- 关于json与java对象转换插件问题
- Nginx配置proxy_pass【转载】
- Linux下命令整理
- 如何解决线程安全问题
- centos下安装php+mysql
- 使用python实现可重入的公平读写锁
- WOJ 1608 Calculation
- 领域驱动设计之领域模型
- [问题记录.VisualStudio]TFS项目映射问题解决
- AjaxPro.2.dll使用方法简介
- codeforces_302D
- Unity3d 用NGUI制作做新手引导的思路
- GetArxPath
- Jquery学习之旅之CSS类的设置和移除