"""simple docstring"""







import numpy as np
from matplotlib import pyplot as plt




def 						_lowercase				(  _SCREAMING_SNAKE_CASE				:				int						)    ->     Optional[int]:







     '''simple docstring'''


     return 1 / (1 + np.exp(-1 * x						))






class 							__snake_case:


    '''simple docstring'''





    def __init__(  self					,       __lowerCamelCase					,       __lowerCamelCase=None					,       __lowerCamelCase=None					,       __lowerCamelCase=False	):




         '''simple docstring'''



         __A					:					List[str]								=		units
         __A					:					List[str]								=		None
         __A					:					List[Any]								=		None
         __A					:					Tuple								=		activation
         if learning_rate is None:
              __A					:					Any								=		0.3
         __A					:					Optional[Any]								=		learning_rate
         __A					:					Any								=		is_input_layer
    def 						_a							(  self					,       __lowerCamelCase	):




         '''simple docstring'''



         __A					:					List[str]								=		np.asmatrix(np.random.normal(0					,       0.5					,       (self.units, back_units)	)	)
         __A					:					Optional[Any]								=		np.asmatrix(np.random.normal(0					,       0.5					,       self.units	)	).T
         if self.activation is None:
              __A					:					List[Any]								=		sigmoid
    def 						_a							(  self	):




         '''simple docstring'''



         if self.activation == sigmoid:
              __A					:					Optional[Any]								=		np.dot(self.output					,       (1 - self.output).T	)
              __A					:					Optional[int]								=		np.diag(np.diag(UpperCamelCase__	)	)
         else:
              __A					:					List[str]								=		1
         return gradient_activation
    def 						_a							(  self					,       __lowerCamelCase	):




         '''simple docstring'''



         __A					:					str								=		xdata
         if self.is_input_layer:
              # input layer
              __A					:					Optional[int]								=		xdata
              __A					:					Any								=		xdata
              return xdata
         else:
              __A					:					List[Any]								=		np.dot(self.weight					,       self.xdata	) - self.bias
              __A					:					str								=		self.activation(self.wx_plus_b	)
              return self.output

    def 						_a							(  self					,       __lowerCamelCase	):




         '''simple docstring'''



         __A					:					Tuple								=		self.cal_gradient()  # i * i 维
         __A					:					int								=		np.asmatrix(np.dot(gradient.T					,       UpperCamelCase__	)	)

         __A					:					int								=		np.asmatrix(self.xdata	)
         __A					:					Union[str, Any]								=		-1
         __A					:					Any								=		self.weight

         __A					:					Dict								=		np.dot(gradient.T					,       self._gradient_weight.T	)
         __A					:					Any								=		gradient * self._gradient_bias
         __A					:					Optional[int]								=		np.dot(UpperCamelCase__					,       self._gradient_x	).T
         # upgrade: the Negative gradient direction
         __A					:					List[Any]								=		self.weight - self.learn_rate * self.gradient_weight
         __A					:					Optional[int]								=		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 							__snake_case:


    '''simple docstring'''





    def __init__(  self	):




         '''simple docstring'''



         __A					:					str								=		[]
         __A					:					List[Any]								=		[]
         __A					:					Any								=		plt.figure()
         __A					:					str								=		self.fig_loss.add_subplot(1					,       1					,       1	)
    def 						_a							(  self					,       __lowerCamelCase	):




         '''simple docstring'''



         self.layers.append(UpperCamelCase__	)
    def 						_a							(  self	):




         '''simple docstring'''



         for i, layer in enumerate(self.layers[:]	):
              if i < 1:
                   __A					:					List[str]								=		True
              else:
                   layer.initializer(self.layers[i - 1].units	)
    def 						_a							(  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 						_a							(  self					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase	):




         '''simple docstring'''



         __A					:					Optional[Any]								=		train_round
         __A					:					int								=		accuracy

         self.ax_loss.hlines(self.accuracy					,       0					,       self.train_round * 1.1	)

         __A					:					Optional[int]								=		np.shape(UpperCamelCase__	)
         for _ in range(UpperCamelCase__	):
              __A					:					List[Any]								=		0
              for row in range(x_shape[0]	):
                   __A					:					Union[str, Any]								=		np.asmatrix(xdata[row, :]	).T
                   __A					:					Tuple								=		np.asmatrix(ydata[row, :]	).T

                   # forward propagation
                   for layer in self.layers:
                        __A					:					Any								=		layer.forward_propagation(_xdata	)

                   __A						,		__A					:					List[Any]								=		self.cal_loss(_ydata					,       _xdata	)
                   __A					:					Optional[Any]								=		all_loss + loss

                   # back propagation: the input_layer does not upgrade
                   for layer in self.layers[:0:-1]:
                        __A					:					List[Any]								=		layer.back_propagation(UpperCamelCase__	)

              __A					:					Any								=		all_loss / x_shape[0]
              self.train_mse.append(UpperCamelCase__	)

              self.plot_loss()

              if mse < self.accuracy:
                   print('----达到精度----'	)
                   return mse
         return None
    def 						_a							(  self					,       __lowerCamelCase					,       __lowerCamelCase	):




         '''simple docstring'''



         __A					:					List[Any]								=		np.sum(np.power((ydata - ydata_)					,       2	)	)
         __A					:					Optional[int]								=		2 * (ydata_ - ydata)
         # vector (shape is the same as _ydata.shape)
         return self.loss, self.loss_gradient

    def 						_a							(  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 						_lowercase				(  )    ->     List[str]:







     '''simple docstring'''


     __A					:					List[str]								=		np.random.randn(10  ,       10						)
     __A					:					List[Any]								=		np.asarray(
         [
             [0.8, 0.4],
             [0.4, 0.3],
             [0.34, 0.45],
             [0.67, 0.32],
             [0.88, 0.67],
             [0.78, 0.77],
             [0.55, 0.66],
             [0.55, 0.43],
             [0.54, 0.1],
             [0.1, 0.5],
         ]						)
     __A					:					Optional[Any]								=		BPNN()
     for i in (10, 20, 30, 2):
          model.add_layer(DenseLayer(__UpperCamelCase						)						)
     model.build()
     model.summary()
     model.train(xdata=__UpperCamelCase  ,       ydata=__UpperCamelCase  ,       train_round=100  ,       accuracy=0.01						)


if __name__ == "__main__":
       example()




"""simple docstring"""

from collections import defaultdict


def    lowerCAmelCase			(__UpperCamelCase							:    int = 5			):
							"""simple docstring"""


							__UpperCamelCase							=defaultdict(__UpperCamelCase			)
							__UpperCamelCase							=0

							while True:
														__UpperCamelCase							=get_digits(__UpperCamelCase			)
														freqs[digits].append(__UpperCamelCase			)

														if len(freqs[digits]			) == max_base:
																					__UpperCamelCase							=freqs[digits][0] ** 3
																					return base

														num += 1


def    lowerCAmelCase			(__UpperCamelCase							:    int			):
							"""simple docstring"""


							return "".join(sorted(str(num**3			)			)			)


if __name__ == "__main__":
				print(f'''{solution() = }''')



