CausalGANGenerator<T>

Models & Types · AiDotNet.NeuralNetworks.SyntheticData

Causal-GAN generator that learns causal graph structure (directed acyclic graph) and generates synthetic data respecting causal relationships between features.

Inheritance: NeuralNetworkBase<T> → NeuralSyntheticTabularGeneratorBase<T> → CausalGANGenerator<T>

Implements: IGeneratedParameterRegistrar<T>, ISyntheticTabularGenerator<T>

For Beginners

Causal-GAN learns which features cause other features:

Instead of just learning that “Age and Income are related” (correlation), it learns “Education causes higher Income” (causation).

This has two benefits:

  1. Generated data respects cause-effect chains, producing more realistic samples
  2. You can simulate “what-if” scenarios (interventions) on specific features

The model learns a weighted adjacency matrix W where W[i,j] means feature i influences feature j. A DAG penalty (NOTEARS) ensures no circular dependencies.

The training uses:

  • WGAN-GP loss for stable adversarial training
  • NOTEARS penalty via augmented Lagrangian for DAG acyclicity constraint
  • L1 sparsity on the adjacency matrix for interpretable causal structure

The NOTEARS constraint is: h(W) = tr(e^(W * W)) - d = 0 where d is the number of features. This is zero if and only if W encodes a DAG. The matrix exponential is computed by scaling and squaring, as scipy.linalg.expm in the NOTEARS reference code.

This implementation follows the standard neural network architecture pattern with:

  • Proper inheritance from NeuralNetworkBase
  • Layer-based architecture using ILayer components
  • Engine-based tensor operations for CPU/GPU acceleration
  • Full autodiff and JIT compilation support

If you provide custom layers in the architecture, those will be used directly for the generator network. Otherwise, the network creates the standard architecture.

Example usage:

How It Works

Causal-GAN discovers causal structure using a NOTEARS-style continuous relaxation for learning a directed acyclic graph (DAG), then generates each feature as a function of its causal parents via structural equation models.

Architecture:

Reference: Zheng et al., “DAGs with NO TEARS: Continuous Optimization for Structure Learning” (NeurIPS 2018)

Constructors

Constructor Summary
CausalGANGenerator() Initializes a new instance of the CausalGANGenerator class.
CausalGANGenerator(NeuralNetworkArchitecture<T> architecture, CausalGANOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction)

Properties

Property Summary
CausalGANOptions<T> Options { get; } Gets the CausalGAN-specific options.
IReadOnlyList<ColumnMetadata> Columns { get; }
bool IsFitted { get; set; }

Methods

Method Summary
Dictionary<string, T> GetFeatureImportance()
Dictionary<string, Tensor<T>> GetNamedLayerActivations(Tensor<T> input) Reports the per-layer activations of the GENERATOR, following the same residual path GeneratorForward uses.
Matrix<T> Generate(int numSamples, Vector<T> conditionColumn, Vector<T> conditionValue) Generates new synthetic tabular data rows respecting the learned causal structure.
ModelMetadata<T> GetModelMetadata()
Task FitAsync(Matrix<T> data, IReadOnlyList<ColumnMetadata> columns, int? epochs, CancellationToken ct)
void Fit(Matrix<T> data, IReadOnlyList<ColumnMetadata> columns, int? epochs) Fits the CausalGAN generator to the provided real tabular data.