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 output << _preambule_(MN) << std::endl;
81 for (
const auto& kv: MN.factors())
82 output << _factorBloc_(MN, *kv.second) << std::endl;
88 if (output.fail()) {
GUM_ERROR(IOError,
"Writing in the ostream failed.") }
100 template < GUM_Numeric GUM_SCALAR >
103 std::ofstream output(std::filesystem::path{filePath}, std::ios_base::trunc);
109 if (output.fail()) {
GUM_ERROR(IOError,
"Writing in the ostream failed.") }
112 template < GUM_Numeric GUM_SCALAR >
114 std::stringstream str;
116 str <<
"MARKOV" << std::endl;
118 str << std::format(
"{} # nbr Nodes\n", MN.size());
120 for (
auto node: MN.nodes())
121 str << MN.variable(node).domainSize() <<
" ";
124 str << std::format(
"{} # nbr Factors \n", MN.factors().size());
126 for (
const auto& kv: MN.factors()) {
127 const auto& nodeset = kv.first;
128 str << nodeset.size() <<
" ";
129 for (
auto k: nodeset) {
138 template < GUM_Numeric GUM_SCALAR >
141 std::stringstream str;
143 str << std::format(
"{} # {{", 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 a Markov net to the given output stream.
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.
~UAIMRFWriter() override
Destructor.
#define GUM_ERROR(type, msg)
Size Idx
Type for indexes.
gum is the global namespace for all aGrUM entities