To use the library in your Python projects, you can use API variables and functions, as well as settings files: settings_common.ini, settings_rnn1.ini, settings_rnn2.ini.
The stages of neural network processing from start to finish are described by the following:
- Common settings initialization
Common settings describing the functioning of the library are listed in the settings_common.ini file. To load them, you need to call the CommonParams (settings_common_file_path) class constructor from the Core/Params.py module, passing the path to the settings file (settings_common_file_path) as an argument:
params = CommonParams(settings_common_file_path)
Since work without a graphical interface does not imply a continuous mode and rendering of layers, it is necessary to set the corresponding variables to False:
self.params.continuous_mode = False
self.params.draw_layers = False
This can be done programmatically, as in the example above, or you can immediately set the corresponding variables to False in the settings_common.ini file.
- RNN cores settings initialization
By analogy with the common settings, the neural network settings are initialized by calling the constructors of the Rnn1Params and Rnn2Params classes located in the same Core/Params.py module. As arguments, they are passed the paths to the corresponding ini files, as well as the structure created at the previous stage with common settings (params):
rnn1_params = Rnn1Params(settings_rnn1_file_path, params)
rnn2_params = Rnn2Params(settings_rnn2_file_path, params)
- RNNs initialization
It is implemented by calling the constructors of the Rnn1Core and Rnn2Core classes located in the Core/Rnn1Core.py and Core/Rnn2Core.py modules, respectively. The common settings (params) and the settings of the neural networks themselves (rnn1_params/rnn2_params) are passed as arguments:
rnn1 = Rnn1Core(params, rnn1_params)
rnn2 = Rnn2Core(params, rnn2_params)
- Start data processing in RNN1
Calls by function:
rnn1.start_process_signals()
This procedure prepares the RNN for data processing and feeds it the first element of the processed sequence.
- Continuous learning RNN1
Done by setting the boolean variable ok = True and looping the function call:
ok = rnn1.process_signals()
while ok != False. The process_signals() function performs one tact of processing and, if the sequence is over, returns False, which means the end of processing.
- Copying RNN1 state to RNN2
If it is necessary to predict or detect the fact of novelty in the data stream, the state of the RNN1 is copied to the RNN2 and processing is started on the RNN2. Features of copying the state of RNN1 to RNN2 differ depending on the processing mode. When predicting, copying is requested by the control unit or the operator. For example, it may be called during a particular processing tact. In the Rnn1Core class, the cntr variable is responsible for the current measure number. Accordingly, if it is necessary to predict the sequence at tacts 35, 40 and 45, then this can be done as follows:
if rnn1.cntr == 35 or rnn1.cntr == 40 or rnn1.cntr == 45:
copied_model = rnn1.copy_model()
When detecting novelty, the trigger for copying is the excess of the novelty threshold of the processed data. The indicator of novelty detection in this mode is a non-empty structure rnn1.novelty_state, and copying the model in this case is done as follows:
if len(rnn1.novelty_state.keys()):
copied_model = rnn1.novelty_state
The copied_model contains main params of RNN1 state, however, before it is transferred to the RNN2, it is necessary to indicate the mode in which the program operates and the processing parameters. For prediction, the processing mode is 'Predict' and the processing parameter is the prediction horizon, denoted by predictStepsNum:
copied_model ['processing_type'] = 'Predict'
copied_model ['predictStepsNum'] = params.predictStepsNum
For novelty, the processing mode is ''Novelty filter' and the processing parameter is the number of elements to filter, denoted by novFiltStepsNum:
rnn1_to_rnn2_data['processing_type'] = 'Novelty filter'
rnn1_to_rnn2_data['novFiltStepsNum'] = self.params.novFiltStepsNum
- Data processing in RNN2
Performed similarly to step 5:
ok = rnn2.process_signals()
- End of processing in RNN2, continuation of processing in RNN1
Upon completion of processing in rnn2, the function finish_process_signals() must be called, which will reset the I / O device and update system variables:
Rnn2.finish_process_signals()
After copying the state of RNN1 to RNN2, new copies are blocked in RNN1 for the duration of processing already copied data in RNN2. To unlock copying at the end of processing in RNN2, you need to call the function:
rnn1.rnn2finished()
- Finish processing
Upon completion of processing on rnn1, it is also necessary to call the function finish_process_signals().