Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Flux.Recur to run nonlinear simulation #67

Closed
MrstupidJ opened this issue May 17, 2023 · 2 comments
Closed

Use Flux.Recur to run nonlinear simulation #67

MrstupidJ opened this issue May 17, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@MrstupidJ
Copy link
Contributor

md = Flux.Recur(forward, x0)

@raywang1987 I copied this piece of code (for running nonlinear system simulation) from our previous example (or maybe we did not use this, as the old example was linear), but it seems not working now.

@nic-barbara
Copy link
Member

@MrstupidJ can you bit more specific on what the error is? Eg: provide a minimal example?

@nic-barbara nic-barbara added the bug Something isn't working label Jun 9, 2023
@MrstupidJ
Copy link
Contributor Author

The Flux document on Flux.Recur was a bit confusing to control people. A simple example provided by the document was using an accumulation function as the cell:
accum(h, x) = (h + x, x)
rnn = Flux.Recur(accum, 0)
In Flux doc, h is the hidden states, x is the input to the cell.

To use Flux.Recur in control context, one can define a (discrete-time) nonlinear system dynamic as:
x, y = f(x, u)
(Note: the order of returned value matters, Flux will take the first as hidden states and second as output)
Then it can be initialized as a Flux model with initial state x0
model = Flux.Recur(f, x0)
Simulate one time step given input u(t):
y = model(u(t))
The hidden state (sate of the dynamic system) can be accessed in model.state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants