feat: Data history storage (for averaging) - #2206
Conversation
| // Prune old data to get to the averagingLength | ||
| while (history_.size() > averagingLength) | ||
| history_.erase(history_.begin()); | ||
|
|
||
| // Perform averaging of the datasets that we have | ||
| T averaged; | ||
| auto weight = 1.0 / history_.size(); | ||
| for (auto &data : history_) | ||
| averaged += *data * weight; |
There was a problem hiding this comment.
| // Prune old data to get to the averagingLength | |
| while (history_.size() > averagingLength) | |
| history_.erase(history_.begin()); | |
| // Perform averaging of the datasets that we have | |
| T averaged; | |
| auto weight = 1.0 / history_.size(); | |
| for (auto &data : history_) | |
| averaged += *data * weight; | |
| // How many items to average | |
| auto length = history.size() < averagingLength ? history.size() : averagingLength; | |
| // Perform averaging of the datasets that we have | |
| T averaged; | |
| auto weight = 1.0 / length; | |
| for (auto &data : std::span(history_.rbegin(), ristory_.rbegin()+length)) | |
| averaged += *data * weight; |
This is an alternate implementation that doesn't lose history. This would allow us to look at multiple averaging lengths simultaneously (the current implementation essentially locks you into the shortest length). The disadvantage is that it can grow without bound, though that could be fixed by replacing the vector with a ring buffer.
This isn't a necessary change - just a suggestion.
There was a problem hiding this comment.
Interesting thought. While I like the idea, my concern is that this could add a lot of bloat as many of the objects being stored here are pretty chunky (I'm looking at you, PartialSet). As such, I would prefer to stick to the ultra-simple, shortest-length version for the time being.
rprospero
left a comment
There was a problem hiding this comment.
Looks good. Also gives us a nice framework for other stats (e.g. standard deviation, median, etc.)
One small suggested change, but, otherwise, things look good.
82378c6 to
ae91a7b
Compare
Co-authored-by: Tristan Youngs <trisyoungs@googlemail.com>
Co-authored-by: Tristan Youngs <trisyoungs@googlemail.com>
Follows #2204 and must be merged before #2203.
This PR introduces a new
Historytemplate class to generalise (and simplify) the functionality of the oldAveragingnamespace. The idea is straightforward - introduce a sort of managedstd::vectorof data which can be easily formed into an average as well as serialised if required (e.g. as node data will require).