code: 
  
  
  '''simple docstring'''
  
  
  
  import numpy as np
  from matplotlib import pyplot as plt
  
  
  
  
  
  
  def 						lowerCamelCase							(_SCREAMING_SNAKE_CASE   :     List[str]     ):
  					return 1 / (1 + np.exp(-1 * x     ))
  
  
  
  
  
  class 							__UpperCamelCase       :
  
  
  
  
  	def __init__(     self		,       __a		,       __a=None		,       __a=None		,       __a=False							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Any      					=						units
  						__a    : Tuple      					=						None
  						__a    : Optional[Any]      					=						None
  						__a    : Tuple      					=						activation
  						if learning_rate is None:
  											__a    : Dict      					=						0.3
  						__a    : Tuple      					=						learning_rate
  						__a    : Any      					=						is_input_layer
  
  
  
  
  	def    __UpperCAmelCase							(     self		,       __a							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : List[str]      					=						np.asmatrix(np.random.normal(0		,       0.5		,       (self.units, back_units)							)							)
  						__a    : Union[str, Any]      					=						np.asmatrix(np.random.normal(0		,       0.5		,       self.units							)							).T
  						if self.activation is None:
  											__a    : List[Any]      					=						sigmoid
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						if self.activation == sigmoid:
  											__a    : Optional[Any]      					=						np.dot(self.output		,       (1 - self.output).T							)
  											__a    : int      					=						np.diag(np.diag(lowercase_							)							)
  						else:
  											__a    : Optional[int]      					=						1
  						return gradient_activation
  
  
  
  
  	def    __UpperCAmelCase							(     self		,       __a							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : List[Any]      					=						xdata
  						if self.is_input_layer:
  											# input layer
  											__a    : Dict      					=						xdata
  											__a    : int      					=						xdata
  											return xdata
  						else:
  											__a    : List[str]      					=						np.dot(self.weight		,       self.xdata							) - self.bias
  											__a    : List[Any]      					=						self.activation(self.wx_plus_b							)
  											return self.output
  
  
  
  
  
  	def    __UpperCAmelCase							(     self		,       __a							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : List[str]      					=						self.cal_gradient()  # i * i 维
  						__a    : Tuple      					=						np.asmatrix(np.dot(gradient.T		,       lowercase_							)							)
  
  						__a    : Optional[int]      					=						np.asmatrix(self.xdata							)
  						__a    : List[str]      					=						-1
  						__a    : Optional[Any]      					=						self.weight
  
  						__a    : Dict      					=						np.dot(gradient.T		,       self._gradient_weight.T							)
  						__a    : Tuple      					=						gradient * self._gradient_bias
  						__a    : Tuple      					=						np.dot(lowercase_		,       self._gradient_x							).T
  						# upgrade: the Negative gradient direction
  						__a    : Dict      					=						self.weight - self.learn_rate * self.gradient_weight
  						__a    : Any      					=						self.bias - self.learn_rate * self.gradient_bias.T
  						# updates the weights and bias according to learning rate (0.3 if undefined)
  						return self.gradient
  
  
  
  
  
  class 							__UpperCamelCase       :
  
  
  
  
  	def __init__(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Optional[int]      					=						[]
  						__a    : Optional[Any]      					=						[]
  						__a    : Any      					=						plt.figure()
  						__a    : List[Any]      					=						self.fig_loss.add_subplot(1		,       1		,       1							)
  
  
  
  
  	def    __UpperCAmelCase							(     self		,       __a							):
  
  						'''simple docstring'''
  
  
  
  
  
  						self.layers.append(lowercase_							)
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						for i, layer in enumerate(self.layers[:]							):
  											if i < 1:
  																__a    : Union[str, Any]      					=						True
  											else:
  																layer.initializer(self.layers[i - 1].units							)
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						for i, layer in enumerate(self.layers[:]							):
  											print(f"""------- layer {i} -------"""							)
  											print('weight.shape '		,       np.shape(layer.weight							)							)
  											print('bias.shape '		,       np.shape(layer.bias							)							)
  
  
  
  
  	def    __UpperCAmelCase							(     self		,       __a		,       __a		,       __a		,       __a							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : int      					=						train_round
  						__a    : int      					=						accuracy
  
  						self.ax_loss.hlines(self.accuracy		,       0		,       self.train_round * 1.1							)
  
  						__a    : Any      					=						np.shape(lowercase_							)
  						for _ in range(lowercase_							):
  											__a    : Tuple      					=						0
  											for row in range(x_shape[0]							):
  																__a    : Any      					=						np.asmatrix(xdata[row, :]							).T
  																__a    : List[str]      					=						np.asmatrix(ydata[row, :]							).T
  
  																# forward propagation
  																for layer in self.layers:
  																					__a    : Optional[Any]      					=						layer.forward_propagation(_xdata							)
  
  																__a					,       __a    : Optional[int]      					=						self.cal_loss(_ydata		,       _xdata							)
  																__a    : int      					=						all_loss + loss
  
  																# back propagation: the input_layer does not upgrade
  																for layer in self.layers[:0:-1]:
  																					__a    : Any      					=						layer.back_propagation(lowercase_							)
  
  											__a    : List[str]      					=						all_loss / x_shape[0]
  											self.train_mse.append(lowercase_							)
  
  											self.plot_loss()
  
  											if mse < self.accuracy:
  																print('----达到精度----'							)
  																return mse
  						return None
  
  
  
  
  	def    __UpperCAmelCase							(     self		,       __a		,       __a							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Tuple      					=						np.sum(np.power((ydata - ydata_)		,       2							)							)
  						__a    : List[str]      					=						2 * (ydata_ - ydata)
  						# vector (shape is the same as _ydata.shape)
  						return self.loss, self.loss_gradient
  
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						if self.ax_loss.lines:
  											self.ax_loss.lines.remove(self.ax_loss.lines[0]							)
  						self.ax_loss.plot(self.train_mse		,       'r-'							)
  						plt.ion()
  						plt.xlabel('step'							)
  						plt.ylabel('loss'							)
  						plt.show()
  						plt.pause(0.1							)
  
  
  
  
  
  
  def 						lowerCamelCase							():
  					__a    : List[str]      					=						np.random.randn(10		,   10     )
  					__a    : Tuple      					=						np.asarray(
  					    [
  					        [0.8, 0.4],
  					        [0.4, 0.3],
  					        [0.3_4, 0.4_5],
  					        [0.6_7, 0.3_2],
  					        [0.8_8, 0.6_7],
  					        [0.7_8, 0.7_7],
  					        [0.5_5, 0.6_6],
  					        [0.5_5, 0.4_3],
  					        [0.5_4, 0.1],
  					        [0.1, 0.5],
  					    ]     )
  					__a    : List[Any]      					=						BPNN()
  					for i in (10, 20, 30, 2):
  										model.add_layer(DenseLayer(_A     )     )
  					model.build()
  					model.summary()
  					model.train(xdata=_A		,   ydata=_A		,   train_round=100		,   accuracy=0.0_1     )
  
  
  if __name__ == "__main__":
  		example()
  
  
  
  
style_context: 
  
  
  '''simple docstring'''
  
  
  
  def 						lowerCamelCase							(_SCREAMING_SNAKE_CASE   :     int = 30     ):
  					__a    : Dict      					=						exponent + 2
  					__a    : List[Any]      					=						(1 + 5**0.5) / 2
  					__a    : Any      					=						(phi**fibonacci_index - (phi - 1) ** fibonacci_index) / 5**0.5
  
  					return int(_SCREAMING_SNAKE_CASE     )
  
  
  if __name__ == "__main__":
  	print(f'''{solution() = }''')
  
  
  
  