From 2621a32acb201e54da163fab361c3aa96aa4cd92 Mon Sep 17 00:00:00 2001 From: "Documenter.jl" Date: Sat, 8 Jun 2024 20:49:28 +0000 Subject: [PATCH] build based on b749816 --- dev/README.jl | 4 +- dev/api/common/index.html | 4 +- dev/api/input_dists/index.html | 4 +- dev/api/probabilistic_circuits/index.html | 8 +- dev/api/types/index.html | 4 +- dev/index.html | 2 +- dev/installation/index.html | 2 +- dev/manual/demo/index.html | 212 +++++++++++----------- dev/manual/gpu/index.html | 4 +- dev/manual/learning/index.html | 2 +- dev/manual/queries/index.html | 10 +- dev/search/index.html | 2 +- dev/search_index.js | 2 +- dev/usage.jl | 2 +- 14 files changed, 131 insertions(+), 131 deletions(-) diff --git a/dev/README.jl b/dev/README.jl index 2a96279b..228fb568 100644 --- a/dev/README.jl +++ b/dev/README.jl @@ -6,9 +6,9 @@ # # ProbabilisticCircuits.jl -# [![Unit Tests](https://github.com/Juice-jl/ProbabilisticCircuits.jl/workflows/Unit%20Tests/badge.svg)](https://github.com/Juice-jl/ProbabilisticCircuits.jl/actions?query=workflow%3A%22Unit+Tests%22+branch%3Amaster) [![codecov](https://codecov.io/gh/Juice-jl/ProbabilisticCircuits.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/Juice-jl/ProbabilisticCircuits.jl) [![](https://img.shields.io/badge/docs-stable-green.svg)](https://juice-jl.github.io/ProbabilisticCircuits.jl/stable) [![](https://img.shields.io/badge/docs-dev-blue.svg)](https://juice-jl.github.io/ProbabilisticCircuits.jl/dev) +# [![Unit Tests](https://github.com/Tractables/ProbabilisticCircuits.jl/workflows/Unit%20Tests/badge.svg)](https://github.com/Tractables/ProbabilisticCircuits.jl/actions?query=workflow%3A%22Unit+Tests%22+branch%3Amaster) [![codecov](https://codecov.io/gh/Tractables/ProbabilisticCircuits.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/Tractables/ProbabilisticCircuits.jl) [![](https://img.shields.io/badge/docs-stable-green.svg)](https://Tractables.github.io/ProbabilisticCircuits.jl/stable) [![](https://img.shields.io/badge/docs-dev-blue.svg)](https://Tractables.github.io/ProbabilisticCircuits.jl/dev) -# This package provides functionalities for learning/constructing probabilistic circuits and using them to compute various probabilistic queries. It is part of the [Juice package](https://github.com/Juice-jl) (Julia Circuit Empanada). +# This package provides functionalities for learning/constructing probabilistic circuits and using them to compute various probabilistic queries. It is part of the [Juice package](https://github.com/Tractables) (Julia Circuit Empanada). # ## Testing diff --git a/dev/api/common/index.html b/dev/api/common/index.html index 92175180..7b0fbea0 100644 --- a/dev/api/common/index.html +++ b/dev/api/common/index.html @@ -6,5 +6,5 @@ ga('create', 'UA-136089579-2', 'auto'); ga('send', 'pageview', {'page': location.pathname + location.search + location.hash}); -

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
+

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
diff --git a/dev/api/input_dists/index.html b/dev/api/input_dists/index.html index 03ed6ef0..f49bedc3 100644 --- a/dev/api/input_dists/index.html +++ b/dev/api/input_dists/index.html @@ -6,7 +6,7 @@ ga('create', 'UA-136089579-2', 'auto'); ga('send', 'pageview', {'page': location.pathname + location.search + location.hash}); -

Input Distributions

Currently we support Indicator{T}, Categorical, Bernoulli (special case of Categorical) distributions in the InputNodes.

Support new InputDist

To support new type of Input Distributions you need to implement the following functions:

num_parameters
+

Input Distributions

Currently we support Indicator{T}, Categorical, Bernoulli (special case of Categorical) distributions in the InputNodes.

Support new InputDist

To support new type of Input Distributions you need to implement the following functions:

num_parameters
 params
 init_params
 loglikelihood

Support movement between CPU/GPU for InputDist

To support moving between CPU/GPU you need to implement the following:

bits
@@ -16,4 +16,4 @@
 init_heap_map_state!
 init_heap_map_loglikelihood!
 map_state
-map_loglikelihood
+map_loglikelihood
diff --git a/dev/api/probabilistic_circuits/index.html b/dev/api/probabilistic_circuits/index.html index c2aee2e5..5760adb6 100644 --- a/dev/api/probabilistic_circuits/index.html +++ b/dev/api/probabilistic_circuits/index.html @@ -6,12 +6,12 @@ ga('create', 'UA-136089579-2', 'auto'); ga('send', 'pageview', {'page': location.pathname + location.search + location.hash}); -

Probabilistic Circuits

