Skip to content

Commit

Permalink
Allow Agent name; docstring (#63)
Browse files Browse the repository at this point in the history
* agent docstring clarification

* agent docstring

* add name attribute to Agent

* default name for rocksample agent

* black
  • Loading branch information
kaiyu-zheng committed Mar 29, 2024
1 parent e6ea846 commit dcb32d3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions pomdp_py/framework/basics.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ cdef class Agent:
cdef GenerativeDistribution _cur_belief
cdef tuple _history
cdef dict __dict__
cdef str _name

cdef class Environment:
cdef State _init_state
Expand Down
25 changes: 19 additions & 6 deletions pomdp_py/framework/basics.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -319,32 +319,36 @@ cdef class Observation:

cdef class Agent:
""" An Agent operates in an environment by taking actions, receiving
observations, and updating its belief. Taking actions is the job of a
planner (:class:`Planner`), and the belief update is the job taken care of
by the belief representation or the planner. But, the Agent supplies the
observations, and updating its belief. Deciding what action to take is the
job of a planner (:class:`Planner`), and the belief update is usually done
outside of the agent, taken care of e.g. by the belief representation, or by
the planner. The Agent supplies its own version of the
:class:`TransitionModel`, :class:`ObservationModel`, :class:`RewardModel`,
OR :class:`BlackboxModel` to the planner or the belief update algorithm.
__init__(self, init_belief,
policy_model,
policy_model=None,
transition_model=None,
observation_model=None,
reward_model=None,
blackbox_model=None)
blackbox_model=None,
name=None)
"""
def __init__(self, init_belief,
policy_model=None,
transition_model=None,
observation_model=None,
reward_model=None,
blackbox_model=None):
blackbox_model=None,
name=None):
self._init_belief = init_belief
self._policy_model = policy_model

self._transition_model = transition_model
self._observation_model = observation_model
self._reward_model = reward_model
self._blackbox_model = blackbox_model
self._name = name

# For online planning
self._cur_belief = init_belief
Expand Down Expand Up @@ -414,6 +418,15 @@ cdef class Agent:
def generative_model(self):
return self.blackbox_model

@property
def name(self):
return self._name

def set_name(self, str name):
"""set_name(self, str name)
gives this agent a name"""
self._name = name

def set_models(self, transition_model=None, observation_model=None,
reward_model=None, blackbox_model=None, policy_model=None):
"""Re-assign the models to be the ones given."""
Expand Down
1 change: 1 addition & 0 deletions pomdp_py/problems/rocksample/rocksample_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ def __init__(
RSTransitionModel(n, rock_locs, self.in_exit_area),
RSObservationModel(rock_locs, half_efficiency_dist=half_efficiency_dist),
RSRewardModel(rock_locs, self.in_exit_area),
name=f"RockSampleAgent({n}, {k})",
)
env = pomdp_py.Environment(
init_state,
Expand Down

0 comments on commit dcb32d3

Please sign in to comment.