MachineIntelligenceCore:ReinforcementLearning
|
Class emulating the maze of digits environment. More...
#include <MazeOfDigits.hpp>
Public Member Functions | |
MazeOfDigits (std::string node_name_="maze_of_digits") | |
MazeOfDigits (const mic::environments::MazeOfDigits &md_) | |
virtual | ~MazeOfDigits () |
mic::environments::MazeOfDigits & | operator= (const mic::environments::MazeOfDigits &md) |
virtual size_t | getObservationSize () |
virtual void | initializePropertyDependentVariables () |
virtual void | initializeEnvironment () |
void | initExemplaryMaze () |
void | reRandomAgentPosition () |
void | initFullyRandomMaze () |
void | initRandomStructuredMaze () |
void | initRandomPathMaze () |
void | setBiggerDigit (size_t x_, size_t y_, size_t value_) |
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::MatrixXfPtr | encodeAgentGrid () |
Encode the current state of the reduced grid (only the agent position) as a matrix of size [1, width * height]. More... | |
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 | 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 | gridToString (mic::types::TensorXfPtr &grid_) |
Protected Attributes | |
mic::configuration::Property < short > | type |
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 maze of digits environment.
Definition at line 50 of file MazeOfDigits.hpp.
mic::environments::MazeOfDigits::MazeOfDigits | ( | std::string | node_name_ = "maze_of_digits" | ) |
Constructor. Registers properties.
node_name_ | Name of the node in configuration file. |
Definition at line 29 of file MazeOfDigits.cpp.
References mic::environments::Environment::channels, mic::environments::Count, and type.
mic::environments::MazeOfDigits::MazeOfDigits | ( | const mic::environments::MazeOfDigits & | md_ | ) |
Copying constructor.
md_ | Maze of digits to be cloned. |
Definition at line 38 of file MazeOfDigits.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, type, and mic::environments::Environment::width.
|
virtual |
Destructor. Empty for now.
Definition at line 53 of file MazeOfDigits.cpp.
|
virtual |
Encode the current state of the reduced grid (only the agent position) as a matrix of size [1, width * height].
Definition at line 651 of file MazeOfDigits.cpp.
References mic::environments::Agent, mic::environments::Environment::environment_grid, mic::environments::Environment::height, and mic::environments::Environment::width.
|
virtual |
Encodes the current state of the environment in as a matrix of size [1, width * height * channels].
Implements mic::environments::Environment.
Definition at line 585 of file MazeOfDigits.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 597 of file MazeOfDigits.cpp.
References encodeEnvironment(), getAgentPosition(), getObservation(), mic::environments::Environment::pomdp_flag, and mic::environments::Environment::roi_size.
Referenced by mic::application::MazeOfDigitsDLRERPOMPD::getPredictedRewardsForGivenState(), mic::application::MazeOfDigitsDLRERPOMPD::performSingleStep(), and mic::application::MazeOfDigitsDLRERPOMPD::streamNetworkResponseTable().
|
virtual |
Returns the current state of the environment in the form of a string.
Implements mic::environments::Environment.
Definition at line 571 of file MazeOfDigits.cpp.
References mic::environments::Environment::environment_grid, and gridToString().
Referenced by mic::application::MazeOfDigitsDLRERPOMPD::performSingleStep().
|
virtual |
Calculates the agent position.
Implements mic::environments::Environment.
Definition at line 673 of file MazeOfDigits.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::MazeOfDigitsDLRERPOMPD::getPredictedRewardsForGivenState(), moveAgentToPosition(), mic::application::MazeOfDigitsDLRERPOMPD::performSingleStep(), mic::application::MazeOfDigitsDLRERPOMPD::startNewEpisode(), and mic::application::MazeOfDigitsDLRERPOMPD::streamNetworkResponseTable().
mic::types::TensorXfPtr mic::environments::MazeOfDigits::getObservation | ( | ) |
Returns the tensor being the observation.
Definition at line 620 of file MazeOfDigits.cpp.
References getAgentPosition(), mic::environments::Environment::observation_grid, and mic::environments::Environment::roi_size.
Referenced by encodeObservation(), mic::application::MazeOfDigitsDLRERPOMPD::initializePropertyDependentVariables(), observationToString(), mic::application::MazeOfDigitsDLRERPOMPD::performSingleStep(), and mic::application::MazeOfDigitsDLRERPOMPD::startNewEpisode().
|
inlinevirtual |
Returns the observation size, depending on the process type: FOMDP (width * height * channels) or POMDP (roi_size * roi_size * 1!) (an overridden method)
Reimplemented from mic::environments::Environment.
Definition at line 78 of file MazeOfDigits.hpp.
References mic::environments::Environment::channels, mic::environments::Environment::height, mic::environments::Environment::pomdp_flag, mic::environments::Environment::roi_size, and mic::environments::Environment::width.
Referenced by mic::application::MazeOfDigitsDLRERPOMPD::getPredictedRewardsForGivenState(), mic::application::MazeOfDigitsDLRERPOMPD::initializePropertyDependentVariables(), mic::application::MazeOfDigitsDLRERPOMPD::performSingleStep(), and mic::application::MazeOfDigitsDLRERPOMPD::streamNetworkResponseTable().
|
virtual |
Returns the reward associated with the given state.
pos_ | Position (state). |
Implements mic::environments::Environment.
Definition at line 705 of file MazeOfDigits.cpp.
References mic::environments::Environment::environment_grid, and mic::environments::Goals.
Referenced by mic::application::MazeOfDigitsDLRERPOMPD::performSingleStep().
|
protected |
Returns the current state of the grid passed as an argument in the form of a string.
grid_ | Grid to be processed. |
Definition at line 534 of file MazeOfDigits.cpp.
References mic::environments::Agent, and mic::environments::Walls.
Referenced by environmentToString(), and observationToString().
void mic::environments::MazeOfDigits::initExemplaryMaze | ( | ) |
Method initializes the exemplary maze.
[['2','4','7','7'], ['1','5','7','9'], ['2','3','6','8'], ['A','2','5','6']]
Definition at line 95 of file MazeOfDigits.cpp.
References mic::environments::Environment::channels, mic::environments::Digits, mic::environments::Environment::environment_grid, mic::environments::Goals, mic::environments::Environment::height, mic::environments::Environment::initial_position, moveAgentToPosition(), optimal_path_length, and mic::environments::Environment::width.
Referenced by initializeEnvironment().
void mic::environments::MazeOfDigits::initFullyRandomMaze | ( | ) |
Generates a fully random maze of size (width x height), with spatially independent values of digits.
Definition at line 178 of file MazeOfDigits.cpp.
References mic::environments::Agent, mic::environments::Environment::channels, mic::environments::Digits, mic::environments::Environment::environment_grid, mic::environments::Goals, mic::environments::Environment::height, mic::environments::Environment::initial_position, moveAgentToPosition(), optimal_path_length, reRandomAgentPosition(), type, and mic::environments::Environment::width.
Referenced by initializeEnvironment().
|
virtual |
(Re)initializes the environment - generates the maze of a required (defined by property) type, sets agent, goal etc.
Implements mic::environments::Environment.
Definition at line 73 of file MazeOfDigits.cpp.
References mic::environments::Environment::height, initExemplaryMaze(), initFullyRandomMaze(), initRandomPathMaze(), initRandomStructuredMaze(), mic::environments::Environment::observation_grid, mic::environments::Environment::pomdp_flag, mic::environments::Environment::roi_size, type, and mic::environments::Environment::width.
Referenced by mic::application::MazeOfDigitsDLRERPOMPD::initializePropertyDependentVariables(), and mic::application::MazeOfDigitsDLRERPOMPD::startNewEpisode().
|
virtual |
Initializes all variables that are property-dependent.
Definition at line 69 of file MazeOfDigits.cpp.
void mic::environments::MazeOfDigits::initRandomPathMaze | ( | ) |
Generates a random maze of size (width x height), with spatially dependent values of digits, creating a path leading to the goal (9).
Definition at line 324 of file MazeOfDigits.cpp.
References mic::environments::Agent, mic::environments::Environment::channels, mic::environments::Digits, mic::environments::Environment::environment_grid, mic::environments::Goals, mic::environments::Environment::height, mic::environments::Environment::initial_position, moveAgentToPosition(), optimal_path_length, reRandomAgentPosition(), setBiggerDigit(), type, and mic::environments::Environment::width.
Referenced by initializeEnvironment().
void mic::environments::MazeOfDigits::initRandomStructuredMaze | ( | ) |
Generates a random maze of size (width x height), with spatially dependent values of digits, creating a heat map around the goal (9).
Definition at line 245 of file MazeOfDigits.cpp.
References mic::environments::Agent, mic::environments::Environment::channels, mic::environments::Digits, mic::environments::Environment::environment_grid, mic::environments::Goals, mic::environments::Environment::height, mic::environments::Environment::initial_position, moveAgentToPosition(), optimal_path_length, reRandomAgentPosition(), type, and mic::environments::Environment::width.
Referenced by initializeEnvironment().
|
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 714 of file MazeOfDigits.cpp.
References mic::environments::Environment::environment_grid, and mic::environments::Walls.
Referenced by moveAgentToPosition(), and mic::application::MazeOfDigitsDLRERPOMPD::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 729 of file MazeOfDigits.cpp.
References mic::environments::Environment::environment_grid, and mic::environments::Goals.
Referenced by mic::application::MazeOfDigitsDLRERPOMPD::performSingleStep(), and mic::application::MazeOfDigitsDLRERPOMPD::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 688 of file MazeOfDigits.cpp.
References mic::environments::Agent, getAgentPosition(), and isStateAllowed().
Referenced by mic::application::MazeOfDigitsDLRERPOMPD::getPredictedRewardsForGivenState(), initExemplaryMaze(), initFullyRandomMaze(), initRandomPathMaze(), initRandomStructuredMaze(), mic::application::MazeOfDigitsDLRERPOMPD::performSingleStep(), reRandomAgentPosition(), and mic::application::MazeOfDigitsDLRERPOMPD::streamNetworkResponseTable().
|
virtual |
Returns the current observation taken in the environment in the form of a string.
Implements mic::environments::Environment.
Definition at line 575 of file MazeOfDigits.cpp.
References mic::environments::Environment::environment_grid, getObservation(), gridToString(), and mic::environments::Environment::pomdp_flag.
Referenced by mic::application::MazeOfDigitsDLRERPOMPD::performSingleStep().
mic::environments::MazeOfDigits & mic::environments::MazeOfDigits::operator= | ( | const mic::environments::MazeOfDigits & | md | ) |
Assign operator. Copies the gridworld state along with its properties.
Definition at line 57 of file MazeOfDigits.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 205 of file MazeOfDigits.hpp.
References optimal_path_length.
Referenced by mic::application::MazeOfDigitsDLRERPOMPD::finishCurrentEpisode().
void mic::environments::MazeOfDigits::reRandomAgentPosition | ( | ) |
Generates only the agent new position, leaving the maze unchanged. Recalculates optimal path length to (unchanged) goal.
Definition at line 144 of file MazeOfDigits.cpp.
References mic::environments::Environment::environment_grid, mic::environments::Goals, mic::environments::Environment::height, mic::environments::Environment::initial_position, moveAgentToPosition(), optimal_path_length, and mic::environments::Environment::width.
Referenced by initFullyRandomMaze(), initRandomPathMaze(), and initRandomStructuredMaze().
void mic::environments::MazeOfDigits::setBiggerDigit | ( | size_t | x_, |
size_t | y_, | ||
size_t | value_ | ||
) |
Sets the digit.
point_ | |
value_ |
Definition at line 525 of file MazeOfDigits.cpp.
References mic::environments::Digits, and mic::environments::Environment::environment_grid.
Referenced by initRandomPathMaze().
|
protected |
Optimal number of steps from initial agent position to goal.
Definition at line 231 of file MazeOfDigits.hpp.
Referenced by initExemplaryMaze(), initFullyRandomMaze(), initRandomPathMaze(), initRandomStructuredMaze(), optimalPathLength(), and reRandomAgentPosition().
|
protected |
Property: type of the generated gridworld. Currently available types: 0: the exemplary maze 4x4. -1 (or else): random maze - random maze generated, but generated only once, random initial agent position in each episode -2 (or else): random maze - all randomly generated each time
Definition at line 219 of file MazeOfDigits.hpp.
Referenced by initFullyRandomMaze(), initializeEnvironment(), initRandomPathMaze(), initRandomStructuredMaze(), and MazeOfDigits().