-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from UFRN-URNAI/issue-72
Resolves #72
- Loading branch information
Showing
4 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import unittest | ||
from abc import ABCMeta | ||
|
||
from urnai.states.state_base import StateBase | ||
|
||
|
||
class TestStateBase(unittest.TestCase): | ||
|
||
def test_abstract_methods(self): | ||
StateBase.__abstractmethods__ = set() | ||
|
||
class FakeState(StateBase): | ||
def __init__(self): | ||
super().__init__() | ||
|
||
fake_state = FakeState() | ||
update_return = fake_state.update("observation") | ||
state = fake_state.state | ||
dimension = fake_state.dimension | ||
reset_return = fake_state.reset() | ||
assert isinstance(StateBase, ABCMeta) | ||
assert update_return is None | ||
assert state is None | ||
assert dimension is None | ||
assert reset_return is None |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import Any, List | ||
|
||
|
||
class StateBase(ABC): | ||
""" | ||
Every Agent needs to own an instance of this base class | ||
in order to define its State. | ||
So every time we want to create a new agent, | ||
we should either use an existing State implementation or create a new one. | ||
""" | ||
|
||
@abstractmethod | ||
def update(self, obs) -> List[Any]: | ||
""" | ||
This method receives as a parameter an Observation and returns a State, which | ||
is usually a list of features extracted from the Observation. The Agent uses | ||
this State during training to receive a new action from its model and also to | ||
make it learn, that's why this method should always return a list. | ||
""" | ||
pass | ||
|
||
@property | ||
@abstractmethod | ||
def state(self): | ||
"""Returns the State currently saved.""" | ||
pass | ||
|
||
@property | ||
@abstractmethod | ||
def dimension(self): | ||
"""Returns the dimensions of the States returned by the update method.""" | ||
pass | ||
|
||
@abstractmethod | ||
def reset(self): | ||
"""Resets the State currently saved.""" | ||
pass |