AIToolbox
A library that offers tools for AI problem solving.
AIToolbox::Factored::DynamicDecisionNetworkGraph Class Reference

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 StategetS () const
 This function returns the state space of the DDNGraph. More...
 
const ActiongetA () 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...
 

Detailed Description

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 ]

Constructor & Destructor Documentation

◆ DynamicDecisionNetworkGraph()

AIToolbox::Factored::DynamicDecisionNetworkGraph::DynamicDecisionNetworkGraph ( State  S,
Action  A 
)

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.

See also
push(ParentSet);
Parameters
SThe state space of the DDN.
AThe action space of the DDN.

Member Function Documentation

◆ getA()

const Action& AIToolbox::Factored::DynamicDecisionNetworkGraph::getA ( ) const

This function returns the action space of the DDNGraph.

Returns
The action space.

◆ getId() [1/3]

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.

See also
getSize(size_t);
Parameters
featureThe feature to compute the id for.
sThe state to compute the id for.
aThe action to compute the id for.
Returns
A unique id in [0, getSize(feature)).

◆ getId() [2/3]

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.

See also
getSize(size_t);
Parameters
featureThe feature to compute the id for.
sThe state to compute the id for.
aThe action to compute the id for.
Returns
A unique id in [0, getSize(feature)).

◆ getId() [3/3]

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.

See also
getIds(size_t, const State &, const Action &);
getSize(size_t);
Parameters
featureThe feature to compute the id for.
parentIdThe precomputed parent id.
actionIdThe precomputed action id.
Returns
A unique id in [0, getSize(feature)).

◆ getIds() [1/3]

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.

See also
getPartialSize(size_t);
getPartialSize(size_t, size_t);
Parameters
featureThe feature to compute the id for.
sThe state to compute the id for.
aThe action to compute the id for.
Returns
A pair of <parent id, action id>.

◆ getIds() [2/3]

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.

See also
getPartialSize(size_t);
getPartialSize(size_t, size_t);
Parameters
featureThe feature to compute the id for.
sThe state to compute the id for.
aThe action to compute the id for.
Returns
A pair of <parent id, action id>.

◆ getIds() [3/3]

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.

See also
getPartialSize(size_t);
getPartialSize(size_t, size_t);
Parameters
featureThe feature to compute the id for.
jThe global id to decompose.
Returns
A pair of <parent id, action id>.

◆ getParentSets()

const std::vector<ParentSet>& AIToolbox::Factored::DynamicDecisionNetworkGraph::getParentSets ( ) const

This function returns the internal parent sets of the DDNGraph.

Returns
The internal parent sets.

◆ getPartialSize() [1/2]

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.

Parameters
featureThe feature to compute the size for.
Returns
The "action" size of the feature.

◆ getPartialSize() [2/2]

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.

Parameters
featureThe feature to compute the size for.
actionIdThe id of the action values of the parent agents.
Returns
The "parent" size of the feature, given the parent action.

◆ getS()

const State& AIToolbox::Factored::DynamicDecisionNetworkGraph::getS ( ) const

This function returns the state space of the DDNGraph.

Returns
The state space.

◆ getSize()

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.

Parameters
featureThe feature to compute the size for.
Returns
The "global" size of the feature.

◆ push()

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.

Parameters
parentsThe ParentSet to insert.

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