@@ -11,8 +11,18 @@ class SimpleANN:
11
11
- Example demonstrates solving the XOR problem.
12
12
"""
13
13
14
+ < << << << HEAD
14
15
def __init__ (self , input_size : int , hidden_size : int , output_size : int ,
15
16
learning_rate : float = 0.1 ) -> None :
17
+ == == == =
18
+ def __init__ (
19
+ self ,
20
+ input_size : int ,
21
+ hidden_size : int ,
22
+ output_size : int ,
23
+ learning_rate : float = 0.1 ,
24
+ ) -> None :
25
+ >> >> >> > 79 fed0c49891c60d2134ee45c6f6592c19f4cef5
16
26
"""
17
27
Initialize the neural network with random weights and biases.
18
28
@@ -93,8 +103,14 @@ def feedforward(self, inputs: np.ndarray) -> np.ndarray:
93
103
self .final_output = self .sigmoid (self .final_input )
94
104
return self .final_output
95
105
106
+ < << << << HEAD
96
107
def backpropagation (self , inputs : np .ndarray , targets : np .ndarray ,
97
108
outputs : np .ndarray ) -> None :
109
+ == == == =
110
+ def backpropagation (
111
+ self , inputs : np .ndarray , targets : np .ndarray , outputs : np .ndarray
112
+ ) -> None :
113
+ >> >> >> > 79 fed0c49891c60d2134ee45c6f6592c19f4cef5
98
114
"""
99
115
Perform backpropagation to adjust the weights and biases.
100
116
@@ -122,15 +138,25 @@ def backpropagation(self, inputs: np.ndarray, targets: np.ndarray,
122
138
np .sum (output_gradient , axis = 0 , keepdims = True ) * self .learning_rate
123
139
)
124
140
141
+ < << << << HEAD
125
142
self .weights_input_hidden += (
126
143
inputs .T .dot (hidden_gradient ) * self .learning_rate
127
144
)
145
+ == == == =
146
+ self .weights_input_hidden += inputs .T .dot (hidden_gradient ) * self .learning_rate
147
+ >> >> >> > 79 fed0c49891c60d2134ee45c6f6592c19f4cef5
128
148
self .bias_hidden += (
129
149
np .sum (hidden_gradient , axis = 0 , keepdims = True ) * self .learning_rate
130
150
)
131
151
152
+ < << << << HEAD
132
153
def train (self , inputs : np .ndarray , targets : np .ndarray ,
133
154
epochs : int = 10000 , verbose : bool = False ) -> None :
155
+ == == == =
156
+ def train (
157
+ self , inputs : np .ndarray , targets : np .ndarray , epochs : int = 10000
158
+ ) -> None :
159
+ >> >> >> > 79 fed0c49891c60d2134ee45c6f6592c19f4cef5
134
160
"""
135
161
Train the neural network on the given input and target data.
136
162
0 commit comments