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

Change type of horizon from float to int. #66

Merged
merged 1 commit into from
Oct 28, 2022
Merged
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
11 changes: 6 additions & 5 deletions src/seals/base_envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def __init__(
*,
transition_matrix: np.ndarray,
reward_matrix: np.ndarray,
horizon: float = np.inf,
horizon: Optional[int] = None,
initial_state_dist: Optional[np.ndarray] = None,
):
"""Build tabular environment.
Expand All @@ -226,7 +226,8 @@ def __init__(
assumes neither the `action` nor `next_state` are used.
Of shape `(n_states,n_actions,n_states)[:n]` where `n`
is the dimensionality of the array.
horizon: Maximum number of timesteps, default `np.inf`.
horizon: Maximum number of timesteps. The default is `None`,
which represents an infinite horizon.
initial_state_dist: Distribution from which state is sampled at the
start of the episode. If `None`, it is assumed initial state
is always 0. Shape `(n_states,)`.
Expand Down Expand Up @@ -314,7 +315,7 @@ def reward(self, state: int, action: int, new_state: int) -> float:

def terminal(self, state: int, n_actions_taken: int) -> bool:
"""Checks if state is terminal."""
return n_actions_taken >= self.horizon
return self.horizon is not None and n_actions_taken >= self.horizon

@property
def feature_matrix(self):
Expand Down Expand Up @@ -356,7 +357,7 @@ def __init__(
transition_matrix: np.ndarray,
observation_matrix: np.ndarray,
reward_matrix: np.ndarray,
horizon: float = np.inf,
horizon: Optional[int] = None,
initial_state_dist: Optional[np.ndarray] = None,
):
"""Initializes a tabular model POMDP."""
Expand Down Expand Up @@ -423,7 +424,7 @@ def __init__(
*,
transition_matrix: np.ndarray,
reward_matrix: np.ndarray,
horizon: float = np.inf,
horizon: Optional[int] = None,
initial_state_dist: Optional[np.ndarray] = None,
):
"""Initializes a tabular model MDP.
Expand Down