Skip to content

Uncertainty, structured prediction, and causal learning · Uncertainty, structured prediction, and causal learning · UNC011 · Algorithm

NOTEARS continuous directed-acyclic-graph learning

Convert weighted DAG structure estimation into a continuous constrained optimization problem. The key contribution is a smooth acyclicity constraint, enabling optimization over adjacency weights instead of a purely…

Runs in CodeSplash Component demo, not a trained model CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page.

Do it in CodeSplash Run it on your own data, in Python or R.

Availability
Runs in CodeSplash
Code example
Component demo, not a trained model
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
Verified in Python and R through discover.structure. The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Convert weighted DAG structure estimation into a continuous constrained optimization problem. The key contribution is a smooth acyclicity constraint, enabling optimization over adjacency weights instead of a purely combinatorial graph search. A fitted DAG is a candidate structural explanation, not automatically an identified causal graph.

Question / hypotheses

Which sparse acyclic linear dependency structure fits the observed variables under a chosen structural-equation model? Whether an edge is causal requires additional assumptions, interventions or domain knowledge beyond achieving a small optimization loss.

Architecture / computational structure

For centered data X, a weighted adjacency matrix W predicts each variable from its candidate parents. An augmented-Lagrangian optimizer combines data fit, sparsity and the acyclicity constraint. Zero diagonal removes self-edges; a final threshold produces a graph whose acyclicity must be checked numerically.

Assumptions

The linear least-squares version assumes a compatible additive structural model and suitable noise/sample conditions. Hidden confounding, feedback cycles, selection effects and misspecified nonlinear relations undermine causal interpretation. Observational data alone can leave multiple equivalent orientations unless identification assumptions break that equivalence.

Formula / computational definition

min⁡W12n∥X−XW∥F2+λ∥W∥1\min_W\frac1{2n}\|X-XW\|_F^2+\lambda\|W\|_1 subject to h(W)=tr⁡(exp⁡(W⊙W))−d=0h(W)=\operatorname{tr}(\exp(W\odot W))-d=0. Here WijW_{ij} encodes i→ji\to j, dd is variable count, and ⊙\odot is elementwise multiplication. The constraint gradient is ∇h=exp⁡(W⊙W)T⊙2W\nabla h=\exp(W\odot W)^T\odot 2W.

Parameters and notation

Learned: edge weights W; the augmented-Lagrangian dual variable is optimization state rather than a scientific effect. Hyperparameters/design choices: sparsity λ, threshold, allowed/forbidden edges, scaling, penalty schedule, restarts and feasibility tolerance. Report residual h(W), not merely the solver success flag.

Fitting, fine-tuning, and adaptation

Neural fine-tuning is inapplicable to the linear algorithm. Warm-start W when refitting with new samples, but compare independent starts and verify acyclicity again. New variables change the optimization domain; changing measurement scales can change the sparsity tradeoff and selected graph.

How to use and calibrate

Standardize or otherwise justify measurement scales. Assess graph stability across resamples, prediction error, edge-orientation sensitivity and fit under domain constraints. On synthetic data, report structural Hamming distance and intervention consequences; on real data, do not invent ground-truth edge accuracy.

Example application

Explore a candidate dependency graph among measured process variables, then prioritize edges for follow-up interventions. Plot bootstrap selection frequencies alongside edge weights rather than displaying one graph as established truth.

Interpretation / pitfalls

Watch out

Acyclicity certifies a combinatorial property, not causality. A near-zero continuous constraint plus thresholding can still be numerically problematic. Scores and edge directions can be sensitive to variance scaling and identification assumptions; publish those choices.

Python and R code examples

Scope: Acyclicity constraint and gradient component, comparing a DAG with a cyclic matrix. Python uses SciPy matrix exponential; the R example implements a convergent power series for these tiny bounded matrices, not a general replacement for a production expm routine.

Dependencies / validation: use the shared NumPy/SciPy or base-R setup above. Python executed successfully with assertions; R reviewed but not executed.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — Acyclicity constraint and gradient component, comparing a DAG with a cyclic matrix. Python uses SciPy matrix exponential; the R example implements a convergent power series for these tiny bounded matrices, not a general replacement for a production expm routine.

Shared setup for this chapter
import numpy as np
from scipy.special import logsumexp, gammaln
from scipy.linalg import expm
from itertools import product

def rbf(a, b, ell=1.0):
    a, b = np.atleast_2d(a), np.atleast_2d(b)
    return np.exp(-np.sum((a[:, None, :] - b[None, :, :])**2, axis=2)/(2*ell**2))
W = np.array([[0.,.5,0.],[0.,0.,.7],[0.,0.,0.]])
C = W.copy(); C[2,0]=.4
h = lambda a: np.trace(expm(a*a))-len(a)
grad = expm(C*C).T*(2*C); eps=1e-6
Cp,Cm=C.copy(),C.copy(); Cp[2,0]+=eps; Cm[2,0]-=eps
fd = (h(Cp)-h(Cm))/(2*eps)
assert abs(h(W))<1e-12 and h(C)>0 and np.isclose(fd,grad[2,0],atol=1e-7)
print({'dag_constraint':float(h(W)),'cyclic_constraint':float(h(C)),'gradient':float(grad[2,0])})
R

Component demo, not a trained model — Acyclicity constraint and gradient component, comparing a DAG with a cyclic matrix. Python uses SciPy matrix exponential; the R example implements a convergent power series for these tiny bounded matrices, not a general replacement for a production expm routine.

W <- matrix(c(0,.5,0,0,0,.7,0,0,0),3,3,byrow=TRUE)
C <- W; C[3,1] <- .4
expm_small <- function(M) {
 ans <- term <- diag(nrow(M))
 for(k in 1:100) { term <- term%*%M/k; ans <- ans+term; if(max(abs(term))<1e-15) break }
 ans
}
h <- function(a) sum(diag(expm_small(a*a)))-nrow(a)
grad <- t(expm_small(C*C))*(2*C); Cp <- Cm <- C
Cp[3,1] <- Cp[3,1]+1e-6; Cm[3,1] <- Cm[3,1]-1e-6
fd <- (h(Cp)-h(Cm))/(2e-6)
stopifnot(abs(h(W))<1e-12,h(C)>0,abs(fd-grad[3,1])<1e-7)
print(c(dag_constraint=h(W),cyclic_constraint=h(C),gradient=grad[3,1]))

Sources

From the CodeSplash reference, entry UNC011.