45#ifndef DOXYGEN_SHOULD_SKIP_THIS
53 template < GUM_Numeric GUM_SCALAR >
61 template < GUM_Numeric GUM_SCALAR >
73 template < GUM_Numeric GUM_SCALAR >
76 if (!output.good()) {
GUM_ERROR(IOError,
"Input/Output error : stream not writable.") }
78 output << _heading_(bn) << std::endl;
80 output <<
"<!-- Variables -->" << std::endl;
82 for (
auto node: bn.nodes())
83 output << _variableBloc_(bn.variable(node)) << std::endl;
85 output <<
"<!-- Probability distributions -->" << std::endl;
87 for (
auto node: bn.nodes())
88 output << _variableDefinition_(node, bn);
92 output << _documentend_();
96 if (output.fail()) {
GUM_ERROR(IOError,
"Writing in the ostream failed.") }
108 template < GUM_Numeric GUM_SCALAR >
111 std::ofstream output(std::filesystem::path{filePath}, std::ios_base::trunc);
113 _doWrite(output, bn);
116 if (output.fail()) {
GUM_ERROR(IOError,
"Writing in the ostream failed.") }
122 template < GUM_Numeric GUM_SCALAR >
124 std::stringstream str;
127 str <<
"<?xml version=\"1.0\" ?>" << std::endl;
153 str << std::endl <<
"<BIF VERSION=\"0.3\">" << std::endl;
156 str <<
"<NETWORK>" << std::endl;
157 str << std::format(
"<NAME>{}</NAME>\n", bn.propertyWithDefault(
"name",
"unnamedBN"));
158 str <<
"<PROPERTY>software aGrUM</PROPERTY>" << std::endl;
166 template < GUM_Numeric GUM_SCALAR >
178 std::stringstream str;
181 str <<
"<VARIABLE TYPE=\"nature\">" << std::endl;
184 str << std::format(
"\t<NAME>{}</NAME>\n", var.name());
185 str << std::format(
"\t<PROPERTY>description = {}</PROPERTY>\n", var.description());
186 str << std::format(
"\t<PROPERTY>fast = {}</PROPERTY>\n", var.toFast());
189 str <<
"<!--OUTCOME are not used in pyAgrum BIFXML (see fast property) but are kept for "
192 for (
Idx i = 0; i < var.domainSize(); i++)
193 str << std::format(
"\t<OUTCOME>{}</OUTCOME>\n", var.label(i));
196 str <<
"</VARIABLE>" << std::endl;
204 template < GUM_Numeric GUM_SCALAR >
213 std::stringstream str;
216 str <<
"<DEFINITION>" << std::endl;
219 str << std::format(
"\t<FOR>{}</FOR>\n", bn.variable(varNodeId).name());
228 for (
Idx i = 1; i < cpt.nbrDim(); i++)
229 str << std::format(
"\t<GIVEN>{}</GIVEN>\n", cpt.variable(i).name());
232 inst << cpt.variable(0);
234 for (
Idx i = cpt.nbrDim() - 1; i > 0; i--)
235 inst << cpt.variable(i);
239 for (inst.setFirst(); !inst.end(); inst.inc()) {
240 if (inst.val(0) == 0) str << std::endl <<
"\t\t";
246 str << std::endl <<
"\t</TABLE>" << std::endl;
249 str <<
"</DEFINITION>" << std::endl;
257 template < GUM_Numeric GUM_SCALAR >
259 std::stringstream str;
261 str <<
"</NETWORK>" << std::endl;
262 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 a Bayes net in the given output 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