This page lists all the API documentation for ProbabilisticCircuits package.

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
DirectedAcyclicGraphs.foldupMethod
foldup(node::ProbCircuit, 
+

Probabilistic Circuits

This page lists all the API documentation for ProbabilisticCircuits package.

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
DirectedAcyclicGraphs.foldupMethod
foldup(node::ProbCircuit, 
     f_i::Function, 
     f_m::Function, 
-    f_s::Function)::T where {T}

Compute a function bottom-up on the circuit. f_in is called on input nodes, f_m is called on product nodes, and f_s is called on sum nodes. Values of type T are passed up the circuit and given to f_m and f_s through a callback from the children.

source
DirectedAcyclicGraphs.foldup_aggregateMethod
foldup_aggregate(node::ProbCircuit, 
+    f_s::Function)::T where {T}

Compute a function bottom-up on the circuit. f_in is called on input nodes, f_m is called on product nodes, and f_s is called on sum nodes. Values of type T are passed up the circuit and given to f_m and f_s through a callback from the children.

source
DirectedAcyclicGraphs.foldup_aggregateMethod
foldup_aggregate(node::ProbCircuit, 
     f_i::Function, 
     f_m::Function, 
     f_s::Function, 
-    ::Type{T})::T where T

Compute a function bottom-up on the circuit. f_in is called on input nodes, f_m is called on product nodes, and f_s is called on sum nodes. Values of type T are passed up the circuit and given to f_m and f_s in an aggregate vector from the children.

source
ProbabilisticCircuits.MAPMethod
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
ProbabilisticCircuits.MAPMethod
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.RATMethod
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
ProbabilisticCircuits.RAT_InputFuncMethod

Default input_func for different types. This function returns another function input_func. Then input_func(var) should generate a new input function with the desired distribution.

source
ProbabilisticCircuits.balanced_fully_factorized_leavesMethod

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.bitsMethod
bits(d::InputDist, heap)

Appends the required memory for this input dist to the heap.

Used internally for moving from CPU to GPU.

source
ProbabilisticCircuits.clear_memoryMethod
clear_memory(d::InputDist, heap, rate)

Clears the accumulated flow values on the heap by multiplying it by rate. rate == 0.0 will be equivalent to initializing the value to 0.0.

source
ProbabilisticCircuits.eval_circuit!Method
eval_circuit!(mars, linPC::AbstractVector{<:ProbCircuit}, data::Matrix, example_ids;  node2idx::Dict{ProbCircuit, UInt32}, Float=Float32)

Used internally. Evaluates the marginals of the circuit on cpu. Stores the values in mars.

  • mars: (batch_size, nodes)
  • linPC: linearized PC. (i.e. linearize(pc))
  • data: data Matrix (num_examples, features)
  • example_ids: Array or collection of ids for current batch
  • node2idx: Index of each ProbCircuit node in the linearized circuit
source
ProbabilisticCircuits.eval_circuit_max!Method
eval_circuit_max!(mars, linPC::AbstractVector{<:ProbCircuit}, data::Matrix, example_ids;  node2idx::Dict{ProbCircuit, UInt32}, Float=Float32)

Used internally. Evaluates the MAP upward pass of the circuit on cpu. Stores the values in mars.

  • mars: (batch_size, nodes)
  • linPC: linearized PC. (i.e. linearize(pc))
  • data: data Matrix (num_examples, features)
  • example_ids: Array or collection of ids for current batch
  • node2idx: Index of each ProbCircuit node in the linearized circuit
source
ProbabilisticCircuits.full_batch_emMethod
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
ProbabilisticCircuits.hcltMethod
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.loglikelihoodMethod
loglikelihood(root::ProbCircuit, data::Matrix, example_id; Float=Float32)

Computes marginal loglikelihood recursively on cpu for a single instance data[example_id, :].

Note: Quite slow, only use for demonstration/educational purposes.

source
ProbabilisticCircuits.loglikelihoodsMethod
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
ProbabilisticCircuits.loglikelihoodsMethod
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.map_down_rec!Method
map_down_rec!(mars, node::ProbCircuit, data, states::Matrix, batch_idx, example_idx; node2idx::Dict{ProbCircuit, UInt32}, Float=Float32)

Downward pass on cpu for MAP. Recursively chooses the best (max) sum node children according to the "MAP upward pass" values. Updates the missing values with map_state of that input node.

source
ProbabilisticCircuits.mini_batch_emMethod
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.prep_memoryFunction
prep_memory(reuse, sizes, exact = map(x -> true, sizes))

Mostly used internally. Prepares memory for the specifed size, reuses reuse if possible to avoid memory allocation/deallocation.

source
ProbabilisticCircuits.random_region_graphMethod
random_region_graph(X::AbstractVector, 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(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
ProbabilisticCircuits.sampleMethod
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
ProbabilisticCircuits.sampleMethod
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
ProbabilisticCircuits.sampleMethod
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
ProbabilisticCircuits.sample_stateMethod
sample_state(d::InputDist, threshold::Float32, heap)

Returns a sample from InputDist. Threshold is a uniform random value in range (0, 1) given to this API by the sampleing algorithm

source
ProbabilisticCircuits.unbitsMethod
unbits(d::InputDist, heap)

Returns the InputDist struct from the heap. Note, each input dist type needs to store where in the heap its paramters are to be able to do this.

Used internally for moving from GPU to CPU.

source
+ ::Type{T})::T where T

Compute a function bottom-up on the circuit. f_in is called on input nodes, f_m is called on product nodes, and f_s is called on sum nodes. Values of type T are passed up the circuit and given to f_m and f_s in an aggregate vector from the children.

source
ProbabilisticCircuits.MAPMethod
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
ProbabilisticCircuits.MAPMethod
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.RATMethod
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
ProbabilisticCircuits.RAT_InputFuncMethod

Default input_func for different types. This function returns another function input_func. Then input_func(var) should generate a new input function with the desired distribution.

source
ProbabilisticCircuits.balanced_fully_factorized_leavesMethod

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.bitsMethod
bits(d::InputDist, heap)

Appends the required memory for this input dist to the heap.

Used internally for moving from CPU to GPU.

source
ProbabilisticCircuits.clear_memoryMethod
clear_memory(d::InputDist, heap, rate)

Clears the accumulated flow values on the heap by multiplying it by rate. rate == 0.0 will be equivalent to initializing the value to 0.0.

source
ProbabilisticCircuits.eval_circuit!Method
eval_circuit!(mars, linPC::AbstractVector{<:ProbCircuit}, data::Matrix, example_ids;  node2idx::Dict{ProbCircuit, UInt32}, Float=Float32)

Used internally. Evaluates the marginals of the circuit on cpu. Stores the values in mars.

  • mars: (batch_size, nodes)
  • linPC: linearized PC. (i.e. linearize(pc))
  • data: data Matrix (num_examples, features)
  • example_ids: Array or collection of ids for current batch
  • node2idx: Index of each ProbCircuit node in the linearized circuit
source
ProbabilisticCircuits.eval_circuit_max!Method
eval_circuit_max!(mars, linPC::AbstractVector{<:ProbCircuit}, data::Matrix, example_ids;  node2idx::Dict{ProbCircuit, UInt32}, Float=Float32)

Used internally. Evaluates the MAP upward pass of the circuit on cpu. Stores the values in mars.

  • mars: (batch_size, nodes)
  • linPC: linearized PC. (i.e. linearize(pc))
  • data: data Matrix (num_examples, features)
  • example_ids: Array or collection of ids for current batch
  • node2idx: Index of each ProbCircuit node in the linearized circuit
source
ProbabilisticCircuits.full_batch_emMethod
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
ProbabilisticCircuits.hcltMethod
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.loglikelihoodMethod
loglikelihood(root::ProbCircuit, data::Matrix, example_id; Float=Float32)

Computes marginal loglikelihood recursively on cpu for a single instance data[example_id, :].

Note: Quite slow, only use for demonstration/educational purposes.

source
ProbabilisticCircuits.loglikelihoodsMethod
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
ProbabilisticCircuits.loglikelihoodsMethod
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.map_down_rec!Method
map_down_rec!(mars, node::ProbCircuit, data, states::Matrix, batch_idx, example_idx; node2idx::Dict{ProbCircuit, UInt32}, Float=Float32)

Downward pass on cpu for MAP. Recursively chooses the best (max) sum node children according to the "MAP upward pass" values. Updates the missing values with map_state of that input node.

source
ProbabilisticCircuits.mini_batch_emMethod
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.prep_memoryFunction
prep_memory(reuse, sizes, exact = map(x -> true, sizes))

Mostly used internally. Prepares memory for the specifed size, reuses reuse if possible to avoid memory allocation/deallocation.

source
ProbabilisticCircuits.random_region_graphMethod
random_region_graph(X::AbstractVector, 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(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
ProbabilisticCircuits.sampleMethod
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
ProbabilisticCircuits.sampleMethod
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
ProbabilisticCircuits.sampleMethod
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
ProbabilisticCircuits.sample_stateMethod
sample_state(d::InputDist, threshold::Float32, heap)

Returns a sample from InputDist. Threshold is a uniform random value in range (0, 1) given to this API by the sampleing algorithm

source
ProbabilisticCircuits.unbitsMethod
unbits(d::InputDist, heap)

Returns the InputDist struct from the heap. Note, each input dist type needs to store where in the heap its paramters are to be able to do this.

Used internally for moving from GPU to CPU.

source
diff --git a/dev/api/types/index.html b/dev/api/types/index.html index 7d13136a..256732d3 100644 --- a/dev/api/types/index.html +++ b/dev/api/types/index.html @@ -6,7 +6,7 @@ ga('create', 'UA-136089579-2', 'auto'); ga('send', 'pageview', {'page': location.pathname + location.search + location.hash}); -

Types

The following code snippet provides an easy way to print the type tree of probabilistic circuits.

using InteractiveUtils;
+

Types

The following code snippet provides an easy way to print the type tree of probabilistic circuits.

using InteractiveUtils;
 using ProbabilisticCircuits;
 using AbstractTrees;
 AbstractTrees.children(x::Type) = subtypes(x);

For example, we can see ProbabilisticCircuits.ProbCircuit's type tree.

AbstractTrees.print_tree(ProbCircuit)
ProbCircuit
@@ -19,4 +19,4 @@
 ├─ Categorical
 ├─ Indicator
 ├─ BitsBinomial
-└─ BitsCategorical
+└─ BitsCategorical
diff --git a/dev/index.html b/dev/index.html index ff21a35d..c8394b13 100644 --- a/dev/index.html +++ b/dev/index.html @@ -6,4 +6,4 @@ ga('create', 'UA-136089579-2', 'auto'); ga('send', 'pageview', {'page': location.pathname + location.search + location.hash}); -

ProbabilisticCircuits.jl

This module provides a Julia implementation of Probabilistic Circuits (PCs), tools to learn structure and parameters of PCs from data, and tools to do tractable exact inference with them.

What are Probabilistic Circuits?

Probabilistic Circuits provides a unifying framework for several family of tractable probabilistic models. PCs are represented as a computational graphs that define a joint probability distribution as recursive mixtures (sum units) and factorizations (product units) of simpler distributions (input units).

Given certain structural properties, PCs enable different range of tractable exact probabilistic queries such as computing marginals, conditionals, maximum a posteriori (MAP), and more advanced probabilistic queries.

In additon to parameters, the structure of PCs can also be learned from data. There are several approaches in learning PCs, while keeping the needed structural constrains intact. Currently, This module includes implementation for few of these approaches with plans to add more over time.

Additionally, parallelism (on both CPU and GPU) is leveraged to provide faster implementation of learning and inference.

Where to learn more about them?

For an overview of the motivation and theory behind PCs, you can start by watching the ECML-PKDD tutorial on Probabilistic Circuits.

  • Probabilistic Circuits: Representations, Inference, Learning and Theory (Video)

For more details and additional references, you can refer to:

  • Probabilistic Circuits: A Unifying Framework for Tractable Probabilistic Models (PDF)
+

ProbabilisticCircuits.jl

This module provides a Julia implementation of Probabilistic Circuits (PCs), tools to learn structure and parameters of PCs from data, and tools to do tractable exact inference with them.

What are Probabilistic Circuits?

Probabilistic Circuits provides a unifying framework for several family of tractable probabilistic models. PCs are represented as a computational graphs that define a joint probability distribution as recursive mixtures (sum units) and factorizations (product units) of simpler distributions (input units).

Given certain structural properties, PCs enable different range of tractable exact probabilistic queries such as computing marginals, conditionals, maximum a posteriori (MAP), and more advanced probabilistic queries.

In additon to parameters, the structure of PCs can also be learned from data. There are several approaches in learning PCs, while keeping the needed structural constrains intact. Currently, This module includes implementation for few of these approaches with plans to add more over time.

Additionally, parallelism (on both CPU and GPU) is leveraged to provide faster implementation of learning and inference.

Where to learn more about them?

For an overview of the motivation and theory behind PCs, you can start by watching the ECML-PKDD tutorial on Probabilistic Circuits.

  • Probabilistic Circuits: Representations, Inference, Learning and Theory (Video)

For more details and additional references, you can refer to:

  • Probabilistic Circuits: A Unifying Framework for Tractable Probabilistic Models (PDF)
diff --git a/dev/installation/index.html b/dev/installation/index.html index 54794016..182544dd 100644 --- a/dev/installation/index.html +++ b/dev/installation/index.html @@ -6,4 +6,4 @@ ga('create', 'UA-136089579-2', 'auto'); ga('send', 'pageview', {'page': location.pathname + location.search + location.hash}); -

Installation

Prerequisites

Julia 1.6 or greater. For installation, please refer to the official Julia Website.

Installing ProbabilisticCircuits

You can use Julia's package manager, Pkg, to install this module and its dependencies. There are different options on how to do that, for example through command line or julia REPL. For more information and options on how to use Julia pacakge manager, please refer to Pkg's Documentation.

From Command Line

To install the latest stable release, run:

julia -e 'using Pkg; Pkg.add("ProbabilisticCircuits")'

You can also install the package with the latest commits on master branch.

julia -e 'using Pkg; Pkg.add([PackageSpec(url="https://github.com/Juice-jl/ProbabilisticCircuits.jl.git")])'

From Package mode

Note

To get to Pkg mode, you need to run julia, then to press ]. Press backspace or ^C to get back to normal REPL mode.

While in Pkg mode, run the following to install the latest release:

add ProbabilisticCircuits

Similarly, to install from the latest commits on master branch, run:

add ProbabilisticCircuits#master

Testing

If you are installing the latest commit, we recommend running the test suite to make sure everything is in order, to do that run:

julia --color=yes -e 'using Pkg; Pkg.test("ProbabilisticCircuits")'

Note: If you want the tests to run faster, you can use multiple cores. To do that set the following environment variable (default = 1 core):

export JIVE_PROCS=8
+

Installation

Prerequisites

Julia 1.6 or greater. For installation, please refer to the official Julia Website.

Installing ProbabilisticCircuits

You can use Julia's package manager, Pkg, to install this module and its dependencies. There are different options on how to do that, for example through command line or julia REPL. For more information and options on how to use Julia pacakge manager, please refer to Pkg's Documentation.

From Command Line

To install the latest stable release, run:

julia -e 'using Pkg; Pkg.add("ProbabilisticCircuits")'

You can also install the package with the latest commits on master branch.

julia -e 'using Pkg; Pkg.add([PackageSpec(url="https://github.com/Tractables/ProbabilisticCircuits.jl.git")])'

From Package mode

Note

To get to Pkg mode, you need to run julia, then to press ]. Press backspace or ^C to get back to normal REPL mode.

While in Pkg mode, run the following to install the latest release:

add ProbabilisticCircuits

Similarly, to install from the latest commits on master branch, run:

add ProbabilisticCircuits#master

Testing

If you are installing the latest commit, we recommend running the test suite to make sure everything is in order, to do that run:

julia --color=yes -e 'using Pkg; Pkg.test("ProbabilisticCircuits")'

Note: If you want the tests to run faster, you can use multiple cores. To do that set the following environment variable (default = 1 core):

export JIVE_PROCS=8
diff --git a/dev/manual/demo/index.html b/dev/manual/demo/index.html index 66a7ca28..310216bb 100644 --- a/dev/manual/demo/index.html +++ b/dev/manual/demo/index.html @@ -6,7 +6,7 @@ ga('create', 'UA-136089579-2', 'auto'); ga('send', 'pageview', {'page': location.pathname + location.search + location.hash}); -

Quick Demo

In this section, we provide quick code snippets to get started with ProbabilisticCircuits and provide basic understanding of them. PCs are represented as a computational graphs that define a joint probability distribution as recursive mixtures (sum units) and factorizations (product units) of simpler distributions (input units).

Generally, we learn structure and parameters of circuit from data. Alternatively, we can also specify circuits in code. For example, the following snippet defines a circuit depending on 3 random variables. The literals function returns the input units of the circuit, in this case we get 6 different units (3 for positive literals, and 3 for negative literlas). You can use * and + operators to build a circuits.

using ProbabilisticCircuits;
+

Quick Demo

In this section, we provide quick code snippets to get started with ProbabilisticCircuits and provide basic understanding of them. PCs are represented as a computational graphs that define a joint probability distribution as recursive mixtures (sum units) and factorizations (product units) of simpler distributions (input units).

Generally, we learn structure and parameters of circuit from data. Alternatively, we can also specify circuits in code. For example, the following snippet defines a circuit depending on 3 random variables. The literals function returns the input units of the circuit, in this case we get 6 different units (3 for positive literals, and 3 for negative literlas). You can use * and + operators to build a circuits.

using ProbabilisticCircuits;
 
 X1, X2, X3    = [InputNode(i, Indicator(true))  for i=1:3]
 X1_, X2_, X3_ = [InputNode(i, Indicator(false)) for i=1:3]
@@ -18,94 +18,94 @@
 
 
 
-
+
 
 
-
+
 
 
-
+
 
 
-
+
 
 
-
+
 
 
-
+
 
 
-
+
 
 
-
+
 
 
-
+
 
 
-
+
 
 
-
+
 
 
-
+
 
 
-
+
 
 
-
+
 
 
-
+
 
 
-
+
 
 
-
+
 
 
-
+
 
 
-
+
 
 
-
+
 
 
-
+
 
 
-
+
 
 
-
+
 
 
-
+
 
 
-
+
 
 
-
+
 
 
-
+
 
 
-
+
 
 
-
+
 
 
-
+
 
 
 
@@ -114,16 +114,16 @@
 
 
 
-  
-  
-  
+  
+  
+  
 
 
 
 
-  
-  
-  
+  
+  
+  
 
 
 
@@ -132,16 +132,16 @@
 
 
 
-  
-  
-  
+  
+  
+  
 
 
 
 
-  
-  
-  
+  
+  
+  
 
 
 
@@ -150,160 +150,160 @@
 
 
 
-  
-  
-  
+  
+  
+  
 
 
 
 
-  
-  
-  
+  
+  
+  
 
 
-  
+  
 
 
-  
+  
 
 
-  
+  
 
 
-  
+  
 
 
-  
+  
 
 
-  
-  
+  
+  
 
 
-  
-  
+  
+  
 
 
-  
+  
 
 
-  
+  
 
 
-  
+  
 
 
-  
+  
 
 
-  
+  
 
 
-  
-  
+  
+  
 
 
-  
-  
+  
+  
 
 
-  
+  
 
 
-  
+  
 
 
-  
+  
 
 
-  
+  
 
 
-  
-  
+  
+  
 
 
-  
-  
+  
+  
 
 
-  
+  
 
 
-  
+  
 
 
-  
+  
 
 
-  
+  
 
 
-  
+  
 
 
-  
+  
 
 
-  
-  
+  
+  
 
 
-  
-  
+  
+  
 
 
-  
+  
 
 
-  
+  
 
 
-  
+  
 
 
-  
+  
 
 
-  
-  
+  
+  
 
 
-  
-  
+  
+  
 
 
-  
+  
 
 
-  
+  
 
 
-  
+  
 
 
-  
+  
 
 
-  
+  
 
 
-  
-  
+  
+  
 
 
-  
-  
+  
+  
 
 
-  
+  
 
 
-  
+  
 
 
-  
+  
 
 
 
@@ -313,4 +313,4 @@
 save(PDF("plot"), z);
 save(SVG("plot"), z);
 save(TEX("plot"), z);
-save(TIKZ("plot"), z);
+save(TIKZ("plot"), z);
diff --git a/dev/manual/gpu/index.html b/dev/manual/gpu/index.html index 531303b5..a5cc5767 100644 --- a/dev/manual/gpu/index.html +++ b/dev/manual/gpu/index.html @@ -6,5 +6,5 @@ ga('create', 'UA-136089579-2', 'auto'); ga('send', 'pageview', {'page': location.pathname + location.search + location.hash}); -

GPU Support

Most queries and learning APIs support both CPU and GPU implementations. To use the GPU implementations you need to move the circuit and the dataset to GPU, then call the corresponding API.

Moving to GPU

Moving Data to GPU

Currently, the APIs support CuArray type of gpu implemetations. One simple way to move to gpu is using the cu function from CUDA.jl.

using CUDA
-train_x_gpu, test_x_gpu = cu.(train_x, test_x)

In case of missing values we use Missing type, so for example if you have categorical features with some missing values, the data type on gpu would be CuArray{Union{Missing, UInt32}}.

Moving ProbCircuits to GPU

ProbCircuits are stored in DAG structure and are not GPU friendly by default. So, we convert them into BitsProbCircuits (or bit circuits) as a lower level representation that is GPU friendly. The GPU version of bit circuits has type CuBitsProbCircuit, so to move your circuit to GPU you can simply do:

bpc = CuBitsProbCircuit(circuit);

GPU APIs

The GPU supported APIs generally have the same name as their CPU counterpart, for a comprehensive list of supported functions see the API documentation. For example, we support the following on gpu:

+

GPU Support

Most queries and learning APIs support both CPU and GPU implementations. To use the GPU implementations you need to move the circuit and the dataset to GPU, then call the corresponding API.

Moving to GPU

Moving Data to GPU

Currently, the APIs support CuArray type of gpu implemetations. One simple way to move to gpu is using the cu function from CUDA.jl.

using CUDA
+train_x_gpu, test_x_gpu = cu.(train_x, test_x)

In case of missing values we use Missing type, so for example if you have categorical features with some missing values, the data type on gpu would be CuArray{Union{Missing, UInt32}}.

Moving ProbCircuits to GPU

ProbCircuits are stored in DAG structure and are not GPU friendly by default. So, we convert them into BitsProbCircuits (or bit circuits) as a lower level representation that is GPU friendly. The GPU version of bit circuits has type CuBitsProbCircuit, so to move your circuit to GPU you can simply do:

bpc = CuBitsProbCircuit(circuit);

GPU APIs

The GPU supported APIs generally have the same name as their CPU counterpart, for a comprehensive list of supported functions see the API documentation. For example, we support the following on gpu:

diff --git a/dev/manual/learning/index.html b/dev/manual/learning/index.html index ceb6172b..1b7942f1 100644 --- a/dev/manual/learning/index.html +++ b/dev/manual/learning/index.html @@ -6,4 +6,4 @@ ga('create', 'UA-136089579-2', 'auto'); ga('send', 'pageview', {'page': location.pathname + location.search + location.hash}); -

Learning

In this section we provide few learning scenarios for circuits. In general, learning tasks for PCs can be separted into two categories: parameter learning and structure learning.

Structures

Currently we are supporting the following structures:

  • HiddenChowLiuTrees: See hclt.
  • RAT-SPNs: See RAT.

Parameter Learning

Currently we are supporting the following parameters learning APIs:

Future Docs

  • Learning a circuit from missing data
  • Learn a mixture of circuits
  • Learn a circuit from logical constraints and data
+

Learning

In this section we provide few learning scenarios for circuits. In general, learning tasks for PCs can be separted into two categories: parameter learning and structure learning.

Structures

Currently we are supporting the following structures:

  • HiddenChowLiuTrees: See hclt.
  • RAT-SPNs: See RAT.

Parameter Learning

Currently we are supporting the following parameters learning APIs:

Future Docs

  • Learning a circuit from missing data
  • Learn a mixture of circuits
  • Learn a circuit from logical constraints and data
diff --git a/dev/manual/queries/index.html b/dev/manual/queries/index.html index f28d6049..56d317a9 100644 --- a/dev/manual/queries/index.html +++ b/dev/manual/queries/index.html @@ -6,7 +6,7 @@ ga('create', 'UA-136089579-2', 'auto'); ga('send', 'pageview', {'page': location.pathname + location.search + location.hash}); -

Queries

In this section, we go over most common probabilistic reasoning tasks, and provide code snippets to compute those queries.

Setup

First, we load some pretrained PC, and the corresponding data.

using CircuitModelZoo: zoo_psdd_file
+

Queries

In this section, we go over most common probabilistic reasoning tasks, and provide code snippets to compute those queries.

Setup

First, we load some pretrained PC, and the corresponding data.

using CircuitModelZoo: zoo_psdd_file
 using DensityEstimationDatasets: twenty_datasets
 using ProbabilisticCircuits
 using Tables
@@ -30,13 +30,13 @@
 end;
 data_miss = make_missing(data[1:1000,:]);

Now, we can use loglikelihoods to compute the marginal queries.

probs = loglikelihoods(pc, data_miss; batch_size=64);
 probs[1:3]
3-element Vector{Float32}:
-  -5.857102
- -11.6324
- -20.414034

Note that loglikelihoods can also be used to compute probabilisties if all data is observed, as we saw in previous section.

Conditionals (CON)

In this case, given observed features $x^o$, we would like to compute $p(Q \mid x^o)$, where $Q$ is a subset of features disjoint with $x^o$. We can use Bayes rule to compute conditionals as two seperate MAR queries as follows:

\[p(q \mid x^o) = \cfrac{p(q, x^o)}{p(x^o)}\]

Currently, this has to be done manually by the user. We plan to add a simple API for this case in the future.

Maximum a posteriori (MAP, MPE)

In this case, given the observed features $x^o$ the goal is to fill out the missing features in a way that $p(x^m, x^o)$ is maximized.

We can use the MAP method to compute MAP, which outputs the states that maximize the probability and the log-likelihoods of each state.

data_miss = make_missing(data[1:1000,:], keep_prob=0.5);
+  -6.21686
+ -14.510717
+ -22.768972

Note that loglikelihoods can also be used to compute probabilisties if all data is observed, as we saw in previous section.

Conditionals (CON)

In this case, given observed features $x^o$, we would like to compute $p(Q \mid x^o)$, where $Q$ is a subset of features disjoint with $x^o$. We can use Bayes rule to compute conditionals as two seperate MAR queries as follows:

\[p(q \mid x^o) = \cfrac{p(q, x^o)}{p(x^o)}\]

Currently, this has to be done manually by the user. We plan to add a simple API for this case in the future.

Maximum a posteriori (MAP, MPE)

In this case, given the observed features $x^o$ the goal is to fill out the missing features in a way that $p(x^m, x^o)$ is maximized.

We can use the MAP method to compute MAP, which outputs the states that maximize the probability and the log-likelihoods of each state.

data_miss = make_missing(data[1:1000,:], keep_prob=0.5);
 states = MAP(pc, data_miss; batch_size = 64);
 size(states)
(1000, 69)

Sampling

We can also sample from the distrubtion $p(x)$ defined by a Probabilistic Circuit. You can use sample to achieve this task.

samples = sample(pc, 100, [Bool]);
 size(samples)
(100, 1, 69)

Additionally, we can do conditional samples $x \sim p(x \mid x^o)$, where $x^o$ are the observed features ($x^o \subseteq x$), and could be any arbitrary subset of features.

#3 random evidences for the examples
 evidence = rand( (missing,true,false), (2, num_randvars(pc)));
 
 samples = sample(pc, 3, evidence; batch_size = 2);
-size(samples)
(3, 2, 69)
+size(samples)
(3, 2, 69)
diff --git a/dev/search/index.html b/dev/search/index.html index ce630284..82f429d7 100644 --- a/dev/search/index.html +++ b/dev/search/index.html @@ -6,4 +6,4 @@ ga('create', 'UA-136089579-2', 'auto'); ga('send', 'pageview', {'page': location.pathname + location.search + location.hash}); -

Loading search...

    +

    Loading search...

      diff --git a/dev/search_index.js b/dev/search_index.js index 9924bbe7..c202b7bf 100644 --- a/dev/search_index.js +++ b/dev/search_index.js @@ -1,3 +1,3 @@ var documenterSearchIndex = {"docs": -[{"location":"api/common/#api-common","page":"Common APIs","title":"Common APIs","text":"","category":"section"},{"location":"api/common/","page":"Common APIs","title":"Common APIs","text":"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.","category":"page"},{"location":"api/common/","page":"Common APIs","title":"Common APIs","text":"Pages = [\"common.md\"]","category":"page"},{"location":"api/common/#Circuit-IO","page":"Common APIs","title":"Circuit IO","text":"","category":"section"},{"location":"api/common/","page":"Common APIs","title":"Common APIs","text":"read\nwrite","category":"page"},{"location":"api/common/#Base.read","page":"Common APIs","title":"Base.read","text":"Base.read(file::AbstractString, ::Type{C}) where C <: ProbCircuit\n\nReads circuit from file; uses extension to detect format type, for example \".psdd\" for PSDDs.\n\n\n\n\n\n","category":"function"},{"location":"api/common/#Base.write","page":"Common APIs","title":"Base.write","text":"Base.write(file::AbstractString, circuit::ProbCircuit)\n\nWrites circuit to file; uses file name extention to detect file format.\n\n\n\n\n\n","category":"function"},{"location":"api/common/#Circuit-Structures","page":"Common APIs","title":"Circuit Structures","text":"","category":"section"},{"location":"api/common/","page":"Common APIs","title":"Common APIs","text":"hclt\nRAT","category":"page"},{"location":"api/common/#ProbabilisticCircuits.hclt","page":"Common APIs","title":"ProbabilisticCircuits.hclt","text":"hclt(data, num_hidden_cats; num_cats = nothing, input_type = LiteralDist)\n\nLearns HiddenChowLiuTree (hclt) circuit structure from data.\n\ndata: Matrix or CuMatrix\nnum_hidden_cats: Number of categories in hidden variables\ninput_type: Distribution type for the inputs\nnum_cats: Number of categories (in case of categorical inputs). Automatically deduced if not given explicilty.\n\n\n\n\n\n","category":"function"},{"location":"api/common/#ProbabilisticCircuits.RAT","page":"Common APIs","title":"ProbabilisticCircuits.RAT","text":"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)\n\nGenerate 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.\n\nnum_features: Number of features in the dataset, assuming x1...xn\ninput_func: Function to generate a new input node for variable when calling input_func(var).\n\nThe list of hyperparamters are:\n\nrg_depth: how many layers to do splits in the region graph\nrg_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)\nnum_nodes_root: number of sum nodes in the root region\nnum_nodes_leaf: number of sum nodes per leaf region\nnum_nodes_region: number of in each region except root and leaves\nnum_splits: number of splits for each parition; split variables into random equaly sized regions\n\n\n\n\n\n","category":"function"},{"location":"api/common/#Learning-Circuit-Parameters","page":"Common APIs","title":"Learning Circuit Parameters","text":"","category":"section"},{"location":"api/common/","page":"Common APIs","title":"Common APIs","text":"mini_batch_em\nfull_batch_em","category":"page"},{"location":"api/common/#ProbabilisticCircuits.mini_batch_em","page":"Common APIs","title":"ProbabilisticCircuits.mini_batch_em","text":"mini_batch_em(bpc::CuBitsProbCircuit, raw_data::CuArray, num_epochs; batch_size, pseudocount,\n param_inertia, param_inertia_end = param_inertia, shuffle=:each_epoch)\n\nUpdate the parameters of the CuBitsProbCircuit by doing EM, update the parameters after each batch.\n\n\n\n\n\n","category":"function"},{"location":"api/common/#ProbabilisticCircuits.full_batch_em","page":"Common APIs","title":"ProbabilisticCircuits.full_batch_em","text":"full_batch_em(bpc::CuBitsProbCircuit, raw_data::CuArray, num_epochs; batch_size, pseudocount)\n\nUpdate the paramters of the CuBitsProbCircuit by doing EM on the full batch (i.e. update paramters at the end of each epoch).\n\n\n\n\n\n","category":"function"},{"location":"api/common/#Circuit-Queries","page":"Common APIs","title":"Circuit Queries","text":"","category":"section"},{"location":"api/common/","page":"Common APIs","title":"Common APIs","text":"loglikelihoods\nMAP\nsample","category":"page"},{"location":"api/common/#ProbabilisticCircuits.loglikelihoods","page":"Common APIs","title":"ProbabilisticCircuits.loglikelihoods","text":"loglikelihoods(bpc::CuBitsProbCircuit, data::CuArray; batch_size, mars_mem = nothing)\n\nReturns loglikelihoods for each datapoint on gpu. Missing values should be denoted by missing.\n\nbpc: BitCircuit on gpu\ndata: CuArray{Union{Missing, data_types...}}\nbatch_size\nmars_mem: Not required, advanced usage. CuMatrix to reuse memory and reduce allocations. See prep_memory and cleanup_memory.\n\n\n\n\n\nloglikelihoods(pc::ProbCircuit, data::Matrix)\n\nComputes loglikelihoods of the circuit over the data on cpu. Linearizes the circuit and computes the marginals in batches.\n\n\n\n\n\n","category":"function"},{"location":"api/common/#ProbabilisticCircuits.MAP","page":"Common APIs","title":"ProbabilisticCircuits.MAP","text":"MAP(bpc::CuBitsProbCircuit, data::CuArray; batch_size, mars_mem=nothing)\n\nRetruns the MAP states for a given circuit and data on gpu. Missing values should be denoted as missing.\n\nNote that the MAP states are exact only when the circuit is both decomposable and deterministic, otherwise its just an approximation.\n\nbpc: BitCircuit on gpu\ndata: CuArray{Union{Missing, data_types...}}\nbatch_size\nmars_mem: Not required, advanced usage. CuMatrix to reuse memory and reduce allocations. See prep_memory and cleanup_memory.\n\n\n\n\n\nMAP(pc::ProbCircuit, data::Matrix; batch_size, Float=Float32)\n\nEvaluate max a posteriori (MAP) state of the circuit for given input(s) on cpu.\n\nNote: 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.\n\n\n\n\n\n","category":"function"},{"location":"api/common/#ProbabilisticCircuits.sample","page":"Common APIs","title":"ProbabilisticCircuits.sample","text":"sample(bpc::CuBitsProbCircuit, num_samples::Int, num_rand_vars::Int, types; rng=default_rng())\n\nGenerate num_samples from the joint distribution of the circuit without any conditions. Samples are genearted on the GPU. \n\nbpc: Circuit on gpu (CuBitProbCircuit)\nnum_samples: how many samples to generate\nnum_rand_vars: number of random variables in the circuit\ntypes: Array of possible input types\nrng: (Optional) Random Number Generator\n\nThe size of returned Array is (num_samples, 1, size(data, 2)).\n\n\n\n\n\nsample(bpc::CuBitsProbCircuit, num_samples, data::CuMatrix; rng=default_rng())\n\nGenerate num_samples for each datapoint in data from the joint distribution of the circuit conditioned on the data. Samples are generated using GPU. \n\nbpc: Circuit on gpu (CuBitProbCircuit)\nnum_samples: how many samples to generate\nrng: (Optional) Random Number Generator\n\nThe size of returned CuArray is (num_samples, size(data, 1), size(data, 2)).\n\n\n\n\n\nsample(pc::ProbCircuit, num_samples; rng = default_rng())\n\nGenerate num_samples from the joint distribution of the circuit without any conditions. Samples are generated on the CPU.\n\n\n\n\n\nsample(pc::ProbCircuit, num_samples, data::Matrix;; batch_size, rng = default_rng())\n\nGenerate num_samples from the joint distribution of the circuit conditioned on the data.\n\n\n\n\n\n","category":"function"},{"location":"manual/gpu/#man-gpu","page":"GPU Support","title":"GPU Support","text":"","category":"section"},{"location":"manual/gpu/","page":"GPU Support","title":"GPU Support","text":"Most queries and learning APIs support both CPU and GPU implementations. To use the GPU implementations you need to move the circuit and the dataset to GPU, then call the corresponding API.","category":"page"},{"location":"manual/gpu/#Moving-to-GPU","page":"GPU Support","title":"Moving to GPU","text":"","category":"section"},{"location":"manual/gpu/#Moving-Data-to-GPU","page":"GPU Support","title":"Moving Data to GPU","text":"","category":"section"},{"location":"manual/gpu/","page":"GPU Support","title":"GPU Support","text":"Currently, the APIs support CuArray type of gpu implemetations. One simple way to move to gpu is using the cu function from CUDA.jl.","category":"page"},{"location":"manual/gpu/","page":"GPU Support","title":"GPU Support","text":"using CUDA\ntrain_x_gpu, test_x_gpu = cu.(train_x, test_x)","category":"page"},{"location":"manual/gpu/","page":"GPU Support","title":"GPU Support","text":"In case of missing values we use Missing type, so for example if you have categorical features with some missing values, the data type on gpu would be CuArray{Union{Missing, UInt32}}.","category":"page"},{"location":"manual/gpu/#Moving-ProbCircuits-to-GPU","page":"GPU Support","title":"Moving ProbCircuits to GPU","text":"","category":"section"},{"location":"manual/gpu/","page":"GPU Support","title":"GPU Support","text":"ProbCircuits are stored in DAG structure and are not GPU friendly by default. So, we convert them into BitsProbCircuits (or bit circuits) as a lower level representation that is GPU friendly. The GPU version of bit circuits has type CuBitsProbCircuit, so to move your circuit to GPU you can simply do:","category":"page"},{"location":"manual/gpu/","page":"GPU Support","title":"GPU Support","text":"bpc = CuBitsProbCircuit(circuit);","category":"page"},{"location":"manual/gpu/#GPU-APIs","page":"GPU Support","title":"GPU APIs","text":"","category":"section"},{"location":"manual/gpu/","page":"GPU Support","title":"GPU Support","text":"The GPU supported APIs generally have the same name as their CPU counterpart, for a comprehensive list of supported functions see the API documentation. For example, we support the following on gpu:","category":"page"},{"location":"manual/gpu/","page":"GPU Support","title":"GPU Support","text":"sample\nMAP\nloglikelihoods\nmini_batch_em\nfull_batch_em","category":"page"},{"location":"api/types/#api-types","page":"Types ","title":"Types ","text":"","category":"section"},{"location":"api/types/","page":"Types ","title":"Types ","text":"The following code snippet provides an easy way to print the type tree of probabilistic circuits.","category":"page"},{"location":"api/types/","page":"Types ","title":"Types ","text":"using InteractiveUtils;\nusing ProbabilisticCircuits;\nusing AbstractTrees;\nAbstractTrees.children(x::Type) = subtypes(x);","category":"page"},{"location":"api/types/","page":"Types ","title":"Types ","text":"For example, we can see ProbabilisticCircuits.ProbCircuit's type tree.","category":"page"},{"location":"api/types/","page":"Types ","title":"Types ","text":"AbstractTrees.print_tree(ProbCircuit)","category":"page"},{"location":"api/types/","page":"Types ","title":"Types ","text":"AbstractTrees.print_tree(InputDist)","category":"page"},{"location":"manual/queries/#man-queries","page":"Queries","title":"Queries","text":"","category":"section"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"In this section, we go over most common probabilistic reasoning tasks, and provide code snippets to compute those queries.","category":"page"},{"location":"manual/queries/#Setup","page":"Queries","title":"Setup","text":"","category":"section"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"First, we load some pretrained PC, and the corresponding data.","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"# This is needed to hide output from downloading artifacts\nusing CircuitModelZoo; #hide\nusing ProbabilisticCircuits; #hide\nusing DensityEstimationDatasets; #hide\npc = read(zoo_psdd_file(\"plants.psdd\"), ProbCircuit);\ndata, _, _ = twenty_datasets(\"plants\");","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"using CircuitModelZoo: zoo_psdd_file\nusing DensityEstimationDatasets: twenty_datasets\nusing ProbabilisticCircuits\nusing Tables\n\npc = read(zoo_psdd_file(\"plants.psdd\"), ProbCircuit);\ndata, _, _ = twenty_datasets(\"plants\");\ndata = Tables.matrix(data);\nprintln(\"circuit with $(num_nodes(pc)) nodes and $(num_parameters(pc)) parameters.\")\nprintln(\"dataset with $(size(data, 2)) features and $(size(data, 1)) examples.\")","category":"page"},{"location":"manual/queries/#Full-Evidence-(EVI)","page":"Queries","title":"Full Evidence (EVI)","text":"","category":"section"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"EVI refers to computing the probability when full evidence is given, i.e. when x is fully observed, the output is p(x). We can use loglikelihoods method to compute logp(x):","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"probs = loglikelihoods(pc, data[1:100, :]; batch_size=64);\nprobs[1:3]","category":"page"},{"location":"manual/queries/#Partial-Evidence-(MAR)","page":"Queries","title":"Partial Evidence (MAR)","text":"","category":"section"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"In this case we have some missing values. Let x^o denote the observed features, and x^m the missing features. We would like to compute p(x^o) which is defined as p(x^o) = sum_x^m p(x^o x^m). Of course, computing this directly by summing over all possible ways to fill the missing values is not tractable. ","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"The good news is that given a smooth and decomposable PC, the marginal can be computed exactly and in linear time to the size of the PC.","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"First, we randomly make some features go missing.","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"using DataFrames\nusing Tables\nfunction make_missing(d; keep_prob=0.8)\n m = missings(Bool, size(d)...)\n flag = rand(size(d)...) .<= keep_prob\n m[flag] .= d[flag]\n return m\nend;\ndata_miss = make_missing(data[1:1000,:]);\nnothing #hide","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"Now, we can use loglikelihoods to compute the marginal queries.","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"probs = loglikelihoods(pc, data_miss; batch_size=64);\nprobs[1:3]","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"Note that loglikelihoods can also be used to compute probabilisties if all data is observed, as we saw in previous section.","category":"page"},{"location":"manual/queries/#Conditionals-(CON)","page":"Queries","title":"Conditionals (CON)","text":"","category":"section"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"In this case, given observed features x^o, we would like to compute p(Q mid x^o), where Q is a subset of features disjoint with x^o. We can use Bayes rule to compute conditionals as two seperate MAR queries as follows:","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"p(q mid x^o) = cfracp(q x^o)p(x^o)","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"Currently, this has to be done manually by the user. We plan to add a simple API for this case in the future.","category":"page"},{"location":"manual/queries/#Maximum-a-posteriori-(MAP,-MPE)","page":"Queries","title":"Maximum a posteriori (MAP, MPE)","text":"","category":"section"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"In this case, given the observed features x^o the goal is to fill out the missing features in a way that p(x^m x^o) is maximized.","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"We can use the MAP method to compute MAP, which outputs the states that maximize the probability and the log-likelihoods of each state.","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"data_miss = make_missing(data[1:1000,:], keep_prob=0.5);\nstates = MAP(pc, data_miss; batch_size = 64);\nsize(states)","category":"page"},{"location":"manual/queries/#Sampling","page":"Queries","title":"Sampling","text":"","category":"section"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"We can also sample from the distrubtion p(x) defined by a Probabilistic Circuit. You can use sample to achieve this task.","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"samples = sample(pc, 100, [Bool]);\nsize(samples)","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"Additionally, we can do conditional samples x sim p(x mid x^o), where x^o are the observed features (x^o subseteq x), and could be any arbitrary subset of features.","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"#3 random evidences for the examples\nevidence = rand( (missing,true,false), (2, num_randvars(pc)));\n\nsamples = sample(pc, 3, evidence; batch_size = 2);\nsize(samples)","category":"page"},{"location":"manual/learning/#man-learning","page":"Learning","title":"Learning","text":"","category":"section"},{"location":"manual/learning/","page":"Learning","title":"Learning","text":"In this section we provide few learning scenarios for circuits. In general, learning tasks for PCs can be separted into two categories: parameter learning and structure learning.","category":"page"},{"location":"manual/learning/#Structures","page":"Learning","title":"Structures","text":"","category":"section"},{"location":"manual/learning/","page":"Learning","title":"Learning","text":"Currently we are supporting the following structures:","category":"page"},{"location":"manual/learning/","page":"Learning","title":"Learning","text":"HiddenChowLiuTrees: See hclt.\nRAT-SPNs: See RAT.","category":"page"},{"location":"manual/learning/#Parameter-Learning","page":"Learning","title":"Parameter Learning","text":"","category":"section"},{"location":"manual/learning/","page":"Learning","title":"Learning","text":"Currently we are supporting the following parameters learning APIs:","category":"page"},{"location":"manual/learning/","page":"Learning","title":"Learning","text":"mini_batch_em\nfull_batch_em","category":"page"},{"location":"manual/learning/#Future-Docs","page":"Learning","title":"Future Docs","text":"","category":"section"},{"location":"manual/learning/","page":"Learning","title":"Learning","text":"Learning a circuit from missing data\nLearn a mixture of circuits\nLearn a circuit from logical constraints and data","category":"page"},{"location":"installation/#Installation","page":"Installation","title":"Installation","text":"","category":"section"},{"location":"installation/#Prerequisites","page":"Installation","title":"Prerequisites","text":"","category":"section"},{"location":"installation/","page":"Installation","title":"Installation","text":"Julia 1.6 or greater. For installation, please refer to the official Julia Website.","category":"page"},{"location":"installation/#Installing-ProbabilisticCircuits","page":"Installation","title":"Installing ProbabilisticCircuits","text":"","category":"section"},{"location":"installation/","page":"Installation","title":"Installation","text":"You can use Julia's package manager, Pkg, to install this module and its dependencies. There are different options on how to do that, for example through command line or julia REPL. For more information and options on how to use Julia pacakge manager, please refer to Pkg's Documentation.","category":"page"},{"location":"installation/#From-Command-Line","page":"Installation","title":"From Command Line","text":"","category":"section"},{"location":"installation/","page":"Installation","title":"Installation","text":"To install the latest stable release, run:","category":"page"},{"location":"installation/","page":"Installation","title":"Installation","text":"julia -e 'using Pkg; Pkg.add(\"ProbabilisticCircuits\")'","category":"page"},{"location":"installation/","page":"Installation","title":"Installation","text":"You can also install the package with the latest commits on master branch.","category":"page"},{"location":"installation/","page":"Installation","title":"Installation","text":"julia -e 'using Pkg; Pkg.add([PackageSpec(url=\"https://github.com/Juice-jl/ProbabilisticCircuits.jl.git\")])'","category":"page"},{"location":"installation/#From-Package-mode","page":"Installation","title":"From Package mode","text":"","category":"section"},{"location":"installation/","page":"Installation","title":"Installation","text":"note: Note\nTo get to Pkg mode, you need to run julia, then to press ]. Press backspace or ^C to get back to normal REPL mode.","category":"page"},{"location":"installation/","page":"Installation","title":"Installation","text":"While in Pkg mode, run the following to install the latest release:","category":"page"},{"location":"installation/","page":"Installation","title":"Installation","text":"add ProbabilisticCircuits","category":"page"},{"location":"installation/","page":"Installation","title":"Installation","text":"Similarly, to install from the latest commits on master branch, run:","category":"page"},{"location":"installation/","page":"Installation","title":"Installation","text":"add ProbabilisticCircuits#master","category":"page"},{"location":"installation/#Testing","page":"Installation","title":"Testing","text":"","category":"section"},{"location":"installation/","page":"Installation","title":"Installation","text":"If you are installing the latest commit, we recommend running the test suite to make sure everything is in order, to do that run:","category":"page"},{"location":"installation/","page":"Installation","title":"Installation","text":"julia --color=yes -e 'using Pkg; Pkg.test(\"ProbabilisticCircuits\")'","category":"page"},{"location":"installation/","page":"Installation","title":"Installation","text":"Note: If you want the tests to run faster, you can use multiple cores. To do that set the following environment variable (default = 1 core):","category":"page"},{"location":"installation/","page":"Installation","title":"Installation","text":"export JIVE_PROCS=8","category":"page"},{"location":"api/probabilistic_circuits/#api-internal-probabilistic","page":"Probabilistic Circuits","title":"Probabilistic Circuits","text":"","category":"section"},{"location":"api/probabilistic_circuits/","page":"Probabilistic Circuits","title":"Probabilistic Circuits","text":"This page lists all the API documentation for ProbabilisticCircuits package.","category":"page"},{"location":"api/probabilistic_circuits/","page":"Probabilistic Circuits","title":"Probabilistic Circuits","text":"Modules = [ProbabilisticCircuits]","category":"page"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.Categorical","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.Categorical","text":"A N-value categorical input distribution ranging over integers [0...N-1]\n\n\n\n\n\n","category":"type"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.FlatVectors","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.FlatVectors","text":"An isbits representation of a AbstractVector{<:AbstractVector}\n\n\n\n\n\n","category":"type"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.Indicator","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.Indicator","text":"A input distribution node that places all probability on a single value\n\n\n\n\n\n","category":"type"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.Literal","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.Literal","text":"A logical literal input distribution node\n\n\n\n\n\n","category":"type"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.NodeType","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.NodeType","text":"Probabilistic circuit node types\n\n\n\n\n\n","category":"type"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.NodeType-Tuple{ProbCircuit}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.NodeType","text":"Get the probabilistic circuit node type\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.PlainInnerNode","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.PlainInnerNode","text":"A probabilistic inner node\n\n\n\n\n\n","category":"type"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.PlainInputNode","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.PlainInputNode","text":"A probabilistic input node\n\n\n\n\n\n","category":"type"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.PlainMulNode","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.PlainMulNode","text":"A probabilistic multiplication node\n\n\n\n\n\n","category":"type"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.PlainProbCircuit","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.PlainProbCircuit","text":"Root of the plain probabilistic circuit node hierarchy\n\n\n\n\n\n","category":"type"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.PlainSumNode","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.PlainSumNode","text":"A probabilistic summation node\n\n\n\n\n\n","category":"type"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.ProbCircuit","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.ProbCircuit","text":"Root of the probabilistic circuit node hierarchy\n\n\n\n\n\n","category":"type"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.RegionGraph","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.RegionGraph","text":"Root of region graph node hierarchy\n\n\n\n\n\n","category":"type"},{"location":"api/probabilistic_circuits/#Base.read-Union{Tuple{C}, Tuple{AbstractString, Type{C}}} where C<:ProbCircuit","page":"Probabilistic Circuits","title":"Base.read","text":"Base.read(file::AbstractString, ::Type{C}) where C <: ProbCircuit\n\nReads circuit from file; uses extension to detect format type, for example \".psdd\" for PSDDs.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#Base.write-Tuple{AbstractString, ProbCircuit}","page":"Probabilistic Circuits","title":"Base.write","text":"Base.write(file::AbstractString, circuit::ProbCircuit)\n\nWrites circuit to file; uses file name extention to detect file format.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#DirectedAcyclicGraphs.foldup-Union{Tuple{T}, Tuple{ProbCircuit, Function, Function, Function, Type{T}}, Tuple{ProbCircuit, Function, Function, Function, Type{T}, Any}} where T","page":"Probabilistic Circuits","title":"DirectedAcyclicGraphs.foldup","text":"foldup(node::ProbCircuit, \n f_i::Function, \n f_m::Function, \n f_s::Function)::T where {T}\n\nCompute a function bottom-up on the circuit. f_in is called on input nodes, f_m is called on product nodes, and f_s is called on sum nodes. Values of type T are passed up the circuit and given to f_m and f_s through a callback from the children.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#DirectedAcyclicGraphs.foldup_aggregate-Union{Tuple{T}, Tuple{ProbCircuit, Function, Function, Function, Type{T}}, Tuple{ProbCircuit, Function, Function, Function, Type{T}, Any}} where T","page":"Probabilistic Circuits","title":"DirectedAcyclicGraphs.foldup_aggregate","text":"foldup_aggregate(node::ProbCircuit, \n f_i::Function, \n f_m::Function, \n f_s::Function, \n ::Type{T})::T where T\n\nCompute a function bottom-up on the circuit. f_in is called on input nodes, f_m is called on product nodes, and f_s is called on sum nodes. Values of type T are passed up the circuit and given to f_m and f_s in an aggregate vector from the children.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.MAP-Tuple{CuBitsProbCircuit, CUDA.CuArray}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.MAP","text":"MAP(bpc::CuBitsProbCircuit, data::CuArray; batch_size, mars_mem=nothing)\n\nRetruns the MAP states for a given circuit and data on gpu. Missing values should be denoted as missing.\n\nNote that the MAP states are exact only when the circuit is both decomposable and deterministic, otherwise its just an approximation.\n\nbpc: BitCircuit on gpu\ndata: CuArray{Union{Missing, data_types...}}\nbatch_size\nmars_mem: Not required, advanced usage. CuMatrix to reuse memory and reduce allocations. See prep_memory and cleanup_memory.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.MAP-Tuple{ProbCircuit, Matrix}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.MAP","text":"MAP(pc::ProbCircuit, data::Matrix; batch_size, Float=Float32)\n\nEvaluate max a posteriori (MAP) state of the circuit for given input(s) on cpu.\n\nNote: 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.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.RAT-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.RAT","text":"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)\n\nGenerate 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.\n\nnum_features: Number of features in the dataset, assuming x1...xn\ninput_func: Function to generate a new input node for variable when calling input_func(var).\n\nThe list of hyperparamters are:\n\nrg_depth: how many layers to do splits in the region graph\nrg_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)\nnum_nodes_root: number of sum nodes in the root region\nnum_nodes_leaf: number of sum nodes per leaf region\nnum_nodes_region: number of in each region except root and leaves\nnum_splits: number of splits for each parition; split variables into random equaly sized regions\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.RAT_InputFunc-Tuple{Type, Vararg{Any}}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.RAT_InputFunc","text":"Default input_func for different types. This function returns another function input_func. Then input_func(var) should generate a new input function with the desired distribution.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.balance_sum-Tuple{Vector{ProbCircuit}, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.balance_sum","text":"Makes sure the sum nodes does not have too many children. Makes balanced sums of sums to reduce children count.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.balanced_fully_factorized_leaves-Tuple{AbstractVector}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.balanced_fully_factorized_leaves","text":"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.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.bits-Tuple{InputDist, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.bits","text":"bits(d::InputDist, heap)\n\nAppends the required memory for this input dist to the heap.\n\nUsed internally for moving from CPU to GPU.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.cleanup_memory-Tuple{CUDA.CuArray, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.cleanup_memory","text":"Cleansup allocated memory. Used internally.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.clear_memory-Tuple{InputDist, Any, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.clear_memory","text":"clear_memory(d::InputDist, heap, rate)\n\nClears the accumulated flow values on the heap by multiplying it by rate. rate == 0.0 will be equivalent to initializing the value to 0.0.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.dist","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.dist","text":"Get the distribution of a PC input node\n\n\n\n\n\n","category":"function"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.eval_circuit!-Tuple{Any, AbstractVector{<:ProbCircuit}, Matrix, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.eval_circuit!","text":"eval_circuit!(mars, linPC::AbstractVector{<:ProbCircuit}, data::Matrix, example_ids; node2idx::Dict{ProbCircuit, UInt32}, Float=Float32)\n\nUsed internally. Evaluates the marginals of the circuit on cpu. Stores the values in mars.\n\nmars: (batch_size, nodes)\nlinPC: linearized PC. (i.e. linearize(pc))\ndata: data Matrix (num_examples, features)\nexample_ids: Array or collection of ids for current batch\nnode2idx: Index of each ProbCircuit node in the linearized circuit\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.eval_circuit_max!-Tuple{Any, AbstractVector{<:ProbCircuit}, Matrix, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.eval_circuit_max!","text":"eval_circuit_max!(mars, linPC::AbstractVector{<:ProbCircuit}, data::Matrix, example_ids; node2idx::Dict{ProbCircuit, UInt32}, Float=Float32)\n\nUsed internally. Evaluates the MAP upward pass of the circuit on cpu. Stores the values in mars.\n\nmars: (batch_size, nodes)\nlinPC: linearized PC. (i.e. linearize(pc))\ndata: data Matrix (num_examples, features)\nexample_ids: Array or collection of ids for current batch\nnode2idx: Index of each ProbCircuit node in the linearized circuit\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.flow-Tuple{InputDist, Any, Any, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.flow","text":"flow(d::InputDist, value, node_flow, heap)\n\nUpdates the \"flow\" values in the heap for the input node.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.full_batch_em-Tuple{CuBitsProbCircuit, CUDA.CuArray, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.full_batch_em","text":"full_batch_em(bpc::CuBitsProbCircuit, raw_data::CuArray, num_epochs; batch_size, pseudocount)\n\nUpdate the paramters of the CuBitsProbCircuit by doing EM on the full batch (i.e. update paramters at the end of each epoch).\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.hclt-Tuple{Any, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.hclt","text":"hclt(data, num_hidden_cats; num_cats = nothing, input_type = LiteralDist)\n\nLearns HiddenChowLiuTree (hclt) circuit structure from data.\n\ndata: Matrix or CuMatrix\nnum_hidden_cats: Number of categories in hidden variables\ninput_type: Distribution type for the inputs\nnum_cats: Number of categories (in case of categorical inputs). Automatically deduced if not given explicilty.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.init_heap_map_loglikelihood!-Tuple{InputDist, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.init_heap_map_loglikelihood!","text":"init_heap_map_loglikelihood!(d::InputDist, heap)\n\nInitializes the heap for the input dist. Called before running MAP queries.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.init_heap_map_state!-Tuple{InputDist, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.init_heap_map_state!","text":"init_heap_map_state!(d::InputDist, heap)\n\nInitializes the heap for the input dist. Called before running MAP queries.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.init_parameters-Tuple{ProbCircuit}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.init_parameters","text":"init_parameters(pc::ProbCircuit; perturbation = 0.0)\n\nInitialize parameters of ProbCircuit.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.init_params-Tuple{InputDist, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.init_params","text":"init_params(d::InputDist, perturbation)\n\nReturns a new distribution with same type with initialized parameters.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.inputnodes-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.inputnodes","text":"Get all input nodes in a given circuit\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.inputs-Tuple{Any, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.inputs","text":"Get the inputs of a PC node\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.isinput-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.isinput","text":"Is the node an input node?\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.ismul-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.ismul","text":"Is the node a multiplication?\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.isonlysubedge-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.isonlysubedge","text":"whether this sub edge is the only outgoing edge from sub\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.ispartial-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.ispartial","text":"whether this series of edges is partial or complete\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.issum-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.issum","text":"Is the node a summation?\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.loglikelihood-Tuple{CuBitsProbCircuit, CUDA.CuArray}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.loglikelihood","text":"loglikelihood(bpc::CuBitsProbCircuit, data::CuArray; batch_size, mars_mem = nothing)\n\nComputes Average loglikelihood of circuit given the data using gpu. See loglikelihoods for more details.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.loglikelihood-Tuple{InputDist, Any, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.loglikelihood","text":"loglikelihood(d::InputDist, value, heap)\n\nReturns the log( P(input_var == value) ) according to the InputDist.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.loglikelihood-Tuple{ProbCircuit, Matrix, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.loglikelihood","text":"loglikelihood(root::ProbCircuit, data::Matrix, example_id; Float=Float32)\n\nComputes marginal loglikelihood recursively on cpu for a single instance data[example_id, :].\n\nNote: Quite slow, only use for demonstration/educational purposes. \n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.loglikelihoods-Tuple{CuBitsProbCircuit, CUDA.CuArray}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.loglikelihoods","text":"loglikelihoods(bpc::CuBitsProbCircuit, data::CuArray; batch_size, mars_mem = nothing)\n\nReturns loglikelihoods for each datapoint on gpu. Missing values should be denoted by missing.\n\nbpc: BitCircuit on gpu\ndata: CuArray{Union{Missing, data_types...}}\nbatch_size\nmars_mem: Not required, advanced usage. CuMatrix to reuse memory and reduce allocations. See prep_memory and cleanup_memory.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.loglikelihoods-Tuple{ProbCircuit, Matrix}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.loglikelihoods","text":"loglikelihoods(pc::ProbCircuit, data::Matrix)\n\nComputes loglikelihoods of the circuit over the data on cpu. Linearizes the circuit and computes the marginals in batches.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.loglikelihoods_vectorized-Tuple{ProbCircuit, Matrix}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.loglikelihoods_vectorized","text":"Note: Experimental**; will be removed or renamed later\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.map_down_rec!-Tuple{Any, ProbCircuit, Any, Matrix, Any, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.map_down_rec!","text":"map_down_rec!(mars, node::ProbCircuit, data, states::Matrix, batch_idx, example_idx; node2idx::Dict{ProbCircuit, UInt32}, Float=Float32)\n\nDownward pass on cpu for MAP. Recursively chooses the best (max) sum node children according to the \"MAP upward pass\" values. Updates the missing values with map_state of that input node.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.map_loglikelihood-Tuple{InputDist, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.map_loglikelihood","text":"map_loglikelihood(d::InputDist, heap)\n\nReturns the MAP loglikelihoods the most likely state of the InputDist d\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.map_state-Tuple{InputDist, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.map_state","text":"map_state(d::InputDist, heap)\n\nReturns the MAP state for the InputDist d\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.mini_batch_em-Tuple{CuBitsProbCircuit, CUDA.CuArray, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.mini_batch_em","text":"mini_batch_em(bpc::CuBitsProbCircuit, raw_data::CuArray, num_epochs; batch_size, pseudocount,\n param_inertia, param_inertia_end = param_inertia, shuffle=:each_epoch)\n\nUpdate the parameters of the CuBitsProbCircuit by doing EM, update the parameters after each batch.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.mulnodes-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.mulnodes","text":"Get all multiplication nodes in a given circuit\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.multiply","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.multiply","text":"Multiply nodes into a single circuit\n\n\n\n\n\n","category":"function"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.num_inputs-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.num_inputs","text":"Number of inputs of a PC node\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.num_parameters","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.num_parameters","text":"Count the number of parameters in the circuit\n\n\n\n\n\n","category":"function"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.num_parameters-Tuple{InputDist, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.num_parameters","text":"num_parameters(d::InputDist, independent)\n\nReturns number of parameters for the input dist.\n\nindependent: whether to only count independent parameters\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.num_parameters_node-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.num_parameters_node","text":"Count the number of parameters in the node\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.num_randvars-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.num_randvars","text":"Number of variables in the data structure\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.params-Tuple{InputDist}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.params","text":"params(d::InputDist)\n\nReturns paramters of the input dist.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.params-Tuple{ProbCircuit}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.params","text":"Get the parameters associated with a node\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.prep_memory","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.prep_memory","text":"prep_memory(reuse, sizes, exact = map(x -> true, sizes))\n\nMostly used internally. Prepares memory for the specifed size, reuses reuse if possible to avoid memory allocation/deallocation.\n\n\n\n\n\n","category":"function"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.psdd_num_nodes_leafs-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.psdd_num_nodes_leafs","text":"Count the number of decision and leaf nodes in the PSDD\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.random_region_graph-Tuple{AbstractVector}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.random_region_graph","text":"random_region_graph(X::AbstractVector, depth::Int = 5, replicas::Int = 2, num_splits::Int = 2)\n\nX: Vector of all variables to include; for the root region\ndepth: how many layers to do splits\nreplicas: 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)\nnum_splits: number of splits for each parition; split variables into random equaly sized regions\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.randvars","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.randvars","text":"variables(pc::ProbCircuit)::BitSet\n\nGet a bitset of variables mentioned in the circuit.\n\n\n\n\n\n","category":"function"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.region_graph_2_pc-Tuple{RegionGraph}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.region_graph_2_pc","text":"region_graph_2_pc(node::RegionGraph; num_nodes_root, num_nodes_region, num_nodes_leaf, balance_childs_parents)\n\nnum_nodes_root: number of sum nodes in the root region\nnum_nodes_leaf: number of sum nodes per leaf region\nnum_nodes_region: number of in each region except root and leaves\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.sample-Tuple{CuBitsProbCircuit, Any, CUDA.CuArray{T, 2} where T}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.sample","text":"sample(bpc::CuBitsProbCircuit, num_samples, data::CuMatrix; rng=default_rng())\n\nGenerate num_samples for each datapoint in data from the joint distribution of the circuit conditioned on the data. Samples are generated using GPU. \n\nbpc: Circuit on gpu (CuBitProbCircuit)\nnum_samples: how many samples to generate\nrng: (Optional) Random Number Generator\n\nThe size of returned CuArray is (num_samples, size(data, 1), size(data, 2)).\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.sample-Tuple{CuBitsProbCircuit, Int64, Int64, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.sample","text":"sample(bpc::CuBitsProbCircuit, num_samples::Int, num_rand_vars::Int, types; rng=default_rng())\n\nGenerate num_samples from the joint distribution of the circuit without any conditions. Samples are genearted on the GPU. \n\nbpc: Circuit on gpu (CuBitProbCircuit)\nnum_samples: how many samples to generate\nnum_rand_vars: number of random variables in the circuit\ntypes: Array of possible input types\nrng: (Optional) Random Number Generator\n\nThe size of returned Array is (num_samples, 1, size(data, 2)).\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.sample-Tuple{ProbCircuit, Any, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.sample","text":"sample(pc::ProbCircuit, num_samples; rng = default_rng())\n\nGenerate num_samples from the joint distribution of the circuit without any conditions. Samples are generated on the CPU.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.sample-Tuple{ProbCircuit, Any, Matrix}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.sample","text":"sample(pc::ProbCircuit, num_samples, data::Matrix;; batch_size, rng = default_rng())\n\nGenerate num_samples from the joint distribution of the circuit conditioned on the data.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.sample_state-Tuple{InputDist, Any, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.sample_state","text":"sample_state(d::InputDist, threshold::Float32, heap)\n\nReturns a sample from InputDist. Threshold is a uniform random value in range (0, 1) given to this API by the sampleing algorithm\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.soften_data-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.soften_data","text":"Turn binary data into floating point data close to 0 and 1.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.summate","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.summate","text":"Sum nodes into a single circuit\n\n\n\n\n\n","category":"function"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.sumnodes-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.sumnodes","text":"Get all summation nodes in a given circuit\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.unbits-Tuple{InputDist, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.unbits","text":"unbits(d::InputDist, heap)\n\nReturns the InputDist struct from the heap. Note, each input dist type needs to store where in the heap its paramters are to be able to do this.\n\nUsed internally for moving from GPU to CPU.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.update_parameters-Tuple{ProbabilisticCircuits.AbstractBitsProbCircuit}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.update_parameters","text":"map parameters from BitsPC back to the ProbCircuit it was created from\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.update_params-Tuple{InputDist, Any, Any, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.update_params","text":"update_params(d::InputDist, heap, pseudocount, inertia)\n\nUpdate the parameters of the InputDist using stored values on the heap and (pseudocount, inertia)\n\n\n\n\n\n","category":"method"},{"location":"manual/demo/#man-demo","page":"Quick Demo","title":"Quick Demo","text":"","category":"section"},{"location":"manual/demo/","page":"Quick Demo","title":"Quick Demo","text":"In this section, we provide quick code snippets to get started with ProbabilisticCircuits and provide basic understanding of them. PCs are represented as a computational graphs that define a joint probability distribution as recursive mixtures (sum units) and factorizations (product units) of simpler distributions (input units).","category":"page"},{"location":"manual/demo/","page":"Quick Demo","title":"Quick Demo","text":"Generally, we learn structure and parameters of circuit from data. Alternatively, we can also specify circuits in code. For example, the following snippet defines a circuit depending on 3 random variables. The literals function returns the input units of the circuit, in this case we get 6 different units (3 for positive literals, and 3 for negative literlas). You can use * and + operators to build a circuits.","category":"page"},{"location":"manual/demo/","page":"Quick Demo","title":"Quick Demo","text":"using ProbabilisticCircuits;\n\nX1, X2, X3 = [InputNode(i, Indicator(true)) for i=1:3]\nX1_, X2_, X3_ = [InputNode(i, Indicator(false)) for i=1:3]\n\npc = 0.3 * (X1_ *\n (0.2 * X2_ + 0.8 * X3)) +\n 0.7 * (X1 *\n (0.4 * X2 + 0.6 * X3_));\n\nnothing # hide","category":"page"},{"location":"manual/demo/","page":"Quick Demo","title":"Quick Demo","text":"You can ask basic questions about PCs, such as (1) how many variables they depends on, (2) how many nodes, (3) how many edges, (4) or how many parameters they have.","category":"page"},{"location":"manual/demo/","page":"Quick Demo","title":"Quick Demo","text":"num_randvars(pc)","category":"page"},{"location":"manual/demo/","page":"Quick Demo","title":"Quick Demo","text":"num_nodes(pc)","category":"page"},{"location":"manual/demo/","page":"Quick Demo","title":"Quick Demo","text":"num_edges(pc)","category":"page"},{"location":"manual/demo/","page":"Quick Demo","title":"Quick Demo","text":"num_parameters(pc)","category":"page"},{"location":"manual/demo/","page":"Quick Demo","title":"Quick Demo","text":"We can also plot circuits using plot(pc) to see the computation graph (structure and parameters). The output of plot(pc) has a type of TikzPictures.TikzPicture. Generally, notebooks automatically renders it and you see the figure in the notebook. ","category":"page"},{"location":"manual/demo/","page":"Quick Demo","title":"Quick Demo","text":"plot(pc)","category":"page"},{"location":"manual/demo/","page":"Quick Demo","title":"Quick Demo","text":"However, if you are not using a notebook or want to save to file you can use the following commands to save the plot in various formats.","category":"page"},{"location":"manual/demo/","page":"Quick Demo","title":"Quick Demo","text":"using TikzPictures;\nz = plot(pc);\nsave(PDF(\"plot\"), z);\nsave(SVG(\"plot\"), z);\nsave(TEX(\"plot\"), z);\nsave(TIKZ(\"plot\"), z);","category":"page"},{"location":"#ProbabilisticCircuits.jl","page":"Home","title":"ProbabilisticCircuits.jl","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"This module provides a Julia implementation of Probabilistic Circuits (PCs), tools to learn structure and parameters of PCs from data, and tools to do tractable exact inference with them. ","category":"page"},{"location":"#What-are-Probabilistic-Circuits?","page":"Home","title":"What are Probabilistic Circuits?","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Probabilistic Circuits provides a unifying framework for several family of tractable probabilistic models. PCs are represented as a computational graphs that define a joint probability distribution as recursive mixtures (sum units) and factorizations (product units) of simpler distributions (input units).","category":"page"},{"location":"","page":"Home","title":"Home","text":"Given certain structural properties, PCs enable different range of tractable exact probabilistic queries such as computing marginals, conditionals, maximum a posteriori (MAP), and more advanced probabilistic queries.","category":"page"},{"location":"","page":"Home","title":"Home","text":"In additon to parameters, the structure of PCs can also be learned from data. There are several approaches in learning PCs, while keeping the needed structural constrains intact. Currently, This module includes implementation for few of these approaches with plans to add more over time.","category":"page"},{"location":"","page":"Home","title":"Home","text":"Additionally, parallelism (on both CPU and GPU) is leveraged to provide faster implementation of learning and inference.","category":"page"},{"location":"#Where-to-learn-more-about-them?","page":"Home","title":"Where to learn more about them?","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"For an overview of the motivation and theory behind PCs, you can start by watching the ECML-PKDD tutorial on Probabilistic Circuits. ","category":"page"},{"location":"","page":"Home","title":"Home","text":"Probabilistic Circuits: Representations, Inference, Learning and Theory (Video)","category":"page"},{"location":"","page":"Home","title":"Home","text":"For more details and additional references, you can refer to:","category":"page"},{"location":"","page":"Home","title":"Home","text":"Probabilistic Circuits: A Unifying Framework for Tractable Probabilistic Models (PDF)","category":"page"},{"location":"api/input_dists/#new-input-dist","page":"Input Distributions","title":"Input Distributions","text":"","category":"section"},{"location":"api/input_dists/","page":"Input Distributions","title":"Input Distributions","text":"Currently we support Indicator{T}, Categorical, Bernoulli (special case of Categorical) distributions in the InputNodes.","category":"page"},{"location":"api/input_dists/#Support-new-InputDist","page":"Input Distributions","title":"Support new InputDist","text":"","category":"section"},{"location":"api/input_dists/","page":"Input Distributions","title":"Input Distributions","text":"To support new type of Input Distributions you need to implement the following functions:","category":"page"},{"location":"api/input_dists/","page":"Input Distributions","title":"Input Distributions","text":"num_parameters\nparams\ninit_params\nloglikelihood","category":"page"},{"location":"api/input_dists/#Support-movement-between-CPU/GPU-for-InputDist","page":"Input Distributions","title":"Support movement between CPU/GPU for InputDist","text":"","category":"section"},{"location":"api/input_dists/","page":"Input Distributions","title":"Input Distributions","text":"To support moving between CPU/GPU you need to implement the following:","category":"page"},{"location":"api/input_dists/","page":"Input Distributions","title":"Input Distributions","text":"bits\nunbits","category":"page"},{"location":"api/input_dists/#Learning-support-for-InputDist","page":"Input Distributions","title":"Learning support for InputDist","text":"","category":"section"},{"location":"api/input_dists/","page":"Input Distributions","title":"Input Distributions","text":"To support learning you need to implement the following:","category":"page"},{"location":"api/input_dists/","page":"Input Distributions","title":"Input Distributions","text":"flow\nupdate_params\nclear_memory","category":"page"},{"location":"api/input_dists/#Query-support-for-InputDist","page":"Input Distributions","title":"Query support for InputDist","text":"","category":"section"},{"location":"api/input_dists/","page":"Input Distributions","title":"Input Distributions","text":"To support certain queries such as sampling and MAP you need to implement the following:","category":"page"},{"location":"api/input_dists/","page":"Input Distributions","title":"Input Distributions","text":"sample_state\ninit_heap_map_state!\ninit_heap_map_loglikelihood!\nmap_state\nmap_loglikelihood","category":"page"}] +[{"location":"api/common/#api-common","page":"Common APIs","title":"Common APIs","text":"","category":"section"},{"location":"api/common/","page":"Common APIs","title":"Common APIs","text":"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.","category":"page"},{"location":"api/common/","page":"Common APIs","title":"Common APIs","text":"Pages = [\"common.md\"]","category":"page"},{"location":"api/common/#Circuit-IO","page":"Common APIs","title":"Circuit IO","text":"","category":"section"},{"location":"api/common/","page":"Common APIs","title":"Common APIs","text":"read\nwrite","category":"page"},{"location":"api/common/#Base.read","page":"Common APIs","title":"Base.read","text":"Base.read(file::AbstractString, ::Type{C}) where C <: ProbCircuit\n\nReads circuit from file; uses extension to detect format type, for example \".psdd\" for PSDDs.\n\n\n\n\n\n","category":"function"},{"location":"api/common/#Base.write","page":"Common APIs","title":"Base.write","text":"Base.write(file::AbstractString, circuit::ProbCircuit)\n\nWrites circuit to file; uses file name extention to detect file format.\n\n\n\n\n\n","category":"function"},{"location":"api/common/#Circuit-Structures","page":"Common APIs","title":"Circuit Structures","text":"","category":"section"},{"location":"api/common/","page":"Common APIs","title":"Common APIs","text":"hclt\nRAT","category":"page"},{"location":"api/common/#ProbabilisticCircuits.hclt","page":"Common APIs","title":"ProbabilisticCircuits.hclt","text":"hclt(data, num_hidden_cats; num_cats = nothing, input_type = LiteralDist)\n\nLearns HiddenChowLiuTree (hclt) circuit structure from data.\n\ndata: Matrix or CuMatrix\nnum_hidden_cats: Number of categories in hidden variables\ninput_type: Distribution type for the inputs\nnum_cats: Number of categories (in case of categorical inputs). Automatically deduced if not given explicilty.\n\n\n\n\n\n","category":"function"},{"location":"api/common/#ProbabilisticCircuits.RAT","page":"Common APIs","title":"ProbabilisticCircuits.RAT","text":"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)\n\nGenerate 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.\n\nnum_features: Number of features in the dataset, assuming x1...xn\ninput_func: Function to generate a new input node for variable when calling input_func(var).\n\nThe list of hyperparamters are:\n\nrg_depth: how many layers to do splits in the region graph\nrg_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)\nnum_nodes_root: number of sum nodes in the root region\nnum_nodes_leaf: number of sum nodes per leaf region\nnum_nodes_region: number of in each region except root and leaves\nnum_splits: number of splits for each parition; split variables into random equaly sized regions\n\n\n\n\n\n","category":"function"},{"location":"api/common/#Learning-Circuit-Parameters","page":"Common APIs","title":"Learning Circuit Parameters","text":"","category":"section"},{"location":"api/common/","page":"Common APIs","title":"Common APIs","text":"mini_batch_em\nfull_batch_em","category":"page"},{"location":"api/common/#ProbabilisticCircuits.mini_batch_em","page":"Common APIs","title":"ProbabilisticCircuits.mini_batch_em","text":"mini_batch_em(bpc::CuBitsProbCircuit, raw_data::CuArray, num_epochs; batch_size, pseudocount,\n param_inertia, param_inertia_end = param_inertia, shuffle=:each_epoch)\n\nUpdate the parameters of the CuBitsProbCircuit by doing EM, update the parameters after each batch.\n\n\n\n\n\n","category":"function"},{"location":"api/common/#ProbabilisticCircuits.full_batch_em","page":"Common APIs","title":"ProbabilisticCircuits.full_batch_em","text":"full_batch_em(bpc::CuBitsProbCircuit, raw_data::CuArray, num_epochs; batch_size, pseudocount)\n\nUpdate the paramters of the CuBitsProbCircuit by doing EM on the full batch (i.e. update paramters at the end of each epoch).\n\n\n\n\n\n","category":"function"},{"location":"api/common/#Circuit-Queries","page":"Common APIs","title":"Circuit Queries","text":"","category":"section"},{"location":"api/common/","page":"Common APIs","title":"Common APIs","text":"loglikelihoods\nMAP\nsample","category":"page"},{"location":"api/common/#ProbabilisticCircuits.loglikelihoods","page":"Common APIs","title":"ProbabilisticCircuits.loglikelihoods","text":"loglikelihoods(bpc::CuBitsProbCircuit, data::CuArray; batch_size, mars_mem = nothing)\n\nReturns loglikelihoods for each datapoint on gpu. Missing values should be denoted by missing.\n\nbpc: BitCircuit on gpu\ndata: CuArray{Union{Missing, data_types...}}\nbatch_size\nmars_mem: Not required, advanced usage. CuMatrix to reuse memory and reduce allocations. See prep_memory and cleanup_memory.\n\n\n\n\n\nloglikelihoods(pc::ProbCircuit, data::Matrix)\n\nComputes loglikelihoods of the circuit over the data on cpu. Linearizes the circuit and computes the marginals in batches.\n\n\n\n\n\n","category":"function"},{"location":"api/common/#ProbabilisticCircuits.MAP","page":"Common APIs","title":"ProbabilisticCircuits.MAP","text":"MAP(bpc::CuBitsProbCircuit, data::CuArray; batch_size, mars_mem=nothing)\n\nRetruns the MAP states for a given circuit and data on gpu. Missing values should be denoted as missing.\n\nNote that the MAP states are exact only when the circuit is both decomposable and deterministic, otherwise its just an approximation.\n\nbpc: BitCircuit on gpu\ndata: CuArray{Union{Missing, data_types...}}\nbatch_size\nmars_mem: Not required, advanced usage. CuMatrix to reuse memory and reduce allocations. See prep_memory and cleanup_memory.\n\n\n\n\n\nMAP(pc::ProbCircuit, data::Matrix; batch_size, Float=Float32)\n\nEvaluate max a posteriori (MAP) state of the circuit for given input(s) on cpu.\n\nNote: 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.\n\n\n\n\n\n","category":"function"},{"location":"api/common/#ProbabilisticCircuits.sample","page":"Common APIs","title":"ProbabilisticCircuits.sample","text":"sample(bpc::CuBitsProbCircuit, num_samples::Int, num_rand_vars::Int, types; rng=default_rng())\n\nGenerate num_samples from the joint distribution of the circuit without any conditions. Samples are genearted on the GPU. \n\nbpc: Circuit on gpu (CuBitProbCircuit)\nnum_samples: how many samples to generate\nnum_rand_vars: number of random variables in the circuit\ntypes: Array of possible input types\nrng: (Optional) Random Number Generator\n\nThe size of returned Array is (num_samples, 1, size(data, 2)).\n\n\n\n\n\nsample(bpc::CuBitsProbCircuit, num_samples, data::CuMatrix; rng=default_rng())\n\nGenerate num_samples for each datapoint in data from the joint distribution of the circuit conditioned on the data. Samples are generated using GPU. \n\nbpc: Circuit on gpu (CuBitProbCircuit)\nnum_samples: how many samples to generate\nrng: (Optional) Random Number Generator\n\nThe size of returned CuArray is (num_samples, size(data, 1), size(data, 2)).\n\n\n\n\n\nsample(pc::ProbCircuit, num_samples; rng = default_rng())\n\nGenerate num_samples from the joint distribution of the circuit without any conditions. Samples are generated on the CPU.\n\n\n\n\n\nsample(pc::ProbCircuit, num_samples, data::Matrix;; batch_size, rng = default_rng())\n\nGenerate num_samples from the joint distribution of the circuit conditioned on the data.\n\n\n\n\n\n","category":"function"},{"location":"manual/gpu/#man-gpu","page":"GPU Support","title":"GPU Support","text":"","category":"section"},{"location":"manual/gpu/","page":"GPU Support","title":"GPU Support","text":"Most queries and learning APIs support both CPU and GPU implementations. To use the GPU implementations you need to move the circuit and the dataset to GPU, then call the corresponding API.","category":"page"},{"location":"manual/gpu/#Moving-to-GPU","page":"GPU Support","title":"Moving to GPU","text":"","category":"section"},{"location":"manual/gpu/#Moving-Data-to-GPU","page":"GPU Support","title":"Moving Data to GPU","text":"","category":"section"},{"location":"manual/gpu/","page":"GPU Support","title":"GPU Support","text":"Currently, the APIs support CuArray type of gpu implemetations. One simple way to move to gpu is using the cu function from CUDA.jl.","category":"page"},{"location":"manual/gpu/","page":"GPU Support","title":"GPU Support","text":"using CUDA\ntrain_x_gpu, test_x_gpu = cu.(train_x, test_x)","category":"page"},{"location":"manual/gpu/","page":"GPU Support","title":"GPU Support","text":"In case of missing values we use Missing type, so for example if you have categorical features with some missing values, the data type on gpu would be CuArray{Union{Missing, UInt32}}.","category":"page"},{"location":"manual/gpu/#Moving-ProbCircuits-to-GPU","page":"GPU Support","title":"Moving ProbCircuits to GPU","text":"","category":"section"},{"location":"manual/gpu/","page":"GPU Support","title":"GPU Support","text":"ProbCircuits are stored in DAG structure and are not GPU friendly by default. So, we convert them into BitsProbCircuits (or bit circuits) as a lower level representation that is GPU friendly. The GPU version of bit circuits has type CuBitsProbCircuit, so to move your circuit to GPU you can simply do:","category":"page"},{"location":"manual/gpu/","page":"GPU Support","title":"GPU Support","text":"bpc = CuBitsProbCircuit(circuit);","category":"page"},{"location":"manual/gpu/#GPU-APIs","page":"GPU Support","title":"GPU APIs","text":"","category":"section"},{"location":"manual/gpu/","page":"GPU Support","title":"GPU Support","text":"The GPU supported APIs generally have the same name as their CPU counterpart, for a comprehensive list of supported functions see the API documentation. For example, we support the following on gpu:","category":"page"},{"location":"manual/gpu/","page":"GPU Support","title":"GPU Support","text":"sample\nMAP\nloglikelihoods\nmini_batch_em\nfull_batch_em","category":"page"},{"location":"api/types/#api-types","page":"Types ","title":"Types ","text":"","category":"section"},{"location":"api/types/","page":"Types ","title":"Types ","text":"The following code snippet provides an easy way to print the type tree of probabilistic circuits.","category":"page"},{"location":"api/types/","page":"Types ","title":"Types ","text":"using InteractiveUtils;\nusing ProbabilisticCircuits;\nusing AbstractTrees;\nAbstractTrees.children(x::Type) = subtypes(x);","category":"page"},{"location":"api/types/","page":"Types ","title":"Types ","text":"For example, we can see ProbabilisticCircuits.ProbCircuit's type tree.","category":"page"},{"location":"api/types/","page":"Types ","title":"Types ","text":"AbstractTrees.print_tree(ProbCircuit)","category":"page"},{"location":"api/types/","page":"Types ","title":"Types ","text":"AbstractTrees.print_tree(InputDist)","category":"page"},{"location":"manual/queries/#man-queries","page":"Queries","title":"Queries","text":"","category":"section"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"In this section, we go over most common probabilistic reasoning tasks, and provide code snippets to compute those queries.","category":"page"},{"location":"manual/queries/#Setup","page":"Queries","title":"Setup","text":"","category":"section"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"First, we load some pretrained PC, and the corresponding data.","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"# This is needed to hide output from downloading artifacts\nusing CircuitModelZoo; #hide\nusing ProbabilisticCircuits; #hide\nusing DensityEstimationDatasets; #hide\npc = read(zoo_psdd_file(\"plants.psdd\"), ProbCircuit);\ndata, _, _ = twenty_datasets(\"plants\");","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"using CircuitModelZoo: zoo_psdd_file\nusing DensityEstimationDatasets: twenty_datasets\nusing ProbabilisticCircuits\nusing Tables\n\npc = read(zoo_psdd_file(\"plants.psdd\"), ProbCircuit);\ndata, _, _ = twenty_datasets(\"plants\");\ndata = Tables.matrix(data);\nprintln(\"circuit with $(num_nodes(pc)) nodes and $(num_parameters(pc)) parameters.\")\nprintln(\"dataset with $(size(data, 2)) features and $(size(data, 1)) examples.\")","category":"page"},{"location":"manual/queries/#Full-Evidence-(EVI)","page":"Queries","title":"Full Evidence (EVI)","text":"","category":"section"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"EVI refers to computing the probability when full evidence is given, i.e. when x is fully observed, the output is p(x). We can use loglikelihoods method to compute logp(x):","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"probs = loglikelihoods(pc, data[1:100, :]; batch_size=64);\nprobs[1:3]","category":"page"},{"location":"manual/queries/#Partial-Evidence-(MAR)","page":"Queries","title":"Partial Evidence (MAR)","text":"","category":"section"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"In this case we have some missing values. Let x^o denote the observed features, and x^m the missing features. We would like to compute p(x^o) which is defined as p(x^o) = sum_x^m p(x^o x^m). Of course, computing this directly by summing over all possible ways to fill the missing values is not tractable. ","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"The good news is that given a smooth and decomposable PC, the marginal can be computed exactly and in linear time to the size of the PC.","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"First, we randomly make some features go missing.","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"using DataFrames\nusing Tables\nfunction make_missing(d; keep_prob=0.8)\n m = missings(Bool, size(d)...)\n flag = rand(size(d)...) .<= keep_prob\n m[flag] .= d[flag]\n return m\nend;\ndata_miss = make_missing(data[1:1000,:]);\nnothing #hide","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"Now, we can use loglikelihoods to compute the marginal queries.","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"probs = loglikelihoods(pc, data_miss; batch_size=64);\nprobs[1:3]","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"Note that loglikelihoods can also be used to compute probabilisties if all data is observed, as we saw in previous section.","category":"page"},{"location":"manual/queries/#Conditionals-(CON)","page":"Queries","title":"Conditionals (CON)","text":"","category":"section"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"In this case, given observed features x^o, we would like to compute p(Q mid x^o), where Q is a subset of features disjoint with x^o. We can use Bayes rule to compute conditionals as two seperate MAR queries as follows:","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"p(q mid x^o) = cfracp(q x^o)p(x^o)","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"Currently, this has to be done manually by the user. We plan to add a simple API for this case in the future.","category":"page"},{"location":"manual/queries/#Maximum-a-posteriori-(MAP,-MPE)","page":"Queries","title":"Maximum a posteriori (MAP, MPE)","text":"","category":"section"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"In this case, given the observed features x^o the goal is to fill out the missing features in a way that p(x^m x^o) is maximized.","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"We can use the MAP method to compute MAP, which outputs the states that maximize the probability and the log-likelihoods of each state.","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"data_miss = make_missing(data[1:1000,:], keep_prob=0.5);\nstates = MAP(pc, data_miss; batch_size = 64);\nsize(states)","category":"page"},{"location":"manual/queries/#Sampling","page":"Queries","title":"Sampling","text":"","category":"section"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"We can also sample from the distrubtion p(x) defined by a Probabilistic Circuit. You can use sample to achieve this task.","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"samples = sample(pc, 100, [Bool]);\nsize(samples)","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"Additionally, we can do conditional samples x sim p(x mid x^o), where x^o are the observed features (x^o subseteq x), and could be any arbitrary subset of features.","category":"page"},{"location":"manual/queries/","page":"Queries","title":"Queries","text":"#3 random evidences for the examples\nevidence = rand( (missing,true,false), (2, num_randvars(pc)));\n\nsamples = sample(pc, 3, evidence; batch_size = 2);\nsize(samples)","category":"page"},{"location":"manual/learning/#man-learning","page":"Learning","title":"Learning","text":"","category":"section"},{"location":"manual/learning/","page":"Learning","title":"Learning","text":"In this section we provide few learning scenarios for circuits. In general, learning tasks for PCs can be separted into two categories: parameter learning and structure learning.","category":"page"},{"location":"manual/learning/#Structures","page":"Learning","title":"Structures","text":"","category":"section"},{"location":"manual/learning/","page":"Learning","title":"Learning","text":"Currently we are supporting the following structures:","category":"page"},{"location":"manual/learning/","page":"Learning","title":"Learning","text":"HiddenChowLiuTrees: See hclt.\nRAT-SPNs: See RAT.","category":"page"},{"location":"manual/learning/#Parameter-Learning","page":"Learning","title":"Parameter Learning","text":"","category":"section"},{"location":"manual/learning/","page":"Learning","title":"Learning","text":"Currently we are supporting the following parameters learning APIs:","category":"page"},{"location":"manual/learning/","page":"Learning","title":"Learning","text":"mini_batch_em\nfull_batch_em","category":"page"},{"location":"manual/learning/#Future-Docs","page":"Learning","title":"Future Docs","text":"","category":"section"},{"location":"manual/learning/","page":"Learning","title":"Learning","text":"Learning a circuit from missing data\nLearn a mixture of circuits\nLearn a circuit from logical constraints and data","category":"page"},{"location":"installation/#Installation","page":"Installation","title":"Installation","text":"","category":"section"},{"location":"installation/#Prerequisites","page":"Installation","title":"Prerequisites","text":"","category":"section"},{"location":"installation/","page":"Installation","title":"Installation","text":"Julia 1.6 or greater. For installation, please refer to the official Julia Website.","category":"page"},{"location":"installation/#Installing-ProbabilisticCircuits","page":"Installation","title":"Installing ProbabilisticCircuits","text":"","category":"section"},{"location":"installation/","page":"Installation","title":"Installation","text":"You can use Julia's package manager, Pkg, to install this module and its dependencies. There are different options on how to do that, for example through command line or julia REPL. For more information and options on how to use Julia pacakge manager, please refer to Pkg's Documentation.","category":"page"},{"location":"installation/#From-Command-Line","page":"Installation","title":"From Command Line","text":"","category":"section"},{"location":"installation/","page":"Installation","title":"Installation","text":"To install the latest stable release, run:","category":"page"},{"location":"installation/","page":"Installation","title":"Installation","text":"julia -e 'using Pkg; Pkg.add(\"ProbabilisticCircuits\")'","category":"page"},{"location":"installation/","page":"Installation","title":"Installation","text":"You can also install the package with the latest commits on master branch.","category":"page"},{"location":"installation/","page":"Installation","title":"Installation","text":"julia -e 'using Pkg; Pkg.add([PackageSpec(url=\"https://github.com/Tractables/ProbabilisticCircuits.jl.git\")])'","category":"page"},{"location":"installation/#From-Package-mode","page":"Installation","title":"From Package mode","text":"","category":"section"},{"location":"installation/","page":"Installation","title":"Installation","text":"note: Note\nTo get to Pkg mode, you need to run julia, then to press ]. Press backspace or ^C to get back to normal REPL mode.","category":"page"},{"location":"installation/","page":"Installation","title":"Installation","text":"While in Pkg mode, run the following to install the latest release:","category":"page"},{"location":"installation/","page":"Installation","title":"Installation","text":"add ProbabilisticCircuits","category":"page"},{"location":"installation/","page":"Installation","title":"Installation","text":"Similarly, to install from the latest commits on master branch, run:","category":"page"},{"location":"installation/","page":"Installation","title":"Installation","text":"add ProbabilisticCircuits#master","category":"page"},{"location":"installation/#Testing","page":"Installation","title":"Testing","text":"","category":"section"},{"location":"installation/","page":"Installation","title":"Installation","text":"If you are installing the latest commit, we recommend running the test suite to make sure everything is in order, to do that run:","category":"page"},{"location":"installation/","page":"Installation","title":"Installation","text":"julia --color=yes -e 'using Pkg; Pkg.test(\"ProbabilisticCircuits\")'","category":"page"},{"location":"installation/","page":"Installation","title":"Installation","text":"Note: If you want the tests to run faster, you can use multiple cores. To do that set the following environment variable (default = 1 core):","category":"page"},{"location":"installation/","page":"Installation","title":"Installation","text":"export JIVE_PROCS=8","category":"page"},{"location":"api/probabilistic_circuits/#api-internal-probabilistic","page":"Probabilistic Circuits","title":"Probabilistic Circuits","text":"","category":"section"},{"location":"api/probabilistic_circuits/","page":"Probabilistic Circuits","title":"Probabilistic Circuits","text":"This page lists all the API documentation for ProbabilisticCircuits package.","category":"page"},{"location":"api/probabilistic_circuits/","page":"Probabilistic Circuits","title":"Probabilistic Circuits","text":"Modules = [ProbabilisticCircuits]","category":"page"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.Categorical","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.Categorical","text":"A N-value categorical input distribution ranging over integers [0...N-1]\n\n\n\n\n\n","category":"type"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.FlatVectors","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.FlatVectors","text":"An isbits representation of a AbstractVector{<:AbstractVector}\n\n\n\n\n\n","category":"type"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.Indicator","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.Indicator","text":"A input distribution node that places all probability on a single value\n\n\n\n\n\n","category":"type"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.Literal","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.Literal","text":"A logical literal input distribution node\n\n\n\n\n\n","category":"type"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.NodeType","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.NodeType","text":"Probabilistic circuit node types\n\n\n\n\n\n","category":"type"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.NodeType-Tuple{ProbCircuit}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.NodeType","text":"Get the probabilistic circuit node type\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.PlainInnerNode","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.PlainInnerNode","text":"A probabilistic inner node\n\n\n\n\n\n","category":"type"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.PlainInputNode","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.PlainInputNode","text":"A probabilistic input node\n\n\n\n\n\n","category":"type"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.PlainMulNode","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.PlainMulNode","text":"A probabilistic multiplication node\n\n\n\n\n\n","category":"type"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.PlainProbCircuit","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.PlainProbCircuit","text":"Root of the plain probabilistic circuit node hierarchy\n\n\n\n\n\n","category":"type"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.PlainSumNode","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.PlainSumNode","text":"A probabilistic summation node\n\n\n\n\n\n","category":"type"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.ProbCircuit","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.ProbCircuit","text":"Root of the probabilistic circuit node hierarchy\n\n\n\n\n\n","category":"type"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.RegionGraph","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.RegionGraph","text":"Root of region graph node hierarchy\n\n\n\n\n\n","category":"type"},{"location":"api/probabilistic_circuits/#Base.read-Union{Tuple{C}, Tuple{AbstractString, Type{C}}} where C<:ProbCircuit","page":"Probabilistic Circuits","title":"Base.read","text":"Base.read(file::AbstractString, ::Type{C}) where C <: ProbCircuit\n\nReads circuit from file; uses extension to detect format type, for example \".psdd\" for PSDDs.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#Base.write-Tuple{AbstractString, ProbCircuit}","page":"Probabilistic Circuits","title":"Base.write","text":"Base.write(file::AbstractString, circuit::ProbCircuit)\n\nWrites circuit to file; uses file name extention to detect file format.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#DirectedAcyclicGraphs.foldup-Union{Tuple{T}, Tuple{ProbCircuit, Function, Function, Function, Type{T}}, Tuple{ProbCircuit, Function, Function, Function, Type{T}, Any}} where T","page":"Probabilistic Circuits","title":"DirectedAcyclicGraphs.foldup","text":"foldup(node::ProbCircuit, \n f_i::Function, \n f_m::Function, \n f_s::Function)::T where {T}\n\nCompute a function bottom-up on the circuit. f_in is called on input nodes, f_m is called on product nodes, and f_s is called on sum nodes. Values of type T are passed up the circuit and given to f_m and f_s through a callback from the children.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#DirectedAcyclicGraphs.foldup_aggregate-Union{Tuple{T}, Tuple{ProbCircuit, Function, Function, Function, Type{T}}, Tuple{ProbCircuit, Function, Function, Function, Type{T}, Any}} where T","page":"Probabilistic Circuits","title":"DirectedAcyclicGraphs.foldup_aggregate","text":"foldup_aggregate(node::ProbCircuit, \n f_i::Function, \n f_m::Function, \n f_s::Function, \n ::Type{T})::T where T\n\nCompute a function bottom-up on the circuit. f_in is called on input nodes, f_m is called on product nodes, and f_s is called on sum nodes. Values of type T are passed up the circuit and given to f_m and f_s in an aggregate vector from the children.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.MAP-Tuple{CuBitsProbCircuit, CUDA.CuArray}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.MAP","text":"MAP(bpc::CuBitsProbCircuit, data::CuArray; batch_size, mars_mem=nothing)\n\nRetruns the MAP states for a given circuit and data on gpu. Missing values should be denoted as missing.\n\nNote that the MAP states are exact only when the circuit is both decomposable and deterministic, otherwise its just an approximation.\n\nbpc: BitCircuit on gpu\ndata: CuArray{Union{Missing, data_types...}}\nbatch_size\nmars_mem: Not required, advanced usage. CuMatrix to reuse memory and reduce allocations. See prep_memory and cleanup_memory.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.MAP-Tuple{ProbCircuit, Matrix}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.MAP","text":"MAP(pc::ProbCircuit, data::Matrix; batch_size, Float=Float32)\n\nEvaluate max a posteriori (MAP) state of the circuit for given input(s) on cpu.\n\nNote: 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.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.RAT-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.RAT","text":"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)\n\nGenerate 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.\n\nnum_features: Number of features in the dataset, assuming x1...xn\ninput_func: Function to generate a new input node for variable when calling input_func(var).\n\nThe list of hyperparamters are:\n\nrg_depth: how many layers to do splits in the region graph\nrg_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)\nnum_nodes_root: number of sum nodes in the root region\nnum_nodes_leaf: number of sum nodes per leaf region\nnum_nodes_region: number of in each region except root and leaves\nnum_splits: number of splits for each parition; split variables into random equaly sized regions\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.RAT_InputFunc-Tuple{Type, Vararg{Any}}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.RAT_InputFunc","text":"Default input_func for different types. This function returns another function input_func. Then input_func(var) should generate a new input function with the desired distribution.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.balance_sum-Tuple{Vector{ProbCircuit}, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.balance_sum","text":"Makes sure the sum nodes does not have too many children. Makes balanced sums of sums to reduce children count.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.balanced_fully_factorized_leaves-Tuple{AbstractVector}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.balanced_fully_factorized_leaves","text":"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.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.bits-Tuple{InputDist, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.bits","text":"bits(d::InputDist, heap)\n\nAppends the required memory for this input dist to the heap.\n\nUsed internally for moving from CPU to GPU.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.cleanup_memory-Tuple{CUDA.CuArray, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.cleanup_memory","text":"Cleansup allocated memory. Used internally.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.clear_memory-Tuple{InputDist, Any, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.clear_memory","text":"clear_memory(d::InputDist, heap, rate)\n\nClears the accumulated flow values on the heap by multiplying it by rate. rate == 0.0 will be equivalent to initializing the value to 0.0.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.dist","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.dist","text":"Get the distribution of a PC input node\n\n\n\n\n\n","category":"function"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.eval_circuit!-Tuple{Any, AbstractVector{<:ProbCircuit}, Matrix, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.eval_circuit!","text":"eval_circuit!(mars, linPC::AbstractVector{<:ProbCircuit}, data::Matrix, example_ids; node2idx::Dict{ProbCircuit, UInt32}, Float=Float32)\n\nUsed internally. Evaluates the marginals of the circuit on cpu. Stores the values in mars.\n\nmars: (batch_size, nodes)\nlinPC: linearized PC. (i.e. linearize(pc))\ndata: data Matrix (num_examples, features)\nexample_ids: Array or collection of ids for current batch\nnode2idx: Index of each ProbCircuit node in the linearized circuit\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.eval_circuit_max!-Tuple{Any, AbstractVector{<:ProbCircuit}, Matrix, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.eval_circuit_max!","text":"eval_circuit_max!(mars, linPC::AbstractVector{<:ProbCircuit}, data::Matrix, example_ids; node2idx::Dict{ProbCircuit, UInt32}, Float=Float32)\n\nUsed internally. Evaluates the MAP upward pass of the circuit on cpu. Stores the values in mars.\n\nmars: (batch_size, nodes)\nlinPC: linearized PC. (i.e. linearize(pc))\ndata: data Matrix (num_examples, features)\nexample_ids: Array or collection of ids for current batch\nnode2idx: Index of each ProbCircuit node in the linearized circuit\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.flow-Tuple{InputDist, Any, Any, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.flow","text":"flow(d::InputDist, value, node_flow, heap)\n\nUpdates the \"flow\" values in the heap for the input node.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.full_batch_em-Tuple{CuBitsProbCircuit, CUDA.CuArray, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.full_batch_em","text":"full_batch_em(bpc::CuBitsProbCircuit, raw_data::CuArray, num_epochs; batch_size, pseudocount)\n\nUpdate the paramters of the CuBitsProbCircuit by doing EM on the full batch (i.e. update paramters at the end of each epoch).\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.hclt-Tuple{Any, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.hclt","text":"hclt(data, num_hidden_cats; num_cats = nothing, input_type = LiteralDist)\n\nLearns HiddenChowLiuTree (hclt) circuit structure from data.\n\ndata: Matrix or CuMatrix\nnum_hidden_cats: Number of categories in hidden variables\ninput_type: Distribution type for the inputs\nnum_cats: Number of categories (in case of categorical inputs). Automatically deduced if not given explicilty.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.init_heap_map_loglikelihood!-Tuple{InputDist, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.init_heap_map_loglikelihood!","text":"init_heap_map_loglikelihood!(d::InputDist, heap)\n\nInitializes the heap for the input dist. Called before running MAP queries.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.init_heap_map_state!-Tuple{InputDist, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.init_heap_map_state!","text":"init_heap_map_state!(d::InputDist, heap)\n\nInitializes the heap for the input dist. Called before running MAP queries.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.init_parameters-Tuple{ProbCircuit}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.init_parameters","text":"init_parameters(pc::ProbCircuit; perturbation = 0.0)\n\nInitialize parameters of ProbCircuit.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.init_params-Tuple{InputDist, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.init_params","text":"init_params(d::InputDist, perturbation)\n\nReturns a new distribution with same type with initialized parameters.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.inputnodes-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.inputnodes","text":"Get all input nodes in a given circuit\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.inputs-Tuple{Any, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.inputs","text":"Get the inputs of a PC node\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.isinput-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.isinput","text":"Is the node an input node?\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.ismul-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.ismul","text":"Is the node a multiplication?\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.isonlysubedge-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.isonlysubedge","text":"whether this sub edge is the only outgoing edge from sub\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.ispartial-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.ispartial","text":"whether this series of edges is partial or complete\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.issum-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.issum","text":"Is the node a summation?\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.loglikelihood-Tuple{CuBitsProbCircuit, CUDA.CuArray}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.loglikelihood","text":"loglikelihood(bpc::CuBitsProbCircuit, data::CuArray; batch_size, mars_mem = nothing)\n\nComputes Average loglikelihood of circuit given the data using gpu. See loglikelihoods for more details.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.loglikelihood-Tuple{InputDist, Any, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.loglikelihood","text":"loglikelihood(d::InputDist, value, heap)\n\nReturns the log( P(input_var == value) ) according to the InputDist.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.loglikelihood-Tuple{ProbCircuit, Matrix, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.loglikelihood","text":"loglikelihood(root::ProbCircuit, data::Matrix, example_id; Float=Float32)\n\nComputes marginal loglikelihood recursively on cpu for a single instance data[example_id, :].\n\nNote: Quite slow, only use for demonstration/educational purposes. \n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.loglikelihoods-Tuple{CuBitsProbCircuit, CUDA.CuArray}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.loglikelihoods","text":"loglikelihoods(bpc::CuBitsProbCircuit, data::CuArray; batch_size, mars_mem = nothing)\n\nReturns loglikelihoods for each datapoint on gpu. Missing values should be denoted by missing.\n\nbpc: BitCircuit on gpu\ndata: CuArray{Union{Missing, data_types...}}\nbatch_size\nmars_mem: Not required, advanced usage. CuMatrix to reuse memory and reduce allocations. See prep_memory and cleanup_memory.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.loglikelihoods-Tuple{ProbCircuit, Matrix}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.loglikelihoods","text":"loglikelihoods(pc::ProbCircuit, data::Matrix)\n\nComputes loglikelihoods of the circuit over the data on cpu. Linearizes the circuit and computes the marginals in batches.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.loglikelihoods_vectorized-Tuple{ProbCircuit, Matrix}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.loglikelihoods_vectorized","text":"Note: Experimental**; will be removed or renamed later\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.map_down_rec!-Tuple{Any, ProbCircuit, Any, Matrix, Any, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.map_down_rec!","text":"map_down_rec!(mars, node::ProbCircuit, data, states::Matrix, batch_idx, example_idx; node2idx::Dict{ProbCircuit, UInt32}, Float=Float32)\n\nDownward pass on cpu for MAP. Recursively chooses the best (max) sum node children according to the \"MAP upward pass\" values. Updates the missing values with map_state of that input node.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.map_loglikelihood-Tuple{InputDist, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.map_loglikelihood","text":"map_loglikelihood(d::InputDist, heap)\n\nReturns the MAP loglikelihoods the most likely state of the InputDist d\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.map_state-Tuple{InputDist, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.map_state","text":"map_state(d::InputDist, heap)\n\nReturns the MAP state for the InputDist d\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.mini_batch_em-Tuple{CuBitsProbCircuit, CUDA.CuArray, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.mini_batch_em","text":"mini_batch_em(bpc::CuBitsProbCircuit, raw_data::CuArray, num_epochs; batch_size, pseudocount,\n param_inertia, param_inertia_end = param_inertia, shuffle=:each_epoch)\n\nUpdate the parameters of the CuBitsProbCircuit by doing EM, update the parameters after each batch.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.mulnodes-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.mulnodes","text":"Get all multiplication nodes in a given circuit\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.multiply","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.multiply","text":"Multiply nodes into a single circuit\n\n\n\n\n\n","category":"function"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.num_inputs-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.num_inputs","text":"Number of inputs of a PC node\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.num_parameters","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.num_parameters","text":"Count the number of parameters in the circuit\n\n\n\n\n\n","category":"function"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.num_parameters-Tuple{InputDist, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.num_parameters","text":"num_parameters(d::InputDist, independent)\n\nReturns number of parameters for the input dist.\n\nindependent: whether to only count independent parameters\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.num_parameters_node-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.num_parameters_node","text":"Count the number of parameters in the node\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.num_randvars-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.num_randvars","text":"Number of variables in the data structure\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.params-Tuple{InputDist}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.params","text":"params(d::InputDist)\n\nReturns paramters of the input dist.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.params-Tuple{ProbCircuit}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.params","text":"Get the parameters associated with a node\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.prep_memory","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.prep_memory","text":"prep_memory(reuse, sizes, exact = map(x -> true, sizes))\n\nMostly used internally. Prepares memory for the specifed size, reuses reuse if possible to avoid memory allocation/deallocation.\n\n\n\n\n\n","category":"function"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.psdd_num_nodes_leafs-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.psdd_num_nodes_leafs","text":"Count the number of decision and leaf nodes in the PSDD\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.random_region_graph-Tuple{AbstractVector}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.random_region_graph","text":"random_region_graph(X::AbstractVector, depth::Int = 5, replicas::Int = 2, num_splits::Int = 2)\n\nX: Vector of all variables to include; for the root region\ndepth: how many layers to do splits\nreplicas: 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)\nnum_splits: number of splits for each parition; split variables into random equaly sized regions\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.randvars","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.randvars","text":"variables(pc::ProbCircuit)::BitSet\n\nGet a bitset of variables mentioned in the circuit.\n\n\n\n\n\n","category":"function"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.region_graph_2_pc-Tuple{RegionGraph}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.region_graph_2_pc","text":"region_graph_2_pc(node::RegionGraph; num_nodes_root, num_nodes_region, num_nodes_leaf, balance_childs_parents)\n\nnum_nodes_root: number of sum nodes in the root region\nnum_nodes_leaf: number of sum nodes per leaf region\nnum_nodes_region: number of in each region except root and leaves\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.sample-Tuple{CuBitsProbCircuit, Any, CUDA.CuArray{T, 2} where T}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.sample","text":"sample(bpc::CuBitsProbCircuit, num_samples, data::CuMatrix; rng=default_rng())\n\nGenerate num_samples for each datapoint in data from the joint distribution of the circuit conditioned on the data. Samples are generated using GPU. \n\nbpc: Circuit on gpu (CuBitProbCircuit)\nnum_samples: how many samples to generate\nrng: (Optional) Random Number Generator\n\nThe size of returned CuArray is (num_samples, size(data, 1), size(data, 2)).\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.sample-Tuple{CuBitsProbCircuit, Int64, Int64, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.sample","text":"sample(bpc::CuBitsProbCircuit, num_samples::Int, num_rand_vars::Int, types; rng=default_rng())\n\nGenerate num_samples from the joint distribution of the circuit without any conditions. Samples are genearted on the GPU. \n\nbpc: Circuit on gpu (CuBitProbCircuit)\nnum_samples: how many samples to generate\nnum_rand_vars: number of random variables in the circuit\ntypes: Array of possible input types\nrng: (Optional) Random Number Generator\n\nThe size of returned Array is (num_samples, 1, size(data, 2)).\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.sample-Tuple{ProbCircuit, Any, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.sample","text":"sample(pc::ProbCircuit, num_samples; rng = default_rng())\n\nGenerate num_samples from the joint distribution of the circuit without any conditions. Samples are generated on the CPU.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.sample-Tuple{ProbCircuit, Any, Matrix}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.sample","text":"sample(pc::ProbCircuit, num_samples, data::Matrix;; batch_size, rng = default_rng())\n\nGenerate num_samples from the joint distribution of the circuit conditioned on the data.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.sample_state-Tuple{InputDist, Any, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.sample_state","text":"sample_state(d::InputDist, threshold::Float32, heap)\n\nReturns a sample from InputDist. Threshold is a uniform random value in range (0, 1) given to this API by the sampleing algorithm\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.soften_data-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.soften_data","text":"Turn binary data into floating point data close to 0 and 1.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.summate","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.summate","text":"Sum nodes into a single circuit\n\n\n\n\n\n","category":"function"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.sumnodes-Tuple{Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.sumnodes","text":"Get all summation nodes in a given circuit\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.unbits-Tuple{InputDist, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.unbits","text":"unbits(d::InputDist, heap)\n\nReturns the InputDist struct from the heap. Note, each input dist type needs to store where in the heap its paramters are to be able to do this.\n\nUsed internally for moving from GPU to CPU.\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.update_parameters-Tuple{ProbabilisticCircuits.AbstractBitsProbCircuit}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.update_parameters","text":"map parameters from BitsPC back to the ProbCircuit it was created from\n\n\n\n\n\n","category":"method"},{"location":"api/probabilistic_circuits/#ProbabilisticCircuits.update_params-Tuple{InputDist, Any, Any, Any}","page":"Probabilistic Circuits","title":"ProbabilisticCircuits.update_params","text":"update_params(d::InputDist, heap, pseudocount, inertia)\n\nUpdate the parameters of the InputDist using stored values on the heap and (pseudocount, inertia)\n\n\n\n\n\n","category":"method"},{"location":"manual/demo/#man-demo","page":"Quick Demo","title":"Quick Demo","text":"","category":"section"},{"location":"manual/demo/","page":"Quick Demo","title":"Quick Demo","text":"In this section, we provide quick code snippets to get started with ProbabilisticCircuits and provide basic understanding of them. PCs are represented as a computational graphs that define a joint probability distribution as recursive mixtures (sum units) and factorizations (product units) of simpler distributions (input units).","category":"page"},{"location":"manual/demo/","page":"Quick Demo","title":"Quick Demo","text":"Generally, we learn structure and parameters of circuit from data. Alternatively, we can also specify circuits in code. For example, the following snippet defines a circuit depending on 3 random variables. The literals function returns the input units of the circuit, in this case we get 6 different units (3 for positive literals, and 3 for negative literlas). You can use * and + operators to build a circuits.","category":"page"},{"location":"manual/demo/","page":"Quick Demo","title":"Quick Demo","text":"using ProbabilisticCircuits;\n\nX1, X2, X3 = [InputNode(i, Indicator(true)) for i=1:3]\nX1_, X2_, X3_ = [InputNode(i, Indicator(false)) for i=1:3]\n\npc = 0.3 * (X1_ *\n (0.2 * X2_ + 0.8 * X3)) +\n 0.7 * (X1 *\n (0.4 * X2 + 0.6 * X3_));\n\nnothing # hide","category":"page"},{"location":"manual/demo/","page":"Quick Demo","title":"Quick Demo","text":"You can ask basic questions about PCs, such as (1) how many variables they depends on, (2) how many nodes, (3) how many edges, (4) or how many parameters they have.","category":"page"},{"location":"manual/demo/","page":"Quick Demo","title":"Quick Demo","text":"num_randvars(pc)","category":"page"},{"location":"manual/demo/","page":"Quick Demo","title":"Quick Demo","text":"num_nodes(pc)","category":"page"},{"location":"manual/demo/","page":"Quick Demo","title":"Quick Demo","text":"num_edges(pc)","category":"page"},{"location":"manual/demo/","page":"Quick Demo","title":"Quick Demo","text":"num_parameters(pc)","category":"page"},{"location":"manual/demo/","page":"Quick Demo","title":"Quick Demo","text":"We can also plot circuits using plot(pc) to see the computation graph (structure and parameters). The output of plot(pc) has a type of TikzPictures.TikzPicture. Generally, notebooks automatically renders it and you see the figure in the notebook. ","category":"page"},{"location":"manual/demo/","page":"Quick Demo","title":"Quick Demo","text":"plot(pc)","category":"page"},{"location":"manual/demo/","page":"Quick Demo","title":"Quick Demo","text":"However, if you are not using a notebook or want to save to file you can use the following commands to save the plot in various formats.","category":"page"},{"location":"manual/demo/","page":"Quick Demo","title":"Quick Demo","text":"using TikzPictures;\nz = plot(pc);\nsave(PDF(\"plot\"), z);\nsave(SVG(\"plot\"), z);\nsave(TEX(\"plot\"), z);\nsave(TIKZ(\"plot\"), z);","category":"page"},{"location":"#ProbabilisticCircuits.jl","page":"Home","title":"ProbabilisticCircuits.jl","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"This module provides a Julia implementation of Probabilistic Circuits (PCs), tools to learn structure and parameters of PCs from data, and tools to do tractable exact inference with them. ","category":"page"},{"location":"#What-are-Probabilistic-Circuits?","page":"Home","title":"What are Probabilistic Circuits?","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Probabilistic Circuits provides a unifying framework for several family of tractable probabilistic models. PCs are represented as a computational graphs that define a joint probability distribution as recursive mixtures (sum units) and factorizations (product units) of simpler distributions (input units).","category":"page"},{"location":"","page":"Home","title":"Home","text":"Given certain structural properties, PCs enable different range of tractable exact probabilistic queries such as computing marginals, conditionals, maximum a posteriori (MAP), and more advanced probabilistic queries.","category":"page"},{"location":"","page":"Home","title":"Home","text":"In additon to parameters, the structure of PCs can also be learned from data. There are several approaches in learning PCs, while keeping the needed structural constrains intact. Currently, This module includes implementation for few of these approaches with plans to add more over time.","category":"page"},{"location":"","page":"Home","title":"Home","text":"Additionally, parallelism (on both CPU and GPU) is leveraged to provide faster implementation of learning and inference.","category":"page"},{"location":"#Where-to-learn-more-about-them?","page":"Home","title":"Where to learn more about them?","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"For an overview of the motivation and theory behind PCs, you can start by watching the ECML-PKDD tutorial on Probabilistic Circuits. ","category":"page"},{"location":"","page":"Home","title":"Home","text":"Probabilistic Circuits: Representations, Inference, Learning and Theory (Video)","category":"page"},{"location":"","page":"Home","title":"Home","text":"For more details and additional references, you can refer to:","category":"page"},{"location":"","page":"Home","title":"Home","text":"Probabilistic Circuits: A Unifying Framework for Tractable Probabilistic Models (PDF)","category":"page"},{"location":"api/input_dists/#new-input-dist","page":"Input Distributions","title":"Input Distributions","text":"","category":"section"},{"location":"api/input_dists/","page":"Input Distributions","title":"Input Distributions","text":"Currently we support Indicator{T}, Categorical, Bernoulli (special case of Categorical) distributions in the InputNodes.","category":"page"},{"location":"api/input_dists/#Support-new-InputDist","page":"Input Distributions","title":"Support new InputDist","text":"","category":"section"},{"location":"api/input_dists/","page":"Input Distributions","title":"Input Distributions","text":"To support new type of Input Distributions you need to implement the following functions:","category":"page"},{"location":"api/input_dists/","page":"Input Distributions","title":"Input Distributions","text":"num_parameters\nparams\ninit_params\nloglikelihood","category":"page"},{"location":"api/input_dists/#Support-movement-between-CPU/GPU-for-InputDist","page":"Input Distributions","title":"Support movement between CPU/GPU for InputDist","text":"","category":"section"},{"location":"api/input_dists/","page":"Input Distributions","title":"Input Distributions","text":"To support moving between CPU/GPU you need to implement the following:","category":"page"},{"location":"api/input_dists/","page":"Input Distributions","title":"Input Distributions","text":"bits\nunbits","category":"page"},{"location":"api/input_dists/#Learning-support-for-InputDist","page":"Input Distributions","title":"Learning support for InputDist","text":"","category":"section"},{"location":"api/input_dists/","page":"Input Distributions","title":"Input Distributions","text":"To support learning you need to implement the following:","category":"page"},{"location":"api/input_dists/","page":"Input Distributions","title":"Input Distributions","text":"flow\nupdate_params\nclear_memory","category":"page"},{"location":"api/input_dists/#Query-support-for-InputDist","page":"Input Distributions","title":"Query support for InputDist","text":"","category":"section"},{"location":"api/input_dists/","page":"Input Distributions","title":"Input Distributions","text":"To support certain queries such as sampling and MAP you need to implement the following:","category":"page"},{"location":"api/input_dists/","page":"Input Distributions","title":"Input Distributions","text":"sample_state\ninit_heap_map_state!\ninit_heap_map_loglikelihood!\nmap_state\nmap_loglikelihood","category":"page"}] } diff --git a/dev/usage.jl b/dev/usage.jl index a97d08e0..709a2434 100644 --- a/dev/usage.jl +++ b/dev/usage.jl @@ -33,7 +33,7 @@ exp(circuit(true, true, true) - circuit(missing, true, true)) # Pr(rain=1|rainbo assignments, log_prob = MAP(circuit, [missing, missing, missing]; batch_size=1) print("The MAP assignment of the circuit is (rain=$(assignments[1]), rainbow=$(assignments[2]), wet=$(assignments[3])), with probability $(exp(log_prob)).") -# Besides the above examples, ProbabilisticCircuits.jl provides functionalities for a wide variety of queries, which are detailed in [this manual](https://juice-jl.github.io/ProbabilisticCircuits.jl/stable/manual/queries/). +# Besides the above examples, ProbabilisticCircuits.jl provides functionalities for a wide variety of queries, which are detailed in [this manual](https://Tractables.github.io/ProbabilisticCircuits.jl/stable/manual/queries/). # ### Building complex circuit structures