43#ifndef DOXYGEN_SHOULD_SKIP_THIS
52 template <
typename GUM_SCALAR >
60 template <
typename GUM_SCALAR >
72 template <
typename GUM_SCALAR >
75 if (!output.good()) {
GUM_ERROR(IOError,
"Input/Output error : stream not writable.") }
77 output << _preambule_(bn) << std::endl;
79 for (
auto node: bn.nodes())
80 output << _cptBloc_(bn, node) << std::endl;
86 if (output.fail()) {
GUM_ERROR(IOError,
"Writing in the ostream failed.") }
98 template <
typename GUM_SCALAR >
101 std::ofstream output(filePath.c_str(), std::ios_base::trunc);
103 _doWrite(output, bn);
106 if (output.fail()) {
GUM_ERROR(IOError,
"Writing in the ostream failed.") }
109 template <
typename GUM_SCALAR >
111 std::stringstream str;
113 str <<
"BAYES" << std::endl;
115 str << bn.size() << std::endl;
117 for (
auto node: bn.nodes())
118 str << bn.variable(node).domainSize() <<
" ";
121 str << bn.size() << std::endl;
123 for (
auto node: bn.nodes()) {
124 const auto& p = bn.cpt(node);
125 str << p.nbrDim() <<
" ";
130 for (
auto k: p.variablesSequence()) {
133 first = bn.idFromName(k->name());
135 str << bn.idFromName(k->name()) <<
" ";
138 str << first <<
" # " << bn.variable(node).name() << std::endl;
145 template <
typename GUM_SCALAR >
148 std::stringstream str;
150 const auto& p = bn.cpt(node);
151 str << p.domainSize();
153 for (I.setFirst(); !I.end(); ++I) {
154 if (I.val(0) == 0) str << std::endl <<
" ";
Definition file for UAI exportation class.
Class representing the minimal interface for Bayesian network with no numerical data.
Class for assigning/browsing values to tuples of discrete variables.
Writes an bayes net in a text file with UAI format.
UAIBNWriter()
Default constructor.
std::string _cptBloc_(const IBayesNet< GUM_SCALAR > &bn, NodeId node)
void _doWrite(std::ostream &output, const IBayesNet< GUM_SCALAR > &bn) final
Writes an bayes net in the given ouput stream.
~UAIBNWriter() override
Destructor.
std::string _preambule_(const IBayesNet< GUM_SCALAR > &bn)
Returns the header of the BIF file.
#define GUM_ERROR(type, msg)
Size NodeId
Type for node ids.
gum is the global namespace for all aGrUM entities