Premade models

The Hierarchical Gaussian Filtering package contains a set of premade HGF's and HGF-agents for you to use. We will provide an overview of how to work with the premade agent models, and lastly a total overview of the premade HGF models to use in the package.

Premade HGF-agents

  1. HGF Gaussian Action Noise
  2. HGF Binary Softmax
  3. HGF unit square sigmoid
  4. HGF-Predict-Category

HGF with Gaussian Action Noise agent

This premade agent model can be found as "hgf_gaussian" in the package. The Action distribution is a gaussian distribution with mean of the target state from the chosen HGF, and the standard deviation consisting of the action precision parameter inversed.

  • Default hgf: contionus_2level
  • Default Target state: (x, posterior mean)
  • Default Parameters: gaussian action precision = 1

HGF Binary Softmax agent

The action distribution is a Bernoulli distribution, and the parameter is action probability. Action probability is calculated using a softmax on the action precision parameter and the target value from the HGF.

  • Default hgf: binary_3level
  • Default target state; (xbin, prediction mean)
  • Default parameters: softmax action precision = 1

HGF unit square sigmoid agent

The action distribution is Bernoulli distribution with the parameter beinga a softmax of the target value and action precision.

  • Default hgf: binary_3level
  • Default target state; (xbin, prediction mean)
  • Default parameters: softmax action precision = 1

HGF Predict Category agent

The action distribution is a categorical distribution. The action model takes the target node from the HGF, and takes out the prediction state. This state is a vector of values for each category. The vector is the only thing used in the categorical distribution

  • Default hgf: categorical_3level
  • Default target state: Target categorical node xcat
  • Default parameters: none

Using premade agents

We will demonstrate how to work with a premade agent with basic functions from the ActionModels.jl package.

Getting a list of premade HGF agents

using HierarchicalGaussianFiltering
using ActionModels

Define an agent with default parameter values and default HGF

action_model = ActionModel(HGFSoftmax(; HGF = "binary_3level"))
agent = init_agent(action_model, save_history = :xbin_prediction_mean)
-- ActionModels Agent --
Action model: hgf_softmax
This agent has received 0 observations

Utility functions for accessing parameters and states

Get all parameters in an agent:

get_parameters(agent)
(action_noise = 1.0, xprob_drift = 0, xvol_autoconnection_strength = 1, xvol_initial_mean = 0, xbin_xprob_coupling_strength = 1, xprob_autoconnection_strength = 1, xvol_volatility = -2, xprob_initial_precision = 1, xprob_initial_mean = 0, xvol_drift = 0, xvol_initial_precision = 1, xprob_xvol_coupling_strength = 1, xprob_volatility = -2)

Get specific parameter in agent:

get_parameters(agent, :xvol_initial_precision)
1

Get all states in an agent:

get_states(agent)
(xvol_prediction_precision = 0.8807970779778823, xbin_posterior_precision = missing, xbin_prediction_precision = missing, xvol_posterior_precision = 1, xprob_value_prediction_error = missing, xprob_precision_prediction_error = missing, xprob_prediction_precision = 0.8807970779778823, xprob_effective_prediction_precision = 0.11920292202211755, xvol_effective_prediction_precision = 0.11920292202211755, xbin_prediction_mean = missing, xvol_posterior_mean = 0, xprob_posterior_precision = 1, xbin_value_prediction_error = missing, xprob_prediction_mean = 0, xprob_posterior_mean = 0, u_input_value = missing, xbin_posterior_mean = missing, xvol_precision_prediction_error = missing, xvol_value_prediction_error = missing, xvol_prediction_mean = 0)

Get specific state in an agent:

get_states(agent, :xbin_posterior_precision)
missing

Set a parameter value

set_parameters!(agent, :xvol_initial_precision, 0.4)

Set multiple parameter values

set_parameters!(agent, (xvol_initial_precision = 1, xvol_volatility = 0))

Let us move on to giving a set of inputs to the agent.

Define inputs

input = [1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0]
15-element Vector{Int64}:
 1
 0
 0
 1
 1
 0
 0
 1
 1
 1
 1
 1
 0
 1
 0

Give inputs and generate actions

actions = simulate!(agent, input)
15-element Vector{Bool}:
 1
 0
 0
 1
 1
 1
 0
 0
 0
 1
 1
 1
 1
 1
 1

Get the history of a single state in the agent

get_history(agent, :xbin_prediction_mean)
16-element Vector{Union{Missing, Float64}}:
  missing
 0.5
 0.6087750196146673
 0.48575922478252176
 0.39370357795486527
 0.5049341916814218
 0.5931971048444235
 0.4890530297162737
 0.4048131440410199
 0.506818955091594
 0.5905859235685965
 0.6563381311003009
 0.7074989752214864
 0.7476172177230727
 0.6368889826919596
 0.6931395008967419

We can plot the input and prediciton means with plot trajectory. Notice, when using plot_trajectory!() you can layer plots.

using StatsPlots

plot(agent, ("u", "input_value"))

Let's add prediction mean on top of the plot

plot!(agent, ("xbin", "prediction_mean"))

This page was generated using Literate.jl.