Skip to content

Commit

Permalink
Resolve #24
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewcarbone committed May 26, 2024
1 parent 9287895 commit 3783e85
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 50 deletions.
24 changes: 15 additions & 9 deletions inc/obs2.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,27 @@ class Aging
};


class AgingConfigData
{
public:
// Results holder
std::vector<std::string> results;

// Define the pointer
size_t pointer = 0;


};

class AgingConfig : public Aging
{
protected:

// Results
std::vector<std::string> results1;
std::vector<std::string> results2;

// Define the pointers
size_t pointer1 = 0;
size_t pointer2 = 0;
AgingConfigData d1, d2;
unsigned long long state_index = 0;

// Helpers
void _help_step_1(const double simulation_clock);
void _help_step_2(const double simulation_clock);
void _help_step(const double simulation_clock, const size_t index);

public:
AgingConfig(const utils::SimulationParameters params, const SpinSystem& spin_system);
Expand Down
63 changes: 27 additions & 36 deletions src/obs2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

#include <math.h>
/* #include <string> */

#include "obs2.h"
#include "utils.h"
Expand Down Expand Up @@ -247,65 +248,55 @@ Aging::Aging(const utils::SimulationParameters params, const SpinSystem& spin_sy
}



// TODO - refactor!

void AgingConfig::_help_step_1(const double simulation_clock)
void AgingConfig::_help_step(const double simulation_clock, const size_t index)
{

// Two break conditions
if (grid_pi1[pointer1] >= simulation_clock) {return;}
if (pointer1 > length - 1) {return;}

const std::string state = spin_system_ptr->get_previous_state_string_rep();

while (grid_pi1[pointer1] < simulation_clock)
{
results1.push_back(state);
pointer1 += 1;
if (pointer1 > length - 1){break;}
}
}


void AgingConfig::_help_step_2(const double simulation_clock)
{
AgingConfigData* d = (index == 0) ? &d1 : &d2;
const std::vector<double> g = (index == 0) ? grid_pi1 : grid_pi2;

// Two break conditions
if (grid_pi2[pointer2] >= simulation_clock) {return;}
if (pointer2 > length - 1) {return;}
if (g[d->pointer] >= simulation_clock) {return;}
if (d->pointer > length - 1) {return;}

const std::string state = spin_system_ptr->get_previous_state_string_rep();
// std::cout << "state(2) " << state << std::endl;

while (grid_pi2[pointer2] < simulation_clock)
// This accounts for the state index, which changes every time the
// state does (it increments by 1)
const std::string state2 = state + "-" + std::to_string(state_index);

while (g[d->pointer] < simulation_clock)
{
results2.push_back(state);
pointer2 += 1;
if (pointer2 > length - 1){break;}
d->results.push_back(state2);
d->pointer += 1;
if (d->pointer > length - 1){break;}
}
}


AgingConfig::AgingConfig(const utils::SimulationParameters params, const SpinSystem& spin_system) : Aging(params, spin_system) {}


void AgingConfig::step(const double simulation_clock)
{
_help_step_1(simulation_clock);
_help_step_2(simulation_clock);
_help_step(simulation_clock, 0);
_help_step(simulation_clock, 1);

// If we've changed state, then the state_index should increment
const std::string state = spin_system_ptr->get_previous_state_string_rep();
if (state != spin_system_ptr->get_current_state_string_rep())
{
state_index += 1;
}
}

json AgingConfig::as_json() const
{

// Sanity checks to make sure that every vector was filled completely
assert(length == results1.size());
assert(length == results2.size());
assert(length == d1.results.size());
assert(length == d2.results.size());

json j;
j["aging_config_pi1"] = results1;
j["aging_config_pi2"] = results2;
j["aging_config_pi1"] = d1.results;
j["aging_config_pi2"] = d2.results;
return j;
}

Expand Down
22 changes: 17 additions & 5 deletions src/processing_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,8 @@ json get_ridge_statistics(const std::vector<json> results, const std::string key
}


json get_aging_config_statistics(const std::vector<json> results)
json get_aging_config_statistics(const std::vector<json> results, const bool coarsen)
{

auto t_start = std::chrono::high_resolution_clock::now();

json j;
Expand All @@ -239,12 +238,24 @@ json get_aging_config_statistics(const std::vector<json> results)

std::vector<double> tmp;
std::vector<double> means, medians, standard_deviations, standard_errors;
std::string c1, c2;
for (size_t jj=0; jj<M; jj++)
{
tmp.clear();
for (size_t ii=0; ii<N; ii++)
{
tmp.push_back(aging_pi1[ii][jj] == aging_pi2[ii][jj] ? 1.0 : 0.0);
c1 = aging_pi1[ii][jj];
c2 = aging_pi2[ii][jj];

if (coarsen)
{
// Coarsened dynamics are what we are usually doing, which is
// just taking the state index, disregarding if we've left
// the state or not
c1 = c1.substr(0, c1.find("-"));
c2 = c2.substr(0, c2.find("-"));
}
tmp.push_back(c1 == c2 ? 1.0 : 0.0);
}
const double mean = utils::mean_vector(tmp);
const double median = utils::median_vector(tmp);
Expand All @@ -264,7 +275,7 @@ json get_aging_config_statistics(const std::vector<json> results)

const double dt = utils::get_time_delta(t_start);

printf("Aging config statistics : done in %.02f s\n", dt);
printf("Aging config (coarsen=%i) statistics : done in %.02f s\n", int(coarsen), dt);

return j;
}
Expand Down Expand Up @@ -410,7 +421,8 @@ void postprocess()
j["psi_basin_S"] = get_standard_statistics(results, "psi_basin_S");
}

j["aging_config"] = get_aging_config_statistics(results);
j["aging_config_coarsened"] = get_aging_config_statistics(results, true);
j["aging_config_uncoarsened"] = get_aging_config_statistics(results, false);
j["aging_basin_E"] = get_aging_basin_statistics(results, "aging_basin_E");
if (valid_entropic_attractor)
{
Expand Down

0 comments on commit 3783e85

Please sign in to comment.