Jump to content
  • Advertisement
Sign in to follow this  
L. Spiro

"Real-Time" Smoothing

This topic is 896 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I stupidly threw away my notes from Stanford on various smoothing techniques, including Laplace smoothing, Bayesian averages, etc.
Now I am having trouble remember the name of the method I seek.

I want to monitor a value over time, hopefully without keeping a history (hence real-time).
I want to take certain actions when the value is in certain ranges, but the action I take will have an effect on the value.

As an example, I could monitor the FPS (or some performance metric) and when it goes up and down I could activate some kind of optimization. The optimization will of course impact the performance metric I am measuring. So the FPS would go back up and I would get a ping-pong effect.

In addition to having one threshold for applying the optimization and a separate one for disabling it, I want to dampen/smoothen the performance values. But I don’t want to keep a history of performance values. There should be a way to modify the current value with new incoming values in “real time”. I can make my own fairly easily (divide the difference between the current value and the new value by some dampener and then add that to the current value) but I am certain there is a tried-and-true complex method already out there.


I can’t remember which type of smoothing we can use for this because I threw away my notes. I was mistaking it for Laplace smoothing originally but that is actually for something else.
Bayesian averages seems to need a history of values.

Any ideas?


L. Spiro

Share this post


Link to post
Share on other sites
Advertisement

If you've got a previous and new value, that's a 1-frame history buffer - is keeping it at 1 instead of N frames a hard requirement?

 

Some other options that don't include 'smoothing' in their names:

You can model a spring with only 1-frame worth of state - a critically dampened one would try to avoid oscilation.

A PID controller requires history for the I term (1 frame probably wouldn't be enough), but a PD controller would be possible - and is similar to your own invention that you're proposing. There's a lot of theory on how to tune these, but it still seems like a black art to me laugh.png

Share this post


Link to post
Share on other sites

is keeping it at 1 instead of N frames a hard requirement?

Let’s consider it a last resort.

I will look into the other things.
This is just my first pass on the implementation, and later plan to include in the formula how much my activated switches are effecting the current results. The equation might get pretty complicated, which is one reason for wanting to avoid a history.


L. Spiro

Share this post


Link to post
Share on other sites

I would track the derivatives of FPS at those ping/pong moments and take them in account with the next change.
(Additionally I don't know a method without any kind of history, maybe smoothing every N-th sample, while keeping track of N-1 samples sum(or something like that)).

Edited by imoogiBG

Share this post


Link to post
Share on other sites

I think what you are looking for is a low pass filter. Using only the previous and the new value you can do a one order infinite impulse response filter:

 

y[n] = k*x[n] + (1-k)*x[n-1]

 

Adjust k between 0 (too smoothe) and 1 (no filtering).

 

You can have better filtering by using more history but then you need to take care about stability.

 

But are you sure that this is what you want? Smoothing the value can be ok for example if you want to display the fps value to the player, but usually applying a low pass filter before an automatic regulation algorithm makes it more unstable, because the smoothing make the system sluggish and the regulation algorithm will try to overcompensate. It can be counter-intuitive but if you want an analogy think about a car with such a smoothing applied to the tachometer. If you wanted to accelerate, you would see that the car speed doesn't increase very fast and would tend to push more on the gas pedal. Then suddenly the displayed speed would increase a bit more than what you want, and you'd have do decelerate or even brake. Then a bit later the speed would again go under the desired value and you would need to accelerate. That is unstable regulation. On the other hand if you didn't have any smoothing and had a fast response on the tachometer it would be a lot easier for you to drive at the speed you want.

So I think that instead of smoothing your metric values, you should select a regulation algorithm that is adapted to your problem. If your optimizations are just on/off switches, then just using a hysteresis should be fine. Turn the optimizations on if the FPS go under a certain value, and turn them off if they go over another value. Just pick the two values apart enough so that it doesn't ping-pong.

If you are regulating a continuous value instead of on/off switches, then a PID regulator can help a lot. But they are indeed a bit painful to tune.

Share this post


Link to post
Share on other sites
I call this 'error feedback' and it's the reason for many problems i was unable to solve satisfactionary.
Think of a rope from 3 particles and 2 springs under gravity.
The lowest particle will pull the top spring apart, we increase spring strength.
Next frame top spring feels ok and starts decreasing strength to the default level.
Same thing happens again, produces jitter which is even worse than the initial problem.

Just one of many examples. Neither PID nor low pass filter helps.

Next time i encounter something like this, ill try to store history of 2 error values.
Then we have error velocity and error acceleration, so it's possible to predict error at any point in time with more accuracy.
But i'm pretty sure i'd just reinvent PID, with the only difference that i would understand how it works biggrin.png

Following with high interest...

Share this post


Link to post
Share on other sites

Kalman filtering: You have a model of a system, and maintain an estimate of its state. Each update you make a prediction of the new state, which is then updated with measurements. 

Share this post


Link to post
Share on other sites

I think what you are looking for is a low pass filter. Using only the previous and the new value you can do a one order infinite impulse response filter:

 

y[n] = k*x[n] + (1-k)*x[n-1]

 

Adjust k between 0 (too smoothe) and 1 (no filtering).

 

You can have better filtering by using more history but then you need to take care about stability.

 

 

This. Formally it is known as Exponential Smoothing.

Share this post


Link to post
Share on other sites

 

I think what you are looking for is a low pass filter. Using only the previous and the new value you can do a one order infinite impulse response filter:

 

y[n] = k*x[n] + (1-k)*x[n-1]

 

Adjust k between 0 (too smoothe) and 1 (no filtering).

 

You can have better filtering by using more history but then you need to take care about stability.

 

 

This. Formally it is known as Exponential Smoothing.

 

Also used in estimating RTT.

Share this post


Link to post
Share on other sites

And of course I made a mistake... the actual formula is:

y[n] = k*x[n] + (1-k)*y[n-1]

You take the old smoothed value, multiply it by (1-k) and add to it the new raw value multiplied by k

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!