def trainNeuralNetwork(MyNeuralNetwork):
    print(
        'Input "target error(0.1)", "speed(0.01)" , "max training times (-1 for infinite)"'
    )
    rawinput = input('>>>')
    rawinput = rawinput.split()
    error = float(rawinput[0])
    speed = float(rawinput[1])
    times = int(rawinput[2])
    Datas = IO.getDatas()
    # Get Input/OutputData to matrix
    if IO.getValuefromConfigfile('setting.json', 'Verbose') != None:
        verbose = int(IO.getValuefromConfigfile('setting.json', 'Verbose'))
    else:
        verbose = VERBOSE_DEFAULT
    if IO.getValuefromConfigfile('setting.json', 'Loop_per_N_times') != None:
        loop = int(
            IO.getValuefromConfigfile('setting.json', 'Loop_per_N_times'))
    else:
        loop = VERBOSE_PER_LOOP_DEFAULT
    # Setting from config file
    TrainingType.trainbyBatch(MyNeuralNetwork,
                              Datas,
                              error,
                              times,
                              speed,
                              VerbosePerLoop=loop,
                              Verbose=verbose)
    MyNeuralNetwork.savetoFile()
    print('Saved to "' + MyNeuralNetwork.Name + '.node".')
def printMatrix():
    name = input(
        'Input matrix\'s name to be printed. (Read from ".mtrx" file)\n>>>')
    raw = IO.RAWReader()
    raw.open(name + '.mtrx')
    matrix = IO.getAMatrix(raw)
    np.set_printoptions(threshold=np.nan)
    print(matrix)
def listConfigfileValues():
    print('Config list:')
    print('[v] Verbose Level. -> ' +
          str(IO.getValuefromConfigfile('setting.json', 'Verbose')))
    print('[n] Verbose per "N" times. -> ' +
          str(IO.getValuefromConfigfile('setting.json', 'Loop_per_N_times')))
    print('[s] Default training speed. -> ' +
          str(IO.getValuefromConfigfile('setting.json', 'Training_Speed')))
def setValuetoConfigfile():
    print('Config list:')
    print('[v] Verbose Level. -> ' +
          str(IO.getValuefromConfigfile('setting.json', 'Verbose')))
    print('[n] Verbose per "N" times. -> ' +
          str(IO.getValuefromConfigfile('setting.json', 'Loop_per_N_times')))
    print('[s] Default training speed. -> ' +
          str(IO.getValuefromConfigfile('setting.json', 'Training_Speed')))
    name = input('Name Code:\n')
    value = input('Value:\n')
    IO.setValuetoConfigfile('setting.json', ConfigDict[str(name)], value)
 def savetoFile(self, Filename=''):
     if Filename == '':
         Filename = self.Name
     MyRAWWriter = IO.RAWWriter()
     MyRAWWriter.append(int(self.LayersCount))
     for layer in range(0, self.LayersCount):
         MyRAWWriter.append(int(self.LayerNeuronsCount[layer]))
     # Save each layer's neurons count one by one
     MyRAWWriter.newline()
     for layer in range(0, self.LayersCount - 1):
         IO.writeAMatrix(self.Weight[layer], MyRAWWriter)
     # Save each layer's weight one by one
     for layer in range(0, self.LayersCount - 1):
         IO.writeAMatrix(self.Bias[layer], MyRAWWriter)
     # Save each layer's bias one by one
     MyRAWWriter.write(Filename + '.node')
 def loadfromFile(self, Filename):
     try:
         MyRAWReader = IO.RAWReader()
         MyRAWReader.open(Filename + '.node')
         self.Name = Filename
         self.LayersCount = int(MyRAWReader.pop())
         self.LayerNeuronsCount = []
         self.Weight = []
         self.Bias = []
         # Get the LayersCount first and Initlalize LayerNeuronsCount, Weight and Bias
         for layer in range(0, self.LayersCount):
             self.LayerNeuronsCount.append(int(MyRAWReader.pop()))
         # Get each layer's neurons count one by one
         for layer in range(0, self.LayersCount - 1):
             self.Weight.append(IO.getAMatrix(MyRAWReader))
         # Get each layer's weight one by one
         for layer in range(0, self.LayersCount - 1):
             self.Bias.append(IO.getAMatrix(MyRAWReader))
         # Get each layer's bias one by one
     except:
         print('warning: Loading ' + Filename + '.node error!')
def idx2mtrx():
    FilenameIn = input('Input input IDX file name\n')
    FilenameOut = input('Input output mtrx filename.\n')
    IO.idx2mtrx(FilenameIn, FilenameOut)