Re: Calculating a moving average

From: "Jim C(dot) Nasby" <decibel(at)decibel(dot)org>
To: Dann Corbit <DCorbit(at)connx(dot)com>
Cc: "Vanole, Mike" <Mike(dot)Vanole(at)cingular(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Calculating a moving average
Date: 2005-01-21 05:09:02
Message-ID: 20050121050902.GQ67721@decibel.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Also, if you don't need an exact moving average, you might consider a
weighted mean. Something like:

mean = mean * 0.9 + new_value * 0.1

Much easier to maintain than a moving average.

On Thu, Jan 20, 2005 at 08:40:24PM -0800, Dann Corbit wrote:
> Why not use a cursor?
>
>
>
> P.S.
>
> A moving average will look much better if you Hahn the tails.
>
>
> To do a normal 7 point moving average, you take (x[i]+ x[i+1]+ x[i+2]+
> x[i+3]+ x[i+4]+ x[i+5]+ x[i+6])/7 as point xprime[i] and (y[i]+ y[i+1]+
> y[i+2]+ y[i+3]+ y[i+4]+ y[i+5]+ y[i+6])/7 as point yprime[i].
>
>
>
> But when you start let x[0], y[0] be the first point, and then average
> the next 2 for the second point... until you get to 7 and then do the
> same thing in the other end. Otherwise, you get a very strange looking
> curve.
>
>
>
> IMO-YMMV
>
> ________________________________
>
> From: pgsql-general-owner(at)postgresql(dot)org
> [mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Vanole, Mike
> Sent: Wednesday, January 19, 2005 1:34 PM
> To: pgsql-general(at)postgresql(dot)org
> Subject: [GENERAL] Calculating a moving average
>
>
>
> Hi,
>
>
>
> I need to calculate a moving average and I would like to do it with SQL,
> or a Pg function built for this purpose. I'm on Pg 7.4. Is this possible
> in Pg without a bunch of self joins, or is there a funtion available?
>
>
>
> Thanks,
>
> Mike
>

--
Jim C. Nasby, Database Consultant decibel(at)decibel(dot)org
Give your computer some brain candy! www.distributed.net Team #1828

Windows: "Where do you want to go today?"
Linux: "Where do you want to go tomorrow?"
FreeBSD: "Are you guys coming, or what?"

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andrew L. Gould 2005-01-21 05:40:48 Re: Best Linux Distribution
Previous Message Wes 2005-01-21 04:45:24 Re: Shared memory and Mac OS X