FLOP#
- class causalbase.order.FLOP(criterion='bdeu', ess=1.0, expected_parents=1.0, prior='bernoulli', penalty_discount=1.0, alpha_w=None, init='ges', max_iter=None, time_limit=60.0, random_state=None, cache_mb=2048, n_jobs=1)[source]#
Learn a Bayesian network with FLOP (Wienöbst, Henckel and Weichwald, 2026).
The search is
flop()on the score criterion names: a local search over orders with FLOP’s grow-shrink evaluator and reinsertion moves, from a topological order of the network GES (or XGES) learns, or of initial_graph infit(), then an iterated local search with random swaps.- Parameters:
- criterion{“bdeu”, “bic”, “gaussian_bic”, “bge”}, default=”bdeu”
The score: BDeu or BIC over categorical data, or the BIC or BGe of a linear Gaussian model over continuous data.
- essfloat, default=1.0
Equivalent sample size: of the BDeu prior, or of BGe’s prior on the mean. Also the prior of the parameters behind
score()on categorical data.- expected_parentsfloat or None, default=1.0
Expected in-degree under the structure prior, for every criterion; see
FamilyScore.Noneis a uniform prior.- prior{“bernoulli”, “tetrad”}, default=”bernoulli”
The structure prior: the Bernoulli prior of
FamilyScore, or, for BDeu only, Tetrad 7.6.5’s, with expected_parents as Tetrad’s structure prior (seeBDeuScore).- penalty_discountfloat, default=1.0
Multiplier of the penalty of the two BIC criteria; larger values give sparser structures.
- alpha_wfloat or None, default=None
Degrees of freedom of BGe’s Wishart prior, above
n_vars + 1;Noneisn_vars + 2. SeeBGeScore.- init{“ges”, “xges”}, default=”ges”
Algorithm whose network gives the first order, without initial_graph.
- max_iterint or None, default=None
Kicks of the iterated local search.
- time_limitfloat or None, default=60.0
Seconds of search, after the starting network is learned. At least one of the two limits must be set.
- random_stateint or None, default=None
Seeds every random choice; None draws a fresh seed.
- cache_mbfloat or None, default=2048
Memory budget of the search’s caches, in MiB; None leaves them unbounded. The result does not depend on it, a tight budget only slows the search down.
- n_jobsint, default=1
Threads of the score’s compiled kernels; -1 is every thread numba has. The result does not depend on it.
- Attributes:
- dag_DAG
The learned network.
- cpdag_PDAG
Its Markov equivalence class.
- score_float
The score of dag_ under criterion, with the structure prior chosen (with
prior="tetrad", the value Tetrad reports).adjacency_pandas.DataFramepandas.DataFrame: The learned CPDAG as a named adjacency matrix.
- n_features_in_int
Number of variables.
- feature_names_in_ndarray of str
Variable names.
- n_iter_int
Kicks performed.
- trace_list of tuple
(seconds, iteration, score)at the start and each time the best score improved.
Examples
>>> from causalbase import FLOP >>> from causalbase.datasets import load_asia >>> model = FLOP(max_iter=3, time_limit=None, random_state=0).fit(load_asia().data) >>> model.n_iter_ 3
Methods
fit(X[, y, initial_graph])Learn the structure of X.
get_params([deep])Return the estimator's hyperparameters by name.
score(X[, y])Return the mean log likelihood per row of X under the learned network.
set_params(**params)Set hyperparameters by name and return the estimator.
- property adjacency_#
pandas.DataFrame: The learned CPDAG as a named adjacency matrix.
- fit(X, y=None, initial_graph=None)#
Learn the structure of X.
- Parameters:
- XDiscreteDataset, ContinuousDataset, pandas.DataFrame or array-like
Of shape (n_rows, n_vars). For the discrete criteria every distinct value of a column is a level; for
"gaussian_bic"and"bge"the columns are real-valued.- yNone
Ignored.
- initial_graphDAG or PDAG, optional
Where the search starts, over the columns of X: the graph itself for the searches over graphs and equivalence classes, a topological order of it for the searches over orders, and the first solution of the integer program for
ExactSearchwith a parent limit (the dynamic programming has no starting point). A PDAG stands for a DAG it extends to. By default each estimator’s own start, which its docstring gives.
- Returns:
- self
- Raises:
- ValueError
If X has no rows, initial_graph has another number of nodes, or a hyperparameter is out of range (including
prior="tetrad"with a criterion other than"bdeu").
- get_params(deep=True)#
Return the estimator’s hyperparameters by name.
- score(X, y=None)#
Return the mean log likelihood per row of X under the learned network.
The parameters are learned from the training data: by a BDeu prior of equivalent sample size ess for categorical data, by maximum likelihood for continuous data. Higher is better, so a scikit-learn parameter search can select the hyperparameters on held-out rows.
- Parameters:
- XDiscreteDataset, ContinuousDataset, pandas.DataFrame or array-like
Rows over the training variables, with no level the training data lacks.
- yNone
Ignored.
- Returns:
- float
- Raises:
- ValueError
If X has other variables, or a level the training data lacks.
- set_params(**params)#
Set hyperparameters by name and return the estimator.