57 template <
typename GUM_SCALAR >
68 template <
typename GUM_SCALAR >
70 ICPTGenerator< GUM_SCALAR >* cptGenerator) {
80 template <
typename GUM_SCALAR >
93 template <
typename GUM_SCALAR >
95 ICPTGenerator< GUM_SCALAR >* cptGenerator,
103 template <
typename GUM_SCALAR >
117 template <
typename GUM_SCALAR >
120 GUM_SCALAR arcDensity,
121 GUM_SCALAR chanceNodeDensity,
122 GUM_SCALAR utilityNodeDensity,
127 std::stringstream strBuff;
130 for (
Idx i = 0; i < nbrNodes; ++i) {
132 nb_mod = (max_modality == 2) ? 2 : 2 +
randomValue(max_modality - 1);
134 GUM_SCALAR cnd = chanceNodeDensity;
135 GUM_SCALAR und = utilityNodeDensity;
142 influenceDiagram->addChanceNode(
RangeVariable(strBuff.str(),
"", 0, nb_mod - 1)));
143 else if (d < (cnd + und))
148 influenceDiagram->addDecisionNode(
RangeVariable(strBuff.str(),
"", 0, nb_mod - 1)));
154 GUM_SCALAR p = arcDensity;
156 for (
Size i = 0; i < nbrNodes; ++i)
157 if (!influenceDiagram->isUtilityNode(map[i]))
158 for (
Size j = i + 1; j < nbrNodes; ++j)
159 if (((GUM_SCALAR)
randomProba()) < p) { influenceDiagram->addArc(map[i], map[j]); }
162 for (
Size i = 0; i < nbrNodes; ++i)
163 if (influenceDiagram->isChanceNode(map[i]))
165 influenceDiagram->cpt(map[i]).pos(influenceDiagram->variable(map[i])),
166 influenceDiagram->cpt(map[i]));
167 else if (influenceDiagram->isUtilityNode(map[i]))
169 influenceDiagram->utility(map[i]).pos(influenceDiagram->variable(map[i])),
170 influenceDiagram->utility(map[i]));
174 return influenceDiagram;
177 template <
typename GUM_SCALAR >
183 auto orderIter = order.
begin();
188 if (orderIter == order.
end())
return;
190 NodeId parentDecision = (*orderIter);
194 for (; orderIter != order.
end(); ++orderIter)
196 infdiag->
addArc(parentDecision, (*orderIter));
197 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.
bool isDecisionNode(NodeId varId) const
Returns true if node is a decision one.
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.
Defines a discrete random variable over an integer interval.
const iterator & end() const noexcept
<agrum/BN/generator/simpleCPTGenerator.h>
Class for generating Utility Tables.
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.
Idx randomValue(const Size max=2)
Returns a random Idx between 0 and max-1 included.
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.