Skip to content

Commit 8fe045b

Browse files
authored
Merge pull request #71 from JAMCVP/patch-1
task2.py
2 parents 9a9c4c4 + 4909a0e commit 8fe045b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Tasks/daily tasks/Jamcey_V_P/task2.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import torch
2+
import torch.nn as nn
3+
4+
class neural_network(nn.Module):
5+
def __init__(self, ):
6+
super(neural_network, self).__init__()
7+
8+
self.input_layer = 4 # Number of input units
9+
self.hidden_layer1 = 5 # Number of hidden units
10+
self.hidden_layer2 = 3 # Number of hidden units
11+
self.output_layer = 1 # Number of output units
12+
13+
# Weights
14+
W1 = torch.randn(self.input_layer, self.hidden_layer1)
15+
W2 = torch.randn(self.hidden_layer1, self.hidden_layer2)
16+
W3 = torch.randn(self.hidden_layer2, self.output_layer)
17+
18+
19+
# bias
20+
B1 = torch.randn((1, self.hidden_layer1))
21+
B2 = torch.randn((1,self.hidden_layer2))
22+
B3 = torch.randn((1,self.output_layer))
23+
24+
def forward(self, X):
25+
z1 = torch.mm(X, w1) + b1
26+
Relu = nn.ReLU()
27+
a1 = Relu(z1)
28+
z2 = torch.mm(X, w2) + b2
29+
Relu = nn.ReLU()
30+
a2 = Relu(z2)
31+
z3 = torch.mm(X, w3) + b3
32+
Sigmoid = nn.Sigmoid()
33+
Result = Sigmoid(z3)
34+
return Result

0 commit comments

Comments
 (0)