causally.scm.scm.MixedLinearNonlinearModel

class causally.scm.scm.MixedLinearNonlinearModel(num_samples: int, graph_generator: GraphGenerator, noise_generator: RandomNoiseDistribution | Distribution, linear_mechanism: PredictionModel, nonlinear_mechanism: PredictionModel, scm_context: SCMContext | None = None, linear_fraction=0.5, seed: int | None = None)

Class for data generation with mixed linear and nonlinear mechanisms.

Parameters:
  • num_samples (int) – Number of samples in the dataset.

  • graph_generator (GraphGenerator) – Random graph generator implementing the get_random_graph method.

  • noise_generator (Distribution) – Sampler of the noise random variables. It must be an instance of a class inheriting from causally.scm.noise.Distribution, implementing the sample method.

  • linear_mechanism (LinearMechanism) – LinearMechanism instance for the generation of effects as a linear combination of the causes.

  • nonlinear_mechanism (PredictionModel) – Object for the generation of the nonlinar causal mechanism. The object passed as argument must implement the PredictionModel abstract class, and have a predict method.

  • scm_context (SCMContext, default None) – SCMContext object specifying the modeling assumptions of the SCM. If None this is equivalent to an SCMContext object with no assumption specified.

  • linear_fraction (float, default 0.5) – The fraction of linear structural equations over the total number of variables. E.g. for linear_fraction = 0.5 data are generated from an SCM with half of the structural equations with linear causal mechanisms. Be aware that causal relations may not be identifiable, e.g. in the case of additive Gaussian noise terms.

  • seed (int, default None) – Seed for reproducibility. If None, then the random seed is not set.

Methods

sample()

Sample a dataset of observations.