如何获取Theano符号变量的中值?

2024-09-29 23:21:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我可以得到无变量的均值,但我不知道如何得到中值。你能帮我找一下吗?我想用中值而不是平均值来计算图像重建成本,我在反向传播中使用它来更新自动编码器的参数。你知道吗

我现在的代码是:

def get_cost_updates(self,input,learning_rate):

    input = utils.get_corrupted_input(input,self.theano_rng,noise_rate)
    hid_layer, recons = self.get_reconstructed_input(input)
    cross_entropy=lambda a,b:-a*T.log(b)-(1-a)*T.log(1-b)
    cost_recons= T.sum((self.x_row.T-recons.T)**2,axis=1)
    mean_activity=T.mean(hid_layer,axis=1)

    cost_sparsity=cross_entropy(self.rho,mean_activity)
    cost=T.mean(cost_recons)+T.mean(cost_sparsity)
    ###
    train_updates=OrderedDict({})
    for p in self.params:
        grad_wrt_param=T.grad(cost,p)
        train_updates[p]=p-learning_rate*grad_wrt_param
    ###
    return (cost.astype(theano.config.floatX),train_updates)

Tags: selflayerinputgetratetraintheanomean

热门问题