当前位置: 首页>>代码示例>>Python>>正文


Python shared_randomstreams.RandomStreams方法代码示例

本文整理汇总了Python中theano.tensor.shared_randomstreams.RandomStreams方法的典型用法代码示例。如果您正苦于以下问题:Python shared_randomstreams.RandomStreams方法的具体用法?Python shared_randomstreams.RandomStreams怎么用?Python shared_randomstreams.RandomStreams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在theano.tensor.shared_randomstreams的用法示例。


在下文中一共展示了shared_randomstreams.RandomStreams方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from theano.tensor import shared_randomstreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
def main(load_id):
        consts = Consts()
        consts.load_from_ids = load_id
        rng = numpy.random.RandomState()
        theano_rng = RandomStreams(rng.randint(2 ** 30))
        user_lines = UserLines(rng = rng,theano_rng = theano_rng,consts = consts)
        rating_info = numpy.zeros(1,dtype=theano.config.floatX)
        wday = 4 # friday
        rating_info[0] = get_aranged(value = wday, min_value = 0, max_value = 6)
        #user_id = user_lines.rng.randint(low=0,high=user_lines.matrix_ids.users_count)
        #user_ids = user_lines.__find_nearest(user_id,5)
        user_indices = [user_lines.rng.randint(low=0,high=len(user_lines.users_cvs)-1) for it in numpy.arange(5)]
        user_ids = [user_lines.users_cvs.at[indice,"id"] for indice in user_indices]
        #user_lines.build_line_for_rand_user(rating_info = rating_info, user_ids = user_ids, consts = consts)
        user_lines.build_rate_for_rand_user(rating_info = rating_info, user_ids = user_ids, consts = consts)
        sys.stdout.write("all done\n")
        return 
开发者ID:freegraphics,项目名称:MIDS,代码行数:19,代码来源:MIDS.py

示例2: __init__

# 需要导入模块: from theano.tensor import shared_randomstreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
def __init__(self, seed=DEFAULT_SEED):
        """
        Initialize seed and global random variables.
        """
        if seed != self.DEFAULT_SEED:
            self._seed = seed
        elif 'DEEPY_SEED' in os.environ:
            self._seed = int(os.environ['DEEPY_SEED'])
        else:
            self._seed = self.DEFAULT_SEED
        if self._seed != self.DEFAULT_SEED:
            logging.info("set global random seed to %d" % self._seed)

        self._numpy_rand = np.random.RandomState(seed=self._seed)
        self._theano_rand = RandomStreams(seed=self._seed)
        self._shared_rand = SharedRandomStreams(seed=self._seed)
        self._default_initializer = None 
开发者ID:zomux,项目名称:deepy,代码行数:19,代码来源:env.py

示例3: reset

# 需要导入模块: from theano.tensor import shared_randomstreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
def reset(self):
        # Set Original ordering
        self.ordering.set_value(np.arange(self._input_size, dtype=theano.config.floatX))

        # Reset RandomStreams
        self._rng.seed(self._random_seed)

        # Initial layer connectivity
        self.layers_connectivity[0].set_value((self.ordering + 1).eval())
        for i in range(1, len(self.layers_connectivity)-1):
            self.layers_connectivity[i].set_value(np.zeros((self._hidden_sizes[i-1]), dtype=theano.config.floatX))
        self.layers_connectivity[-1].set_value(self.ordering.get_value())

        # Reset MRG_RandomStreams (GPU)
        self._mrng.rstate = self._initial_mrng_rstate
        for state, value in zip(self._mrng.state_updates, self._initial_mrng_state_updates):
            state[0].set_value(value)

        self.sample_connectivity() 
开发者ID:ajbrock,项目名称:Neural-Photo-Editor,代码行数:21,代码来源:mask_generator.py

示例4: __init__

