-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjeddy.py
75 lines (63 loc) · 1.75 KB
/
jeddy.py
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
67
68
69
70
71
72
73
74
75
import torch.nn as nn
import torch.optim as optim
from alias_utils.data import house
from alias_utils.model import RunnerBuilder as Builder
from alias_utils.loss import MSELoss
from alias_utils.metrics import (
Loss as LossMetric,
RSquared as RSquaredMetric,
DesignMatNorm as MNormMetric,
)
from matplotlib import pyplot as plt
def full_data():
data = house.data()
wrapper = (
Builder()
.name("Model")
.loss(MSELoss())
.optimizer(optim.Adam)
.steps(
nn.Linear(13, 32),
nn.Linear(32, 64),
nn.Linear(64, 32),
nn.Linear(32, 8),
nn.Linear(8, 1),
)
.with_metric(LossMetric())
.with_metric(RSquaredMetric())
.with_metric(MNormMetric())
.build()
)
wrapper.train(data, n_epochs=5000)
wrapper.plot_two(LossMetric, MNormMetric)
# wrapper.plot_two(LossMetric, MNormMetric, log=True)
plt.title('Loss vs Design Matrix Norm on Full Dataset')
plt.tight_layout()
plt.show()
def batched_data():
data = house.data(batch_size = 32)
wrapper = (
Builder()
.name("Model")
.loss(MSELoss())
.optimizer(optim.Adam)
.steps(
nn.Linear(13, 32),
nn.Linear(32, 64),
nn.Linear(64, 32),
nn.Linear(32, 8),
nn.Linear(8, 1),
)
.with_metric(LossMetric())
.with_metric(RSquaredMetric())
.with_metric(MNormMetric())
.build()
)
wrapper.train(data, n_epochs=5000)
wrapper.plot_two(LossMetric, MNormMetric)
plt.title('Loss vs Design Matrix Norm on Batched Dataset')
plt.tight_layout()
plt.show()
if __name__ == "__main__":
full_data()
batched_data()