From: Luna Moon on
Hi all,

I have two questions:

-------------------------------------------
Q1:

Let's say we have an array "x", which is an Nx1 column vector of time
series data, following the order of days...

And we would like to output another Nx1 column vector "y", with "0" or
"1" binary values.

Intially the Nx1 output column vector "y" contains all "0"s.

We would like to count, cumulatively, that in the past "m" days, how
many days the data number is below a threshold "t".

And if the number of below-threshold occurence exceeds "n" days, we
would like to output "1" to the output vector,
i.e. set the corresponding location in "y" to be "1", and all the
following values in "y" are set to "1", until the opposite
situation occurs, i.e. until when the number of days that the data
number in "x" is above the threshold "t" (num of above-threshold
occurence)
exceeds "n" days, then we turn the output back to "0", and all the
following values in "y" are set to "0".

So the number of below-threshold occurence and the number of above-
threshold occurence exceeding "n" days are our switch-on and switch-
off points.

Q2:

The same as Q1, except the switch-on and switch-off points becoem:

the number of consequtive(several days in a row) below-threshold
occurence in the past "m" days

and the number of consequtive(several days in a row) above-threshold
occurence in the past "m" days

exceeding "n" days...

-------------------------------------------

I currently wrote this logic with a bunch of "for" loops and it's
really slow,

and I guess the gurus on this forum may have some experience about how
to do this logic without for loops and pure vector operations.


Please help me!

Thank you!
From: Luna Moon on
On Jul 28, 11:24 am, Luna Moon <lunamoonm...(a)gmail.com> wrote:
> Hi all,
>
> I have two questions:
>
> -------------------------------------------
> Q1:
>
> Let's say we have an array "x", which is an Nx1 column vector of time
> series data, following the order of days...
>
> And we would like to output another Nx1 column vector "y", with "0" or
> "1" binary values.
>
> Intially the Nx1 output column vector "y" contains all "0"s.
>
> We would like to count, cumulatively, that in the past "m" days, how
> many days the data number is below a threshold "t".
>
> And if the number of below-threshold occurence exceeds "n" days, we
> would like to output "1" to the output vector,
> i.e. set the corresponding location in "y" to be "1", and all the
> following values in "y" are set to "1", until the opposite
> situation occurs, i.e. until when the number of days that the data
> number in "x" is above the threshold "t" (num of above-threshold
> occurence)
> exceeds "n" days, then we turn the output back to "0", and all the
> following values in "y" are set to "0".
>
> So the number of below-threshold occurence and the number of above-
> threshold occurence exceeding "n" days are our switch-on and switch-
> off points.
>
> Q2:
>
> The same as Q1, except the switch-on and switch-off points becoem:
>
> the number of consequtive(several days in a row) below-threshold
> occurence in the past "m" days
>
> and the number of consequtive(several days in a row) above-threshold
> occurence in the past "m" days
>
> exceeding "n" days...
>
> -------------------------------------------
>
> I currently wrote this logic with a bunch of "for" loops and it's
> really slow,
>
> and I guess the gurus on this forum may have some experience about how
> to do this logic without for loops and pure vector operations.
>
> Please help me!
>
> Thank you!

Anybody?
Thanks a lot!
From: Andy on
Your explanation is long and hard to follow. It would be MUCH clearer what you're doing if you:

1) Provide a small sample of input and what your desired output would be for that input.
2) Provide the code that you say you already have and that is (presumably) working correctly, however slowly.