keras-gym
keras-gym copied to clipboard
Change ActorCritic constructor signature
Implement ActorCritic
such that the constructor only takes a FunctionApproximator
(and some extra config parameters).
class Func(km.FunctionApproximator):
def body(self, S):
...
func = Func(lr=0.01)
ac = km.ActorCritic(func, gamma=0.9, bootstrap_n=5, policy_loss='ppo_clip')
v = ac.v # state value function
pi = ac.pi # updateable policy
This fits better into the structure that would allow for more complex actor-critic objects like a soft actor-critic, which I imagine would be implemented such that it is constructed in the same way:
class Func(km.FunctionApproximator):
def body(self, S):
...
func = Func(lr=0.01)
sac = km.SoftActorCritic(func, gamma=0.9, bootstrap_n=5, policy_loss='ppo_clip')
v = sac.v # state value function
q = sac.q # state-action value function
pi = sac.pi # updateable policy
Perhaps it's better to add a new constructor and leave the default constructor is as, to maintain modularity, e.g.
ac = km.ActorCritic.from_func(func, gamma=0.9, bootstrap_n=5, policy_loss='ppo')
would be equivalent to:
v = km.V(func, gamma=0.9, bootstrap_n=5)
pi = km.SoftmaxPolicy(func, update_strategy='ppo')
ac = km.ActorCritic(pi, v)