mirror of
https://github.com/wassname/kair_algorithms_draft.git
synced 2026-09-09 11:25:10 +08:00
Add TD3 (#10)
* Add td3 * Fix flake8 * Fix action clamping * Increase episode max step, add detach to actor_loss * Fix actor update freq bug * Add per (#8) * Add per and modify etc * Replace pre-commit-config.yaml and add pre-commit hook in .git * Modify .gitignore * Modify .gitignore * Modify buffer and code * Modify replay buffer and per * Modify .gitignore * Add random initial action in ddpg (#13) * Add random initial actions in ddpg * Add reacher-v2 example of ddpg * Add soft actor critic (#12) * Add soft actor critic * Delete unnecessary examples * Add td3 * Fix flake8 * Fix action clamping * Fix flake8 * Increase episode max step, add detach to actor_loss * Fix actor update freq bug * Fix code to reflect PR * Resolve conflict
This commit is contained in:
@@ -15,21 +15,23 @@ class GaussianNoise:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
action_dim: int,
|
||||
min_sigma: float = 1.0,
|
||||
max_sigma: float = 1.0,
|
||||
decay_period: int = 1000000,
|
||||
):
|
||||
"""Initialization."""
|
||||
self.max_sigma = max_sigma
|
||||
self.action_dim = action_dim
|
||||
self.min_sigma = min_sigma
|
||||
self.max_sigma = max_sigma
|
||||
self.decay_period = decay_period
|
||||
|
||||
def sample(self, action_size: int, t: int = 0) -> float:
|
||||
def sample(self, t: int = 0) -> float:
|
||||
"""Get an action with gaussian noise."""
|
||||
sigma = self.max_sigma - (self.max_sigma - self.min_sigma) * min(
|
||||
1.0, t / self.decay_period
|
||||
)
|
||||
return np.random.normal(0, sigma, size=action_size)
|
||||
return np.random.normal(0, sigma, size=self.action_dim)
|
||||
|
||||
|
||||
class OUNoise:
|
||||
|
||||
Reference in New Issue
Block a user