Skip to content

Commit 8d80b20

Browse files
refac: addcommneted out prevous implmentation
1 parent 7aef178 commit 8d80b20

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

try1 (OOP Approach)/cpp/src/classes.cpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,41 @@ void MLP::feedForward(float *inputArr, int inputSize) {
175175
}
176176
}
177177

178+
// this->resetNeuronsActivations();
179+
// Layer *tempInputLayer = new Layer(inputLayerSize, 0);
180+
// Layer *prevLayer = tempInputLayer;
181+
//
182+
// if (inputSize != this->inputLayerSize)
183+
// throw runtime_error("Expected Input was Not Received");
184+
// for (int i = 0; i < this->inputLayerSize; i++) {
185+
// tempInputLayer->neurons[i]->activation = inputArr[i];
186+
// }
187+
//
188+
// // for Traversing Each Layer
189+
// for (int i = 0; i < this->hidOutLayerCount; i++) {
190+
// // for Traversing Each Neuron of a Layer
191+
// for (int i2 = 0; i2 < this->hidOutLayerSizes[i]; i2++) {
192+
// Neuron *cNeuron = this->HidOutlayers[i]->neurons[i2];
193+
//
194+
// // For traversing each Weight of current Neuron
195+
// for (int i3 = 0; i3 < cNeuron->prevLayerNeurons_count; i3++) {
196+
// cNeuron->z += prevLayer->neurons[i3]->activation *
197+
// cNeuron->weights[i3];
198+
// }
199+
// cNeuron->activation += sigmoid(cNeuron->z) + cNeuron->bias;
200+
// // TO DIplay Each Neuron's Final Activation in a Formatted way
201+
// // std::cout<<"Neuron ["<<i<<"]"<<"["<<i2<<"] :
202+
// "<<cNeuron->value<<endl;
203+
// }
204+
// prevLayer = this->HidOutlayers[i];
205+
// }
206+
//
207+
// // for Returning output
208+
// const int outputSize = this->hidOutLayerSizes[this->hidOutLayerCount - 1];
209+
// for (int i = 0; i < outputSize; i++) {
210+
// this->predictions[i] = prevLayer->neurons[i]->activation;
211+
// }
212+
// delete tempInputLayer;
178213
}
179214

180215
void MLP::predict(float **inputs, int inputSize, float **target, int targetSize,
@@ -278,8 +313,48 @@ void MLP::backPropogate(float *inputArr, int inputSize, float *targetArr,
278313
}
279314
n->bias -= l_rate * output_layer_deltas[i];
280315
}
316+
// delete[] a_prev;
281317

282318
// For hidden layer Weights Adjustments
319+
// const float *next_layer_deltas = output_layer_deltas;
320+
// for (int layer_idx = this->hidOutLayerCount - 2; layer_idx >= 0;
321+
// layer_idx--) {
322+
// float *a_prev;
323+
// if (layer_idx == 0) {
324+
// a_prev = inputArr;
325+
// } else {
326+
// a_prev = new float[this->hidOutLayerSizes[layer_idx - 1]]();
327+
// for (int i = 0; i < this->hidOutLayerSizes[layer_idx - 1]; i++) {
328+
// a_prev[i] = this->HidOutlayers[layer_idx -
329+
// 1]->neurons[i]->activation;
330+
// }
331+
// }
332+
// float *current_layer_deltas =
333+
// new float[this->hidOutLayerSizes[layer_idx]]();
334+
//
335+
// // Write the actuall code here
336+
// for (int i = 0; i < this->hidOutLayerSizes[layer_idx]; i++) {
337+
// Neuron *n = this->HidOutlayers[layer_idx]->neurons[i];
338+
// float error_sum = 0;
339+
// for (int j = 0; j < this->hidOutLayerSizes[layer_idx + 1]; j++) {
340+
// const Neuron *n_next = this->HidOutlayers[layer_idx + 1]->neurons[j];
341+
// error_sum += next_layer_deltas[j] * n_next->weights[i];
342+
// }
343+
// const float activation_derivative = n->z > 0 ? 1 : 0;
344+
// const float delta = activation_derivative * error_sum;
345+
// current_layer_deltas[i] = delta;
346+
// for (int k = 0; k < n->prevLayerNeurons_count; k++) {
347+
// n->weights[k] -= l_rate * a_prev[k] * delta;
348+
// }
349+
// n->bias -= l_rate * delta;
350+
// next_layer_deltas = current_layer_deltas;
351+
// }
352+
// delete[] current_layer_deltas;
353+
//
354+
// if (layer_idx != 0) {
355+
// delete[] a_prev;
356+
// }
357+
// }
283358

284359
// for (int i = this->hidOutLayerCount - 1; i >= 0; i--) {
285360
// // for Traversing Each Neuron of a Layer

0 commit comments

Comments
 (0)