43#ifndef DOXYGEN_SHOULD_SKIP_THIS
51 template <
typename GUM_SCALAR >
59 template <
typename GUM_SCALAR >
71 template <
typename GUM_SCALAR >
74 if (!output.good()) {
GUM_ERROR(IOError,
"Input/Output error : stream not writable.") }
76 output << _heading_(bn) << std::endl;
78 output <<
"<!-- Variables -->" << std::endl;
80 for (
auto node: bn.nodes())
81 output << _variableBloc_(bn.variable(node)) << std::endl;
83 output <<
"<!-- Probability distributions -->" << std::endl;
85 for (
auto node: bn.nodes())
86 output << _variableDefinition_(node, bn);
90 output << _documentend_();
94 if (output.fail()) {
GUM_ERROR(IOError,
"Writing in the ostream failed.") }
106 template <
typename GUM_SCALAR >
109 std::ofstream output(filePath.c_str(), std::ios_base::trunc);
111 _doWrite(output, bn);
114 if (output.fail()) {
GUM_ERROR(IOError,
"Writing in the ostream failed.") }
120 template <
typename GUM_SCALAR >
122 std::stringstream str;
125 str <<
"<?xml version=\"1.0\" ?>" << std::endl;
151 str << std::endl <<
"<BIF VERSION=\"0.3\">" << std::endl;
154 str <<
"<NETWORK>" << std::endl;
155 str <<
"<NAME>" << bn.propertyWithDefault(
"name",
"unnamedBN") <<
"</NAME>" << std::endl;
156 str <<
"<PROPERTY>software aGrUM</PROPERTY>" << std::endl;
164 template <
typename GUM_SCALAR >
176 std::stringstream str;
179 str <<
"<VARIABLE TYPE=\"nature\">" << std::endl;
182 str <<
"\t<NAME>" << var.name() <<
"</NAME>" << std::endl;
183 str <<
"\t<PROPERTY>description = " << var.description() <<
"</PROPERTY>" << std::endl;
184 str <<
"\t<PROPERTY>fast = " << var.toFast() <<
"</PROPERTY>" << std::endl;
187 str <<
"<!--OUTCOME are not used in pyAgrum BIFXML (see fast property) but are kept for "
190 for (
Idx i = 0; i < var.domainSize(); i++)
191 str <<
"\t<OUTCOME>" << var.label(i) <<
"</OUTCOME>" << std::endl;
194 str <<
"</VARIABLE>" << std::endl;
202 template <
typename GUM_SCALAR >
211 std::stringstream str;
214 str <<
"<DEFINITION>" << std::endl;
217 str <<
"\t<FOR>" << bn.variable(varNodeId).name() <<
"</FOR>" << std::endl;
226 for (
Idx i = 1; i < cpt.nbrDim(); i++)
227 str <<
"\t<GIVEN>" << cpt.variable(i).name() <<
"</GIVEN>" << std::endl;
230 inst << cpt.variable(0);
232 for (
Idx i = cpt.nbrDim() - 1; i > 0; i--)
233 inst << cpt.variable(i);
237 for (inst.setFirst(); !inst.end(); inst.inc()) {
238 if (inst.val(0) == 0) str << std::endl <<
"\t\t";
244 str << std::endl <<
"\t</TABLE>" << std::endl;
247 str <<
"</DEFINITION>" << std::endl;
255 template <
typename GUM_SCALAR >
257 std::stringstream str;
259 str <<
"</NETWORK>" << std::endl;
260 str <<
"</BIF>" << std::endl;
Definition file for BIF XML exportation class.
<agrum/BN/io/BIFXML/BIFXMLBNWriter.h>
BIFXMLBNWriter()
Default constructor.
std::string _variableBloc_(const DiscreteVariable &var)
Returns a bloc defining a variable in the BIF format.
std::string _documentend_()
Returns the end of the BIF file.
void _doWrite(std::ostream &output, const IBayesNet< GUM_SCALAR > &bn) final
Writes an bayes net in the given ouput stream.
std::string _variableDefinition_(const NodeId &varNodeId, const IBayesNet< GUM_SCALAR > &bn)
Returns a bloc defining a variable's table (if she has) in the BIF format.
std::string _heading_(const IBayesNet< GUM_SCALAR > &bn)
Returns the header of the BIF file.
~BIFXMLBNWriter() override
Destructor.
Base class for discrete random variable.
Class representing the minimal interface for Bayesian network with no numerical data.
Class for assigning/browsing values to tuples of discrete variables.
aGrUM's Tensor is a multi-dimensional array with tensor operators.
#define GUM_ERROR(type, msg)
Size Idx
Type for indexes.
Size NodeId
Type for node ids.
gum is the global namespace for all aGrUM entities