|
Modular Megafauna Model 1.1.5
A physiological, dynamic herbivore simulator in C++.
|
Average of a double value over a given time period.
More...
#include <average.h>
Public Member Functions | |
| PeriodAverage (const int count) | |
| Constructor. More... | |
| void | add_value (const double) |
| Add a value to the record. More... | |
| double | get_average () const |
| Get arithmetic mean over all so-far recorded values. More... | |
| double | get_first () const |
| Get first (oldest) value in the record. More... | |
Private Attributes | |
| std::vector< double > | values |
| unsigned int | count |
| unsigned int | current_index = 0 |
Average of a double value over a given time period.
This helper class successively takes double values and stores/records them up to a given count. At any time, the average (arithmetic mean) over the stored values can be queried with get_average().
Use this to keep track of for instance the average body condition of the last month or the average phenology of the last year. In the first case, you would create the object with count==30 and call add_value() exactly once every day. In the second scenario, count would equal 365.
| PeriodAverage::PeriodAverage | ( | const int | count | ) |
Constructor.
| count | Number of values to remember and use for average. |
| std::invalid_argument | If count<=0. |
| void PeriodAverage::add_value | ( | const double | v | ) |
Add a value to the record.
| double PeriodAverage::get_average | ( | ) | const |
Get arithmetic mean over all so-far recorded values.
| std::logic_error | If no values were added yet. |
| double PeriodAverage::get_first | ( | ) | const |
Get first (oldest) value in the record.
| std::logic_error | If no values were added yet. |
|
private |
|
private |
|
private |