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.readFunction
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.writeFunction
Base.write(file::AbstractString, circuit::ProbCircuit)

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

source

Circuit Structures

ProbabilisticCircuits.hcltFunction
hclt(data, num_hidden_cats; num_cats = nothing, input_type = LiteralDist)

Learns HiddenChowLiuTree (hclt) circuit structure from data.

  • data: Matrix or CuMatrix
  • num_hidden_cats: Number of categories in hidden variables
  • input_type: Distribution type for the inputs
  • num_cats: Number of categories (in case of categorical inputs). Automatically deduced if not given explicilty.
source
ProbabilisticCircuits.RATFunction
RAT(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...xn
  • input_func: Function to generate a new input node for variable when calling input_func(var).

The list of hyperparamters are:

  • rg_depth: how many layers to do splits in the region graph
  • rg_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 region
  • num_nodes_leaf: number of sum nodes per leaf region
  • num_nodes_region: number of in each region except root and leaves
  • num_splits: number of splits for each parition; split variables into random equaly sized regions
source

Learning Circuit Parameters

ProbabilisticCircuits.mini_batch_emFunction
mini_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.

source
ProbabilisticCircuits.full_batch_emFunction
full_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).

source

Circuit Queries

ProbabilisticCircuits.loglikelihoodsFunction
loglikelihoods(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 gpu
  • data: CuArray{Union{Missing, data_types...}}
  • batch_size
  • mars_mem: Not required, advanced usage. CuMatrix to reuse memory and reduce allocations. See prep_memory and cleanup_memory.
source
loglikelihoods(pc::ProbCircuit, data::Matrix)

Computes loglikelihoods of the circuit over the data on cpu. Linearizes the circuit and computes the marginals in batches.

source
ProbabilisticCircuits.MAPFunction
MAP(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 gpu
  • data: CuArray{Union{Missing, data_types...}}
  • batch_size
  • mars_mem: Not required, advanced usage. CuMatrix to reuse memory and reduce allocations. See prep_memory and cleanup_memory.
source
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.

source
ProbabilisticCircuits.sampleFunction
sample(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 generate
  • num_rand_vars: number of random variables in the circuit
  • types: Array of possible input types
  • rng: (Optional) Random Number Generator

The size of returned Array is (num_samples, 1, size(data, 2)).

source
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 generate
  • rng: (Optional) Random Number Generator

The size of returned CuArray is (num_samples, size(data, 1), size(data, 2)).

source
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.

source
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.

source