-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgate.cpp
More file actions
45 lines (37 loc) · 1.33 KB
/
Copy pathgate.cpp
File metadata and controls
45 lines (37 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "functions.hpp"
#include "matrix.hpp"
#include "regression.hpp"
#include <cstddef>
#include <iostream>
int main() {
mat::Matrix<double> train = {
{0, 0, 0},
{0, 1, 0},
{1, 0, 0},
{1, 1, 1},
};
mat::Matrix<double> w(1, 2);
mat::Matrix<double> b(1, 1);
func::randmat(w, 0, 10);
func::randmat(b, 0, 10);
mat::Matrix<double> x_t = train.take_block(0, 0, 3, 1);
mat::Matrix<double> y_t = train.take_block(0, 2, 3, 2);
double cost = reg::MSE(x_t, y_t, w, b);
std::cout << "w: " << w << std::endl;
std::cout << "b: " << b << std::endl;
std::cout << "Cost: " << cost << std::endl;
double l_r = 1e-3;
mat::Matrix<double> grad(mat::Matrix<double>(x_t.row_view()[0]).cols,
mat::Matrix<double>(x_t.row_view()[0]).rows);
mat::Matrix<double> d(mat::Matrix<double>(x_t.row_view()[0]).cols,
mat::Matrix<double>(x_t.row_view()[0]).rows);
for (size_t n = 0; n < 1000 * 10000; ++n) {
w = reg::dMSE(x_t, y_t, w, b, l_r);
cost = reg::MSE(x_t, y_t, w, b);
std::cout << "Cost: " << cost << std::endl;
}
std::cout << "Gradient: " << grad << std::endl;
std::cout << "w: " << w << std::endl;
std::cout << "b: " << b << std::endl;
std::cout << "Cost: " << cost << std::endl;
}