Skip to content

anypinn.catalog.van_der_pol

MU_KEY = 'mu' module-attribute

U_KEY = 'u' module-attribute

VanDerPolDataModule

Bases: PINNDataModule

DataModule for Van der Pol oscillator inverse problem.

Generates synthetic data via odeint.

Source code in src/anypinn/catalog/van_der_pol.py
class VanDerPolDataModule(PINNDataModule):
    """DataModule for Van der Pol oscillator inverse problem.

    Generates synthetic data via odeint.
    """

    def __init__(
        self,
        hp: ODEHyperparameters,
        gen_props: ODEProperties,
        noise_std: float = 0.0,
        validation: ValidationRegistry | None = None,
        callbacks: Sequence[DataCallback] | None = None,
    ):
        super().__init__(hp, validation, callbacks)
        self.gen_props = gen_props
        self.noise_std = noise_std

    @override
    def gen_data(self, config: GenerationConfig) -> tuple[Tensor, Tensor]:
        """Generate synthetic Van der Pol data using odeint + Gaussian noise."""

        def vdp_ode(t: Tensor, y: Tensor) -> Tensor:
            return self.gen_props.ode(t, y, self.gen_props.args)

        t = config.x

        sol = odeint(vdp_ode, self.gen_props.y0, t)  # [T, 2]
        u_true = sol[:, 0]

        u_obs = u_true + self.noise_std * torch.randn_like(u_true)

        return t.unsqueeze(-1), u_obs.unsqueeze(-1).unsqueeze(1)

gen_props = gen_props instance-attribute

noise_std = noise_std instance-attribute

__init__(hp: ODEHyperparameters, gen_props: ODEProperties, noise_std: float = 0.0, validation: ValidationRegistry | None = None, callbacks: Sequence[DataCallback] | None = None)

Source code in src/anypinn/catalog/van_der_pol.py
def __init__(
    self,
    hp: ODEHyperparameters,
    gen_props: ODEProperties,
    noise_std: float = 0.0,
    validation: ValidationRegistry | None = None,
    callbacks: Sequence[DataCallback] | None = None,
):
    super().__init__(hp, validation, callbacks)
    self.gen_props = gen_props
    self.noise_std = noise_std

gen_data(config: GenerationConfig) -> tuple[Tensor, Tensor]

Generate synthetic Van der Pol data using odeint + Gaussian noise.

Source code in src/anypinn/catalog/van_der_pol.py
@override
def gen_data(self, config: GenerationConfig) -> tuple[Tensor, Tensor]:
    """Generate synthetic Van der Pol data using odeint + Gaussian noise."""

    def vdp_ode(t: Tensor, y: Tensor) -> Tensor:
        return self.gen_props.ode(t, y, self.gen_props.args)

    t = config.x

    sol = odeint(vdp_ode, self.gen_props.y0, t)  # [T, 2]
    u_true = sol[:, 0]

    u_obs = u_true + self.noise_std * torch.randn_like(u_true)

    return t.unsqueeze(-1), u_obs.unsqueeze(-1).unsqueeze(1)