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_(MN) << std::endl;
79 for (
const auto& kv: MN.factors())
80 output << _factorBloc_(MN, *kv.second) << 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);
107 if (output.fail()) {
GUM_ERROR(IOError,
"Writing in the ostream failed.") }
110 template <
typename GUM_SCALAR >
113 std::stringstream str;
115 str <<
"MARKOV" << std::endl;
117 str << MN.size() <<
" # nbr Nodes" << std::endl;
119 for (
auto node: MN.nodes())
120 str << MN.variable(node).domainSize() <<
" ";
123 str << MN.factors().size() <<
" # nbr Factors " << std::endl;
125 for (
const auto& kv: MN.factors()) {
126 const auto& nodeset = kv.first;
127 str << nodeset.size() <<
" ";
128 for (
auto k: nodeset) {
137 template <
typename GUM_SCALAR >
141 std::stringstream str;
143 str << clikpot.domainSize() <<
" # {";
145 for (
Idx k = 0; k < clikpot.nbrDim(); k++) {
146 str << MN.idFromName(clikpot.variable(k).name());
147 if (k == clikpot.nbrDim() - 1) str <<
"}";
151 for (I.setFirst(); !I.end(); ++I) {
152 if (I.val(0) == 0) str << std::endl <<
" ";
153 str << clikpot[I] <<
" ";
Definition file for UAI exportation class.
Class representing the minimal interface for Markov random field.
Class for assigning/browsing values to tuples of discrete variables.
aGrUM's Tensor is a multi-dimensional array with tensor operators.
<agrum/MRF/io/UAI/UAIMRFWriter.h>
void write(std::ostream &output, const IMarkovRandomField< GUM_SCALAR > &MN) final
Writes an Markov net in the given ouput stream.
~UAIMRFWriter()
Destructor.
std::string _preambule_(const IMarkovRandomField< GUM_SCALAR > &MN)
Returns the header of the BIF file.
std::string _factorBloc_(const IMarkovRandomField< GUM_SCALAR > &MN, const Tensor< GUM_SCALAR > &clikpot)
UAIMRFWriter()
Default constructor.
#define GUM_ERROR(type, msg)
Size Idx
Type for indexes.
gum is the global namespace for all aGrUM entities