feat: Add Neural Network (Multilayer Perceptron) (#1025)

* Completed NN

* Made changes

* Added return in identity function

* Added <random> and fixed namespace naming

* clang-tidy changes

* Update machine_learning/neural_network.cpp

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update machine_learning/neural_network.cpp

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update machine_learning/neural_network.cpp

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update machine_learning/vector_ops.hpp

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update machine_learning/vector_ops.hpp

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update machine_learning/neural_network.cpp

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update machine_learning/neural_network.cpp

Co-authored-by: David Leal <halfpacho@gmail.com>

* added std::cerr and changed argmax's namespace

* Done suggested changes

* Fixed a comment

* clang-tidy fixes

Co-authored-by: David Leal <halfpacho@gmail.com>
This commit is contained in:
Deep Raval
2020-08-20 00:55:32 +05:30
committed by GitHub
parent dfe5bd7638
commit 4a34bec125
3 changed files with 1426 additions and 0 deletions

152
machine_learning/iris.csv Normal file
View File

@@ -0,0 +1,152 @@
https://archive.ics.uci.edu/ml/datasets/iris
sepal length in cm,sepal width in cm,petal length in cm,petal width in cm
5.1,3.5,1.4,.2,0
4.9,3,1.4,.2,0
4.7,3.2,1.3,.2,0
4.6,3.1,1.5,.2,0
5,3.6,1.4,.2,0
5.4,3.9,1.7,.4,0
4.6,3.4,1.4,.3,0
5,3.4,1.5,.2,0
4.4,2.9,1.4,.2,0
4.9,3.1,1.5,.1,0
5.4,3.7,1.5,.2,0
4.8,3.4,1.6,.2,0
4.8,3,1.4,.1,0
4.3,3,1.1,.1,0
5.8,4,1.2,.2,0
5.7,4.4,1.5,.4,0
5.4,3.9,1.3,.4,0
5.1,3.5,1.4,.3,0
5.7,3.8,1.7,.3,0
5.1,3.8,1.5,.3,0
5.4,3.4,1.7,.2,0
5.1,3.7,1.5,.4,0
4.6,3.6,1,.2,0
5.1,3.3,1.7,.5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.3,2
6.3,2.5,5,1.9,2
6.5,3,5.2,2,2
6.2,3.4,5.4,2.3,2
5.9,3,5.1,1.8,2
1 https://archive.ics.uci.edu/ml/datasets/iris
2 sepal length in cm,sepal width in cm,petal length in cm,petal width in cm
3 5.1,3.5,1.4,.2,0
4 4.9,3,1.4,.2,0
5 4.7,3.2,1.3,.2,0
6 4.6,3.1,1.5,.2,0
7 5,3.6,1.4,.2,0
8 5.4,3.9,1.7,.4,0
9 4.6,3.4,1.4,.3,0
10 5,3.4,1.5,.2,0
11 4.4,2.9,1.4,.2,0
12 4.9,3.1,1.5,.1,0
13 5.4,3.7,1.5,.2,0
14 4.8,3.4,1.6,.2,0
15 4.8,3,1.4,.1,0
16 4.3,3,1.1,.1,0
17 5.8,4,1.2,.2,0
18 5.7,4.4,1.5,.4,0
19 5.4,3.9,1.3,.4,0
20 5.1,3.5,1.4,.3,0
21 5.7,3.8,1.7,.3,0
22 5.1,3.8,1.5,.3,0
23 5.4,3.4,1.7,.2,0
24 5.1,3.7,1.5,.4,0
25 4.6,3.6,1,.2,0
26 5.1,3.3,1.7,.5,0
27 4.8,3.4,1.9,.2,0
28 5,3,1.6,.2,0
29 5,3.4,1.6,.4,0
30 5.2,3.5,1.5,.2,0
31 5.2,3.4,1.4,.2,0
32 4.7,3.2,1.6,.2,0
33 4.8,3.1,1.6,.2,0
34 5.4,3.4,1.5,.4,0
35 5.2,4.1,1.5,.1,0
36 5.5,4.2,1.4,.2,0
37 4.9,3.1,1.5,.2,0
38 5,3.2,1.2,.2,0
39 5.5,3.5,1.3,.2,0
40 4.9,3.6,1.4,.1,0
41 4.4,3,1.3,.2,0
42 5.1,3.4,1.5,.2,0
43 5,3.5,1.3,.3,0
44 4.5,2.3,1.3,.3,0
45 4.4,3.2,1.3,.2,0
46 5,3.5,1.6,.6,0
47 5.1,3.8,1.9,.4,0
48 4.8,3,1.4,.3,0
49 5.1,3.8,1.6,.2,0
50 4.6,3.2,1.4,.2,0
51 5.3,3.7,1.5,.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.9,5.6,1.8,2
107 6.5,3,5.8,2.2,2
108 7.6,3,6.6,2.1,2
109 4.9,2.5,4.5,1.7,2
110 7.3,2.9,6.3,1.8,2
111 6.7,2.5,5.8,1.8,2
112 7.2,3.6,6.1,2.5,2
113 6.5,3.2,5.1,2,2
114 6.4,2.7,5.3,1.9,2
115 6.8,3,5.5,2.1,2
116 5.7,2.5,5,2,2
117 5.8,2.8,5.1,2.4,2
118 6.4,3.2,5.3,2.3,2
119 6.5,3,5.5,1.8,2
120 7.7,3.8,6.7,2.2,2
121 7.7,2.6,6.9,2.3,2
122 6,2.2,5,1.5,2
123 6.9,3.2,5.7,2.3,2
124 5.6,2.8,4.9,2,2
125 7.7,2.8,6.7,2,2
126 6.3,2.7,4.9,1.8,2
127 6.7,3.3,5.7,2.1,2
128 7.2,3.2,6,1.8,2
129 6.2,2.8,4.8,1.8,2
130 6.1,3,4.9,1.8,2
131 6.4,2.8,5.6,2.1,2
132 7.2,3,5.8,1.6,2
133 7.4,2.8,6.1,1.9,2
134 7.9,3.8,6.4,2,2
135 6.4,2.8,5.6,2.2,2
136 6.3,2.8,5.1,1.5,2
137 6.1,2.6,5.6,1.4,2
138 7.7,3,6.1,2.3,2
139 6.3,3.4,5.6,2.4,2
140 6.4,3.1,5.5,1.8,2
141 6,3,4.8,1.8,2
142 6.9,3.1,5.4,2.1,2
143 6.7,3.1,5.6,2.4,2
144 6.9,3.1,5.1,2.3,2
145 5.8,2.7,5.1,1.9,2
146 6.8,3.2,5.9,2.3,2
147 6.7,3.3,5.7,2.5,2
148 6.7,3,5.2,2.3,2
149 6.3,2.5,5,1.9,2
150 6.5,3,5.2,2,2
151 6.2,3.4,5.4,2.3,2
152 5.9,3,5.1,1.8,2