sanity check, 'cos I'm tired:
I've got a list of objects with a Vector3 position. I want to create a rolling mean that is updated with a new object is added to the list.
am I correct in saying that this will update the mean properly:
MeanPosition = Vector3.Lerp(MeanPosition, newObject.position, 1.0 / list.Count);
@gsuberland i fear it's just an approximation. Any reason you can't have a running sum?
@ekg not sure what you mean by "just an approximation".
running sum won't work because I constantly need access to the group mean to decide where to put new elements, so I'd be recomputing the mean on every iteration and end up with something close to O(n^3)
@gsuberland i an not certain but I believe that earlier elements could have greater influence then later. And I don't like the constant re-normalisation of floating point values.
Runsum = vec3.sum( Runsum, newel);
Mean = vec3.Lerp( 0, Runsum, 1.0 / count);
Should be as fast.
@ekg @gsuberland why do you need Lerp for this, why not just
Mean = Runsum / count;
@ekg @gsuberland well,
Mean = Runsum * (1.0 / count);
would probably be better
@mrsbeanbag I would let the compiler decide, and write whatever is the most ergonomic.
@ekg hm tbh i wouldn't. compilers are sometimes not allowed to do "obvious" things with floating point computations. because floating point. signed a compiler engineer
@mrsbeanbag that's what --ffast-math is for. But I am more than willing to acknowledge my limited experience working with floating point math, I had to look up what Lerp was...
@mrsbeanbag I would say: that is what testing is for. But I have never setup a proper testing infrastructure for any of the projects I have started.
Unit test should catch these errors, but you would have to set up one for every critical math function.
@mrsbeanbag remember to test your test.
@ekg oh yeah we have a full suite of IEEE compliance tests. rofl