Skip to content

Commit

Permalink
Change type of horizon from float to int.
Browse files Browse the repository at this point in the history
Or `None`, for infinite horizon.
  • Loading branch information
ianyfan committed Oct 28, 2022
1 parent eeb9beb commit 547d5bb
Showing 1 changed file with 6 additions and 5 deletions.
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

0 comments on commit 547d5bb

Please sign in to comment.