Skip to content

Commit

Permalink
Merge pull request #167 from ilabcode/dev
Browse files Browse the repository at this point in the history
regorganization of actionmodels dependencies
  • Loading branch information
PTWaade authored Oct 8, 2024
2 parents ef01e41 + cdfa85b commit ee23276
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 60 deletions.
39 changes: 0 additions & 39 deletions src/ActionModels_variations/core/plot_predictive_simulation.jl

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 10 additions & 11 deletions src/HierarchicalGaussianFiltering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using ActionModels, Distributions, RecipesBase
export init_node, init_hgf, premade_hgf, check_hgf, update_hgf!
export get_prediction, get_surprise
export premade_agent,
init_agent, plot_predictive_simulation, plot_trajectory, plot_trajectory!
init_agent, plot_trajectory, plot_trajectory!
export get_history,
get_parameters, get_states, set_parameters!, reset!, give_inputs!, set_save_history!
export ParameterGroup
Expand Down Expand Up @@ -36,16 +36,15 @@ end
include("create_hgf/hgf_structs.jl")

#Overloading ActionModels functions
include("ActionModels_variations/core/create_premade_agent.jl")
include("ActionModels_variations/core/plot_predictive_simulation.jl")
include("ActionModels_variations/core/plot_trajectory.jl")
include("ActionModels_variations/utils/get_history.jl")
include("ActionModels_variations/utils/get_parameters.jl")
include("ActionModels_variations/utils/get_states.jl")
include("ActionModels_variations/utils/give_inputs.jl")
include("ActionModels_variations/utils/reset.jl")
include("ActionModels_variations/utils/set_parameters.jl")
include("ActionModels_variations/utils/set_save_history.jl")
include("ActionModels_variations/create_premade_agent.jl")
include("ActionModels_variations/plot_trajectory.jl")
include("ActionModels_variations/get_history.jl")
include("ActionModels_variations/get_parameters.jl")
include("ActionModels_variations/get_states.jl")
include("ActionModels_variations/give_inputs.jl")
include("ActionModels_variations/reset.jl")
include("ActionModels_variations/set_parameters.jl")
include("ActionModels_variations/set_save_history.jl")

#Functions for updating the HGF
include("update_hgf/update_hgf.jl")
Expand Down
29 changes: 19 additions & 10 deletions test/testsuite/test_fit_model.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
using ActionModels
using HierarchicalGaussianFiltering
using Test
using Plots
using StatsPlots
using Distributions
using Turing
using ActionModels: Turing

@testset "Model fitting" begin

@testset "Continuous 2level" begin

#Set inputs and responses
test_input = [1.0, 2, 3, 4, 5]
test_responses = [1.1, 2.2, 3.3, 4.4, 5.5]
test_input = [1.0, 1.0, 1.0, 1.0, 1.0]
test_responses = [1.0, 1.0, 1.0, 1.0, 1.0]

#Create HGF
test_hgf = premade_hgf("continuous_2level", verbose = false)
Expand All @@ -22,20 +21,18 @@ using Turing

# Set fixed parsmeters and priors for fitting
test_fixed_parameters = Dict(
("x", "initial_mean") => 100,
("x", "initial_mean") => 1,
("xvol", "initial_mean") => 1.0,
("xvol", "initial_precision") => 600,
("xvol", "initial_precision") => 1,
("x", "xvol", "coupling_strength") => 1.0,
"action_noise" => 0.01,
("xvol", "volatility") => -4,
("xvol", "volatility") => -10,
("u", "input_noise") => 4,
("xvol", "drift") => 1,
)

test_param_priors = Dict(
("x", "volatility") => Normal(log(100.0), 4),
("x", "initial_mean") => Normal(1, sqrt(100.0)),
("x", "drift") => Normal(0, 1),
("x", "volatility") => Normal(-10, 0.1),
)

#Create model
Expand All @@ -44,6 +41,18 @@ using Turing
#Fit single chain with defaults
fitted_model = fit_model(model; n_iterations = 10, n_chains = 1)

chains = fitted_model.chains
renamed_model = rename_chains(chains, model)
#Extract agent parameters
agent_parameters = extract_quantities(model, chains)

estimates_df = get_estimates(agent_parameters)
estimates_dict = get_estimates(agent_parameters, Dict)

#Extract state trajectories
state_trajectories = get_trajectories(model, chains, [("x", "value_prediction_error"), "action"])
trajectory_estimates_df = get_estimates(state_trajectories)

@test fitted_model isa ActionModels.FitModelResults

#Plot the parameter distribution
Expand Down

2 comments on commit ee23276

@PTWaade
Copy link
Collaborator Author

@PTWaade PTWaade commented on ee23276 Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

##Minor change
Made the package compatible with ActionModels new version

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/116837

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.2 -m "<description of version>" ee23276f85e3ec8abd5fef84ad9df9a89a28edbe
git push origin v0.6.2

Please sign in to comment.