Skip to content

generators.utils.stepper

Data - Generators - Stepper¤

BaseStepper ¤

Bases: ABC, StepperOperator

A framework to evolve a DGP to the next step

Source code in eerily/generators/utils/stepper.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
class BaseStepper(ABC, StepperOperator):
    """A framework to evolve a DGP to the next step"""

    def __init__(
        self, model_params: StepperParams, length: Optional[int] = None
    ) -> None:
        self.model_params = model_params
        self.current_state = copy.deepcopy(self.model_params.initial_state)
        self.length = length
        self._counter = 0

    def __iter__(self):
        return self

    def __next__(self):
        if self.length is None:
            logger.warning("length is not set")
            self._counter += 1
            return self.compute_step()
        else:
            if self._counter < self.length:
                self._counter += 1
                return self.compute_step()
            else:
                raise StopIteration

    def __len__(self):
        return self.length

    def get_iterator(self):
        return self.__iter__()

    def __str__(self) -> str:
        return f"Model Parameters: {self.model_params}"

    @abstractmethod
    def compute_step(self):
        pass

StepperOperator ¤

Allowing & and + for the steppers.

Source code in eerily/generators/utils/stepper.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class StepperOperator:
    """Allowing `&` and `+` for the steppers."""

    def __add__(
        self,
        another_stepper: Union[
            StepperOperator, BaseStepper, SequentialStepper, MergedStepper
        ],
    ) -> SequentialStepper:
        return SequentialStepper([self, another_stepper])

    def __and__(
        self,
        another_stepper: Union[
            StepperOperator, BaseStepper, SequentialStepper, MergedStepper
        ],
    ) -> MergedStepper:
        return MergedStepper([self, another_stepper])

StepperParams dataclass ¤

Base Parameters for Stepper

:param initial_state: the initial state, e.g., np.array([1]) :param variable_name: variable names of the time series provided as a list.

Source code in eerily/generators/utils/stepper.py
31
32
33
34
35
36
37
38
39
40
@dataclass(frozen=True)
class StepperParams:
    """Base Parameters for Stepper

    :param initial_state: the initial state, e.g., `np.array([1])`
    :param variable_name: variable names of the time series provided as a list.
    """

    initial_state: Any
    variable_names: List[Any]