I am struggling with a summation problem that fails with insufficient or overflow.
I have more than 8271571 double values, of which I need the arithmetic mean.
But the main problem is that I'm not smart enough to do this.
I am currently simply summing them up and dividing by size. This does not work in most cases in under or overflow mode, giving me -1. # INF or 1. # INF.
for(size_t j = 0; j < 12; j++) { double a = 0.0; for(size_t i=0; i < Features->size(); i++) { a += Features->at(i)->at(j); } meanVector[j] = a / Features->size(); }
However, there is no way to say its just a positive or negative value, so I can not set the data type for signing.
I also tried to use the separation constant in the summation or divide by size already when adding them, but this also does not help.
Values can vary, from what I saw during quick viewing, from -20 to +30, but I can’t say for sure.
So maybe someone can give me a hint on how to do the math or use a workaround. It should be possible, but I just don't have enough ideas.
Edit:
The size is never 0, a check is performed before division. In addition, none of the values is in any way. Taking them out, I already check for #IND and NaN.
If I already divided by summation, I think this is also not the correct result?
a+= Features->at(i)->at(j) / Features->size()
results in -3.7964983860343639e + 305
but for each iteration. It can't be right and looks like a border
Edit 2:
So, some of you guys were absolutely right. A lot of sh * t garbage happens ..
0: size: 8327571, min: -2.24712e + 307, no more: 3362.12 1: size: 8327571, min: -2.24712e + 307, no more: 142181 2: size: 8327571, min: -2.24712e + 307, max: 59537.8 3: size: 8327571, min: -2.24712e + 307, no more: 236815 4: size: 8327571, min: -2.24712e + 307, max: 353488 5: size: 8327571, min: -2.24712 e + 307, max: 139960 6: size: 8327571, min: 0, max: 0 7: size: 8327571, min: 0, max: 0 8: size: 8327571, min: 0, max: 0 9: size: 8327571, min: 0, max: 0 10: size: 8327571, min: 0, max: 0 11: size: 8327571, min: 0, max: 0