-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsingle.cpp
More file actions
47 lines (36 loc) · 1.17 KB
/
Copy pathsingle.cpp
File metadata and controls
47 lines (36 loc) · 1.17 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
46
47
#include "functions.hpp"
#include "graph.hpp"
#include "matrix.hpp"
#include "raylib.h"
#include "regression.hpp"
#include <cstddef>
#include <cstdlib>
#include <print>
int main() {
mat::Matrix<double> train = {
{1, 2}, {2, 4}, {3, 6}, {4, 8}, {5, 10},
};
double w = func::randf(1, 10);
std::println("WeightBefore: {}", w);
std::println("Cost: {}", reg::MSE(train, w));
float width = 800;
float height = 600;
InitWindow(width, height, "Machine Learning");
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(WHITE);
graph::DrawAxis(width, height);
graph::DrawFunction(width, height, -100, 100,
[&](double x) { return 0.005 * reg::MSE(train, x); });
for (size_t i = 0; i < 100; ++i) {
w = reg::dMSE(train, w, 1e-3);
std::println("Cost: {}", reg::MSE(train, w));
}
for (auto row : train.row_view()) {
std::println("{} -> {} : {}", row(0, 0), reg::forward(row, w), row(0, 1));
}
std::println("WeightAfter: {}", w);
std::println("Cost: {}", reg::MSE(train, w));
EndDrawing();
}
}