DagSim: Combining DAG-based model structure with unconstrained data types and relations for flexible, transparent, and modularized data simulation

Ghadi S. Al Hajj, Johan Pensar, Geir Kjetil Sandve

TL;DR

DagSim is a new Python-based framework that brings the transparency of Directed Acyclic Graphs (DAGs) to the simulation of complex, high-dimensional data. By allowing researchers to define relationships using arbitrary Python functions and succinct YAML files, it bridges the gap between traditional causal modeling and modern deep learning data types like images and bio-sequences.

What Problem Does This Paper Address?

In machine learning and causal inference, simulating data is essential for benchmarking algorithms against a known "ground truth." Traditionally, researchers have used Directed Acyclic Graphs (DAGs) to define these simulations because they clearly show how variables depend on one another.

However, existing DAG-based simulation libraries (such as bnlearn or pgmpy) are largely restricted to simple data types—like discrete categories or continuous scalars—and specific functional forms, such as linear regressions or probability tables. Modern machine learning, however, operates on tensors, sequences, and sets. Until now, there has been a lack of a modular framework that allows users to build complex, multi-stage simulators where a "node" in the graph could be an entire image or a DNA sequence generated by a custom, non-linear function.

Methods

DagSim introduces a modular approach to data simulation by separating the model structure from the simulation logic:

  • DAG Backbone: The user defines the dependency structure of the model as a DAG. This ensures that the simulation follows a logical "topological ordering" (sampling parents before children).
  • Unconstrained Functional Relations: Unlike previous tools, DagSim places no restrictions on the functions used to generate data. Each node is assigned a standard Python function. Parent values are passed directly as native Python objects, allowing for any data type (NumPy arrays, PyTorch tensors, etc.) to flow through the graph.
  • Succinct Specification: Users can define the graph structure using a domain-specific language (DSL) in Python or an external YAML format. This makes the "big picture" of the simulation transparent and easy to share.
  • Specialized Node Types: The framework includes built-in support for common simulation challenges:
  • Selection Nodes: To simulate sample selection bias.
  • Missing Nodes: To simulate various missing data schemes.
  • Stratify Nodes: To automatically split simulated data into separate files based on specific criteria.

Datasets

As a simulation framework, the paper does not train on existing datasets but demonstrates its utility through two stylized use cases:

  1. Image Simulation: Reproducing a study where scalar metadata (like shape type or position) controls the generation of 2D numeric tensors (images) with specific shapes overlaid on a background.
  2. Bio-sequence Simulation: Simulating Adaptive Immune Receptor Repertoires (AIRR). Here, low-dimensional patient characteristics (age, disease state) influence the generation of high-dimensional sets of DNA sequences.

Key Insights and Ideas

  • Transparency through YAML: By moving the model definition to a YAML file, DagSim allows researchers to understand the causal assumptions of a complex simulator at a glance, without wading through thousands of lines of procedural code.
  • Modularization: Because each node is a standalone Python function, components of a simulator can be easily swapped, updated, or reused across different projects.
  • Bridging the Gap: The framework effectively treats "Deep Learning-style" data as first-class citizens in the world of "Causal Inference-style" graphical modeling. This allows for the simulation of interventions and counterfactuals on complex data types.

Key Results

The authors successfully demonstrate that DagSim can handle data types that are traditionally difficult for graphical modeling software:

  • Flexibility: The framework successfully simulated 2D images and complex bio-sequences, maintaining a clear DAG structure throughout.
  • Comparison with Existing Tools: The paper provides a comprehensive table (Table 1) comparing DagSim to ten other frameworks (like simCausal, MXM, and lavaan). DagSim is the only one identified that supports "Any data type" and "Any functional form" while providing utilities for plates and selection bias.

Limitations and Future Work

While powerful, the authors note several areas for expansion:

  • Time-Series Data: The current version does not natively support Dynamic Bayesian Networks (DBNs), which are necessary for simulating complex temporal dependencies.
  • Advanced Plate Notation: Future iterations aim to support nested and intersecting "plate" structures, which are used to represent repeated experimental units (e.g., multiple measurements per patient).
  • Performance: While using native Python functions offers maximum flexibility, it may introduce performance overhead for extremely large-scale simulations compared to frameworks optimized for specific mathematical forms.

Summary updated

BibTeX
@inproceedings{hajj2023dagsim,
  author = {Ghadi S. Al Hajj and Johan Pensar and Geir Kjetil Sandve},
  title = {{DagSim: Combining DAG-based model structure with unconstrained data types and relations for flexible, transparent, and modularized data simulation}},
  booktitle = {PLoS},
  year = {2023},
  doi = {10.1371/journal.pone.0284443},
}
Figure