help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Vectorize a function that depends on previous function value


From: gergo
Subject: Re: Vectorize a function that depends on previous function value
Date: Mon, 19 May 2014 06:52:58 -0700 (PDT)

Hi Kai,

thanks for your reply. I suspect, my snippet was somehow misleading. 


siko1056 wrote
> From your code snippet I conclude, that you don't have data dependencies
> from the left hand side (lhs) to the rhs, like a(n) = a(n) + a(n -1),
> right? 

That is correct, only the lhs depends on the rhs (for the current time
step).
 

siko1056 wrote
> In your loop, your previous a(n) will be dropped and a(1) is
> generated by a different rule, still right? 

No, what I need is a series of responses of my model to the data. Each of
the responses (the a(n)) depend on the current data(n) and the last response
a(n-1) (and on a hidden state b(n)). 

The way you tried it in your code was also my first attempt. However, in
your code the values depend on some preliminary values in a. The following
snippet hopefully points out my problem more clearly. Imagine data was
constantly 2, and the nonlinear terms were gone:

a = ones(10,1);
a(2:end) = a(1:end-1) *2;

This yields a = [1 2 2 2 ...]';
What I needed was: a = [1 2 4 8 ...]';

My first snippet, what was intended to be rather a formula than octave code
would be:

function [a,b] = dynamicalSystmem(data, params, a1, b1)
  a = zeros(N,1); 
  b = zeros(N,1);
  a(1) = a1; b(1) = b1;
  for n = 2:N
    a(n) = a(n-1) + data(n) + b(n-1) + someNonLinearFunction(a(n-1));
    b(n) = b(n-1) + someOtherNonlinearFctn(a(n-1));
  end
end

The goal is, to remove that for loop there.... Ah, and yes, the
nonLinearFunctions are vectorized.

Any idea?

Thanks

Gerald







--
View this message in context: 
http://octave.1599824.n4.nabble.com/Vectorize-a-function-that-depends-on-previous-function-value-tp4664169p4664177.html
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]