質問

Theanoを使用して、いくつかの単純なニューラルネットケースを理解しようとしています。 deeplearning.netサイトは、ロジスティック回帰アプリケーションを簡単なケースに実装するための次の簡単なコードを提供します。

import numpy
import theano
import theano.tensor as T
rng = numpy.random

N = 400
feats = 784
D = (rng.randn(N, feats), rng.randint(size=N, low=0, high=2))
training_steps = 10000

# Declare Theano symbolic variables
x = T.matrix("x")
y = T.vector("y")
w = theano.shared(rng.randn(feats), name="w")
b = theano.shared(0., name="b")
print("Initial model:")
print(w.get_value())
print(b.get_value())

# Construct Theano expression graph
p_1 = 1 / (1 + T.exp(-T.dot(x, w) - b))   # Probability that target = 1
prediction = p_1 > 0.5                    # The prediction thresholded
xent = -y * T.log(p_1) - (1-y) * T.log(1-p_1) # Cross-entropy loss function
cost = xent.mean() + 0.01 * (w ** 2).sum()# The cost to minimize
gw, gb = T.grad(cost, [w, b])             # Compute the gradient of the cost
                                          # (we shall return to this in a
                                          # following section of this tutorial)

# Compile
train = theano.function(
          inputs=[x,y],
          outputs=[prediction, xent],
          updates=((w, w - 0.1 * gw), (b, b - 0.1 * gb)))
predict = theano.function(inputs=[x], outputs=prediction)

# Train
for i in range(training_steps):
    pred, err = train(D[0], D[1])

print("Final model:")
print(w.get_value())
print(b.get_value())
print("target values for D:")
print(D[1])
print("prediction on D:")
print(predict(D[0]))

P_1はロジスティック回帰関数であることを理解しています。予測は、値が0クラスであるか1クラスであるか、Xentは損失関数、つまり正しい距離が予測であるかどうかです。私は次の行、コストを理解していません。コストはXent、すなわち損失に等しいべきではありませんか?ここで表すコスト関数は何ですか?また、なぜバイアスが最初に0に設定され、重みのような乱数ではないのですか?

役に立ちましたか?

解決

私は次の行、コストを理解していません。コストはXent、すなわち損失に等しいべきではありませんか?ここで表すコスト関数は何ですか?

コストはエラー(xent.mean()) +いくつかの正規化(0.01 *(w ** 2).sum())です

なぜバイアスが最初に0に設定され、重みのような乱数ではないのですか?

非対称性の破壊は重みの小さな乱数によって提供されるため、バイアスをゼロに初期化することが可能です。

詳細 ここ.

ライセンス: CC-BY-SA帰属
所属していません datascience.stackexchange
scroll top