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