MathGroup Archive 2009

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

Search the Archive

Re: Replace Table[Sum...]...] with Functional code

  • To: mathgroup at
  • Subject: [mg98751] Re: Replace Table[Sum...]...] with Functional code
  • From: green tea <cetech07 at>
  • Date: Sat, 18 Apr 2009 03:36:20 -0400 (EDT)
  • References: <grn1l3$n0t$>

On Apr 10, 5:57 pm, Andreas <aa... at> wrote:
> I use the following two functions to analyze time series:
> mm[data_, period_] := Table[Sum[(Log[data[[t]]] - Log[data[[t - i]]]) / Sqrt[i], {i, 1, period}] / period, {t, period + 1, Length[data]}]
> mr[data_, period_] := Table[Sum[Log[data[[t - i]] / data[[-i + t - 1]]] * (Sqrt[i] - Sqrt[i - 1]), {i, 1, period}],{t, period + 2, Length[data]}]
> They have a similar structure, Table[Sum[...]...], which sums a bunch of stuff from the time series at each point in the series.
> I'd like to convert them into functional programing constructs, but as the increments in the Table function come into play in the Sum, I haven't been able to figure out a way to do it.
> I've tried Map with Partition and a bunch of other things, but I could use some pointers.
> Any help much appreciated.

ListCorrelate is very fast, but
generalized ListCorrelate like "ListCorrelate[{1,1},data,{1,-1},
1,Times,Log[#2/#1]&]" is terribly slow.
I don't know why.

instead use these codes.

ListConvolve's computational compexity is O(n log(n)),
and it does not create intermediate list structure like Partition and
Dot combination.
so it is more suitable for this time series analysis.

mm[data_, period_] :=
 With[{kernel = (period Sqrt[Range[1., period]])^-1, list = Log
  list[[period + 1 ;;]] Total[kernel] - ListConvolve[kernel, list[[;;

mr[data_, period_] :=
 With[{kernel = Differences[Sqrt[Range[0., period]]], list = Log[Ratios
  ListConvolve[kernel, list[[;; -2]]]]

  • Prev by Date: Re: Passing arrays to MathLink without extra memory allocation
  • Next by Date: Re: running mathematica notebooks without interface
  • Previous by thread: Re: Replace Table[Sum...]...] with Functional code
  • Next by thread: Why does ImageCompose degrade the result and can you do anything