# 需要导入模块: from theano.tensor import shared_randomstreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
def __init__(self, memory_size: int, num_node_types: int, max_num_children: int, hyperparameters: dict,
                 rng: RandomStreams, name: str = "single_layer_combination"):
        self.__memory_size = memory_size
        self.__rng = rng
        self.__name = name
        self.__hyperparameters = hyperparameters

        w = np.random.randn(num_node_types, memory_size, max_num_children * memory_size) * \
            10 ** self.__hyperparameters["log_init_scale_embedding"]
        self.__w = theano.shared(w.astype(theano.config.floatX), name=name + ":w")

        bias = np.random.randn(num_node_types, memory_size) * 10 ** self.__hyperparameters["log_init_scale_embedding"]
        self.__bias = theano.shared(bias.astype(theano.config.floatX), name=name + ":b")

        self.__w_with_dropout = \
            dropout(self.__hyperparameters['dropout_rate'], self.__rng, self.__w, True) 
开发者ID:mast-group,项目名称:eqnet,代码行数:18,代码来源:model.py

示例5: __init__

# 需要导入模块: from theano.tensor import shared_randomstreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
def __init__(self, embeddings, memory_size: int, embeddings_size: int, hyperparameters: dict, rng: RandomStreams,
                 name="SequenceAveragingGRU", use_centroid=False):
        """
        :param embeddings: the embedding matrix
        """
        self.__name = name
        self.__embeddings = embeddings
        self.__memory_size = memory_size
        self.__embeddings_size = embeddings_size
        self.__hyperparameters = hyperparameters
        self.__rng = rng

        if use_centroid:
            self.__gru = GruCentroidsCell(memory_size, embeddings_size, hyperparameters['num_centroids'],
                                          hyperparameters['centroid_use_rate'], self.__rng, self.__name + ":GRUCell",
                                          hyperparameters['log_init_noise'])
        else:
            self.__gru = GruCell(memory_size, embeddings_size, self.__name + ":GRUCell",
                                 hyperparameters['log_init_noise'])

        self.__params = {self.__name + ":" + n: v for n, v in self.__gru.get_params().items()} 
开发者ID:mast-group,项目名称:eqnet,代码行数:23,代码来源:layers.py

示例6: __init__

# 需要导入模块: from theano.tensor import shared_randomstreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
def __init__(self,n_visible,n_hidden,batch_size):
        self.n_visible = n_visible
        self.n_hidden = n_hidden

        np_rng = np.random.RandomState(1234)
        theano_rng = RandomStreams(np_rng.randint(2 ** 30))

        initial_W = np.asarray(np_rng.uniform(low=-4*np.sqrt(6./(n_hidden + n_visible)),high=4*np.sqrt(6./(n_hidden+n_visible)),
            size=(n_visible, n_hidden)),dtype=theano.config.floatX)
        W = theano.shared(value=initial_W, name='W', borrow=True)

        hbias = theano.shared(value=np.zeros(n_hidden,dtype=theano.config.floatX),name='hbias',borrow=True)
        vbias = theano.shared(value=np.zeros(n_visible,dtype=theano.config.floatX),name='vbias',borrow=True)

        self.input = T.matrix('input')
        self.W = W
        self.hbias = hbias
        self.vbias = vbias
        self.theano_rng = theano_rng
        self.params = [self.W, self.hbias, self.vbias]
        
        self.persistent_chain = theano.shared(np.zeros((batch_size,n_hidden),dtype=theano.config.floatX),borrow=True)
        self.cost, self.updates = self.get_cost_updates(lr=0.1,persistent=self.persistent_chain, k=15)
        self.train = theano.function([self.input],self.cost,updates=self.updates,name='train_rbm')
        
        _i,_j,self._output_hidden = self.sample_h_given_v(self.input)
        self.output_hidden = theano.function([self.input],self._output_hidden) 
开发者ID:iamshang1,项目名称:Projects,代码行数:29,代码来源:rbm_pretraining.py

示例7: test_connection_pattern

# 需要导入模块: from theano.tensor import shared_randomstreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
def test_connection_pattern(self):
        # Basic case
        x, y, z = T.matrices('xyz')
        out1 = x * y
        out2 = y * z

        op1 = OpFromGraph([x, y, z], [out1, out2])
        results = op1.connection_pattern(None)
        expect_result = [[True, False],
                         [True, True],
                         [False, True]]
        assert results == expect_result

        # Graph with ops that don't have a 'full' connection pattern
        # and with ops that have multiple outputs
        m, n, p, q = T.matrices('mnpq')
        o1, o2 = op1(m, n, p)
        out1, out2 = op1(o1, q, o2)
        op2 = OpFromGraph([m, n, p, q], [out1, out2])

        results = op2.connection_pattern(None)
        expect_result = [[True, False],
                         [True, True],
                         [False, True],
                         [True, True]]
        assert results == expect_result

        # Inner graph where some computation doesn't rely on explicit inputs
        srng = RandomStreams(seed=234)
        rv_u = srng.uniform((2, 2))
        x, y = T.matrices('xy')
        out1 = x + rv_u
        out2 = y + 3
        out3 = 3 + rv_u
        op3 = OpFromGraph([x, y], [out1, out2, out3])

        results = op3.connection_pattern(None)
        expect_result = [[True, False, False],
                         [False, True, False],
                         [True, False, True]]
        assert results == expect_result 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:43,代码来源:test_builders.py

