-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
45 lines (39 loc) · 1.17 KB
/
Copy pathutil.py
File metadata and controls
45 lines (39 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
import torch
from torch.autograd import Variable
import torch.nn as nn
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.fc1 = nn.Linear(2, 4, False)
self.fc2 = nn.Linear(4, 1, False)
def forward(self, x):
x = torch.sigmoid(self.fc1(x))
x = self.fc2(x)
return x
#TRAIN DATA
inputs = list(map(lambda s: Variable(torch.Tensor([s])), [
[0, 0],
[0, 1],
[1, 0],
[1, 1]
]))
targets = list(map(lambda s: Variable(torch.Tensor([s])), [
[0],
[1],
[1],
[0]
]))
#TEST DATA
inputs_test = list(map(lambda s: Variable(torch.Tensor([s])), [[1.0002, 0.0001]]))
targets_test = list(map(lambda s: Variable(torch.Tensor([s])), [[1]]))
#TEST
def test(inputs, targets, net):
for input, target in zip(inputs, targets):
output = net(input)
print("Input:[{},{}] Target:[{}] Predicted:[{}] Error:[{}]".format(
int(input.data.numpy()[0][0]),
int(input.data.numpy()[0][1]),
int(target.data.numpy()[0]),
round(float(output.data.numpy()[0]), 4),
round(float(abs(target.data.numpy()[0] - output.data.numpy()[0])), 4)
))