MachineIntelligenceCore:Toolchain
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
EpisodicTrainAndTestApplication.cpp
Go to the documentation of this file.
1 
24 
25 namespace mic {
26 namespace application {
27 
28 
30  episode(0),
31  learning_iteration(0),
32  number_of_episodes("number_of_episodes", 0)
33 {
34  // Register properties - so their values can be overridden (read from the configuration file).
36 
37  // Start from learning.
38  APP_STATE->setLearningModeOn();
39 }
40 
41 
43 
44  // Start from learning.
45  APP_STATE->setLearningModeOn();
46 
47  // Start a new episode.
49 
50  // Main application loop.
51  while (!APP_STATE->Quit()) {
52 
53  // If not paused.
54  if (!APP_STATE->isPaused()) {
55  // If single step mode - pause after the step.
56  if (APP_STATE->isSingleStepModeOn())
57  APP_STATE->pressPause();
58 
59  // Enter critical section - with the use of scoped lock from AppState!
61 
62  // Increment iteration number - at START!
63  iteration++;
64  // Perform single step and - if required - break the loop.
65  if (!performSingleStep())
66  break;
67 
68  } //: if! is paused & end of critical section
69 
70  // Sleep.
71  APP_SLEEP();
72  }//: while
73 }
74 
76  // If learning mode.
77  if (APP_STATE->isLearningModeOn()) {
78  // Perform learning - until there is something to learn.
79  if (!performLearningStep()) {
80  APP_STATE->setLearningModeOff();
81  }
82  } else {
83  // Perform testing - until there is something to test.
84  if (!performTestingStep()) {
85  // Finish the current episode.
86  episode++;
88 
89  // Check terminal condition.
90  if (((unsigned int)number_of_episodes != 0) && ( episode >= (unsigned int) number_of_episodes))
91  return false;
92 
93  APP_STATE->setLearningModeOn();
94 
95  // Else - start a new episode.
97 
98  }//: if
99 
100  }//: else
101 
102  return true;
103 }
104 
105 
106 
107 } /* namespace application */
108 } /* namespace mic */
#define APP_SLEEP()
Macro which sleeps the application for a time specified by the sleep_interval variable stored in APP_...
mic::configuration::Property< unsigned long > number_of_episodes
Base class for all applications.
Definition: Application.hpp:38
#define APP_STATE
Macro returning application state instance.
#define APP_DATA_SYNCHRONIZATION_SCOPED_LOCK()
Macro creating a scoped lock with the use of data_synchronizaton_mutex stored by WindowManager.
Contains declaration of a base class for all episodic learning type applications. ...
unsigned long iteration
Iteration counter.
Definition: Application.hpp:72
void registerProperty(PropertyInterface &prop)