Common APIs
This page lists documentation for the most commonly used functions of ProbabilisticCircuits.jl. Visit the internals section for a auto generated documentation for all APIs.
Circuit IO
Base.read — FunctionBase.read(file::AbstractString, ::Type{C}) where C <: ProbCircuitReads circuit from file; uses extension to detect format type, for example ".psdd" for PSDDs.
Base.write — FunctionBase.write(file::AbstractString, circuit::ProbCircuit)Writes circuit to file; uses file name extention to detect file format.
Circuit Structures
ProbabilisticCircuits.hclt — Functionhclt(data, num_hidden_cats; num_cats = nothing, input_type = LiteralDist)Learns HiddenChowLiuTree (hclt) circuit structure from data.
data: Matrix or CuMatrixnum_hidden_cats: Number of categories in hidden variablesinput_type: Distribution type for the inputsnum_cats: Number of categories (in case of categorical inputs). Automatically deduced if not given explicilty.
ProbabilisticCircuits.RAT — FunctionRAT(num_features; input_func::Function = RAT_InputFunc(Literal), num_nodes_region, num_nodes_leaf, rg_depth, rg_replicas, num_nodes_root = 1, balance_childs_parents = true)Generate a RAT-SPN structure. First, it generates a random region graph with depth, and replicas. Then uses the random region graph to generate a ProbCircuit conforming to that region graph.
num_features: Number of features in the dataset, assuming x1...xninput_func: Function to generate a new input node for variable when callinginput_func(var).
The list of hyperparamters are:
rg_depth: how many layers to do splits in the region graphrg_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_nodes_root: number of sum nodes in the root regionnum_nodes_leaf: number of sum nodes per leaf regionnum_nodes_region: number of in each region except root and leavesnum_splits: number of splits for each parition; split variables into random equaly sized regions
Learning Circuit Parameters
ProbabilisticCircuits.mini_batch_em — Functionmini_batch_em(bpc::CuBitsProbCircuit, raw_data::CuArray, num_epochs; batch_size, pseudocount,
param_inertia, param_inertia_end = param_inertia, shuffle=:each_epoch)Update the parameters of the CuBitsProbCircuit by doing EM, update the parameters after each batch.
ProbabilisticCircuits.full_batch_em — Functionfull_batch_em(bpc::CuBitsProbCircuit, raw_data::CuArray, num_epochs; batch_size, pseudocount)Update the paramters of the CuBitsProbCircuit by doing EM on the full batch (i.e. update paramters at the end of each epoch).
Circuit Queries
ProbabilisticCircuits.loglikelihoods — Functionloglikelihoods(bpc::CuBitsProbCircuit, data::CuArray; batch_size, mars_mem = nothing)Returns loglikelihoods for each datapoint on gpu. Missing values should be denoted by missing.
bpc: BitCircuit on gpudata: CuArray{Union{Missing, data_types...}}batch_sizemars_mem: Not required, advanced usage. CuMatrix to reuse memory and reduce allocations. Seeprep_memoryandcleanup_memory.
loglikelihoods(pc::ProbCircuit, data::Matrix)Computes loglikelihoods of the circuit over the data on cpu. Linearizes the circuit and computes the marginals in batches.
ProbabilisticCircuits.MAP — FunctionMAP(bpc::CuBitsProbCircuit, data::CuArray; batch_size, mars_mem=nothing)Retruns the MAP states for a given circuit and data on gpu. Missing values should be denoted as missing.
Note that the MAP states are exact only when the circuit is both decomposable and deterministic, otherwise its just an approximation.
bpc: BitCircuit on gpudata: CuArray{Union{Missing, data_types...}}batch_sizemars_mem: Not required, advanced usage. CuMatrix to reuse memory and reduce allocations. Seeprep_memoryandcleanup_memory.
MAP(pc::ProbCircuit, data::Matrix; batch_size, Float=Float32)Evaluate max a posteriori (MAP) state of the circuit for given input(s) on cpu.
Note: This algorithm is only exact if the circuit is both decomposable and determinisitic. If the circuit is only decomposable and not deterministic, this will give inexact results without guarantees.
ProbabilisticCircuits.sample — Functionsample(bpc::CuBitsProbCircuit, num_samples::Int, num_rand_vars::Int, types; rng=default_rng())Generate num_samples from the joint distribution of the circuit without any conditions. Samples are genearted on the GPU.
bpc: Circuit on gpu (CuBitProbCircuit)num_samples: how many samples to generatenum_rand_vars: number of random variables in the circuittypes: Array of possible input typesrng: (Optional) Random Number Generator
The size of returned Array is (num_samples, 1, size(data, 2)).
sample(bpc::CuBitsProbCircuit, num_samples, data::CuMatrix; rng=default_rng())Generate num_samples for each datapoint in data from the joint distribution of the circuit conditioned on the data. Samples are generated using GPU.
bpc: Circuit on gpu (CuBitProbCircuit)num_samples: how many samples to generaterng: (Optional) Random Number Generator
The size of returned CuArray is (num_samples, size(data, 1), size(data, 2)).
sample(pc::ProbCircuit, num_samples; rng = default_rng())Generate num_samples from the joint distribution of the circuit without any conditions. Samples are generated on the CPU.
sample(pc::ProbCircuit, num_samples, data::Matrix;; batch_size, rng = default_rng())Generate num_samples from the joint distribution of the circuit conditioned on the data.