32 template <
typename GUM_SCALAR >
43 template <
typename GUM_SCALAR >
45 ICPTGenerator< GUM_SCALAR >* cptGenerator) {
47 __cptGenerator = cptGenerator;
55 template <
typename GUM_SCALAR >
60 __utGenerator = utGenerator;
69 template <
typename GUM_SCALAR >
71 ICPTGenerator< GUM_SCALAR >* cptGenerator,
UTGenerator* utGenerator) {
73 __cptGenerator = cptGenerator;
74 __utGenerator = utGenerator;
78 template <
typename GUM_SCALAR >
81 delete __cptGenerator;
92 template <
typename GUM_SCALAR >
96 GUM_SCALAR arcDensity,
97 GUM_SCALAR chanceNodeDensity,
98 GUM_SCALAR utilityNodeDensity,
104 std::stringstream strBuff;
107 for (
Idx i = 0; i < nbrNodes; ++i) {
109 nb_mod = (max_modality == 2) ? 2 : 2 + rand() % (max_modality - 1);
111 GUM_SCALAR cnd = chanceNodeDensity * (GUM_SCALAR)RAND_MAX;
112 GUM_SCALAR und = utilityNodeDensity * (GUM_SCALAR)RAND_MAX;
114 GUM_SCALAR d = (GUM_SCALAR)rand();
120 else if (d < (cnd + und))
133 GUM_SCALAR p = arcDensity * (GUM_SCALAR)RAND_MAX;
135 for (
Size i = 0; i < nbrNodes; ++i)
137 for (
Size j = i + 1; j < nbrNodes; ++j)
138 if (((GUM_SCALAR)rand()) < p) {
139 influenceDiagram->
addArc(map[i], map[j]);
143 for (
Size i = 0; i < nbrNodes; ++i)
145 __cptGenerator->generateCPT(
146 influenceDiagram->
cpt(map[i]).pos(influenceDiagram->
variable(map[i])),
147 influenceDiagram->
cpt(map[i]));
149 __utGenerator->generateUT(influenceDiagram->
utility(map[i]).pos(
150 influenceDiagram->
variable(map[i])),
151 influenceDiagram->
utility(map[i]));
153 __checkTemporalOrder(influenceDiagram);
155 return influenceDiagram;
158 template <
typename GUM_SCALAR >
164 auto orderIter = order.
begin();
169 if (orderIter == order.
end())
return;
171 NodeId parentDecision = (*orderIter);
175 for (; orderIter != order.
end(); ++orderIter)
177 infdiag->
addArc(parentDecision, (*orderIter));
178 parentDecision = (*orderIter);
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.
InfluenceDiagramGenerator()
Default constructor.
Class for generating Utility Tables.
iterator begin() const
Returns an unsafe begin iterator.
void addArc(NodeId tail, NodeId head)
Add an arc in the ID, and update diagram's potential nodes cpt if necessary.
bool isChanceNode(NodeId varId) const
Returns true if node is a chance one.
NodeId addChanceNode(const DiscreteVariable &variable, NodeId id=0)
Add a chance variable, it's associate node and it's CPT.
virtual const DiscreteVariable & variable(NodeId id) const
Returns a constant reference over a variabe given it's node id.
void __checkTemporalOrder(InfluenceDiagram< GUM_SCALAR > *infdiag)
Class for generating bayesian networks.
virtual const Potential< GUM_SCALAR > & utility(NodeId varId) const
Returns the utility table of a utility node.
gum is the global namespace for all aGrUM entities
<agrum/ID/generator/influenceDiagramGenerator.h>
bool isDecisionNode(NodeId varId) const
Returns true if node is a decision one.
bool isUtilityNode(NodeId varId) const
Returns true if node is a utility one.
const Sequence< NodeId > & topologicalOrder(bool clear=true) const
The topological order stays the same as long as no variable or arcs are added or erased src the topol...
<agrum/BN/generator/simpleCPTGenerator.h>
bool decisionOrderExists() const
True if a directed path exist with all decison nodes.
~InfluenceDiagramGenerator()
Destructor.
NodeId addUtilityNode(const DiscreteVariable &variable, NodeId id=0)
Add a utility variable, it's associate node and it's UT.
Size Idx
Type for indexes.
NodeId addDecisionNode(const DiscreteVariable &variable, NodeId id=0)
Add a decision variable.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
const iterator & end() const noexcept
Returns the unsafe end iterator.
Abstract class for generating Utility Tables.
Size NodeId
Type for node ids.
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const
Returns the CPT of a potential variable.
Class representing an Influence Diagram.