Probabilistic Circuits

Base.readMethod
Base.read(file::AbstractString, ::Type{C}) where C <: ProbCircuit

Reads circuit from file; uses extension to detect format type, for example ".psdd" for PSDDs.

source
Base.writeMethod
Base.write(file::AbstractString, circuit::ProbCircuit)

Writes circuit to file; uses file name extention to detect file format.

source
Base.writeMethod
Base.write(files::Tuple{AbstractString,AbstractString}, circuit::StructProbCircuit)

Saves circuit and vtree to file.

source
ProbabilisticCircuits.MARFunction
MAR(pc, data) = marginal

Computes Marginal log likelhood of data. MAR is juat an alias for marginal. See docs for marginal for more details.

source
ProbabilisticCircuits.MSTMethod

Compute the Minimum Spanning Tree (MST) of graph g with weights weights, with constraints such that included_edges should be included while excluded_edges should be excluded.

source
ProbabilisticCircuits.apply_entropy_reg_cpuMethod
apply_entropy_reg_cpu(bc::BitCircuit; log_params::Vector{Float64}, edge_counts::Vector{Float64}, total_data_counts::Float64, pseudocount::Float64 = 0.1, entropy_reg::Float64 = 0.0)::Vector{Float64}

Add entropy regularization to a deterministic (see LogicCircuits.isdeterministic) probabilistic circuit. alpha is a hyperparameter that balances the weights between the likelihood and the entropy: rgmax{ heta} L( heta) = llmean( heta) + alpha * entropy( heta).

source
ProbabilisticCircuits.apply_entropy_reg_gpuMethod
apply_entropy_reg_gpu(bc::BitCircuit; log_params, edge_counts, total_data_counts::Float64, pseudocount::Float64 = 0.1, entropy_reg::Float64 = 0.0)

Add entropy regularization to a deterministic (see LogicCircuits.isdeterministic) probabilistic circuit. alpha is a hyperparameter that balances the weights between the likelihood and the entropy: rgmax{ heta} L( heta) = llmean( heta) + alpha * entropy( heta).

source
ProbabilisticCircuits.balanced_fully_factorizedMethod

Makes sure input nodes don't have too many parents. Makes a dummy sum node for each input per partition. Then nodes corresponding to the partition use the dummy node as their children instead of the input node. This way instead of numnodesroot * numnodesleaf, we would have numnodesroot parents nodes.

source
ProbabilisticCircuits.chow_liu_treeMethod

Compute the Chow-Liu Tree given a binary dataset. Automatically convert to categorical dataset if specified by num_vars' andnumcats'. If `numtrees` is greater than 1, the algorithm returns the top-K maximum spanning trees with respect to the pairwise_MI weights. Reference: Listing all the minimum spanning trees in an undirected graph http://www.nda.ac.jp/~yamada/paper/enum-mst.pdf

source
ProbabilisticCircuits.ensemble_sample_psddMethod

Creates an ensemble of n SamplePSDD-generated probabilistic circuits, with v the total number of variables in the data, ϕ the logic constraints, D the data to be learned and k the maximum number of primes to be sampled.

Keyword arguments for sample_psdd are passed down. Optionally, the function takes keyword argument vtree_bias, which samples more left (value closer to 0.0) or right-leaning (value closer to 1.0) vtrees. If a negative value is given, sample uniformly distributed vtrees.

Weights are computed by the given strategy. These can be any one of the following: 1. :likelihood for likelihood weighting; 2. :uniform for uniform weights; 3. :em for Expectation-Maximization; 4. :stacking for mixture model Stacking;

source
ProbabilisticCircuits.estimate_parameters!Method
estimate_parameters!(spc::SharedProbCircuit, data; pseudocount::Float64, entropy_reg::Float64 = 0.0)

Maximum likelihood estimation of a SharedProbCircuit's parameters given data.

bagging support: If spc is a SharedProbCircuit and data is an array of DataFrames with the same number of "components", learn each circuit with its corresponding dataset.

source
ProbabilisticCircuits.estimate_parameters_em!Method
estimate_parameters_em!(pc::ProbCircuit, data; pseudocount::Float64, entropy_reg::Float64 = 0.0, exp_update_factor::Float64 = 0.0, update_per_batch::Bool = false)

