pulse2percept.models.base¶
Classes
BaseModel(**kwargs) |
Base model |
Exceptions
NotBuiltError |
Exception class used to raise if model is used before building |
-
class
pulse2percept.models.base.BaseModel(**kwargs)[source]¶ Base model
The BaseModel class defines which methods and attributes a model must have. You can create your own model by adding a class that derives from BaseModel:
class MyModel(BaseModel):
The constructor is the only place where you can add new variables (i.e., class attributes). The signature of your own constructor should look like this:
def __init__(self, **kwargs):
meaning that all arguments are passed as keyword arguments. Also, make sure to call the BaseModel constructor first thing. So a complete example of a constructor could look like this:
class MyModel(BaseModel): def __init__(self, **kwargs): super(MyModel, self).__init__(self, **kwargs) self.newvar = 0
This is the only place where you can add new class attributes. Trying to set
self.someothervaroutside the constructor will raise an AttributeError. Of course, you can always setself.newvar = Nonein the constructor to make sure the variable exists, and then assign a new value in other class methods.Note
Please note: If
self.newvaralready exists in the BaseModel class, the last line of the above code snippet would overwrite it.To make the model complete (and compile), you will also need to fill in all methods marked with
@abc.abstractmethodbelow. These includebuildandpredict_percept. Have a look at the ScoreboardModel or AxonMapModel classes below to get an idea of how to write a complete model.-
build(**build_params)[source]¶ Build the model
Every model must have a
`buildmethod, which is meant to perform all expensive one-time calculations. You must callbuildbefore callingpredict_percept.You can override
buildin your own model (for a good example, see the AxonMapModel). You will want to make sure that:- all
build_paramstake effect, - the flag
_is_builtis set, - the method returns
self.
One way to do this is to call the BaseModel’s
buildmethod from within your own model:class MyModel(BaseModel):
- def build(self, **build_params):
- super(MyModel, self).build(self, **build_params) # Add your own code here…
Parameters: **build_params (Additional build parameters) – Additional build parameters passed as keyword arguments (e.g., model.build(engine='joblib')). Note that these must be listed inget_params; i.e., you can’t add any new parameters outside the constructor.- all
-
predict_percept(implant, t=None)[source]¶ Predict a percept
Parameters: - implant (
ProsthesisSystem) – Stimulus can be passed viastim. - fps (int, double) – Frames per second at which the percept should be rendered.
- n_frames (int) – If None, will simulate for the duration of the stimulus plus one frame (rounding up).
- implant (
-
-
exception
pulse2percept.models.base.NotBuiltError[source]¶ Exception class used to raise if model is used before building
This class inherits from both ValueError and AttributeError to help with exception handling and backward compatibility.
-
with_traceback()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-