Skip to Content

Formula

Context

Conditional Probability Tables (CPTs) can be defined efficiently using BayesiaLab’s Formula Editor. The formula you specify generates the values of all cells in a CPT, and the results are automatically normalized for each parent-state configuration.

Usage

Double-click a node in Modeling Mode to open the Node Editor, then select Probability Distribution > Formula. You can also open Node Contextual Menu > Edit, then select Probability Distribution > Formula in the Node Editor.

Node Editor with Probability Distribution and Formula selected
Node Editor with Probability Distribution and Formula selected

Formula Editor

The Formula Editor provides controls for entering a formula, generating a probability table and inserting functions or variables. The example below uses the continuous node N1\mathit{N1} and the probabilistic formula Uniform(?N1?, 1, 4).

Current Formula Editor showing the Uniform formula and its input, generation and catalog controls
Current Formula Editor showing the Uniform formula and its input, generation and catalog controls

Return type and formula input

The Return Type specifies what the formula returns upon evaluation.

  • Deterministic (Node States) returns node values.
  • Probabilistic (Numerical Values) returns numerical values, which are normalized automatically to obtain probabilities.

The formula heading reflects the selected Return Type. In a probabilistic formula, the node variable identifies the corresponding column in the probability table. In this example, ?N1? identifies the numerical value at which the Uniform density is evaluated.

The formula language is strongly typed and uses functions and infix notation. Strong typing restricts how different data types can be combined. Infix notation places operators between their operands, as in 2 + 2.

The message panel reports validation errors or confirms successful table generation. Click Validate to generate the table from the formula. For a continuous node with a deterministic formula, computed values may fall outside the node’s domain. In that case, BayesiaLab can suggest extending the range to accommodate them.

Sampling, smoothing and seed

Samples specifies the number of random samples used to generate probability tables. Values can be drawn from the intervals of discretized continuous variables involved in the formula.

Smoothing initializes the occurrence count in each table cell. A positive value smooths the distribution and gives all states a nonzero associated probability. This control is unavailable for deterministic formulas.

Fixed Seed lets you specify a repeatable random seed. The illustrated settings use 10,000 samples, zero smoothing and seed 31.

Probabilistic formula, successful table-generation message, Samples, Smoothing and Fixed Seed controls
Probabilistic formula, successful table-generation message, Samples, Smoothing and Fixed Seed controls

Functions, variables and variable details

The catalog groups the available distributions, functions and operators. The current categories include discrete and continuous probability distributions, special functions, variable attributes, arithmetic functions, transformation functions, conversion functions, trigonometric functions, special operators, relational operators, Boolean operators and arithmetic operators. Double-click an entry to insert its template into the formula. The Search field helps locate an entry.

The variable list contains the current node and its parents, when applicable. If the network defines Time\mathit{Time}, it is also available. Defined constants appear under Constants. Double-click a variable or constant to insert it into the formula. Variable references are enclosed in question marks.

Selecting a variable displays its details in the right-hand pane. For the continuous node N1\mathit{N1} in this example, the pane shows its domain, [0.0,5.0][0.0, 5.0]. State values or constants can be displayed when appropriate to the selected entry.

Function catalog, selected variable N1 and its continuous domain in the details pane
Function catalog, selected variable N1 and its continuous domain in the details pane

Arithmetic functions with multiple arguments

The functions below accept multiple arguments.

FunctionResultExample
Max(x1, ..., xn)Largest argumentMax(2, 4, 6) gives 6
Min(x1, ..., xn)Smallest argumentMin(2, 4, 6) gives 2
Mult(x1, ..., xn)Product of the argumentsMult(2, 4, 6) gives 48
Sum(x1, ..., xn)Sum of the argumentsSum(2, 4, 6) gives 12
Mean(x1, ..., xn)Arithmetic mean of the argumentsMean(2, 4, 6) gives 4

The Function Node F1\mathit{F1} below evaluates Mean(2, 4, 6). Its Monitor displays the result 4.

Loading SVG...
Function Node F1 evaluates Mean(2, 4, 6) and displays 4.

The Arithmetic Functions reference describes additional arithmetic operations.

State values and variable attributes

The Variable Attributes group provides functions that read properties of a variable.

FunctionPurpose
StateCount(v)Number of states of variable v
StateValueAt(v, s)Numerical value associated with state s of variable v
Cost(v)Cost associated with variable v

StateValue(v) uses the numerical value associated with a node state in an expression. These values are configured in Node Editor > Values. See also Variable Types and Cost.

Inference functions in Function Nodes

The functions available in the catalog depend on the node being edited. Function Nodes provide an Inference Functions group for expressions that read inference results.

FunctionPurpose
JointProb()Joint probability of the current evidence
Entropy(v, n)Entropy of variable v, normalized when n is true and unnormalized when it is false
Utility(u)Expected utility of Utility Node u
OverallUtility()Sum of the network’s utilities

For example, if two Utility Nodes have expected utilities of 10 and −5, their overall utility is 5. Applying Utility(u) to the first node returns 10. A Function Node can use OverallUtility() without an arc connecting it to the Utility Nodes.

Utility Nodes describes how utilities are assigned and combined.