MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Need to speed up a matrix calculation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105677] Need to speed up a matrix calculation
  • From: Garapata <warsaw95826 at mypacks.net>
  • Date: Tue, 15 Dec 2009 07:26:08 -0500 (EST)

I have a calculation, which I want to do in a more direct,  elegant,
and faster calculating way.

Start with 3 variables and
2 matrices:

	intervals = 10;
	samples  = 5;
	measurements = 3;

	p = Array[a, {intervals -1, samples, measurements}];
        m = Array[b, {samples, intervals}];

In real life these matrices will get very large, hence the reason I
want speed.

The matrices represent values associated with a time series during an
intermediate state of calculation.  So as a preliminary step to the
next calculation, to make them the same time length, I drop a column
from matrix m.  This enables me to use the previous valves in m with
the current values in p in the subsequent calculation:

	mMost = Drop[w, None, -1];

This also shortens the length the next line, the one I need help with.

	composition = (Transpose[p[[#]]] . mMost[[All, #]] ) * 5 / Total[mMost
[[All, #]]] & /@ Range[Length[p]]

This works, but will likely get quite slow as I increase the number of
intervals, samples, and measurements.  I'd like a more direct way to
do this.  The above seems bit like making map like an iterative loop,
kind of cheating at functional programing.

Any help much appreciated.


  • Prev by Date: hyperlink back button
  • Next by Date: Re: Return in function
  • Previous by thread: hyperlink back button
  • Next by thread: Re: Need to speed up a matrix calculation