ray/rllib/utils/schedules/polynomial_schedule.py
Eric Liang be48e1964b
[rllib] Fix per-worker exploration in Ape-X; make more kwargs required for future safety (#7504)
* fix sched

* lintc

* lint

* fix

* add unit test

* fix

* format

* fix test

* fix test
2020-03-10 11:14:14 -07:00

39 lines
1.3 KiB
Python

from ray.rllib.utils.schedules.schedule import Schedule
from ray.rllib.utils.framework import try_import_tf
tf = try_import_tf()
class PolynomialSchedule(Schedule):
def __init__(self,
schedule_timesteps,
final_p,
framework,
initial_p=1.0,
power=2.0):
"""
Polynomial interpolation between initial_p and final_p over
schedule_timesteps. After this many time steps always `final_p` is
returned.
Agrs:
schedule_timesteps (int): Number of time steps for which to
linearly anneal initial_p to final_p
final_p (float): Final output value.
initial_p (float): Initial output value.
framework (Optional[str]): One of "tf", "torch", or None.
"""
super().__init__(framework=framework)
assert schedule_timesteps > 0
self.schedule_timesteps = schedule_timesteps
self.final_p = final_p
self.initial_p = initial_p
self.power = power
def _value(self, t):
"""
Returns the result of:
final_p + (initial_p - final_p) * (1 - `t`/t_max) ** power
"""
return self.final_p + (self.initial_p - self.final_p) * (
1.0 - (t / self.schedule_timesteps))**self.power