示例8: dropout_layer

# 需要导入模块: from theano.tensor import shared_randomstreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
def dropout_layer(layer, p_dropout):
    srng = shared_randomstreams.RandomStreams(
        np.random.RandomState(0).randint(999999))
    mask = srng.binomial(n=1, p=1-p_dropout, size=layer.shape)
    return layer*T.cast(mask, theano.config.floatX) 
开发者ID:dalmia,项目名称:WannaPark,代码行数:7,代码来源:network3.py

示例9: test_connection_pattern

# 需要导入模块: from theano.tensor import shared_randomstreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
def test_connection_pattern(self):
        # Basic case 
        x, y, z = T.matrices('xyz')
        out1 = x * y
        out2 = y * z

        op1 = OpFromGraph([x ,y, z], [out1, out2])
        results = op1.connection_pattern(None)
        expect_result = [[True, False],
                         [True, True],
                         [False, True]]
        assert results == expect_result

        # Graph with ops that don't have a 'full' connection pattern
        # and with ops that have multiple outputs 
        m, n, p, q = T.matrices('mnpq')
        o1, o2 = op1(m, n, p)
        out1, out2 = op1(o1, q, o2)
        op2 = OpFromGraph([m, n, p, q], [out1, out2])

        results = op2.connection_pattern(None)
        expect_result = [[True, False],
                         [True, True],
                         [False, True],
                         [True, True]]
        assert results == expect_result

        # Inner graph where some computation doesn't rely on explicit inputs
        srng = RandomStreams(seed=234)
        rv_u = srng.uniform((2,2))
        x, y = T.matrices('xy')
        out1 = x + rv_u
        out2 = y + 3
        out3 = 3 + rv_u
        op3 = OpFromGraph([x, y], [out1, out2, out3])

        results = op3.connection_pattern(None)
        expect_result = [[True, False, False],
                         [False, True, False],
                         [True, False, True]]
        assert results == expect_result 
开发者ID:rizar,项目名称:attention-lvcsr,代码行数:43,代码来源:test_builders.py

示例10: __init__

# 需要导入模块: from theano.tensor import shared_randomstreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
def __init__(self, input, n_input, n_hidden, W=None, bhid=None, bout=None):
		self.input = input
		self.n_input = n_input
		self.n_output = n_input
		self.n_hidden = n_hidden 

		if W is None:
			initial_W = numpy.random.uniform(
					low=-4*numpy.sqrt(6. / (n_hidden + n_input)),
                    high=4*numpy.sqrt(6. / (n_hidden + n_input)),
                    size=(n_input, n_hidden)).astype(theano.config.floatX)
			W = theano.shared(value = initial_W, name = 'W')
		self.W = W
		
		if bhid is None:
			initial_bhid = numpy.zeros(shape=(n_hidden, )).astype(theano.config.floatX)
			bhid = theano.shared(value = initial_bhid, name = 'bhid')
		self.bhid = bhid
		
		if bout is None:
			initial_bout = numpy.zeros(shape=(n_input, )).astype(theano.config.floatX)
			bout = theano.shared(value = initial_bout, name = 'bout')
		self.bout = bout
		
		# 自编码器的输入层和输出层是相同的
		self.W_pi = self.W.T
		self.params = [self.W, self.bhid, self.bout]
		self.hidden = self.get_hidden_value(self.input)
		self.output = self.get_reconstructed_value(self.hidden)
		
		self.theano_rng = RandomStreams(12345) 
开发者ID:innovation-cat,项目名称:DeepLearningBook,代码行数:33,代码来源:sda.py

