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

FQF (Fully Parameterized Quantile Function) agent #579

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions chainerrl/action_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,33 @@ class QuantileDiscreteActionValue(DiscreteActionValue):

Args:
quantiles (chainer.Variable): (batch_size, n_taus, n_actions)
weights (None or chainer.Variable): (batch_size, n_taus)
q_values_formatter (callable):
"""

def __init__(self, quantiles, q_values_formatter=lambda x: x):
def __init__(
self,
quantiles,
weights=None,
q_values_formatter=lambda x: x,
):
assert quantiles.ndim == 3
self.quantiles = quantiles
self.weights = weights
if weights is not None:
assert weights.ndim == 2
assert weights.shape == quantiles.shape[:2]
self.xp = cuda.get_array_module(quantiles.array)
self.n_actions = quantiles.shape[2]
self.q_values_formatter = q_values_formatter

@cached_property
def q_values(self):
with chainer.force_backprop_mode():
return F.mean(self.quantiles, axis=1)
if self.weights is not None:
return F.sum(self.weights[..., None] * self.quantiles, axis=1)
else:
return F.mean(self.quantiles, axis=1)

def evaluate_actions_as_quantiles(self, actions):
"""Return the return quantiles of given actions.
Expand Down
1 change: 1 addition & 0 deletions chainerrl/agents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from chainerrl.agents.double_pal import DoublePAL # NOQA
from chainerrl.agents.dpp import DPP # NOQA
from chainerrl.agents.dqn import DQN # NOQA
from chainerrl.agents.fqf import FQF # NOQA
from chainerrl.agents.iqn import IQN # NOQA
from chainerrl.agents.nsq import NSQ # NOQA
from chainerrl.agents.pal import PAL # NOQA
Expand Down
Loading