n層ニューラルネットワークで勾配を計算するための適切な実装は何ですか?
ウェイト レイヤー:
- 最初の層の重み:
(n_inputs+1, n_units_layer)-matrix
- 隠れ層の重み:
(n_units_layer+1, n_units_layer)-matrix
- 最後の層の重み:
(n_units_layer+1, n_outputs)-matrix
ノート:
- 隠れ層が 1 つしかない場合は、2 つの (重み) 層だけを使用してネットを表します。
inputs --first_layer-> network_unit --second_layer-> output
- 複数の隠れ層を持つ n 層ネットワークの場合、(2) のステップを実装する必要があります。
少しあいまいな擬似コード:
weight_layers = [ layer1, layer2 ] # a list of layers as described above
input_values = [ [0,0], [0,0], [1,0], [0,1] ] # our test set (corresponds to XOR)
target_output = [ 0, 0, 1, 1 ] # what we want to train our net to output
output_layers = [] # output for the corresponding layers
for layer in weight_layers:
output <-- calculate the output # calculate the output from the current layer
output_layers <-- output # store the output from each layer
n_samples = input_values.shape[0]
n_outputs = target_output.shape[1]
error = ( output-target_output )/( n_samples*n_outputs )
""" calculate the gradient here """