示例11: dropout

# 需要导入模块: from theano.tensor import shared_randomstreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
def dropout(rng, x, p=0.5):
    """ Zero-out random values in x with probability p using rng """
    if p > 0. and p < 1.:
        seed = rng.randint(2 ** 30)
        srng = theano.tensor.shared_randomstreams.RandomStreams(seed)
        mask = srng.binomial(n=1, p=1.-p, size=x.shape,
                dtype=theano.config.floatX)
        return x * mask
    return x 
开发者ID:syhw,项目名称:DL4H,代码行数:11,代码来源:dnn.py

示例12: __init__

# 需要导入模块: from theano.tensor import shared_randomstreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
def __init__(self, incoming, num_units, num_outputs=0.01, **kwargs):
		super(BlackoutLayer, self).__init__(incoming, num_units, **kwargs)
		self._srng = RandomStreams(get_rng().randint(1, 2147462579))
		if num_outputs < 1:
			num_outputs = num_outputs * num_units
		self.num_outputs = int(num_outputs) 
开发者ID:rdevooght,项目名称:sequence-based-recommendations,代码行数:8,代码来源:sparse_lstm.py

示例13: train_rates

# 需要导入模块: from theano.tensor import shared_randomstreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
def train_rates():
    consts = Consts()
    rng = numpy.random.RandomState()
    theano_rng = RandomStreams(rng.randint(2 ** 30))
    rs = RecommenderSystem(rng= rng,theano_rng = theano_rng,consts=consts)
    validate_loss_min = 0
    validate_loss = 0
    for i in numpy.arange(100000):
        lt = time.time()
        for j in numpy.arange(consts.ids_move_count):
            loss_rates = rs.train_rates(learning_rate = consts.result_learning_rate)
            t1 = time.time()
            if t1>lt+1:
                sys.stdout.write("\t\t\t\t\t\t\t\t\t\r")
                sys.stdout.write("[%d] loss = %f , val = %f valmin = %f\r" % (i,loss_rates,validate_loss,validate_loss_min))
                lt = lt+1
        trace_rates(i + (consts.load_from_ids*consts.save_cycles),loss_rates,validate_loss_min,validate_loss,consts.trace_rates_file_name)
        if i % consts.save_cycles == 0:
            rs.save_rates((i/consts.save_cycles) + consts.load_from_ids,consts)
        if i % consts.validate_cycles == 0:
            validate_loss = rs.validate_rates(consts=consts)
            if validate_loss_min==0 or validate_loss<validate_loss_min:
                validate_loss_min = validate_loss
                rs.save_rates(0,consts)
        consts.update_index(i + (consts.load_from_ids*consts.save_cycles))
        
    return 
开发者ID:freegraphics,项目名称:MIDS,代码行数:29,代码来源:MIDS.py

示例14: __init__

# 需要导入模块: from theano.tensor import shared_randomstreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
def __init__(self, n_visible, n_hidden, nonlinearity="RLU"):
        self.theano_rng = RandomStreams(np.random.randint(2 ** 30))
        self.add_parameter(SizeParameter("n_visible"))
        self.add_parameter(SizeParameter("n_hidden"))
        self.add_parameter(NonLinearityParameter("nonlinearity"))
        self.n_visible = n_visible
        self.n_hidden = n_hidden
        self.parameters["nonlinearity"].set_value(nonlinearity) 
开发者ID:MarcCote,项目名称:NADE,代码行数:10,代码来源:NADE.py

示例15: __init__

# 需要导入模块: from theano.tensor import shared_randomstreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
def __init__(self, rng, input, n_in, n_out,
                 W=None, b=None, activation=T.tanh, dropout_factor=0.5):
        super(DropoutHiddenLayer, self).__init__(
                rng=rng, input=input, n_in=n_in, n_out=n_out, W=W, b=b,
                activation=activation)

        self.theano_rng = RandomStreams(rng.randint(2 ** 30))

        self.dropout_output = _dropout_from_layer(theano_rng = self.theano_rng,
                                                  hid_out = self.output, p=dropout_factor) 
开发者ID:yajiemiao,项目名称:pdnn,代码行数:12,代码来源:mlp_maxout.py


注:本文中的theano.tensor.shared_randomstreams.RandomStreams方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。