Class TrainedDagSimulatorANM
Trained DAG simulator (ANM): learn local mechanisms from a real dataset and resimulate
This class is a “train-then-resimulate” simulator: given an observed DataSet and a
user-supplied acyclic Graph (treated as a DAG), it learns a local conditional mechanism
for each node and then generates new samples by running the DAG forward in topological order.
Primary motivation. This simulator is designed to demonstrate that (i) marginal and pairwise plots can often be made to look “realistic” under substantially different DAGs when the mechanisms are flexible and noise is bootstrapped, yet (ii) likelihood/score-based evaluation should systematically penalize fitting the wrong graph to data generated from the learned mechanisms. In other words: visual realism is cheap; causal correctness should still matter for scoring.
Model family (ANM)
For each node Y with parents Pa(Y), the fitted mechanism is an additive-noise model
Y = f(Pa(Y)) + e
where f is a small neural regressor/classifier and e is drawn by bootstrap from
training residuals (continuous) or via sampling from fitted class probabilities (discrete).
Mixed data support
- Continuous child: 1-hidden-layer MLP regressor trained by SGD; during simulation,
generate
yHat = f(x)and add a bootstrapped residualefrom the training rows used for that node. - Discrete child: 1-hidden-layer MLP softmax classifier; during simulation, sample a category from the predicted class probabilities.
Parent encoding
- Continuous parents enter as z-scored scalars (mean/sd computed from available rows).
- Discrete parents enter as one-hot blocks (levels inferred from
DiscreteVariablemetadata, with a configurable cap).
Missingness
Training is done node-by-node using only rows where the child and all of its parents are observed
(rows with any missing among {Y} ∪ Pa(Y) are skipped for that node). Simulation produces
complete samples given the learned mechanisms.
Notes and limitations
- This is intentionally a lightweight baseline (single hidden layer, tanh activation, SGD, L2 decay), aimed at robustness and ease of packaging rather than state-of-the-art prediction accuracy.
- The quality of the resimulation depends on the supplied DAG and on support coverage of parent values; extrapolation may occur when simulated parent configurations fall outside the training support.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classClass representing a report for a node in the simulation results.static final classDefines various configuration parameters for simulations involving directed acyclic graphs (DAGs).static final classRepresents the result of a simulation, encapsulating the simulation data, variables, the true Directed Acyclic Graph (DAG), and optional diagnostic information. -
Constructor Summary
ConstructorsConstructorDescriptionTrainedDagSimulatorANM(DataSet data, Graph dag, TrainedDagSimulatorANM.Params params) Constructs a TrainedDagSimulatorANM -
Method Summary
Modifier and TypeMethodDescriptionvoidfit()Fit one mechanism per node given its parents in the supplied DAG.Human-readable report (one block per node).Structured per-node reports.static intsafeGetInt(DataSet data, int row, int col) Safely retrieves an integer value from a DataSet, handling missing or non-integer values gracefully.simulate(int nSamples) Simulates the DAG with the given number of samples and random seed.simulate(int nSamples, long seed) Simulates the DAG with the given number of samples and random seed.voidwriteFitReportTxt(File file) Writes a human-readable fit report to a specified text file.
-
Constructor Details
-
TrainedDagSimulatorANM
Constructs a TrainedDagSimulatorANM- Parameters:
data- Training datasetdag- Directed Acyclic Graph (DAG) representing the causal structureparams- Simulation parameters
-
-
Method Details
-
safeGetInt
Safely retrieves an integer value from a DataSet, handling missing or non-integer values gracefully.- Parameters:
data- DataSet containing the datarow- Row indexcol- Column index- Returns:
- Integer value or -1 if missing or non-integer
-
getFitReportText
Human-readable report (one block per node).- Returns:
- String containing the fit report text.
-
getNodeReports
Structured per-node reports.- Returns:
- List of NodeReport objects containing detailed simulation results for each node
-
writeFitReportTxt
Writes a human-readable fit report to a specified text file. The fit report provides per-node details on the training process and its results, including error metrics and parent information.- Parameters:
file- The output file where the fit report will be written.- Throws:
IOException- If an I/O error occurs during writing.
-
fit
public void fit()Fit one mechanism per node given its parents in the supplied DAG. -
simulate
Simulates the DAG with the given number of samples and random seed.- Parameters:
nSamples- Number of samples to generate- Returns:
- SimResult object containing simulation results
- Throws:
IllegalArgumentException- if nSamples is less than 1
-
simulate
Simulates the DAG with the given number of samples and random seed.- Parameters:
nSamples- Number of samples to generateseed- Random seed for the simulation- Returns:
- SimResult object containing simulation results
- Throws:
IllegalArgumentException- if nSamples is less than 1
-