0

私は Theano ベースの自動エンコーダーを使用して作業を行っており、1 つの隠れ層であるガウス分布の混合からのサンプルとして入力を提供しています。出力が入力と同じになることを期待していましたが、達成できていません。このチュートリアルの実装に触発されました。隠れ層が 1 つしかないオートエンコーダーでも、出力の正確なレプリカを復元するのに十分ですか?

私のコードは以下のようになります:

` def train(self, n_epochs=100, mini_batch_size=1, learning_rate=0.01):
    index = T.lscalar()
    x=T.matrix('x')
    params = [self.W, self.b1, self.b2]
    hidden = self.activation_function(T.dot(x, self.W)+self.b1)
    output = T.dot(hidden,T.transpose(self.W))+self.b2
    output = self.output_function(output)


    # Use mean square error
    L = T.sum((x - output) ** 2)
    cost = L.mean()

    updates=[]

    #Return gradient with respect to W, b1, b2.
    gparams = T.grad(cost,params)

    #Create a list of 2 tuples for updates.
    for param, gparam in zip(params, gparams):
        updates.append((param, param-learning_rate*gparam))

    #Train given a mini-batch of the data.
    train = th.function(inputs=[index], outputs=cost, updates=updates,
                        givens={x:self.X[index:index+mini_batch_size,:]})
    import time
    start_time = time.clock()
    acc_cost = []
    for epoch in xrange(n_epochs):

        #print "Epoch:", epoch
        for row in xrange(0,self.m, mini_batch_size):
            cost = train(row)
        acc_cost.append(cost)

    plt.plot(range(n_epochs), acc_cost)
    plt.ylabel("cost")
    plt.xlabel("epochs")
    plt.show()

    # Format input data for plotable format
    norm_data = self.X.get_value()
    plot_var1 = []
    plot_var1.append(norm_data[:,0])
    plot_var2 = []
    plot_var2.append(norm_data[:,1])
    plt.plot(plot_var1, plot_var2, 'ro')

    # Hidden output
    x=T.dmatrix('x')
    hidden = self.activation_function(T.dot(x,self.W)+self.b1)
    transformed_data = th.function(inputs=[x], outputs=[hidden])
    hidden_data = transformed_data(self.X.get_value())
    #print "hidden_output ", hidden_data[0]

    # final output
    y=T.dmatrix('y')
    W = T.transpose(self.W)
    output = self.activation_function(T.dot(y,W) + self.b2)
    transformed_data = th.function(inputs=[y], outputs=[output])
    output_data = transformed_data(hidden_data[0])[0]
    print "decoded_output ", output_data

    # Format output data for plotable format
    plot_var1 = []
    plot_var1.append(output_data[:,0])
    plot_var2 = []
    plot_var2.append(output_data[:,1])
    plt.plot(plot_var1, plot_var2, 'bo')
    plt.show()



' 
4

1 に答える 1

0

あなたのコードで:

    params = [self.W, self.b1, self.b2]
    hidden = self.activation_function(T.dot(x, self.W)+self.b1)
    output = T.dot(hidden,T.transpose(self.W))+self.b2

入力と出力の両方に同じ重みを使用しています。どうですか:

    params = [self.W1, self.W2, self.b1, self.b2]
    hidden = self.activation_function(T.dot(x, self.W1)+self.b1)
    output = T.dot(hidden,self.W2)+self.b2

オートエンコーダーは PCA ではありません。同じ重みを使用したい場合は、重みが直交するように制約することをお勧めします。

それ以外の場合は、より深い AE を作成すると役立つ場合があります。独立した重み行列が 1 つしかないため、提案されたモデルは 3 層 MLP のようなユニバーサル関数近似器として動作することはほとんどありません。

于 2016-11-23T11:14:38.970 に答える