cMHN 1.0
C++ library for learning MHNs with pRC
write_theta.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef cMHN_UTILITY_WRITE_THETA_H
4#define cMHN_UTILITY_WRITE_THETA_H
5
6#include <fstream>
7#include <iomanip>
8#include <map>
9#include <string>
10
11namespace cMHN
12{
28 template<class T, pRC::Size D>
29 static inline auto writeTheta(std::string const &filename,
30 std::string const &header, pRC::Tensor<T, D, D> const &theta,
31 std::map<std::string, std::string> const &logInfoNames = {},
32 std::map<std::string, double> const &logInfoNumbers = {})
33 {
34 std::ofstream file(filename);
35
36 if(!file.is_open())
37 {
38 pRC::Logging::error("Unable to open output file!");
39 }
40
41 // print header and theta matrix into file
42 file << header << std::endl;
43 file << std::fixed << std::showpos << std::setprecision(6);
44
45 for(pRC::Index i = 0; i < D; ++i)
46 {
47 file << theta(i, 0)();
48 for(pRC::Index j = 1; j < D; ++j)
49 {
50 file << " " << theta(i, j)();
51 }
52 file << std::endl;
53 }
54
55 // print additional logging information into file
56 for(auto const &[k, v] : logInfoNames)
57 {
58 file << k << ": " << v << std::endl;
59 }
60 file << std::scientific;
61 for(auto const &[k, v] : logInfoNumbers)
62 {
63 file << k << ": " << v << std::endl;
64 }
65 }
66}
67
68#endif // CMHN_UTILITY_WRITE_THETA_H
pRC::Size const D
Definition: CalculatePThetaTests.cpp:9
Definition: calculate_pTheta.hpp:15
static auto writeTheta(std::string const &filename, std::string const &header, pRC::Tensor< T, D, D > const &theta, std::map< std::string, std::string > const &logInfoNames={}, std::map< std::string, double > const &logInfoNumbers={})
Writes a theta matrix to file, including additional logging information at the bottom.
Definition: write_theta.hpp:29