-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
66 lines (52 loc) · 1.37 KB
/
main.c
File metadata and controls
66 lines (52 loc) · 1.37 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdio.h>
#include <stdlib.h>
#include "GDLR/mathematics.h"
void ExceptionHandler()
{
printf("exception!!!\n");
system("pause");
}
int main() {
struct vector x[4];
x[0].dim = x[1].dim = x[2].dim = x[3].dim = 3;
for (int i = 0; i < 4; i++) {
x[i].val = (double *)malloc(sizeof(double) * 3);
}
x[0].val[0] = 2;
x[0].val[1] = 2;
x[0].val[2] = 3;
x[1].val[0] = 3;
x[1].val[1] = 3;
x[1].val[2] = 4;
x[2].val[0] = 4;
x[2].val[1] = 4;
x[2].val[2] = 5;
x[3].val[0] = 5;
x[3].val[1] = 5;
x[3].val[2] = 6;
double y[4] = {1, 2, 3, 4};
struct vector theta_o;
theta_o.dim = 3;
theta_o.val = (double*)malloc(3*sizeof(double));
theta_o.val[0] = 100;
theta_o.val[1] = 3;
theta_o.val[2] = -3;
double epsilon_o = 0.0;
int iter;
double loss;
struct vector theta;
double epsilon;
printf("---debug---\n");
LinearRegression(x, y, 4, &theta_o, &epsilon_o, 0.02, 0.8, 10000, 10, 100, 1e-6, &iter, &loss, &theta, &epsilon);
printf("---result---\n");
printf("iter : %d\nloss : %lf\nepsilon : %lf\n theta :\n", iter, loss, epsilon);
for (int i = 0; i < 3; i++) {
printf(" theta_%d = %lf\n", i, theta.val[i]);
}
free(theta.val);
free(theta_o.val);
for (int i = 0; i < 4; i++) {
free(x[i].val);
}
return 0;
}