Finding local minima and maxima of a graph

Jonathan Lynch jonathandlynch at gmail.com
Sun Dec 5 08:28:12 EST 2010


Hi again,

Here is the basic algorithm for what I am talking about:

1) Start with a 1 dimensional array, containing all of your numbers
1.1) add four elements, each containing zero, to it.

2) Copy that array, but move the trailing zero to the front

3) Copy the second array, but move the trailing zero to the the front again

4) copy the third array, but move the trailing zero to the front again


You wind up with 5 arrays, each with its number offset by one space from the
previous array. It is important to keep the number of array elements the
same.

so, the following number list:

1,2,3,4,5,6,7,8,9,10,11,12,13,14,15

would become:

1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,0,0,0
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,0,0
0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,0
0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0
0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15


Your next step is to add Matrix 1 to Matrix 3, then add matrix 2 to matrix
3, then add matrix 4 to matrix 3, then add matrix 5 to matrix3, then divide
matrix 3 by 5.

You are using matrix 3 as your primary matrix, so that your associated dates
(or whatever is on your X axis), maintain an averaged view from the middle -
meaning an average of the preceding and advancing two days? Does that make
sense?

Anyway, this will give you a faster way of obtaining the rolling average,
because it performs the actual number crunching under the hood, not through
the transcript interpreter.

Please note that your first four and last four data points, in the final
matrix your produce, will be meaningless, because they will contain those 0s
that you had to use to keep your number of array elements the same for all
the arrays.

The actual functions you would use, if LC, are add and divide. "Add matrix1
to matrix3" adds all the corresponding data points together in one shot.
"Divide matrix3 by 5" divides all data points in matrix3 by 5.

Does all of that help?




On Sun, Dec 5, 2010 at 7:58 AM, <jonathandlynch at gmail.com> wrote:

> I think you could speed it up with some matrix manipulations - when I get
> to my computer I will explain further.
>
>
> Sent from my Verizon Wireless BlackBerry
>
> -----Original Message-----
> From: Bryan McCormick <bryan at deepfoo.com>
> Sender: use-livecode-bounces at lists.runrev.com
> Date: Sun, 05 Dec 2010 02:12:29
> To: <use-livecode at lists.runrev.com>
> Reply-To: How to use LiveCode <use-livecode at lists.runrev.com>
> Subject: Re: Finding local minima and maxima of a graph
>
> Jonathan, Jerry, et al
>
> As to the number of potential observations. Thousands of series, 10s to
> hundreds of thousands of observations per series at a minimum. Possibly
> millions. So computational efficiency isn't a luxury, it is a requirement.
>
> Yes, absolutely, detrending is required. I won't go into the details,
> but suffice to say every model I've seen so far advises this as a step
> to make sure one has significant observations. It will make real peaks
> and troughs much more apparent.
>
> In stats packages, or even Excel, any of the above is trivial.
> Unfortunately in LiveCode there isn't (apparently) much of a base of
> functions to start with.
>
> No, no forecasting. This is merely one step of gathering of data for
> additional observation.
>
> Sure, a rolling window makes sense if you have to step through in a
> semi-brute force manner. If it comes down to it, I'll do it that way. It
> would seem to me there just has to be an easier way to do it.
>
>
> On 12/5/2010 12:33 AM, Bryan McCormick wrote:
> > Jonathan,
> >
> > Sure, that approach can work. But it isn't terribly efficient. It would
> > however be less computationally intensive if I detrend first. That's the
> > first step. So if you have a notion on a least squares linear fit line,
> > that would be most welcome.
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



-- 
Do all things with love



More information about the use-livecode mailing list