AIToolbox
A library that offers tools for AI problem solving.
|
This class represents the structure of a dynamic decision network. More...
#include <AIToolbox/Factored/Utils/BayesianNetwork.hpp>
Classes | |
struct | ParentSet |
This class contains the parent information for a single next-state feature. More... | |
Public Member Functions | |
DynamicDecisionNetworkGraph (State S, Action A) | |
Basic constructor. More... | |
void | push (ParentSet parents) |
This function adds a ParentSet to the graph. More... | |
size_t | getId (size_t feature, const State &s, const Action &a) const |
This function computes an id for the input state and action, for the specified feature. More... | |
size_t | getId (size_t feature, const PartialState &s, const PartialAction &a) const |
This function computes an id for the input state and action, for the specified feature. More... | |
size_t | getId (size_t feature, size_t parentId, size_t actionId) const |
This function computes an id from the input action-parent ids, for the specified feature. More... | |
std::pair< size_t, size_t > | getIds (size_t feature, const State &s, const Action &a) const |
This function computes an action and parent ids for the input state, action and feature. More... | |
std::pair< size_t, size_t > | getIds (size_t feature, const PartialState &s, const PartialAction &a) const |
This function computes an action and parent ids for the input state, action and feature. More... | |
std::pair< size_t, size_t > | getIds (size_t feature, size_t j) const |
This function computes an action and parent ids for the input id and feature. More... | |
size_t | getSize (size_t feature) const |
This function returns the size required to store one element per value of a parent set. More... | |
size_t | getPartialSize (size_t feature) const |
Thus function returns the number of possible values of the parent agents of the feature. More... | |
size_t | getPartialSize (size_t feature, size_t actionId) const |
Thus function returns the number of possible values of the state parent features of the input feature, given the input action id. More... | |
const State & | getS () const |
This function returns the state space of the DDNGraph. More... | |
const Action & | getA () const |
This function returns the action space of the DDNGraph. More... | |
const std::vector< ParentSet > & | getParentSets () const |
This function returns the internal parent sets of the DDNGraph. More... | |
This class represents the structure of a dynamic decision network.
A DDN is a graph that relates how state features and agents are related over a single time steps. In particular, it contains which state-features and agents each next-state-feature depends on.
This class contains this information, and allows to compute easily indices to reference outside matrices for data; for example transition probabilities or rewards.
This class is supposed to be created once and passed as reference to everybody who needs it, to avoid duplicating information for no reason.
This class considers DDNs where the action-parent features are fixed for each next-state-feature, but the state-parent features depend on both the next-state-feature and on what action the parent agents took.
For example, if I have a state space
[3, 4, 2]
then I have 3 state features. If I have an action space
[2, 5, 4, 2]
then I have 4 agents. For each state feature, the DDNGraph has one DDNGraph::ParentSet, so we have 3 of them. Let's assume that the state feature 0 depends on agents 0 and 3; then we will have that, in parents 0,
parents_[0].agents = [0, 3]
Now, the space of joint actions for these two agents is 4 (2 * 2). For each one of these, state feature 0 might depend on different sets of state features. So we could have that
parents_[0].features = [ [0, 1], // For joint action value 0,0 [1, 2, 3], // For joint action value 1,0 [0, 2], // For joint action value 0,1 [1, 3], // For joint action value 1,1 ]
Basic constructor.
Note that in order to be fully initialized, the push(ParentSet) method must be called once for each state feature.
That method is separate to simplify construction and API.
S | The state space of the DDN. |
A | The action space of the DDN. |
const Action& AIToolbox::Factored::DynamicDecisionNetworkGraph::getA | ( | ) | const |
This function returns the action space of the DDNGraph.
size_t AIToolbox::Factored::DynamicDecisionNetworkGraph::getId | ( | size_t | feature, |
const PartialState & | s, | ||
const PartialAction & | a | ||
) | const |
This function computes an id for the input state and action, for the specified feature.
feature | The feature to compute the id for. |
s | The state to compute the id for. |
a | The action to compute the id for. |
size_t AIToolbox::Factored::DynamicDecisionNetworkGraph::getId | ( | size_t | feature, |
const State & | s, | ||
const Action & | a | ||
) | const |
This function computes an id for the input state and action, for the specified feature.
feature | The feature to compute the id for. |
s | The state to compute the id for. |
a | The action to compute the id for. |
size_t AIToolbox::Factored::DynamicDecisionNetworkGraph::getId | ( | size_t | feature, |
size_t | parentId, | ||
size_t | actionId | ||
) | const |
This function computes an id from the input action-parent ids, for the specified feature.
feature | The feature to compute the id for. |
parentId | The precomputed parent id. |
actionId | The precomputed action id. |
std::pair<size_t, size_t> AIToolbox::Factored::DynamicDecisionNetworkGraph::getIds | ( | size_t | feature, |
const PartialState & | s, | ||
const PartialAction & | a | ||
) | const |
This function computes an action and parent ids for the input state, action and feature.
This function is provided in case some code still needs to store the "intermediate" ids of the graph.
The actionId, which is the second in the pair, is a number between 0 and the factorSpacePartial of the parent agents of the feature.
The parentId, which is the first in the pair, is a number between 0 and the factorSpacePartial of the state parent features of the feature, given the input action.
feature | The feature to compute the id for. |
s | The state to compute the id for. |
a | The action to compute the id for. |
std::pair<size_t, size_t> AIToolbox::Factored::DynamicDecisionNetworkGraph::getIds | ( | size_t | feature, |
const State & | s, | ||
const Action & | a | ||
) | const |
This function computes an action and parent ids for the input state, action and feature.
This function is provided in case some code still needs to store the "intermediate" ids of the graph.
The actionId, which is the second in the pair, is a number between 0 and the factorSpacePartial of the parent agents of the feature.
The parentId, which is the first in the pair, is a number between 0 and the factorSpacePartial of the state parent features of the feature, given the input action.
feature | The feature to compute the id for. |
s | The state to compute the id for. |
a | The action to compute the id for. |
std::pair<size_t, size_t> AIToolbox::Factored::DynamicDecisionNetworkGraph::getIds | ( | size_t | feature, |
size_t | j | ||
) | const |
This function computes an action and parent ids for the input id and feature.
This function transform the input "global" id into the action and parent ids.
feature | The feature to compute the id for. |
j | The global id to decompose. |
const std::vector<ParentSet>& AIToolbox::Factored::DynamicDecisionNetworkGraph::getParentSets | ( | ) | const |
This function returns the internal parent sets of the DDNGraph.
size_t AIToolbox::Factored::DynamicDecisionNetworkGraph::getPartialSize | ( | size_t | feature | ) | const |
Thus function returns the number of possible values of the parent agents of the feature.
This function is fast as these sizes are pre-computed.
feature | The feature to compute the size for. |
size_t AIToolbox::Factored::DynamicDecisionNetworkGraph::getPartialSize | ( | size_t | feature, |
size_t | actionId | ||
) | const |
Thus function returns the number of possible values of the state parent features of the input feature, given the input action id.
This function is fast as these sizes are pre-computed.
feature | The feature to compute the size for. |
actionId | The id of the action values of the parent agents. |
const State& AIToolbox::Factored::DynamicDecisionNetworkGraph::getS | ( | ) | const |
This function returns the state space of the DDNGraph.
size_t AIToolbox::Factored::DynamicDecisionNetworkGraph::getSize | ( | size_t | feature | ) | const |
This function returns the size required to store one element per value of a parent set.
Given the input feature, this function returns the number of possible parent sets the feature can have. In other words, it's the sum of the sizes of all state parent features over all possible parent action values.
This function is fast as these sizes are pre-computed.
feature | The feature to compute the size for. |
void AIToolbox::Factored::DynamicDecisionNetworkGraph::push | ( | ParentSet | parents | ) |
This function adds a ParentSet to the graph.
This method MUST be called once per state feature, after construction.
This method will sanity check all sets of parents, both agents and state features. Additionally, it will pre-compute the size of each set to speed up the computation of ids.
parents | The ParentSet to insert. |