MachineIntelligenceCore:ReinforcementLearning
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
mic::environments::MazeOfDigits Class Reference

Class emulating the maze of digits environment. More...

#include <MazeOfDigits.hpp>

Inheritance diagram for mic::environments::MazeOfDigits:
Collaboration diagram for mic::environments::MazeOfDigits:

Public Member Functions

 MazeOfDigits (std::string node_name_="maze_of_digits")
 
 MazeOfDigits (const mic::environments::MazeOfDigits &md_)
 
virtual ~MazeOfDigits ()
 
mic::environments::MazeOfDigitsoperator= (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 ()
 
- Public Member Functions inherited from mic::environments::Environment
 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
 
- Protected Attributes inherited from mic::environments::Environment
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
 

Detailed Description

Class emulating the maze of digits environment.

Author
tkornuta

Definition at line 50 of file MazeOfDigits.hpp.

Constructor & Destructor Documentation

mic::environments::MazeOfDigits::MazeOfDigits ( std::string  node_name_ = "maze_of_digits")

Constructor. Registers properties.

Parameters
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 ( )
virtual

Destructor. Empty for now.

Definition at line 53 of file MazeOfDigits.cpp.

Member Function Documentation

mic::types::MatrixXfPtr mic::environments::MazeOfDigits::encodeAgentGrid ( )
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.

mic::types::MatrixXfPtr mic::environments::MazeOfDigits::encodeEnvironment ( )
virtual

Encodes the current state of the environment in as a matrix of size [1, width * height * channels].

Returns
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().

mic::types::MatrixXfPtr mic::environments::MazeOfDigits::encodeObservation ( )
virtual

Encodes the current observation taken in the environment in as a matrix of size [1, roi_size * roi_size * channels].

Returns
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().

std::string mic::environments::MazeOfDigits::environmentToString ( )
virtual

Returns the current state of the environment in the form of a string.

Returns
String with description of the environment.

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().

mic::types::TensorXfPtr mic::environments::MazeOfDigits::getObservation ( )
virtual size_t mic::environments::MazeOfDigits::getObservationSize ( )
inlinevirtual
float mic::environments::MazeOfDigits::getStateReward ( mic::types::Position2D  pos_)
virtual

Returns the reward associated with the given state.

Parameters
pos_Position (state).
Returns
Reward for being in given state (r).

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().

std::string mic::environments::MazeOfDigits::gridToString ( mic::types::TensorXfPtr &  grid_)
protected

Returns the current state of the grid passed as an argument in the form of a string.

Parameters
grid_Grid to be processed.
Returns
String with description of the grid.

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 ( )
void mic::environments::MazeOfDigits::initializePropertyDependentVariables ( )
virtual

Initializes all variables that are property-dependent.

Definition at line 69 of file MazeOfDigits.cpp.

void mic::environments::MazeOfDigits::initRandomPathMaze ( )
void mic::environments::MazeOfDigits::initRandomStructuredMaze ( )
bool mic::environments::MazeOfDigits::isStateAllowed ( mic::types::Position2D  pos_)
virtual

Checks if position is allowed, i.e. within the gridworld boundaries and there is no wall at that place.

Parameters
pos_Position to be checked.
Returns
True if the position is allowed, false otherwise.

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().

bool mic::environments::MazeOfDigits::isStateTerminal ( mic::types::Position2D  pos_)
virtual

Checks if position is terminal, i.e. agent is standing in a pit or reached the goal. Returns reward associated with given state.

Parameters
pos_Position (state) to be checked.
Returns
The reward associated with "final" action (might be positive or negative), equal to zero means that the position is not final.

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().

bool mic::environments::MazeOfDigits::moveAgentToPosition ( mic::types::Position2D  pos_)
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).

Parameters
pos_Desired position of the agent.
Returns
True if position is valid and was reached, false otherwise.

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().

std::string mic::environments::MazeOfDigits::observationToString ( )
virtual

Returns the current observation taken in the environment in the form of a string.

Returns
String with description of the observation.

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().

unsigned int mic::environments::MazeOfDigits::optimalPathLength ( )
inline

Returns the length of optimal path from agent initial position to goal.

Returns

Definition at line 205 of file MazeOfDigits.hpp.

References optimal_path_length.

Referenced by mic::application::MazeOfDigitsDLRERPOMPD::finishCurrentEpisode().

void mic::environments::MazeOfDigits::reRandomAgentPosition ( )
void mic::environments::MazeOfDigits::setBiggerDigit ( size_t  x_,
size_t  y_,
size_t  value_ 
)

Sets the digit.

Parameters
point_
value_

Definition at line 525 of file MazeOfDigits.cpp.

References mic::environments::Digits, and mic::environments::Environment::environment_grid.

Referenced by initRandomPathMaze().

Member Data Documentation

unsigned int mic::environments::MazeOfDigits::optimal_path_length
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().

mic::configuration::Property<short> mic::environments::MazeOfDigits::type
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().


The documentation for this class was generated from the following files: