From 9937bc3ab57b0d3503612c59e373b1c14cc12425 Mon Sep 17 00:00:00 2001 From: Felipe Montealegre-Mora Date: Sun, 25 Feb 2024 01:33:26 +0000 Subject: [PATCH] added agents --- src/rl4greencrab/agents/__init__.py | 0 src/rl4greencrab/agents/const_action.py | 11 ++++++++++ src/rl4greencrab/agents/const_escapement.py | 23 +++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 src/rl4greencrab/agents/__init__.py create mode 100644 src/rl4greencrab/agents/const_action.py create mode 100644 src/rl4greencrab/agents/const_escapement.py diff --git a/src/rl4greencrab/agents/__init__.py b/src/rl4greencrab/agents/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/rl4greencrab/agents/const_action.py b/src/rl4greencrab/agents/const_action.py new file mode 100644 index 0000000..6695c1b --- /dev/null +++ b/src/rl4greencrab/agents/const_action.py @@ -0,0 +1,11 @@ +class constAction: + def __init__(self, mortality=0, env = None, **kwargs): + self.mortality = mortality + self.action = 2 * self.mortality - 1 + self.env = env + + def predict(self, observation): + return self.action + + + \ No newline at end of file diff --git a/src/rl4greencrab/agents/const_escapement.py b/src/rl4greencrab/agents/const_escapement.py new file mode 100644 index 0000000..60ecdc4 --- /dev/null +++ b/src/rl4greencrab/agents/const_escapement.py @@ -0,0 +1,23 @@ +class constEsc: + def __init__(self, escapement, env = None): + self.escapement = escapement + self.env = env + self.bound = 1 + if self.env is not None: + self.bound = self.env.bound + + def predict(self, observation): + obs_nat_units = self.bound * self.to_01(observation) + if obs_nat_units <= self.escapement or obs_nat_units =< 0: + return -1 + mortality = (obs_nat_units - self.escapement) / self.escapement + return self.to_pm1(mortality) + + def to_01(self, val): + return (val + 1 ) / 2 + + def to_pm1(self, val): + return 2 * val - 1 + + + \ No newline at end of file