58 template < GUM_Numeric GUM_SCALAR >
69 template < GUM_Numeric GUM_SCALAR >
71 ICPTGenerator< GUM_SCALAR >* cptGenerator) {
81 template < GUM_Numeric GUM_SCALAR >
94 template < GUM_Numeric GUM_SCALAR >
96 ICPTGenerator< GUM_SCALAR >* cptGenerator,
104 template < GUM_Numeric GUM_SCALAR >
118 template < GUM_Numeric GUM_SCALAR >
121 GUM_SCALAR arcDensity,
122 GUM_SCALAR chanceNodeDensity,
123 GUM_SCALAR utilityNodeDensity,
130 for (
Idx i = 0; i < nbrNodes; ++i) {
131 const auto varName = std::format(
"{}", i);
132 nb_mod = (max_modality == 2) ? 2 : 2 +
randomValue(max_modality - 1);
134 GUM_SCALAR cnd = chanceNodeDensity;
135 GUM_SCALAR und = utilityNodeDensity;
141 else if (d < (cnd + und))
144 map.
insert(i, influenceDiagram->addDecisionNode(
RangeVariable(varName,
"", 0, nb_mod - 1)));
148 GUM_SCALAR p = arcDensity;
150 for (
Size i = 0; i < nbrNodes; ++i)
151 if (!influenceDiagram->isUtilityNode(map[i]))
152 for (
Size j = i + 1; j < nbrNodes; ++j)
153 if (((GUM_SCALAR)
randomProba()) < p) { influenceDiagram->addArc(map[i], map[j]); }
156 for (
Size i = 0; i < nbrNodes; ++i)
157 if (influenceDiagram->isChanceNode(map[i]))
159 influenceDiagram->cpt(map[i]).pos(influenceDiagram->variable(map[i])),
160 influenceDiagram->cpt(map[i]));
161 else if (influenceDiagram->isUtilityNode(map[i]))
163 influenceDiagram->utility(map[i]).pos(influenceDiagram->variable(map[i])),
164 influenceDiagram->utility(map[i]));
168 return influenceDiagram;
171 template < GUM_Numeric GUM_SCALAR >
177 auto orderIter = order.
begin();
182 if (orderIter == order.
end())
return;
184 NodeId parentDecision = (*orderIter);
188 for (; orderIter != order.
end(); ++orderIter)
190 infdiag->
addArc(parentDecision, (*orderIter));
191 parentDecision = (*orderIter);
Sequence< NodeId > topologicalOrder() const
The topological order stays the same as long as no variable or arcs are added or erased src the topol...
The class for generic Hash Tables.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
InfluenceDiagramGenerator()
Default constructor.
UTGenerator * _utGenerator_
~InfluenceDiagramGenerator()
Destructor.
InfluenceDiagram< GUM_SCALAR > * generateID(Size nbrNodes, GUM_SCALAR arcDensity, GUM_SCALAR chanceNodeDensity, GUM_SCALAR utilityNodeDensity, Size max_modality=2)
Generates an influence diagram using floats.
void _checkTemporalOrder_(InfluenceDiagram< GUM_SCALAR > *infdiag)
ICPTGenerator< GUM_SCALAR > * _cptGenerator_
Class representing an Influence Diagram.
InfluenceDiagram()
Default constructor.
void addArc(NodeId tail, NodeId head)
Add an arc in the ID, and update diagram's tensor nodes cpt if necessary.
bool decisionOrderExists() const
True if a directed path exist with all decision nodes.
bool isDecisionNode(NodeId varId) const
Returns true if node is a decision one.
Defines a discrete random variable over an integer interval.
const iterator & end() const noexcept
SimpleCPTGenerator()
Default constructor.
SimpleUTGenerator()
Default constructor.
Abstract class for generating Utility Tables.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
Size NodeId
Type for node ids.
GUM_SHARED_PUBLIC Idx randomValue(const Size max=2)
Returns a random Idx between 0 and max-1 included.
GUM_SHARED_PUBLIC double randomProba()
Returns a random double between 0 and 1 included (i.e.
Class for generating Bayesian networks.
gum is the global namespace for all aGrUM entities
Contains useful methods for random stuff.