MachineIntelligenceCore:ReinforcementLearning
|
Class emulating the MNISTDigit digit environment. More...
#include <MNISTDigit.hpp>
Public Member Functions | |
MNISTDigit (std::string node_name_="mnist_digit") | |
MNISTDigit (const mic::environments::MNISTDigit &md_) | |
virtual | ~MNISTDigit () |
mic::environments::MNISTDigit & | operator= (const mic::environments::MNISTDigit &md_) |
virtual void | initializePropertyDependentVariables () |
virtual void | initializeEnvironment () |
mic::types::TensorXfPtr | getObservation () |
virtual std::string | environmentToString () |
virtual std::string | observationToString () |
virtual mic::types::MatrixXfPtr | encodeEnvironment () |
virtual mic::types::MatrixXfPtr | encodeObservation () |
virtual mic::types::Position2D | getAgentPosition () |
virtual bool | moveAgentToPosition (mic::types::Position2D pos_) |
virtual float | getStateReward (mic::types::Position2D pos_) |
virtual bool | isStateAllowed (mic::types::Position2D pos_) |
virtual bool | isStateTerminal (mic::types::Position2D pos_) |
unsigned int | optimalPathLength () |
![]() | |
Environment (std::string node_name_) | |
virtual | ~Environment () |
mic::types::TensorXfPtr & | getEnvironment () |
virtual size_t | getEnvironmentWidth () |
virtual size_t | getEnvironmentHeight () |
virtual size_t | getEnvironmentSize () |
virtual size_t | getObservationWidth () |
virtual size_t | getObservationHeight () |
virtual size_t | getObservationSize () |
virtual size_t | getChannels () |
size_t | getROISize () |
bool | moveAgent (mic::types::Action2DInterface ac_) |
virtual void | moveAgentToInitialPosition () |
virtual bool | isStateAllowed (long x_, long y_) |
virtual bool | isStateTerminal (long x_, long y_) |
virtual bool | isActionAllowed (long x_, long y_, size_t action_) |
virtual bool | isActionAllowed (mic::types::Position2D pos_, mic::types::Action2DInterface ac_) |
virtual bool | isActionAllowed (mic::types::Action2DInterface ac_) |
Protected Member Functions | |
std::string | toString (mic::types::TensorXfPtr env_) |
Protected Attributes | |
mic::importers::MNISTMatrixImporter < float > | mnist_importer |
Importer responsible for loading MNIST dataset. More... | |
mic::configuration::Property < size_t > | sample_number |
mic::configuration::Property < short > | agent_x |
mic::configuration::Property < short > | agent_y |
mic::configuration::Property < short > | goal_x |
mic::configuration::Property < short > | goal_y |
unsigned int | optimal_path_length |
![]() | |
mic::configuration::Property < size_t > | width |
Property: width of the environment. More... | |
mic::configuration::Property < size_t > | height |
Property: height of the environment. More... | |
mic::configuration::Property < size_t > | roi_size |
Property: size of the ROI (region of interest). More... | |
size_t | channels |
Number of channels. More... | |
bool | pomdp_flag |
Flag related to. More... | |
mic::types::Position2D | initial_position |
Property: initial position of the agent. More... | |
mic::types::TensorXfPtr | environment_grid |
Tensor storing the environment. More... | |
mic::types::TensorXfPtr | observation_grid |
Class emulating the MNISTDigit digit environment.
Definition at line 50 of file MNISTDigit.hpp.
mic::environments::MNISTDigit::MNISTDigit | ( | std::string | node_name_ = "mnist_digit" | ) |
Constructor. Registers properties.
node_name_ | Name of the node in configuration file. |
Definition at line 29 of file MNISTDigit.cpp.
References agent_x, agent_y, mic::environments::Environment::channels, mic::environments::Count, goal_x, goal_y, and sample_number.
mic::environments::MNISTDigit::MNISTDigit | ( | const mic::environments::MNISTDigit & | md_ | ) |
Copying constructor.
md_ | MNIST digit to be cloned. |
|
virtual |
Destructor. Empty for now.
Definition at line 48 of file MNISTDigit.cpp.
|
virtual |
Encodes the current state of the MNISTDigit in as a matrix of size [1, width * height * channels].
Implements mic::environments::Environment.
Definition at line 174 of file MNISTDigit.cpp.
References mic::environments::Environment::channels, mic::environments::Environment::environment_grid, mic::environments::Environment::height, and mic::environments::Environment::width.
Referenced by encodeObservation().
|
virtual |
Encodes the current observation taken in the environment in as a matrix of size [1, roi_size * roi_size * channels].
Implements mic::environments::Environment.
Definition at line 186 of file MNISTDigit.cpp.
References mic::environments::Environment::channels, encodeEnvironment(), getAgentPosition(), getObservation(), mic::environments::Environment::pomdp_flag, and mic::environments::Environment::roi_size.
Referenced by mic::application::MNISTDigitDLRERPOMDP::getPredictedRewardsForGivenState(), mic::application::MNISTDigitDLRERPOMDP::performSingleStep(), and mic::application::MNISTDigitDLRERPOMDP::streamNetworkResponseTable().
|
virtual |
Returns the current state of the MNISTDigit in the form of a string.
Implements mic::environments::Environment.
Definition at line 160 of file MNISTDigit.cpp.
References mic::environments::Environment::environment_grid, and toString().
Referenced by mic::application::MNISTDigitDLRERPOMDP::performSingleStep().
|
virtual |
Calculates the agent position.
Implements mic::environments::Environment.
Definition at line 238 of file MNISTDigit.cpp.
References mic::environments::Agent, mic::environments::Environment::environment_grid, mic::environments::Environment::height, and mic::environments::Environment::width.
Referenced by encodeObservation(), getObservation(), mic::application::MNISTDigitDLRERPOMDP::getPredictedRewardsForGivenState(), moveAgentToPosition(), mic::application::MNISTDigitDLRERPOMDP::performSingleStep(), mic::application::MNISTDigitDLRERPOMDP::startNewEpisode(), and mic::application::MNISTDigitDLRERPOMDP::streamNetworkResponseTable().
mic::types::TensorXfPtr mic::environments::MNISTDigit::getObservation | ( | ) |
Returns the tensor being the observation.
Definition at line 208 of file MNISTDigit.cpp.
References mic::environments::Agent, getAgentPosition(), mic::environments::Goals, mic::environments::Environment::observation_grid, mic::environments::Pixels, and mic::environments::Environment::roi_size.
Referenced by encodeObservation(), mic::application::MNISTDigitDLRERPOMDP::initializePropertyDependentVariables(), observationToString(), mic::application::MNISTDigitDLRERPOMDP::performSingleStep(), and mic::application::MNISTDigitDLRERPOMDP::startNewEpisode().
|
virtual |
Returns the reward associated with the given state.
pos_ | Position (state). |
Implements mic::environments::Environment.
Definition at line 271 of file MNISTDigit.cpp.
References mic::environments::Environment::environment_grid, and mic::environments::Goals.
Referenced by mic::application::MNISTDigitDLRERPOMDP::performSingleStep().
|
virtual |
(Re)initializes the environment - gets given MNIST digit (sample number), sets agent, goal etc.
Implements mic::environments::Environment.
Definition at line 85 of file MNISTDigit.cpp.
References agent_x, agent_y, mic::environments::Environment::environment_grid, goal_x, goal_y, mic::environments::Goals, mic::environments::Environment::height, mic::environments::Environment::initial_position, mnist_importer, mic::environments::Environment::moveAgentToInitialPosition(), optimal_path_length, mic::environments::Pixels, sample_number, and mic::environments::Environment::width.
Referenced by mic::application::MNISTDigitDLRERPOMDP::startNewEpisode().
|
virtual |
Initializes all variables that are property-dependent - loads MNISTDigit digits.
Definition at line 65 of file MNISTDigit.cpp.
References mic::environments::Environment::channels, mic::environments::Environment::environment_grid, mic::environments::Environment::height, mnist_importer, mic::environments::Environment::observation_grid, mic::environments::Environment::pomdp_flag, mic::environments::Environment::roi_size, and mic::environments::Environment::width.
|
virtual |
Checks if position is allowed, i.e. within the gridworld boundaries and there is no wall at that place.
pos_ | Position to be checked. |
Implements mic::environments::Environment.
Definition at line 280 of file MNISTDigit.cpp.
Referenced by moveAgentToPosition(), and mic::application::MNISTDigitDLRERPOMDP::streamNetworkResponseTable().
|
virtual |
Checks if position is terminal, i.e. agent is standing in a pit or reached the goal. Returns reward associated with given state.
pos_ | Position (state) to be checked. |
Implements mic::environments::Environment.
Definition at line 291 of file MNISTDigit.cpp.
References mic::environments::Environment::environment_grid, and mic::environments::Goals.
Referenced by mic::application::MNISTDigitDLRERPOMDP::performSingleStep(), and mic::application::MNISTDigitDLRERPOMDP::streamNetworkResponseTable().
|
virtual |
Moves the agent to the position. Type of move (deterministic vs stochastic) depends on the environment (the same goes to e.g. circular world assumption).
pos_ | Desired position of the agent. |
Implements mic::environments::Environment.
Definition at line 253 of file MNISTDigit.cpp.
References mic::environments::Agent, getAgentPosition(), and isStateAllowed().
Referenced by mic::application::MNISTDigitDLRERPOMDP::getPredictedRewardsForGivenState(), mic::application::MNISTDigitDLRERPOMDP::performSingleStep(), and mic::application::MNISTDigitDLRERPOMDP::streamNetworkResponseTable().
|
virtual |
Returns the current observation taken in the MNISTDigit in the form of a string.
Implements mic::environments::Environment.
Definition at line 164 of file MNISTDigit.cpp.
References mic::environments::Environment::environment_grid, getObservation(), mic::environments::Environment::pomdp_flag, and toString().
Referenced by mic::application::MNISTDigitDLRERPOMDP::performSingleStep().
mic::environments::MNISTDigit & mic::environments::MNISTDigit::operator= | ( | const mic::environments::MNISTDigit & | md_ | ) |
Assign operator. Copies the MNISTDigit state along with its properties.
Definition at line 52 of file MNISTDigit.cpp.
References mic::environments::Environment::channels, mic::environments::Environment::environment_grid, mic::environments::Environment::height, mic::environments::Environment::initial_position, mic::environments::Environment::observation_grid, and mic::environments::Environment::width.
|
inline |
Returns the length of optimal path from agent initial position to goal.
Definition at line 159 of file MNISTDigit.hpp.
References optimal_path_length.
Referenced by mic::application::MNISTDigitDLRERPOMDP::finishCurrentEpisode().
|
protected |
Returns the current state of the environment passed as an argument in the form of a string.
env_ | Environment (tensor) to be described. |
Definition at line 125 of file MNISTDigit.cpp.
References mic::environments::Agent, and mic::environments::Goals.
Referenced by environmentToString(), and observationToString().
|
protected |
Property: initial agent x position.
Definition at line 176 of file MNISTDigit.hpp.
Referenced by initializeEnvironment(), and MNISTDigit().
|
protected |
Property: initial agent y position.
Definition at line 181 of file MNISTDigit.hpp.
Referenced by initializeEnvironment(), and MNISTDigit().
|
protected |
Property: initial goal x position.
Definition at line 186 of file MNISTDigit.hpp.
Referenced by initializeEnvironment(), and MNISTDigit().
|
protected |
Property: initial goal y position.
Definition at line 191 of file MNISTDigit.hpp.
Referenced by initializeEnvironment(), and MNISTDigit().
|
protected |
Importer responsible for loading MNIST dataset.
Definition at line 166 of file MNISTDigit.hpp.
Referenced by initializeEnvironment(), and initializePropertyDependentVariables().
|
protected |
Optimal number of steps from initial agent position to goal.
Definition at line 196 of file MNISTDigit.hpp.
Referenced by initializeEnvironment(), and optimalPathLength().
|
protected |
Property: MNISTDigit digit - number of sample.
Definition at line 171 of file MNISTDigit.hpp.
Referenced by initializeEnvironment(), and MNISTDigit().