首页 > 其他 > 详细

theano 入门教程1.5

时间:2014-06-11 12:46:54      阅读:441      评论:0      收藏:0      [点我收藏+]

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

"""

Created on Thu Jun 05 17:48:31 2014


@author: Administrator

"""


import theano

import numpy as np

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,))


def copy_random_state(g1, g2):

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())

if __name__ == "__main__":

g1 = Graph(seed=123)

f1 = theano.function([], g1.y)

g2 = Graph(seed=884)

f2 = theano.function([], g2.y)


print ‘f1 return ‘, f1()

print ‘f2 return ‘, f2()

print ‘after copy random state‘

copy_random_state(g1, g2)

print ‘f1 return ‘, f1()

print ‘f2 return ‘, f2()





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

theano 入门教程1.5

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

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