Overview of all functions in the Hierarchical Gaussian Filtering package

HierarchicalGaussianFiltering.calculate_log_predicted_volatility — Method
calculate_log_predicted_volatility(node::ContinuousStateNode, child::ContinuousStateNode, node_value::Real)

Calculates the log of a volatility child's predicted volatility (including the stepsize) as a function of the node's value. The part which does not depend on the node is recovered from the child's prediction, which was made with the node's previous posterior mean. This function is only used in the unbounded HGF update.

source
HierarchicalGaussianFiltering.calculate_unbounded_expansion_point — Method
calculate_unbounded_expansion_point(node::ContinuousStateNode, child::ContinuousStateNode, prior_precision::Real, prior_mean::Real)

Finds the expansion point for the second expansion of the unbounded HGF update: the approximate secondary mode of the variational energy created by a volatility child, in the limit where the variance carried over from the child's previous posterior goes to zero. The mode is found in closed form with the Lambert W function, in the canonical variable y = log(t) + κx + ω, which is the log of the child's predicted volatility. This function is only used in the unbounded HGF update.

source
HierarchicalGaussianFiltering.calculate_unbounded_first_expansion — Method
calculate_unbounded_first_expansion(node::ContinuousStateNode, prior_precision::Real, prior_mean::Real)

Makes the first quadratic expansion of the unbounded HGF update, at the prior mean. The precision uses only the concave part of the variational energy, so it is always positive. Returns the precision and mean of the expansion. This function is only used in the unbounded HGF update.

source
HierarchicalGaussianFiltering.calculate_unbounded_posterior — Method
calculate_unbounded_posterior(node::ContinuousStateNode, prior_mean::Real)

Calculates the posterior precision and mean of a continuous state node with volatility children, using the unbounded HGF update (Mathys et al., 2026). The node's variational energy is approximated with quadratic expansions: a first expansion at the prior mean, which uses only the concave part of the variational energy and therefore always has a positive precision, and a second expansion for each volatility child, at the approximate secondary mode of the variational energy which that child can create, found with the Lambert W function. The expansions are weighted with a softmax over the variational energy at their means, and the posterior is the moment-matched Gaussian of the resulting mixture, so that the posterior precision is positive by construction. The effective prior, which includes the update terms from all children that are not volatility children, is given by the node's stored posterior precision and the passed prior mean.

source
HierarchicalGaussianFiltering.calculate_unbounded_second_expansion — Method
calculate_unbounded_second_expansion(node::ContinuousStateNode, child::ContinuousStateNode, prior_precision::Real, prior_mean::Real)

Makes the second quadratic expansion of the unbounded HGF update for a single volatility child, at the approximate secondary mode of the variational energy which that child can create. The full variational energy, with the contributions from all volatility children, is expanded at this point. Returns the precision and mean of the expansion, or nothing if the expansion is not finite. This function is only used in the unbounded HGF update.

source
HierarchicalGaussianFiltering.calculate_variational_energy — Method
calculate_variational_energy(node::ContinuousStateNode, node_value::Real, prior_precision::Real, prior_mean::Real)

Calculates the variational energy of a continuous state node with volatility children, at a given value of the node (up to a constant). This is the quadratic prior term plus the contributions from each volatility child. This function is only used in the unbounded HGF update.

source
HierarchicalGaussianFiltering.calculate_volatility_coupling_terms — Method
calculate_volatility_coupling_terms(node::ContinuousStateNode, child::ContinuousStateNode, node_value::Real)

For a volatility child, calculates the terms of the unbounded HGF update which depend on the node's value: the child's effective prediction precision (the proportion of its predicted variance that comes from the predicted volatility), its precision prediction error, and its contribution to the node's variational energy. These are calculated in log-space, so that they stay finite when the predicted volatility under- or overflows. This function is only used in the unbounded HGF update.

source
HierarchicalGaussianFiltering.get_prediction — Function
get_prediction(hgf::HGF, node_name::String)

