1- #include < iostream>
21#include " ../include/NeuralNet/classes.h"
2+ #include < iostream>
33
44using namespace std ;
55
6- int *genRandomInts (int arrLen, int min, int max)
7- {
6+ int *genRandomInts (int arrLen, int min, int max) {
87 int *arr = (int *)malloc (arrLen * sizeof (int ));
9- for (int i = 0 ; i < arrLen; i++)
10- {
8+ for (int i = 0 ; i < arrLen; i++) {
119 int randVal = rand () % (max - min + 1 ) + min;
1210 arr[i] = randVal;
1311 }
1412 return arr;
1513}
16- float *genRandomFloats (int arrLen, float min, float max)
17- {
14+ float *genRandomFloats (int arrLen, float min, float max) {
1815 float *arr = new float [arrLen];
19- for (int i = 0 ; i < arrLen; i++)
20- {
16+ for (int i = 0 ; i < arrLen; i++) {
2117 float randVal = ((float )rand () / RAND_MAX) * (max - min) + min;
2218 arr[i] = randVal;
2319 }
2420 return arr;
2521}
26- float **genRandom2DFloats (int rows, int cols, float min, float max)
27- {
22+ float **genRandom2DFloats (int rows, int cols, float min, float max) {
2823 // Allocate memory for the array of row pointers
2924 float **array2D = new float *[rows];
3025 // Generate each row using genRandomFloats
31- for (int i = 0 ; i < rows; i++)
32- {
26+ for (int i = 0 ; i < rows; i++) {
3327 array2D[i] = genRandomFloats (cols, min, max);
3428 }
3529 return array2D;
3630}
3731
38- float **getIdentityMatrix (int rows, int cols)
39- {
32+ float **getIdentityMatrix (int rows, int cols) {
4033 float **matrix = new float *[rows];
41- for (int i = 0 ; i < rows; i++)
42- {
34+ for (int i = 0 ; i < rows; i++) {
4335 matrix[i] = new float [cols];
44- for (int j = 0 ; j < cols; j++)
45- {
36+ for (int j = 0 ; j < cols; j++) {
4637 matrix[i][j] = (i == j) ? 1 .0f : 0 .0f ;
4738 }
4839 }
4940 return matrix;
5041}
5142
52- void print2DArray (float **matrix, int rows, int cols)
53- {
43+ void print2DArray (float **matrix, int rows, int cols) {
5444 cout << " 2D Array : " << endl;
55- for (int i = 0 ; i < rows; i++)
56- {
57- for (int j = 0 ; j < cols; j++)
58- {
45+ for (int i = 0 ; i < rows; i++) {
46+ for (int j = 0 ; j < cols; j++) {
5947 cout << matrix[i][j] << " " ;
6048 }
6149 cout << endl;
6250 }
6351}
6452
65- int main ()
66- {
53+ int main () {
6754 srand (time (NULL ));
6855 const int inputLayerSize = 10 ;
6956 const int hidOutLayerCount = 2 ;
7057 const int outputLayerSize = 10 ;
7158 int *hidOutLayerSizes = genRandomInts (hidOutLayerCount, 16 , 20 );
72- NeuralNet::MLP *MLP = new NeuralNet::MLP (inputLayerSize, hidOutLayerCount, hidOutLayerSizes, outputLayerSize, 0.3 );
59+ NeuralNet::MLP *MLP = new NeuralNet::MLP (
60+ inputLayerSize, hidOutLayerCount, hidOutLayerSizes, outputLayerSize, 0.01 );
7361
7462 // Dataset with labels
7563 const int samples_count = 10 ;
@@ -85,4 +73,4 @@ int main()
8573 // Predict
8674 MLP->predict (inputs, inputLayerSize, targets, outputLayerSize, samples_count);
8775 cout << " Ended" << endl;
88- }
76+ }
0 commit comments