import numpy as np
from otlingam import ExhaustiveOTLiNGAM, GreedyOTLiNGAM
from otlingam.utils import disorder
rng = np.random.default_rng(1); n = 2000
e = rng.laplace(size=(n, 4))
x0 = e[:, 0]; x2 = 0.8 * x0 + e[:, 2]
x1 = -0.7 * x2 + e[:, 1]; x3 = 0.5 * x0 + 0.6 * x1 + e[:, 3]
X = np.c_[x0, x1, x2, x3]
B_true = np.zeros((4, 4)); B_true[2, 0], B_true[1, 2], B_true[3, 0], B_true[3, 1] = .8, -.7, .5, .6
for M in (ExhaustiveOTLiNGAM(), GreedyOTLiNGAM()):
M.fit(X)
print(type(M).__name__, [int(i) for i in M.causal_order_], "disorder:", disorder(B_true, M.causal_order_))