Get the prediction for the next timestep for a specified node in an HGF. If an agent is passed instead of an HGF, the HGF is extracted from the substruct in the agent. A single node can also be passed.

source
HierarchicalGaussianFiltering.get_surprise — Function

getsurprise(hgf::HGF, nodename::String = "u")

Calculates the surprisal at the last input of a specified input node in an HGF. If an agent is passed instead of an HGF, the HGF is extracted from the substruct in the agent. If no node is specified, the surprisal of all input nodes is summed.

source
HierarchicalGaussianFiltering.lambert_w0_from_log — Method
lambert_w0_from_log(log_argument::Real)

The principal branch W₀ of the Lambert W function, which solves w * exp(w) = z for z ≥ 0, given the log of its argument z. Taking the log of the argument means that z itself never has to be represented, so it can be far above the largest representable number. Uses Halley's method, which converges to machine precision in a few iterations. The iteration is written in terms of the residual w - exp(log(z) - w), so that no intermediate value can overflow. This function is only used in the unbounded HGF update.

source
HierarchicalGaussianFiltering.premade_JGET — Method

premade_JGET(config::Dict; verbose::Bool = true)

The HGF used in the JGET model. It has a single continuous input node u, with a value parent x, and a volatility parent xnoise. x has volatility parent xvol, and xnoise has a volatility parent xnoise_vol.

Config defaults:

  • ("u", "input_noise"): -2
  • ("x", "volatility"): -2
  • ("xvol", "volatility"): -2
  • ("xnoise", "volatility"): -2
  • ("xnoise_vol", "volatility"): -2
  • ("u", "x", "coupling_strength"): 1
  • ("u", "xnoise", "coupling_strength"): 1
  • ("x", "xvol", "coupling_strength"): 1
  • ("xnoise", "xnoisevol", "couplingstrength"): 1
  • ("x", "initial_mean"): 0
  • ("x", "initial_precision"): 1
  • ("xvol", "initial_mean"): 0
  • ("xvol", "initial_precision"): 1
  • ("xnoise", "initial_mean"): 0
  • ("xnoise", "initial_precision"): 1
  • ("xnoisevol", "initialmean"): 0
  • ("xnoisevol", "initialprecision"): 1
source
HierarchicalGaussianFiltering.premade_binary_2level — Method
premade_binary_2level(config::Dict; verbose::Bool = true)

The standard binary 2 level HGF model, which takes a binary input, and learns the probability of either outcome. It has one binary input node u, with a binary value parent xbin, which in turn has a continuous value parent xprob.

Config defaults:

source
HierarchicalGaussianFiltering.premade_binary_3level — Method
premade_binary_3level(config::Dict; verbose::Bool = true)

The standard binary 3 level HGF model, which takes a binary input, and learns the probability of either outcome. It has one binary input node u, with a binary value parent xbin, which in turn has a continuous value parent xprob. This then has a continunous volatility parent xvol.

This HGF has five shared parameters: "xprobvolatility" "xprobinitialprecisions" "xprobinitialmeans" "couplingstrengthsxbinxprob" "couplingstrengthsxprob_xvol"

Config defaults:

  • ("xprob", "volatility"): -2
  • ("xvol", "volatility"): -2
  • ("xbin", "xprob", "coupling_strength"): 1
  • ("xprob", "xvol", "coupling_strength"): 1
  • ("xprob", "initial_mean"): 0
  • ("xprob", "initial_precision"): 1
  • ("xvol", "initial_mean"): 0
  • ("xvol", "initial_precision"): 1
source
HierarchicalGaussianFiltering.premade_categorical_3level — Method
premade_categorical_3level(config::Dict; verbose::Bool = true)

