File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Tasks/daily tasks/Jamcey_V_P Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments