Transform Feedforward-Network + solver into a Recurrent-Network
See original GitHub issueHello Patrick,
let me first quickly motivate my feature request. As a side-project i am currently working on Model-based optimal control. For e.g. a only partially-observable environment stateful agents are useful. So, suppose the action selection of an agent is given by the following method
def select_action(params, state, observation, time):
apply = neural_network.apply
state, action = apply(params, state, observation, time)
return state, action
while True:
action = select_action(..., observation, env.time)
observation = env.step(action)
Typically, the apply
-function is some recurrent neural network. Suppose the environment env
is differentiable, because it is just some model of the environment (maybe another network). Now, i would like to replace the recurrent neural network with a feedforward network + solver without changing the API of the agent.
I was wondering if constructing the following is possible and sensible? I.e. i would like to transform a choice of Feedforward-Network + Solver into a Recurrent-Network.
def select_action(params, ode_state, observation, time):
rhs = lambda x,u: neural_network.apply(params, x, u)
solution, ode_state = odeint(ode_state, rhs, t1=time, u=(observation, time))
return ode_state, solution.x(time)
I would like to emphasis that this select_action
must remain differentiable: The x-output w.r.t the network parameters.
I would love to hear your input 😃 Anyways thank you in advance.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
Yep, this is definitely possible. Diffrax is intrinsically differentiable so no special care is needed. Untested, but perhaps something like the following:
It’s not critical, but as a nice-to-have this uses Equinox as a convenient neural network library.
For completeness let me post my minimal working example. Spoiler: This uses haiku, simply because i am already comfortable with that. Equinox probably would make this more beautiful 😃
Thanks Patrick for your help. It works perfectly.