The categorical 3 level HGF model, which takes an input from one of n categories and learns the probability of a category appearing. It has one categorical input node u, with a categorical value parent xcat. The categorical node has a binary value parent xbinn for each category n, each of which has a continuous value parent xprobn. Finally, all of these continuous nodes share a continuous volatility parent xvol. Setting parameter values for xbin and xprob sets that parameter value for each of the xbinn and xprobn nodes.

Config defaults:

  • "n_categories": 4
  • ("xprob", "volatility"): -2
  • ("xvol", "volatility"): -2
  • ("xbin", "xprob", "coupling_strength"): 1
  • ("xprob", "xvol", "coupling_strength"): 1
  • ("xprob", "initial_mean"): 0
  • ("xprob", "initial_precision"): 1
  • ("xvol", "initial_mean"): 0
  • ("xvol", "initial_precision"): 1
source
HierarchicalGaussianFiltering.premade_categorical_state_transitions — Method
premade_categorical_state_transitions(config::Dict; verbose::Bool = true)

The categorical state transition 3 level HGF model, learns state transition probabilities between a set of n categorical states. It has one categorical input node u, with a categorical value parent xcatn for each of the n categories, representing which category was transitioned from. Each categorical node then has a binary parent xbinnm, representing the category m which the transition was towards. Each binary node xbinnm has a continuous parent xprobnm. Finally, all of these continuous nodes share a continuous volatility parent xvol. Setting parameter values for xbin and xprob sets that parameter value for each of the xbinnm and xprobn_m nodes.

This HGF has five shared parameters: "xprobvolatility" "xprobinitialprecisions" "xprobinitialmeans" "couplingstrengthsxbinxprob" "couplingstrengthsxprob_xvol"

Config defaults:

- "n_categories": 4
- ("xprob", "volatility"): -2
- ("xvol", "volatility"): -2
- ("xbin", "xprob", "coupling_strength"): 1
- ("xprob", "xvol", "coupling_strength"): 1
- ("xprob", "initial_mean"): 0
- ("xprob", "initial_precision"): 1
- ("xvol", "initial_mean"): 0
- ("xvol", "initial_precision"): 1
source
HierarchicalGaussianFiltering.premade_continuous_2level — Method
premade_continuous_2level(config::Dict; verbose::Bool = true)

The standard 2 level continuous HGF, which filters a continuous input. It has a continous input node u, with a single value parent x, which in turn has a single volatility parent xvol.

Config defaults:

  • ("u", "input_noise"): -2
  • ("x", "volatility"): -2
  • ("xvol", "volatility"): -2
  • ("u", "x", "coupling_strength"): 1
  • ("x", "xvol", "coupling_strength"): 1
  • ("x", "initial_mean"): 0
  • ("x", "initial_precision"): 1
  • ("xvol", "initial_mean"): 0
  • ("xvol", "initial_precision"): 1
source
HierarchicalGaussianFiltering.premade_hgf — Function
premade_hgf(model_name::String, config::Dict = Dict(); verbose = true)

Create an HGF from the list of premade HGFs.

Arguments

  • 'model_name::String': Name of the premade HGF. Returns a list of possible model names if set to 'help'.
  • 'config::Dict = Dict()': A dictionary with configurations for the HGF, like parameters and settings.
  • 'verbose::Bool = true': If set to false, warnings are hidden.
source
HierarchicalGaussianFiltering.update_hgf! — Method
update_hgf!(
    hgf::HGF,
    inputs::Union{
        Real,
        Missing,
        Vector{<:Union{Real,Missing}},
        Dict{String,<:Union{Real,Missing}},
    },
)

Update all nodes in an HGF based on an input. The input can either be missing, a single value, a vector of values, or a dictionary of input node names and corresponding values.

source
HierarchicalGaussianFiltering.update_node_posterior! — Method
update_node_posterior!(node::AbstractStateNode, update_type::UnboundedUpdate)

Update the posterior of a single continuous state node. This is the unbounded HGF update (Mathys et al., 2026), which guarantees a positive posterior precision for volatility parents.

source

This page was generated using Literate.jl.