There seems to be no easy way to achieve a cummax (a simple O(n)
operation) while avoiding loops.  There are some ways to achieve
it[1], but they all end up being > O(n). 

Thinking about cummax, that is about the only thing in this category
that one cannot achieve using cumsum (and/or cumprod).

I can calculate 

  A(i) = [(sum(a(i)^M)]^(1/M) using cumsum, in a linear, vectorized way,

for any M except when M is infty - the latter works in principle, but
not in practice.  And the latter is what cummax is.

It seems that providing a built-in cummax would solve that problem.

----

[1] One can find ways to achieve it.  Someone on a matlab forum posted
a way using repmat, and max. but that is O(n^2).  




One of my ways is O(N)*times the largest k that separates a high from
a succeding new high:
http://www.gnufans.net/~deego/pub/octave/mine/dev/ascendingmakemy.m


Another way would be to try the infty trick above, but with a large
enough M and rounding - and with a mapping of values into indices -
one can then use a large enough M, round off the answer to get back
the proper indices, and then do a reverse map from indices to the
actual value. But, getting from values to indices requires a sort,
which is O(n*log(n)).  

P.S: More tricks? ^_^ 


Everything is far more complex than the simplest answer, a loop over

 a(i)=max(a(i),a(i-1)).

Now, if only this loop was built-in... using the same mechanism that
cumsum uses..










-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Octave-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/octave-dev

Reply via email to