MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / back_propagate

Method back_propagate

examples/machine_learning/deep_belief_net.cpp:136–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134 }
135
136 void back_propagate(const vector<array> signal, const array &target,
137 const double &alpha) {
138 // Get error for output layer
139 array out = signal[num_total - 1];
140 array err = (out - target);
141 int m = target.dims(0);
142
143 for (int i = num_total - 2; i >= 0; i--) {
144 array in = add_bias(signal[i]);
145 array delta = (deriv(out) * err).T();
146
147 // Adjust weights
148 array grad = -(alpha * matmul(delta, in)) / m;
149 weights[i] += grad.T();
150
151 // Input to current layer is output of previous
152 out = signal[i];
153 err = matmulTT(delta, weights[i]);
154
155 // Remove the error of bias and propagate backward
156 err = err(span, seq(1, out.dims(1)));
157 }
158 }
159
160 public:
161 dbn(const int in_sz, const int out_sz, const std::vector<int> hidden_layers)

Callers

nothing calls this directly

Calls 6

matmulTTFunction · 0.85
seqClass · 0.85
TMethod · 0.80
derivFunction · 0.70
matmulFunction · 0.50
dimsMethod · 0.45

Tested by

no test coverage detected