Behavior#
This class is the base class for all behavior classes. It contains the common methods for all behavior classes.
Constructor#
|
Base class for the behavior of the MacroStat model. |
Simulation and Behavior#
|
Forward pass of the behavior. |
|
Initialize the behavior. |
|
Step function of the behavior. |
Differentiable Operations#
|
Where condition that is differentiable with respect to the condition. |
|
Convert a variable into 0 (x<0) and 1 (x>0) |
|
Smooth approximation to the minimum B: https://mathoverflow.net/questions/35191/a-differentiable-approximation-to-the-minimum-function |
|
Smooth approximation to the minimum B: https://mathoverflow.net/questions/35191/a-differentiable-approximation-to-the-minimum-function |
|
Smooth approximation to the minimum. |
|
Smooth approximation to the maximum for a tensor. |
Notes#
The Behavior class is designed to be a flexible base class that allows users to implement their own model behavior while maintaining a consistent interface. The key methods that users need to implement are initialize() and step(), which define the model’s initialization and simulation behavior respectively.
Example#
A typical implementation of a behavior class might look like:
>>> class MyBehavior(Behavior):
... def initialize(self):
... # Initialize state variables
... self.state['x'] = torch.zeros(1)
...
... def step(self, t, scenario):
... # Update state variables
... self.state['x'] = self.state['x'] + 1