andrey.skewd_mv#
- andrey.skewd_mv(data, *, alpha=0.05, indep_test='kci', tuning_iter=20, max_iter=3000, max_fits=100, seed=None)[source]#
Learn a DAG of a skew-normal location-scale model with SkewD-MV.
SkewD-MV [1] estimates the Markov equivalence class with PC [2] and returns the DAG of the class whose skew-normal location-scale models, one per variable given its parents, have the largest likelihood. It is the graph version of
skewd()’s likelihood criterion.- Parameters:
data (
ArrayLike) – Observed data, one row per sample. Coerced tofloat64. A DataFrame’s column names become the structure’slabels.alpha (
float) – Significance level of PC’s conditional-independence tests, in(0, 1).indep_test (
str|None) – PC’s conditional-independence test, a test of continuous data as inpc(), but not"normal_scores": the likelihood stage reads the values, which ranks would hide. The default is the kernel test [3], the authors’ choice.Nonepicks"fisherz".tuning_iter (
int) – The penalty settings, at least 1, that the Bayesian optimization scores by cross-validation for each conditional model; the first half, rounded up, are Latin hypercube points.max_iter (
int) – The most iterations, at least 1, of the expectation conditional maximization that refines each conditional model.max_fits (
int|None) – The most conditional models, at least 1, the class’s DAGs may need before the call refuses to list more of them (ValueError); 100 is the order up to which the paper expects the method to apply [1].Nonesets no cap, and the call can then run for days. While it is set, a group of undirected edges with more than 65,536 orientations is refused too, and so are groups that share a cycle and have more than 65,536 acyclic combinations.seed (
int|None) –None, the default, is the configured seed,ANDREY_SEEDor0when it is unset, not a fresh random one, so a fit repeats. Seed of PC’s randomized tests and of the random draws of each fit.
- Returns:
Contains a
GraphStructureof kinddag.metadata["algorithm"]is"skewd_mv",metadata["candidates"]the number of DAGs in the class, andmetadata["fits"]the number of conditional models fitted.metadata["indep_test"]names the test the fit used andmetadata["seed"]the seed.metadata["tie_break"]is the tie-break rule the fit ran under,andrey.config.tie_break.- Return type:
- Raises:
TypeError – If an argument has the wrong type, such as a string for a number; the message names the method, the argument, what it accepts, and the value.
ValueError – If an argument lies outside its range or is not one of its choices; the message names the method, the argument, what it accepts, and the value.
- Warns:
DataTypeWarning – When a column holds at most 10 distinct whole numbers and so may hold category codes, which the fit reads as numbers. Each message warns once per process.
ExperimentalWarning – On the first call in a process: the method is not benchmarked yet.
SearchLimitWarning – When a conditional model’s refinement stops at
max_iterrather than on its own rule.
Notes
When to use. SkewD-MV learns a DAG from continuous variables observed i.i.d. under a location-scale noise model, each variable
y = f(pa) + g(pa) nwithg > 0, skew-normal noisenindependent of its parents, and no hidden common cause; it also assumes the faithfulness PC needs, so that the true DAG lies in the estimated class [1]. It is designed for small graphs, 6 to 10 variables in the paper, whose noise scale changes with the parents, which the additive models ofcam()andresit()do not allow.Each column is standardized first [1]. PC, order-independent [2], gives the class. Its DAGs orient the undirected edges with no directed cycle and no new collider [1], and are every combination of one orientation of each connected group of undirected edges, so each group is listed on its own, one DAG at a time, and the listing stops with an error once the groups need more than
max_fitsconditional models or one group has more than 65,536 orientations, so a class too large to score is never listed in full. The edges are oriented in a maximum cardinality search order, so the listing’s time does not depend on the column order. When a group has no such orientation, as conflicting colliders can leave, its candidates are every acyclic orientation of its edges. Each variable with an undirected edge is fitted given its parents in each orientation, once per distinct parent set: the standard Gaussian log-likelihood for a variable without parents, and otherwiseskewd()’s skew-normal fit with additive B-splines of the parents, 10 location and 7 scale columns per parent and a penalty pair per parent chosen by a 5-fold cross-validation [1]. A constant moved between two parents’ location coefficients changes no fitted value, so the fit leaves it out. Only these variables’ terms differ between the DAGs, so their sum decides (Proposition 5.1 of [1]), and each group contributes its own terms: the returned DAG holds the orientation of each group with the largest sum, the first on a tie, which is the DAG of the class with the largest sum. Where a conflicting graph lets the groups’ best orientations close a directed cycle across its directed edges, the search takes the acyclic combination with the largest sum, and a graph with none raises an error. The defaults, 20 candidates of the Bayesian optimization and 3,000 iterations, are those of the paper’s runs. The columns are fitted in the order of their values’ ranks, so the DAG does not depend on the column order; ties followandrey.config.tie_break.Missing values. A
NaNindataraisesValueError: every fit reads every row of its variables, so a row with a missing value has no place in it. Drop the incomplete rows first, which suits values missing completely at random, or usepc()orfci(), whose tests delete rows per test.Limitations. Not benchmarked yet. The paper measures it on skew-normal location-scale graphs of 6 and 10 variables with 1,000 rows [1]. Its cost grows with the number of distinct parent sets the class allows, exponentially in a variable’s undirected edges, and each fit takes minutes at the defaults; it refuses a class that needs more than 100 (
max_fits), where the paper counts parent-child configurations and expects the method to apply while they are in the order of 100. An edge PC misses or misorients stays wrong: the likelihood only chooses among the class’s DAGs. The numbers are a reference, not a hard limit: they change with the data generator, the density, the method’s settings, and the machine.References
Examples
>>> import numpy as np >>> from andrey import skewd_mv >>> rng = np.random.default_rng(0) >>> x = rng.standard_normal(300) >>> y = np.tanh(2 * x) + (0.4 + 0.2 * np.tanh(x)) * rng.standard_normal(300) >>> z = y + 0.5 * rng.standard_normal(300) >>> data = np.column_stack([x, y, z]) >>> out = skewd_mv(data, indep_test="fisherz", tuning_iter=1, max_iter=20, seed=0) >>> out.structure.kind, out.metadata["candidates"] ('dag', 3)