import collections
[docs]class ModelLike(object):
@property
[docs] def dependent_vars(self):
"""
Model dependent variables.
:getter: Return the model dependent variables.
:type: list
"""
return self._dependent_vars
@property
[docs] def independent_var(self):
"""
Symbolic variable representing the independent variable.
:getter: Return the symbol representing the independent variable.
:type: sympy.Symbol
"""
return self._independent_var
@property
def params(self):
"""
Dictionary of model parameters.
:getter: Return the current parameter dictionary.
:setter: Set a new parameter dictionary.
:type: dict
"""
return self._params
@params.setter
[docs] def params(self, value):
"""Set a new parameter dictionary."""
valid_params = self._validate_params(value)
self._params = self._order_params(valid_params)
@property
[docs] def rhs(self):
"""
Symbolic representation of the right-hand side of a system of
differential/difference equations.
:getter: Return the right-hand side of the system of equations.
:type: dict
"""
return self._rhs
@staticmethod
def _order_params(params):
"""Cast a dictionary to an order dictionary."""
return collections.OrderedDict(sorted(params.items()))
@staticmethod
def _validate_params(value):
"""Validate the dictionary of parameters."""
if not isinstance(value, dict):
mesg = "Attribute 'params' must have type dict, not {}"
raise AttributeError(mesg.format(value.__class__))
else:
return value