Skip to content

anypinn.catalog.damped_oscillator

OMEGA_KEY = 'omega0' module-attribute

V_KEY = 'v' module-attribute

X_KEY = 'x' module-attribute

ZETA_KEY = 'zeta' module-attribute

DampedOscillatorDataModule

Bases: PINNDataModule

DataModule for damped oscillator inverse problem. Generates synthetic data via odeint.

Source code in src/anypinn/catalog/damped_oscillator.py
class DampedOscillatorDataModule(PINNDataModule):
    """DataModule for damped 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 damped oscillator data using odeint + Gaussian noise."""

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

        t = config.x

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

        x_obs = x_true + self.noise_std * torch.randn_like(x_true)

        return t.unsqueeze(-1), x_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/damped_oscillator.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 damped oscillator data using odeint + Gaussian noise.

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

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

    t = config.x

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

    x_obs = x_true + self.noise_std * torch.randn_like(x_true)

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