One epoch of Expectation maximization (EM) parameter learning for circuits. Useful when having missing data or non-deterministic circuits.

  • entropy_reg: Entropy Regularization
  • update_per_batch: Whether to update circuit paramters per batch (using the ParamBitCircuit's paramters)
source
ProbabilisticCircuits.estimate_parameters_em_multi_epochs!Method
estimate_parameters_em_multi_epochs!(circuit::ProbCircuit, train_data)

Runs multiple epochs of EM for circuit. It will run on CPU/GPU based on where train_data is.

Arguments:

  • circuit:
  • train_data: training data. If want gpu, move to gpu before calling this to_gpu(train_data).

Keyword arguments:

  • valid_data=nothing: validation data, should be same device as train_data
  • test_data=nothing: test data, data, should be same device as train_data
  • entropy_reg::Float64 = 0.0: Entropy regularization
  • exp_update_factor_start::Float64 = 0.1:
  • exp_update_factor_end::Float64 = 0.9:
  • em_warmup_iters=100 : number of EM Warm up iterations
  • em_finetune_iters=100: number of EM fine tune iterations
  • verbose=false: verbose or not
  • verbose_log_rate=1: how often to print info
  • save_path=nothing: path of the file to save the partially trained circuit
  • save_rate=20: how often to save the circuit to file
source
ProbabilisticCircuits.estimate_parameters_em_per_batch!Method
estimate_parameters_em_per_batch!(pc::ProbCircuit, data; pseudocount::Float64, entropy_reg::Float64 = 0.0, exp_update_factor = 0.0)

One epoch of Expectation maximization (EM) parameter learning for circuits. Useful when having missing data or non-deterministic circuits.

  • entropy_reg: Entropy Regularization
  • update_per_batch: Whether to update circuit paramters per batch (using the ParamBitCircuit's paramters)
source
ProbabilisticCircuits.estimate_parameters_sgd!Method
estimate_parameters_sgd!(pc::ProbCircuit, data; lr::Float64 = 0.01, reuse_values = nothing, reuse_flows = nothing, reuse = (nothing, nothing))

One epoch SGD to learn paramters of a ParamBitCircuit. It will run on CPU/GPU depending on where the data is located.

  • lr: Learning Rate
  • pbc: The ParamBitCircuit
  • 'data': training data
  • 'resue_*`: Allows reusing of allocated memory to avoid extra memory allocation between epochs. If training for only one epoch don't need to specify them.
source
ProbabilisticCircuits.estimate_parameters_sgd!Method
estimate_parameters_sgd!(pc::ProbCircuit, data; lr::Float64 = 0.01, reuse_values = nothing, reuse_flows = nothing, reuse = (nothing, nothing))

One epoch SGD to learn paramters of the pc. It will run on CPU/GPU depending on where the data is located.

  • lr: Learning Rate
  • pc: The ProbCircuit
  • 'data': training data
  • 'resue_*`: Allows reusing of allocated memory to avoid extra memory allocation between epochs. If training for only one epoch don't need to specify them.
source
ProbabilisticCircuits.estimate_single_circuit_parameters!Method
estimate_single_circuit_parameters!(pc::ProbCircuit, data; pseudocount::Float64, component_idx::Integer = 0, entropy_reg::Float64 = 0.0)

Maximum likelihood estimation of a single circuit (for example, ProbCircuit or one component of SharedProbCircuit) parameters given data

source
ProbabilisticCircuits.learn_circuit_missMethod

Learn structure of a single structured decomposable circuit from missing data.

Missing feature are denoted by missing. Median Imputation is used by default for initial structure (set impute_method for other options).

source
ProbabilisticCircuits.map_probMethod
map_prob(root::ProbCircuit, data::Union{Real,Missing}...)
map_prob(root::ProbCircuit, data::Union{Vector{Union{Bool,Missing}},CuVector{UInt8}})
map_prob(circuit::ProbCircuit, data::DataFrame)
map_prob(circuit::ParamBitCircuit, data::DataFrame)

The most likely world probability that agrees with the provided data"

Missing values should be denoted by missing in the data.

source
ProbabilisticCircuits.marginalFunction
marginal(circuit::SharedProbCircuit, data::DataFrame, weights::Union{AbstractArray, Nothing} = nothing; component_idx = 0)::AbstractVector

Computes marginals for one circuit in a SharedProbCircuit.

  • component_idx: index of the SharedProbCircuit component to comptue marginals on.
source
ProbabilisticCircuits.marginalMethod
marginal(root::ProbCircuit, data::Union{Real,Missing}...)
marginal(root::ProbCircuit, data::Union{Vector{Union{Bool,Missing}},CuVector{UInt8}})
marginal(circuit::ProbCircuit, data::DataFrame)
marginal(circuit::ParamBitCircuit, data::DataFrame)::AbstractVector
marginal(circuit::SharedProbCircuit, data::DataFrame, weights::Union{AbstractArray, Nothing}; component_idx)

Evaluate marginals of the circuit bottom-up for given input(s).

Missing values should be denoted by missing in the data.

Outputs $\log{p(x^o)}$ for each data point.

source
ProbabilisticCircuits.marginal_log_likelihoodMethod
marginal_log_likelihood(pc, data)
marginal_log_likelihood(pc, data, weights::DataFrame)
marginal_log_likelihood(pc, data, weights::AbstractArray)
marginal_log_likelihood(pc, data::Vector{DataFrame})

Compute the marginal likelihood of the PC given the data

source
ProbabilisticCircuits.max_a_posterioriMethod
max_a_posteriori(root::ProbCircuit, data::Union{Bool,Missing}...)
max_a_posteriori(root::ProbCircuit, data::Union{Vector{<:Union{Bool,Missing}},CuVector{UInt8}})
max_a_posteriori(circuit::ProbCircuit, data::DataFrame)
max_a_posteriori(pbc::ParamBitCircuit, data; Float=Float32)

Evaluate maximum a-posteriori state of the circuit for given input(s).

Outputs the states, and the corresponding probabilities (in log domain).

source
ProbabilisticCircuits.random_region_graphMethod
random_region_graph(X::AbstractVector{Var}, depth::Int = 5, replicas::Int = 2, num_splits::Int = 2)
  • X: Vector of all variables to include; for the root region
  • depth: how many layers to do splits
  • replicas: number of replicas or paritions (replicas only used for the root region; for other regions only 1 parition (inner nodes), or 0 parition for leaves)
  • num_splits: number of splits for each parition; split variables into random equaly sized regions
source
ProbabilisticCircuits.region_graph_2_pcMethod
region_graph_2_pc(node::RegionGraph; num_nodes_root, num_nodes_region, num_nodes_leaf, balance_childs_parents)
  • num_nodes_root: number of sum nodes in the root region
  • num_nodes_leaf: number of sum nodes per leaf region
  • num_nodes_region: number of in each region except root and leaves
source
ProbabilisticCircuits.sampleMethod
sample(pc::ProbCircuit, num_samples)
sample(pc::ProbCircuit, num_samples, evidences)

Sample states from the probabilistic circuit distribution. Also can do conditional sampling if evidence is given (any subset of features).

source
ProbabilisticCircuits.update_pc_params_from_pbc!Method
function update_pc_params_from_pbc!(pc::ProbCircuit, bc, params; exp_update_factor = 0.0)

During parameter learning pc's paramters are not updated automatically, and only the corresponding ParamBitCircuit's paramters update. This method updates the paramters of pc using the corresponding ParamBitCircuit.

Note: This is mostly for internal use.

source
ProbabilisticCircuits.update_pc_params_from_pbc!Method
update_pc_params_from_pbc!(pc::ProbCircuit, pbc; exp_update_factor = 0.0)

During parameter learning pc's paramters are not updated automatically, and only the corresponding ParamBitCircuit's paramters update. This method updates the paramters of pc using the corresponding ParamBitCircuit.

Note: This is mostly for internal use.

source
ProbabilisticCircuits.update_pc_params_from_pbc!Method
update_pc_params_from_pbc!(pc::SharedProbCircuit, bc, params, component_idx; exp_update_factor = 0.0)

During parameter learning pc's paramters are not updated automatically, and only the corresponding BitCircuit's paramters update. This method updates the paramters of pc using the corresponding BitCircuit.

Note: This is mostly for internal use.

source
ProbabilisticCircuits.wmc_chaviraFunction
wmc_chavira(root::LogicCircuit; varprob::Function)::Float

Compute weighted model count in the context of a chavira encoding (default negative literals to 1) Probability of each variable is given by varprob Function which defauls to 1/2 for every variable.

source