Many thanks Roger.  That's just the solution I was looking for. I had a
feeling '/' was the way to go, but couldn't quite figure out how.

Ronan


On 07/05/2008 21:08, "Roger Hui" <[EMAIL PROTECTED]> wrote:

>    ts '(1+4000-276) %~ > ((*/|.)@[ + ])&.> / (276 <\ i.4000),<0'
> 14.3879 1.03117e7
> 
> That is, not space-constrained for a reasonable PC.
> 
> Since * is a well-behaved function all sorts of
> improvements should be possible.  Unless the vector
> is short or you just need to do this once in which
> case you don't care.
> 
>    v=: 8 [EMAIL PROTECTED] 100
>    a=: (*/ |.) }: v
>    b=: (*/ |.) }. v
>    (1 _1}. a) -: _1 1 }. b
> 1
> 
> 
> 
> ----- Original Message -----
> From: Roger Hui <[EMAIL PROTECTED]>
> Date: Wednesday, May 7, 2008 12:37
> Subject: Re: [Jprogramming] Outer products problem
> To: Programming forum <[email protected]>
> 
>>    ts '276 calcAvgOP i.600'
>> 1.1417 1.35284e8
>>    ts '325 %~ > ((*/|.)@[ + ])&.> / (276 <\ i.600),<0'
>> 0.734065 2.25075e6
>> 
>> 
>> 
>> ----- Original Message -----
>> From: Ronan Reilly <[EMAIL PROTECTED]>
>> Date: Wednesday, May 7, 2008 12:02
>> Subject: [Jprogramming] Outer products problem
>> To: Programming forum <[email protected]>
>> 
>>> I'm doing some analyses on EEG data and have run into a limit
>>> error for
>>> vectors of > 4000 elements.  I'm wondering if there's any
>>> way around it.
>>> 
>>> The code involves moving a fixed width window across a long
>>> vector of values
>>> one element at a time, computing the outer product of the
>>> (reversed) window
>>> of values with itself, and averaging over all the resulting
>>> matrices.  I run
>>> into the limit error for vectors greater than 4000 elements
>> with 
>>> a typical
>>> window size of 276 - yes, I was naive not to expect this :-)
>>> 
>>> Here's the code that hits the limit:
>>> 
>>>  NB. x = window size ; y = vector of EEG values
>>>  calcAvgOP =: [: (+/ % #) (*"0 1 |.)\
>>> 
>>> $M =: 276 calcAvgOP i. 4000
>>> |limit error: calcAvgOP
>>> |   M=:276     calcAvgOP i.4000
>>> 
>>> The problem is having to hold onto the millions of intervening
>>> matricesbefore averaging.  I'd very much like to find a
>>> tacit solution to this
>>> problem and I was wondering if there's a formulation that can
>>> circumvent it.
>>> 
>>> On the other hand, the rather inelegant explicit definition
>>> below works
>>> fine. 
>>> 
>>> NB. x = window size ; y = vector of EEG values
>>> calcAvgOP2 =: dyad define
>>>     i =. 0
>>>     lim =. >: x -~ $y
>>>     acc =. 0 $~ x,x
>>>     while. i < lim do.
>>>         acc =. acc +
>> (*"0 1 
>>> |.) x {. y
>>>         y =. }. y
>>>         i =. >: i
>>>     end.
>>>     acc % i
>>> )
>>> 
>>> $M =: 276 calcAvgOP2 i. 4000
>>> 276 276
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> 

--
Professor Ronan Reilly
Department of Computer Science
NUI Maynooth
Maynooth
Co. Kildare
IRELAND

t: +353-1-7083846
e: [EMAIL PROTECTED]
w: http://www.cs.nuim.ie; http://cortex.cs.nuim.ie



----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to