-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: addition of potentialSet class #1991
base: develop
Are you sure you want to change the base?
Conversation
Co-authored-by: Adam Washington <adam.washington@stfc.ac.uk>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two bits here. First, I've made some suggestions on the operators. Also, we should probably add a unit test for the averaging. It'll be easier to put it in now while the code is fresh in your mind than six months from now when we're tracking down a bug.
Co-authored-by: Adam Washington <adam.washington@stfc.ac.uk>
std::map<std::string, EPData> averagedPotentials = potentials; | ||
|
||
averagedPotentialsStore.emplace_back(potentials); | ||
// Check if ran the right amount of iterations before averaging | ||
if (averagedPotentialsStore.size() > averagingLength_) | ||
{ | ||
averagedPotentialsStore.pop_back(); | ||
} | ||
|
||
// Average the potentials and replace the map with the new averaged | ||
for (const auto &pots : averagedPotentialsStore) | ||
{ | ||
for (auto &&[key, epData] : pots) | ||
{ | ||
averagedPotentials[key].ep += epData.ep; | ||
averagedPotentials[key].ep /= averagingLength_.value(); | ||
} | ||
} | ||
potentials = averagedPotentials; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this section be the issue? The logic here doesn't quite add up, since you store the current potentials as the beginning of averagePotentials
, then add potentials
to the store, then immediately remove it if you have exceeded your averaging length (which past a certain point you always will) and then do the sum over all the store potentials. That will give you N+1 sets of potentials contributing to the average, rather than the N you want, and which will always contain the first N potential sets you ever generate at the beginning of the simulation (since you're doing pop_back
rather than pop_front
. The Averaging
class would sort all this out for you, but I have suggested the necessary modifications to clean this up anyway.
@@ -53,6 +53,26 @@ Module::ExecutionResult EPSRManagerModule::process(ModuleContext &moduleContext) | |||
for (auto &&[key, epData] : potentials) | |||
epData.ep /= epData.count; | |||
|
|||
std::map<std::string, EPData> averagedPotentials = potentials; | |||
|
|||
averagedPotentialsStore.emplace_back(potentials); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
averagedPotentialsStore.emplace_back(potentials); |
// Check if ran the right amount of iterations before averaging | ||
if (averagedPotentialsStore.size() > averagingLength_) | ||
{ | ||
averagedPotentialsStore.pop_back(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Check if ran the right amount of iterations before averaging | |
if (averagedPotentialsStore.size() > averagingLength_) | |
{ | |
averagedPotentialsStore.pop_back(); | |
} | |
// Limit data to average to the most recent N-1 sets | |
while (averagedPotentialsStore.size() >= averagingLength_) | |
{ | |
averagedPotentialsStore.pop_front(); | |
} |
averagedPotentials[key].ep /= averagingLength_.value(); | ||
} | ||
} | ||
potentials = averagedPotentials; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
potentials = averagedPotentials; | |
// Add the current potentials (before averaging) to the average store before we overwrite them | |
averagePotentialsStore.emplace_back(potentials); | |
// Set new averaged potentials | |
potentials = averagedPotentials; |
for (auto &&[key, epData] : pots) | ||
{ | ||
averagedPotentials[key].ep += epData.ep; | ||
averagedPotentials[key].ep /= averagingLength_.value(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You definitely don't want to do this division every time you add a set of potentials, just once at the end!
Addition of potentialSet class for easier averaging of potentials.