Skip to content

Commit

Permalink
Added comments to the code.
Browse files Browse the repository at this point in the history
  • Loading branch information
troiwill committed Mar 25, 2024
1 parent 42e77f0 commit 95efc47
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions pomdp_py/framework/basics.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,17 @@ cdef class ResponseModel:

@staticmethod
def generate_response_model(model_dict, response=Response()):
"""
Generate a response model based on a dictionary of model attributes. This is a
convenience method to make it easier to build a Response model.
Args:
model_dict (dict): A dictionary of models in the form {model_type: model} (e.g., {reward: reward_model})
response (Response): A response that will be used to generate new responses.
Returns:
The response model.
"""
# Do a sanity check to ensure the response model and response are compatible.
for name in model_dict.keys():
if not hasattr(response, name):
Expand All @@ -208,6 +219,12 @@ cdef class ResponseModel:
return model

def add_attrs(self, attr_dict):
"""
Adds attributes to this object dynamically.
Args:
attr_dict: A dictionary of attribute names and values.
"""
if not isinstance(attr_dict, dict):
raise TypeError(f"attr_dict must be type dict, but got {type(attr_dict)}.")

Expand All @@ -217,6 +234,12 @@ cdef class ResponseModel:
setattr(self, ak, None)

def add_models(self, model_dict):
"""
Add models to the response.
Args:
model_dict: A dictionary of models in the form {model_type: model} (e.g., {reward: reward_model}).
"""
if not isinstance(model_dict, dict):
raise TypeError(f"model_dict must be type dict, but got {type(model_dict)}.")

Expand Down Expand Up @@ -249,12 +272,14 @@ cdef class ResponseModel:
]))

def create_response(self, *args, **kwargs):
"""
Create a response with the given arguments.
Returns:
An instance of : class : ` Response ` with the given parameters.
"""
return self._response.new(*args, **kwargs)

# @property
# def response_type(self):
# return type(self._response_type)

cdef class BlackboxModel:
"""
A BlackboxModel is the generative distribution :math:`G(s,a)`
Expand Down Expand Up @@ -387,6 +412,9 @@ cdef class Observation:
return not self.__eq__(other)

cdef class Vector(list):
"""
The Vector class. Provides an implementation of a vector for multi-valued response models.
"""
def __init__(self, values=list()):
if not isinstance(values, list):
raise TypeError(f"values must be type list, but got {type(values)}.")
Expand Down

0 comments on commit 95efc47

Please sign in to comment.