45#ifndef DOXYGEN_SHOULD_SKIP_THIS
54 template < GUM_Numeric GUM_SCALAR >
62 template < GUM_Numeric GUM_SCALAR >
74 template < GUM_Numeric GUM_SCALAR >
77 if (!output.good()) {
GUM_ERROR(IOError,
"Input/Output error : stream not writable.") }
79 _heading_(output, bn);
83 output <<
" <nodes>" << std::endl;
84 for (
auto node: bn.topologicalOrder())
85 _variableBloc_(output, node, bn);
86 output <<
" </nodes>" << std::endl;
89 _headingExtension_(output, bn);
90 for (
auto node: bn.topologicalOrder())
91 _variableExtension_(output, node, bn);
92 _endExtension_(output);
96 _documentEnd_(output);
100 if (output.fail()) {
GUM_ERROR(IOError,
"Writing in the ostream failed.") }
112 template < GUM_Numeric GUM_SCALAR >
115 std::ofstream output(std::filesystem::path{filePath}, std::ios_base::trunc);
117 _doWrite(output, bn);
120 if (output.fail()) {
GUM_ERROR(IOError,
"Writing in the ostream failed.") }
126 template < GUM_Numeric GUM_SCALAR >
130 output <<
"<?xml version=\"1.0\" ?>" << std::endl;
131 output <<
"<!-- This network was created by pyAgrum " << GUM_VERSION
132 <<
" for any purpose you want -->" << std::endl;
134 output <<
"<smile version=\"1.0\" id=\"" << bn.propertyWithDefault(
"name",
"unnamedBN") <<
"\">"
141 template < GUM_Numeric GUM_SCALAR >
145 output <<
" <extensions>" << std::endl;
146 output <<
" <genie version=\"1.0\" app=\"aGrUM " << GUM_VERSION <<
"\" name=\""
147 << bn.propertyWithDefault(
"name",
"unnamedBN") <<
"\">" << std::endl;
153 template < GUM_Numeric GUM_SCALAR >
164 const auto& var = bn.variable(varNodeId);
166 output <<
" <cpt id=\"" << this->_buildNameWithOnlyValidChars(var.name()) <<
"\">"
170 for (
const auto& lab: var.labels()) {
171 output <<
" <state id=\"" << lab <<
"\" />" << std::endl;
177 const auto& cpt = bn.cpt(varNodeId);
178 const auto nd = cpt.nbrDim();
180 output <<
" <parents>";
182 for (
Idx i = 1; i < nd; i++) {
183 if (first) first =
false;
186 output << this->_buildNameWithOnlyValidChars(cpt.variable(i).name());
188 output <<
"</parents>" << std::endl;
191 output <<
" <probabilities>";
192 gum::Instantiation I(cpt);
196 if (first) first =
false;
201 output <<
"</probabilities>" << std::endl;
204 output <<
" </cpt>" << std::endl;
210 template < GUM_Numeric GUM_SCALAR >
217 const std::string& name = bn.variable(varNodeId).name();
218 output <<
" <node id=\"" << this->_buildNameWithOnlyValidChars(name) <<
"\">" << std::endl;
219 output <<
" <name>" << name <<
"</name>" << std::endl;
220 output <<
" </node>" << std::endl;
226 template < GUM_Numeric GUM_SCALAR >
228 output <<
" </genie>" << std::endl;
229 output <<
" </extensions>" << std::endl;
235 template < GUM_Numeric GUM_SCALAR >
237 output <<
"</smile>" << std::endl;
Definition file for XDSL XML exportation class.
Class representing the minimal interface for Bayesian network with no numerical data.
<agrum/BN/io/XDSLXML/XDSLBNWriter.h>
void _endExtension_(std::ostream &output)
void _documentEnd_(std::ostream &output)
send to output the end of the XDSL file.
XDSLBNWriter()
Default constructor.
void _variableBloc_(std::ostream &output, const NodeId &varNodeId, const IBayesNet< GUM_SCALAR > &bn)
send to output a bloc defining a variable in the XDSL format.
void _variableExtension_(std::ostream &output, const NodeId &varNodeId, const IBayesNet< GUM_SCALAR > &bn)
send to output a bloc defining a variable's extensoion in the XDSL
void _heading_(std::ostream &output, const IBayesNet< GUM_SCALAR > &bn)
send to output the header of the XDSL file.
void _doWrite(std::ostream &output, const IBayesNet< GUM_SCALAR > &bn) final
Writes a Bayes net in the given output stream.
void _headingExtension_(std::ostream &output, const IBayesNet< GUM_SCALAR > &bn)
~XDSLBNWriter() override
Destructor.
#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