码迷,mamicode.com
首页 > 其他好文 > 详细

theano 入门教程1.5

时间:2014-06-11 12:49:50      阅读:401      评论:0      收藏:0      [点我收藏+]

标签:style   class   http   get   2014   set   

# -*- 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

标签:style   class   http   get   2014   set   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!