8 #include <athena/coordinates/coordinates.hpp>
9 #include <athena/mesh/mesh.hpp>
10 #include <athena/parameter_input.hpp>
13 #include <application/application.hpp>
14 #include <application/exceptions.hpp>
27 mcmc_initialized_(false),
30 Application::Logger app(
"inversion");
31 app->Log(
"Initialize Inversion");
33 opts_.
a = pin->GetOrAddReal(
"inversion",
"stretch", 2.);
34 opts_.
p = pin->GetOrAddInteger(
"inversion",
"walk", 4);
35 opts_.
print = pin->GetOrAddInteger(
"inversion",
"print", 100);
38 opts_.mpi_comm = MPI_COMM_WORLD;
42 pin->GetOrAddString(
"inversion", name +
".logfile",
43 name +
"_inversion.log")
46 std::string obsfile = pin->GetOrAddString(
"inversion",
"obsfile",
"none");
47 if (obsfile !=
"none") {
75 zz_ =
new Real[nwalker];
76 par_ =
new Real[ndim];
80 Application::Logger app(
"inversion");
81 app->Log(
"Make MCMC Outputs");
84 app->Error(
"mcmc chain uninitialized");
90 Application::Logger app(
"inversion");
91 app->Log(
"Reset MCMC Chain");
94 app->Error(
"mcmc chain uninitialized");
118 memset(
recs_.
par[1][0], 0, nstep * nwalker * ndim *
sizeof(
double));
119 memset(
recs_.
val[1][0], 0, nstep * nwalker * nvalue *
sizeof(
double));
120 memset(
recs_.
lnp[1], 0, nstep * nwalker *
sizeof(
double));
125 Application::Logger app(
"inversion");
126 app->Log(
"Create inversion queue");
128 std::string str = pin->GetOrAddString(
"inversion",
"tasks",
"");
129 std::vector<std::string> task_names =
130 Vectorize<std::string>(str.c_str(),
" ,");
135 for (
auto p : task_names) {
136 if (
p ==
"VLAProfileInversion") {
137 pfit = std::make_shared<VLAProfileInversion>(pmb, pin);
138 }
else if (
p ==
"JunoProfileInversion") {
139 pfit = std::make_shared<JunoProfileInversion>(pmb, pin);
140 }
else if (
p ==
"VLACompositionInversion") {
141 }
else if (
p ==
"JunoCompositionInversion") {
143 throw NotFoundError(
"CreateAllInversions",
p);
145 all_fits.push_back(std::move(pfit));
149 for (
auto &q : all_fits) {
150 q->InitializePositions();
152 jl += q->getX2Span();
155 app->Log(
"Number of inversions = " + std::to_string(all_fits.size()));
164 std::stringstream msg;
165 FILE *fp = fopen(fname.c_str(),
"r");
167 msg <<
"### FATAL ERROR in ProfileInversion::ReadObseravtionFile"
169 << fname <<
" cannot be opened.";
179 sscanf(pl,
"%d", &rows);
180 target->resize(rows);
181 icov->resize(rows, rows);
183 for (
int i = 0; i < rows; ++i) {
185 sscanf(pl,
"%lf", &(*target)(i));
190 for (
int i = 0; i < rows; ++i) {
192 char *
p = strtok_r(pl,
" ", &saveptr);
193 for (
int j = 0;
j < rows; ++
j) {
194 sscanf(
p,
"%lf", &(*icov)(i,
j));
195 p = strtok_r(NULL,
" ", &saveptr);
204 auto qlast = fitq[fitq.size() - 1];
207 for (
auto q : fitq) {
208 int nwalker = q->GetWalkers();
210 for (
int k = 0; k < nwalker; ++k) {
211 q->SetLogProbability(k, qlast->GetLogProbability(k));
void InitializeChain(int nstep, int nwalker, int ndim, int nvalue)
void MakeMCMCOutputs(std::string fname)
Inversion(MeshBlock *pmb, ParameterInput *pin, std::string name)
Constructor and destructor.
static AllInversions Create(MeshBlock *pmb, ParameterInput *pin)
char * NextLine(char *line, int num, FILE *stream)
std::shared_ptr< Inversion > InversionPtr
std::vector< std::shared_ptr< Inversion > > AllInversions
void mcmc_free(mcmc_recs *recs)
void mcmc_alloc(mcmc_recs *recs, int nstep, int nwalker, int ndim, int nvalue)
void mcmc_save_fits(char const *fname, mcmc_opts *opts, mcmc_recs *recs, int include_last)
void read_observation_file(Eigen::VectorXd *target, Eigen::MatrixXd *icov, std::string fname)
void gather_probability(std::vector< Inversion * > const &fitq)