boostorg / boostorg/accumulators
Computed Variance Can be Negative
- Dominant language
- C++
- Stars
- 26
- Forks
- 61
- PR merge metrics
- No merged PRs in 30d
Description
This is an example from [Golub's paper](https://apps.dtic.mil/dtic/tr/fulltext/u2/a133112.pdf):
```cpp
#include
#include
#include
#include
#include
#include
template
void golub_example()
{
std::random_device rd{};
auto seed = rd();
std::mt19937 gen(seed);
std::normal_distribution dis(500.0, 0.01);
std::vector v(50000);
for(size_t i = 0; i < v.size(); ++i)
{
v[i] = dis(gen);
}
accumulator_set> acc;
acc = std::for_each(v.begin(), v.end(), acc);
std::cout << "Variance = " << variance(acc) << "\n";
std::cout << "Seed = " << seed << "\n";
}
int main()
{
golub_example();
}
```
Output:
```bash
Variance (accumulator) = -79.9219
Seed = 1925235287
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.