change saving
This commit is contained in:
parent
60ef1b0bcf
commit
5b5aacff0b
@ -7,6 +7,7 @@
|
|||||||
#include "tetrahedral.h"
|
#include "tetrahedral.h"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
Motion::Motion(std::string name, const double delta, const double eta, std::mt19937_64& rng) : m_name(std::move(name)), m_delta(delta), m_eta(eta), m_rng(rng) {
|
Motion::Motion(std::string name, const double delta, const double eta, std::mt19937_64& rng) : m_name(std::move(name)), m_delta(delta), m_eta(eta), m_rng(rng) {
|
||||||
m_uni_dist = std::uniform_real_distribution(0., 1.);
|
m_uni_dist = std::uniform_real_distribution(0., 1.);
|
||||||
@ -57,6 +58,12 @@ void Motion::setParameters(const std::unordered_map<std::string, double> ¶me
|
|||||||
m_eta = parameters.at("eta");
|
m_eta = parameters.at("eta");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unordered_map<std::string, double> Motion::getParameters() const {
|
||||||
|
return std::unordered_map<std::string, double>{
|
||||||
|
{"delta", m_delta},
|
||||||
|
{"eta", m_eta}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const Motion& m) {
|
std::ostream& operator<<(std::ostream& os, const Motion& m) {
|
||||||
os << m.getName();
|
os << m.getName();
|
||||||
|
@ -21,7 +21,7 @@ public:
|
|||||||
virtual double jump() = 0;
|
virtual double jump() = 0;
|
||||||
|
|
||||||
virtual void setParameters(const std::unordered_map<std::string, double>&);
|
virtual void setParameters(const std::unordered_map<std::string, double>&);
|
||||||
|
[[nodiscard]] virtual std::unordered_map<std::string, double> getParameters() const;
|
||||||
[[nodiscard]] double getDelta() const { return m_delta; }
|
[[nodiscard]] double getDelta() const { return m_delta; }
|
||||||
void setDelta(const double delta) { m_delta = delta; }
|
void setDelta(const double delta) { m_delta = delta; }
|
||||||
[[nodiscard]] double getEta() const { return m_eta; }
|
[[nodiscard]] double getEta() const { return m_eta; }
|
||||||
@ -29,6 +29,8 @@ public:
|
|||||||
[[nodiscard]] std::string getName() const { return m_name; }
|
[[nodiscard]] std::string getName() const { return m_name; }
|
||||||
[[nodiscard]] double getInitOmega() const { return m_initial_omega; };
|
[[nodiscard]] double getInitOmega() const { return m_initial_omega; };
|
||||||
|
|
||||||
|
[[nodiscard]] virtual std::string toString() const = 0;
|
||||||
|
|
||||||
static Motion* createFromInput(const std::string& input, std::mt19937_64& rng);
|
static Motion* createFromInput(const std::string& input, std::mt19937_64& rng);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -29,3 +29,15 @@ void BimodalAngle::setParameters(const std::unordered_map<std::string, double> &
|
|||||||
m_angle2 = parameter.at("angle2") * M_PI / 180.;
|
m_angle2 = parameter.at("angle2") * M_PI / 180.;
|
||||||
m_prob = parameter.at("probability1");
|
m_prob = parameter.at("probability1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unordered_map<std::string, double> BimodalAngle::getParameters() const {
|
||||||
|
auto parameter = Motion::getParameters();
|
||||||
|
parameter["angle1"] = m_angle1 * 180 / M_PI;
|
||||||
|
parameter["angle2"] = m_angle2 * 180 / M_PI;
|
||||||
|
parameter["probality1"] = m_prob;
|
||||||
|
return parameter;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string BimodalAngle::toString() const {
|
||||||
|
return std::string{"BimodalAngle/angle1=" + std::to_string(m_angle1 * 180 / M_PI) + "/angle2=" + std::to_string(m_angle2 * 180 / M_PI) + "/probability1=" + std::to_string(m_prob)};
|
||||||
|
}
|
||||||
|
@ -12,6 +12,8 @@ public:
|
|||||||
void initialize() override;
|
void initialize() override;
|
||||||
double jump() override;
|
double jump() override;
|
||||||
void setParameters(const std::unordered_map<std::string, double> &) override;
|
void setParameters(const std::unordered_map<std::string, double> &) override;
|
||||||
|
[[nodiscard]] std::unordered_map<std::string, double> getParameters() const override;
|
||||||
|
[[nodiscard]] std::string toString() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
double m_angle1{0};
|
double m_angle1{0};
|
||||||
|
@ -25,3 +25,13 @@ void SmallAngle::setParameters(const std::unordered_map<std::string, double> &pa
|
|||||||
m_chi = parameters.at("angle") * M_PI / 180.0;
|
m_chi = parameters.at("angle") * M_PI / 180.0;
|
||||||
Motion::setParameters(parameters);
|
Motion::setParameters(parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unordered_map<std::string, double> SmallAngle::getParameters() const {
|
||||||
|
auto parameter = Motion::getParameters();
|
||||||
|
parameter["angle"] = m_chi * 180 / M_PI;
|
||||||
|
return parameter;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string SmallAngle::toString() const {
|
||||||
|
return std::string{"IsotropicAngle/angle=" + std::to_string(m_chi * 180 / M_PI)};
|
||||||
|
}
|
||||||
|
@ -13,6 +13,8 @@ public:
|
|||||||
void initialize() override;
|
void initialize() override;
|
||||||
double jump() override;
|
double jump() override;
|
||||||
void setParameters(const std::unordered_map<std::string, double> &) override;
|
void setParameters(const std::unordered_map<std::string, double> &) override;
|
||||||
|
[[nodiscard]] std::unordered_map<std::string, double> getParameters() const override;
|
||||||
|
[[nodiscard]] std::string toString() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double m_chi{0};
|
double m_chi{0};
|
||||||
|
@ -6,6 +6,10 @@ RandomJump::RandomJump(const double delta, const double eta, std::mt19937_64 &rn
|
|||||||
|
|
||||||
RandomJump::RandomJump(std::mt19937_64 &rng) : Motion(std::string("RandomJump"), rng) {}
|
RandomJump::RandomJump(std::mt19937_64 &rng) : Motion(std::string("RandomJump"), rng) {}
|
||||||
|
|
||||||
|
std::string RandomJump::toString() const {
|
||||||
|
return {"RandomJump"};
|
||||||
|
}
|
||||||
|
|
||||||
void RandomJump::initialize() {
|
void RandomJump::initialize() {
|
||||||
m_initial_omega = RandomJump::jump();
|
m_initial_omega = RandomJump::jump();
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,8 @@ public:
|
|||||||
RandomJump(double, double, std::mt19937_64&);
|
RandomJump(double, double, std::mt19937_64&);
|
||||||
explicit RandomJump(std::mt19937_64&);
|
explicit RandomJump(std::mt19937_64&);
|
||||||
|
|
||||||
|
[[nodiscard]] std::string toString() const override;
|
||||||
|
|
||||||
void initialize() override;
|
void initialize() override;
|
||||||
double jump() override;
|
double jump() override;
|
||||||
};
|
};
|
||||||
|
@ -28,3 +28,7 @@ double TetrahedralJump::jump() {
|
|||||||
|
|
||||||
return m_corners[m_corner_idx];
|
return m_corners[m_corner_idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string TetrahedralJump::toString() const {
|
||||||
|
return {"FourSiteTetrahedral"};
|
||||||
|
}
|
||||||
|
@ -14,6 +14,8 @@ public:
|
|||||||
void initialize() override;
|
void initialize() override;
|
||||||
double jump() override;
|
double jump() override;
|
||||||
|
|
||||||
|
[[nodiscard]] std::string toString() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const double m_beta{std::acos(-1/3.)};
|
const double m_beta{std::acos(-1/3.)};
|
||||||
|
|
||||||
@ -24,5 +26,4 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif //RWSIM_MOTIONTETRAHEDRAL_H
|
#endif //RWSIM_MOTIONTETRAHEDRAL_H
|
||||||
|
@ -72,8 +72,9 @@ void run_spectrum(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// write fid to files
|
// write fid to files
|
||||||
save_parameter_to_file("timesignal", motion.getName(), dist.getName(), parameter, optional);
|
const auto path = make_directory(motion, dist);
|
||||||
save_data_to_file("timesignal", motion.getName(), dist.getName(), t_fid, fid_dict, optional);
|
save_parameter_to_file(std::string("timesignal"), path, parameter, optional);
|
||||||
|
save_data_to_file(std::string("timesignal"), path, t_fid, fid_dict, optional);
|
||||||
|
|
||||||
printEnd(start);
|
printEnd(start);
|
||||||
}
|
}
|
||||||
@ -163,10 +164,11 @@ void run_ste(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// write to files
|
// write to files
|
||||||
save_parameter_to_file("ste", motion.getName(), dist.getName(), parameter, optional);
|
const auto folders = make_directory(motion, dist);
|
||||||
save_data_to_file("coscos", motion.getName(), dist.getName(), mixing_times, cc_dict, optional);
|
save_parameter_to_file(std::string("ste"), folders, parameter, optional);
|
||||||
save_data_to_file("sinsin", motion.getName(), dist.getName(), mixing_times, ss_dict, optional);
|
save_data_to_file(std::string("coscos"), folders, mixing_times, cc_dict, optional);
|
||||||
save_data_to_file("f2", motion.getName(), dist.getName(), mixing_times, f2, optional);
|
save_data_to_file(std::string("sinsin"), folders, mixing_times, ss_dict, optional);
|
||||||
|
save_data_to_file(std::string("f2"), folders, mixing_times, f2, optional);
|
||||||
|
|
||||||
printEnd(start);
|
printEnd(start);
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,13 @@ void Distribution::setParameters(const std::unordered_map<std::string, double> &
|
|||||||
m_tau = parameters.at("tau");
|
m_tau = parameters.at("tau");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unordered_map<std::string, double> Distribution::getParameters() const {
|
||||||
|
return std::unordered_map<std::string, double>{
|
||||||
|
{"tau", m_tau},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Distribution* Distribution::createFromInput(const std::string& input, std::mt19937_64& rng) {
|
Distribution* Distribution::createFromInput(const std::string& input, std::mt19937_64& rng) {
|
||||||
if (input == "Delta")
|
if (input == "Delta")
|
||||||
return new DeltaDistribution(rng);
|
return new DeltaDistribution(rng);
|
||||||
|
@ -16,11 +16,14 @@ public:
|
|||||||
[[nodiscard]] std::string getName() const { return m_name; };
|
[[nodiscard]] std::string getName() const { return m_name; };
|
||||||
|
|
||||||
virtual void setParameters(const std::unordered_map<std::string, double>&);
|
virtual void setParameters(const std::unordered_map<std::string, double>&);
|
||||||
|
[[nodiscard]] virtual std::unordered_map<std::string, double> getParameters() const;
|
||||||
|
|
||||||
virtual void initialize() = 0;
|
virtual void initialize() = 0;
|
||||||
virtual void draw_tau() = 0;
|
virtual void draw_tau() = 0;
|
||||||
[[nodiscard]] double tau_wait() const;
|
[[nodiscard]] double tau_wait() const;
|
||||||
|
|
||||||
|
[[nodiscard]] virtual std::string toString() const = 0;
|
||||||
|
|
||||||
static Distribution* createFromInput(const std::string& input, std::mt19937_64& rng);
|
static Distribution* createFromInput(const std::string& input, std::mt19937_64& rng);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -9,3 +9,7 @@ void DeltaDistribution::initialize() {
|
|||||||
|
|
||||||
void DeltaDistribution::draw_tau() {}
|
void DeltaDistribution::draw_tau() {}
|
||||||
|
|
||||||
|
std::string DeltaDistribution::toString() const {
|
||||||
|
return {"Delta/tau=" + std::to_string(m_tau)};
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,8 @@ public:
|
|||||||
|
|
||||||
void initialize() override;
|
void initialize() override;
|
||||||
void draw_tau() override;
|
void draw_tau() override;
|
||||||
|
|
||||||
|
[[nodiscard]] std::string toString() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //RWSIM_TIMESDELTA_H
|
#endif //RWSIM_TIMESDELTA_H
|
||||||
|
@ -9,6 +9,12 @@ void LogNormalDistribution::setParameters(const std::unordered_map<std::string,
|
|||||||
Distribution::setParameters(parameters);
|
Distribution::setParameters(parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unordered_map<std::string, double> LogNormalDistribution::getParameters() const {
|
||||||
|
auto parameter = Distribution::getParameters();
|
||||||
|
parameter["sigma"] = m_sigma;
|
||||||
|
return parameter;
|
||||||
|
}
|
||||||
|
|
||||||
void LogNormalDistribution::initialize() {
|
void LogNormalDistribution::initialize() {
|
||||||
m_distribution = std::lognormal_distribution(std::log(m_tau), m_sigma);
|
m_distribution = std::lognormal_distribution(std::log(m_tau), m_sigma);
|
||||||
m_tau_jump = m_distribution(m_rng);
|
m_tau_jump = m_distribution(m_rng);
|
||||||
@ -17,3 +23,7 @@ void LogNormalDistribution::initialize() {
|
|||||||
void LogNormalDistribution::draw_tau() {
|
void LogNormalDistribution::draw_tau() {
|
||||||
m_tau_jump = m_distribution(m_rng);
|
m_tau_jump = m_distribution(m_rng);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string LogNormalDistribution::toString() const {
|
||||||
|
return {"LogNormal/tau=" + std::to_string(m_tau) + "/sigma=" + std::to_string(m_sigma)};
|
||||||
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include "base.h"
|
#include "base.h"
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <set>
|
|
||||||
|
|
||||||
class LogNormalDistribution final : public Distribution {
|
class LogNormalDistribution final : public Distribution {
|
||||||
public:
|
public:
|
||||||
@ -11,6 +10,9 @@ public:
|
|||||||
explicit LogNormalDistribution(std::mt19937_64 &rng);
|
explicit LogNormalDistribution(std::mt19937_64 &rng);
|
||||||
|
|
||||||
void setParameters(const std::unordered_map<std::string, double> &) override;
|
void setParameters(const std::unordered_map<std::string, double> &) override;
|
||||||
|
[[nodiscard]] std::unordered_map<std::string, double> getParameters() const override;
|
||||||
|
|
||||||
|
[[nodiscard]] std::string toString() const override;
|
||||||
|
|
||||||
void initialize() override;
|
void initialize() override;
|
||||||
void draw_tau() override;
|
void draw_tau() override;
|
||||||
|
@ -7,11 +7,15 @@
|
|||||||
#include <complex>
|
#include <complex>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <unordered_map>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
|
#include "../motions/base.h"
|
||||||
|
#include "../times/base.h"
|
||||||
|
|
||||||
|
|
||||||
|
class Motion;
|
||||||
|
|
||||||
std::pair<std::string, double> get_optional_parameter(std::vector<std::string>::const_iterator &it) {
|
std::pair<std::string, double> get_optional_parameter(std::vector<std::string>::const_iterator &it) {
|
||||||
std::string stripped_arg;
|
std::string stripped_arg;
|
||||||
@ -124,16 +128,30 @@ std::unordered_map<std::string, double> read_parameter(const std::filesystem::pa
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string make_directory(
|
||||||
|
const Motion& motion,
|
||||||
|
const Distribution& distribution
|
||||||
|
) {
|
||||||
|
std::ostringstream path_name;
|
||||||
|
path_name << motion.toString() << "/" << distribution.toString();
|
||||||
|
|
||||||
|
if (!std::filesystem::create_directories(path_name.str())) {
|
||||||
|
std::cout << "Created directory " << path_name.str() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return path_name.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void save_parameter_to_file(
|
void save_parameter_to_file(
|
||||||
const std::string& resulttype,
|
const std::string& resulttype,
|
||||||
const std::string& motiontype,
|
const std::string& directory,
|
||||||
const std::string& disttype,
|
const std::unordered_map<std::string, double>& parameter,
|
||||||
std::unordered_map<std::string, double>& parameter,
|
const std::unordered_map<std::string, double>& optional
|
||||||
std::unordered_map<std::string, double>& optional
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
std::ostringstream parameter_filename;
|
std::ostringstream parameter_filename;
|
||||||
parameter_filename << resulttype << "_" << motiontype << "_" << disttype;
|
parameter_filename << directory << "/" << resulttype;
|
||||||
|
|
||||||
parameter_filename << std::setprecision(6) << std::scientific;
|
parameter_filename << std::setprecision(6) << std::scientific;
|
||||||
for (const auto& [key, value]: optional) {
|
for (const auto& [key, value]: optional) {
|
||||||
@ -155,15 +173,15 @@ void save_parameter_to_file(
|
|||||||
|
|
||||||
void save_data_to_file(
|
void save_data_to_file(
|
||||||
const std::string& resulttype,
|
const std::string& resulttype,
|
||||||
const std::string& motiontype,
|
const std::string& directory,
|
||||||
const std::string& disttype,
|
|
||||||
const std::vector<double>& x,
|
const std::vector<double>& x,
|
||||||
const std::map<double, std::vector<double>>& y,
|
const std::map<double, std::vector<double>>& y,
|
||||||
std::unordered_map<std::string, double>& optional
|
const std::unordered_map<std::string, double>& optional
|
||||||
) {
|
) {
|
||||||
// make file name
|
// make file name
|
||||||
std::ostringstream datafile_name;
|
std::ostringstream datafile_name;
|
||||||
datafile_name << resulttype << "_" << motiontype << "_" << disttype;
|
datafile_name << directory << "/" << resulttype;
|
||||||
|
|
||||||
datafile_name << std::setprecision(6) << std::scientific;
|
datafile_name << std::setprecision(6) << std::scientific;
|
||||||
for (const auto& [key, value]: optional) {
|
for (const auto& [key, value]: optional) {
|
||||||
datafile_name << "_" << key << "=" << value;
|
datafile_name << "_" << key << "=" << value;
|
||||||
@ -196,15 +214,15 @@ void save_data_to_file(
|
|||||||
|
|
||||||
void save_data_to_file(
|
void save_data_to_file(
|
||||||
const std::string& resulttype,
|
const std::string& resulttype,
|
||||||
const std::string& motiontype,
|
const std::string& directory,
|
||||||
const std::string& disttype,
|
|
||||||
const std::vector<double>& x,
|
const std::vector<double>& x,
|
||||||
const std::vector<double>& y,
|
const std::vector<double>& y,
|
||||||
std::unordered_map<std::string, double>& optional
|
const std::unordered_map<std::string, double>& optional
|
||||||
) {
|
) {
|
||||||
// make file name
|
// make file name
|
||||||
std::ostringstream datafile_name;
|
std::ostringstream datafile_name;
|
||||||
datafile_name << resulttype << "_" << motiontype << "_" << disttype;
|
datafile_name << directory << "/" << resulttype;
|
||||||
|
|
||||||
datafile_name << std::setprecision(6) << std::scientific;
|
datafile_name << std::setprecision(6) << std::scientific;
|
||||||
for (const auto& [key, value]: optional) {
|
for (const auto& [key, value]: optional) {
|
||||||
datafile_name << "_" << key << "=" << value;
|
datafile_name << "_" << key << "=" << value;
|
||||||
|
@ -7,6 +7,9 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "../motions/base.h"
|
||||||
|
#include "../times/base.h"
|
||||||
|
|
||||||
struct Arguments {
|
struct Arguments {
|
||||||
std::string parameter_file{};
|
std::string parameter_file{};
|
||||||
bool ste = false;
|
bool ste = false;
|
||||||
@ -18,12 +21,12 @@ struct Arguments {
|
|||||||
|
|
||||||
Arguments parse_args(int argc, char* argv[]);
|
Arguments parse_args(int argc, char* argv[]);
|
||||||
std::pair<std::string, double> get_optional_parameter(std::vector<std::string>::const_iterator &it);
|
std::pair<std::string, double> get_optional_parameter(std::vector<std::string>::const_iterator &it);
|
||||||
|
|
||||||
std::unordered_map<std::string, double> read_parameter(const std::filesystem::path&);
|
std::unordered_map<std::string, double> read_parameter(const std::filesystem::path&);
|
||||||
|
|
||||||
|
std::string make_directory(const Motion&, const Distribution&);
|
||||||
|
|
||||||
void save_parameter_to_file(const std::string&, const std::string&, const std::string&, std::unordered_map<std::string, double>&, std::unordered_map<std::string, double>&);
|
void save_parameter_to_file(const std::string&, const std::string&, const std::unordered_map<std::string, double>&, const std::unordered_map<std::string, double>&);
|
||||||
void save_data_to_file(const std::string&, const std::string&, const std::string&, const std::vector<double>&, const std::map<double, std::vector<double>>&, std::unordered_map<std::string, double>&);
|
void save_data_to_file(const std::string&, const std::string&, const std::vector<double>&, const std::map<double, std::vector<double>>&, const std::unordered_map<std::string, double>&);
|
||||||
void save_data_to_file(const std::string&, const std::string&, const std::string&, const std::vector<double>&, const std::vector<double>&, std::unordered_map<std::string, double>&);
|
void save_data_to_file(const std::string&, const std::string&, const std::vector<double>&, const std::vector<double>&, const std::unordered_map<std::string, double>&);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user