Skip to content

Commit

Permalink
Merge pull request #123 from ilabcode/dev
Browse files Browse the repository at this point in the history
Dev to main for next version
  • Loading branch information
PTWaade authored Nov 22, 2023
2 parents c00db49 + 22a7619 commit 1b806fd
Show file tree
Hide file tree
Showing 49 changed files with 18,867 additions and 345 deletions.
6 changes: 4 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
name = "HierarchicalGaussianFiltering"
uuid = "63d42c3e-681c-42be-892f-a47f35336a79"
authors = ["Peter Thestrup Waade [email protected]", "Anna Hedvig Møller [email protected]", "Jacopo Comoglio [email protected]", "Christoph Mathys [email protected]\n and contributors"]
authors = [ "Peter Thestrup Waade [email protected]",
"Anna Hedvig Møller [email protected]",
"Jacopo Comoglio [email protected]",
"Christoph Mathys [email protected]"]
version = "0.3.3"

[deps]
ActionModels = "320cf53b-cc3b-4b34-9a10-0ecb113566a3"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"

[compat]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ plot_trajectory!(agent, ("x1", "prediction"))

````@example index
using Distributions
prior = Dict(("x2", "evolution_rate") => Normal(1, 0.5))
prior = Dict(("x2", "volatility") => Normal(1, 0.5))
model = fit_model(agent, prior, inputs, actions, n_iterations = 20)
````
Expand Down
12 changes: 6 additions & 6 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ makedocs(;
),
pages = [
"Introduction to Hierarchical Gaussian Filtering" => "./index.md",
#"Theory" => [
# "./theory/genmodel.md",
# "./theory/node.md",
# "./theory/vape.md",
# "./theory/vope.md",
#],
"Theory" => [
"./theory/genmodel.md",
"./theory/node.md",
"./theory/vape.md",
"./theory/vope.md",
],
"Using the package" => [
"The HGF Nodes" => "./generated_markdowns/the_HGF_nodes.md",
"Building an HGF" => "./generated_markdowns/building_an_HGF.md",
Expand Down
2 changes: 1 addition & 1 deletion docs/src/Julia_src_files/building_an_HGF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ state_nodes = [
Dict(
"name" => "continuous_state_node",
"type" => "continuous",
"evolution_rate" => -2,
"volatility" => -2,
"initial_mean" => 0,
"initial_precision" => 1,
),
Expand Down
8 changes: 4 additions & 4 deletions docs/src/Julia_src_files/fitting_hgf_models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ using HierarchicalGaussianFiltering
hgf_parameters = Dict(
("u", "category_means") => Real[0.0, 1.0],
("u", "input_precision") => Inf,
("x2", "evolution_rate") => -2.5,
("x2", "volatility") => -2.5,
("x2", "initial_mean") => 0,
("x2", "initial_precision") => 1,
("x3", "evolution_rate") => -6.0,
("x3", "volatility") => -6.0,
("x3", "initial_mean") => 1,
("x3", "initial_precision") => 1,
("x1", "x2", "value_coupling") => 1.0,
Expand Down Expand Up @@ -95,12 +95,12 @@ fixed_parameters = Dict(
("x3", "initial_precision") => 1,
("x1", "x2", "value_coupling") => 1.0,
("x2", "x3", "volatility_coupling") => 1.0,
("x3", "evolution_rate") => -6.0,
("x3", "volatility") => -6.0,
);

# As you can read from the fixed parameters, the evolution rate of x2 is not configured. We set the prior for the x2 evolution rate:
using Distributions
param_priors = Dict(("x2", "evolution_rate") => Normal(-3.0, 0.5));
param_priors = Dict(("x2", "volatility") => Normal(-3.0, 0.5));

# We can fit the evolution rate by inputting the variables:

Expand Down
2 changes: 1 addition & 1 deletion docs/src/Julia_src_files/index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ plot_trajectory!(agent, ("x1", "prediction"))
# ### Fitting parameters

using Distributions
prior = Dict(("x2", "evolution_rate") => Normal(1, 0.5))
prior = Dict(("x2", "volatility") => Normal(1, 0.5))

model = fit_model(agent, prior, inputs, actions, n_iterations = 20)

Expand Down
13 changes: 12 additions & 1 deletion docs/src/Julia_src_files/premade_HGF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# - [Categorical 3-level HGF](#Categorical-3-level-HGF)
# - [Categorical 3-level state transition HGF](#Categorical-3-level-state-transition)

# ![continuous 2-level graph](../images/HGF_structures/all_models.png)

# #Load data for examples

Expand Down Expand Up @@ -40,13 +39,19 @@ inputs_binary = CSV.read(hgf_path_binary * "classic_binary_inputs.csv", DataFram

# ## Continuous 2-level HGF



# ![continuous 2-level graph](../images/HGF_structures/continuous.svg)


# The continuous 2-level HGF is structured with following nodes:

# - input node: continuous
# - state nodes:
# - 1st level: continuous (value coupling to input node)
# - 2nd level: continous (volatility coupling to 1st level)


#Create HGF and Agent
continuous_2_level = premade_hgf("continuous_2level");
agent_continuous_2_level =
Expand Down Expand Up @@ -93,6 +98,9 @@ plot_trajectory(

# ## Binary 2-level HGF

# ![continuous 2-level graph](../images/HGF_structures/binary.svg)


# - input node: binary
# - state nodes:
# - 1st level: binary (value coupling to input node)
Expand Down Expand Up @@ -143,6 +151,9 @@ plot_trajectory(agent_binary_3_level, ("x3", "posterior"))

# ## Categorical 3-level HGF

# ![continuous 2-level graph](../images/HGF_structures/categorical.svg)


# The categorical 3-level HGF model takes an input from one of m categories and learns the probability of a category appearing.

# - input node: categorical
Expand Down
2 changes: 1 addition & 1 deletion docs/src/Julia_src_files/premade_models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ set_parameters!(agent, ("x3", "initial_precision"), 0.4)
# Set multiple parameter values
set_parameters!(
agent,
Dict(("x3", "initial_precision") => 1, ("x3", "evolution_rate") => 0),
Dict(("x3", "initial_precision") => 1, ("x3", "volatility") => 0),
)


Expand Down
72 changes: 10 additions & 62 deletions docs/src/Julia_src_files/the_HGF_nodes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,13 @@

# In this section we will cover the types of nodes, their parameters and the rules for structuring your own HGF.


# ### Overview

# - [The Node Types In an HGF and their states](#The-Node-Types-In-an-HGF)
# - [Building principles ](#Building-principles )

# ### The Node Types In an HGF

# We have six types of nodes in the HGF: binary (state node and input node), categorical (state node and input node), and continuous (state node and input node).

# If a node's parameters are configured with a default value, they are stated below as well.

# We provide an overview of the states in each of the nodes.

# 1. [Binary Nodes](#Binary-Nodes)
# 1. [State Node: States and parameters](#The-states-of-binary-state-nodes-and-parameters)
# 2. [Input Node: States and parameters](#The-states-of-binary-input-nodes-and-parameters)

# 3. [Categorical Nodes](#Categorical-Nodes)
# 1. [State Node: States and parameters](#The-states-of-Categorical-state-nodes-and-parameters)
# 2. [Input Node: States and parameters](#The-states-of-Categorical-Input-nodes-and-parameters)

# 4. [Continuous Nodes](#Continuous-Nodes)
# 1. [State Node: States and parameters](#The-states-of-Continuous-state-nodes-and-parameters)
# 2. [Input Node: States and parameters](#The-states-of-Continuous-Input-nodes-and-parameters)


# ## Binary Nodes

# ### The states of binary state nodes

# - posterior_mean
# - posterior_precision
# - value\_prediction\_error
# - prediction_mean
# - prediction_precision

# ### Parameters

# - Value coupling


# ### The states of binary input nodes and parameters
# ![states and parameters](../images/states_nodes/all_states.svg)

# - input value
# - value prediction error

# ### Parameters

# - Category means (default is [0,1])
# - Input precision (default is infinite input precision)


# ## Categorical Nodes

# ### The states of Categorical state nodes and parameters

# - posterior
# - value prediction error
# - prediction
# ## Building principles

# The following rules apply for connecting nodes, when customizing your own HGF structure:
# ### Parameters

# - no parameters in the categorical state node
Expand Down Expand Up @@ -109,20 +55,18 @@

# ### Parameters

# - evolution rate (default is 0)
# - input noise (default is 0)
# - value coupling
# - volatility coupling



# ## Building principles

# ### Binary state node rules:

# - Can only have exactly one value parent
# - Can only have excatly one value child
# - Can only have a contionus state node as value parent

# ![states and parameters](../images/states_nodes/binary_nodes.svg)

# ### continuous state node rules:

# - Can’t have binary input node as child
Expand All @@ -132,8 +76,12 @@
# - Can’t have the same value parent as volatility parent
# - Can’t have the same value child as volatility child

# ![states and parameters](../images/states_nodes/continuous_nodes.svg)

# ### Categorical state node rules:

# - Can only have exactly one value child
# - Can only have categorical input node as child
# - Can only have binary state node as parents

# ![states and parameters](../images/states_nodes/categorical_nodes.svg)
8 changes: 4 additions & 4 deletions docs/src/Julia_src_files/utility_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ get_parameters(agent)
# ERROR WITH THIS get_parameters(agent, ("x2", "x3", "volatility_coupling"))

# getting multiple parameters specify them in a vector
get_parameters(agent, [("x3", "evolution_rate"), ("x3", "initial_precision")])
get_parameters(agent, [("x3", "volatility"), ("x3", "initial_precision")])


# ### Getting States
Expand All @@ -46,7 +46,7 @@ get_states(agent)
get_states(agent, ("x2", "posterior_precision"))

#getting multiple states
get_states(agent, [("x2", "posterior_precision"), ("x2", "auxiliary_prediction_precision")])
get_states(agent, [("x2", "posterior_precision"), ("x2", "volatility_weighted_prediction_precision")])


# ### Setting Parameters
Expand All @@ -61,10 +61,10 @@ agent_parameter = Dict("sigmoid_action_precision" => 3)
hgf_parameters = Dict(
("u", "category_means") => Real[0.0, 1.0],
("u", "input_precision") => Inf,
("x2", "evolution_rate") => -2.5,
("x2", "volatility") => -2.5,
("x2", "initial_mean") => 0,
("x2", "initial_precision") => 1,
("x3", "evolution_rate") => -6.0,
("x3", "volatility") => -6.0,
("x3", "initial_mean") => 1,
("x3", "initial_precision") => 1,
("x1", "x2", "value_coupling") => 1.0,
Expand Down
1 change: 0 additions & 1 deletion docs/src/generated_markdowns/dummy.jl

This file was deleted.

Binary file removed docs/src/images/HGF_structures/Binary_2_level.png
Binary file not shown.
Binary file removed docs/src/images/HGF_structures/Binary_3_level.png
Binary file not shown.
Binary file removed docs/src/images/HGF_structures/JGET.png
Binary file not shown.
Binary file removed docs/src/images/HGF_structures/all_models.png
Binary file not shown.
Loading

0 comments on commit 1b806fd

Please sign in to comment.