Skip to content

Commit

Permalink
Merge pull request #134 from ilabcode/dev
Browse files Browse the repository at this point in the history
version 0.5.0
  • Loading branch information
PTWaade authored Apr 15, 2024
2 parents 0b272ac + ae5b5ff commit f00c50c
Show file tree
Hide file tree
Showing 79 changed files with 4,147 additions and 4,497 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI_full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ jobs:
- x64
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: lcov.info
4 changes: 2 additions & 2 deletions .github/workflows/CI_small.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ jobs:
- x64
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: lcov.info
2 changes: 1 addition & 1 deletion .github/workflows/automerge_CompatHelper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ jobs:

- name: Auto approve CompatHelper PRs
if: github.actor == 'CompatHelper Julia'
uses: hmarr/auto-approve-action@v3
uses: hmarr/auto-approve-action@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/automerge_dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ jobs:

- name: Auto approve dependabot PRs
if: github.actor == 'dependabot[bot]'
uses: hmarr/auto-approve-action@v3
uses: hmarr/auto-approve-action@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
runs-on: macOS-latest
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
- uses: julia-actions/setup-julia@v2
with:
version: '1'
- uses: julia-actions/julia-buildpkg@v1
Expand Down
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
*.jl.*.cov
*.jl.cov
*.jl.mem
/docs/build/
.DS_Store
.vscode

testing_script*.jl
settings.json

Manifest.toml
docs/Manifest.toml
test/Manifest.toml
/docs/src/generated_markdowns/*.md

/docs/src/generated
/docs/src/index.md
/docs/build/
/build
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ authors = [ "Peter Thestrup Waade [email protected]",
"Anna Hedvig Møller [email protected]",
"Jacopo Comoglio [email protected]",
"Christoph Mathys [email protected]"]
version = "0.4.0"
version = "0.5.0"

[deps]
ActionModels = "320cf53b-cc3b-4b34-9a10-0ecb113566a3"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"

[compat]
ActionModels = "0.4"
ActionModels = "0.5"
Distributions = "0.25"
RecipesBase = "1"
julia = "1.9"
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ premade_agent("help")
### Create agent

````@example index
agent = premade_agent("hgf_binary_softmax_action")
agent = premade_agent("hgf_binary_softmax")
````

### Get states and parameters
Expand All @@ -55,10 +55,10 @@ get_parameters(agent)

![Image1](docs/src/images/readme/get_parameters.png)

Set a new parameter for initial precision of x2 and define some inputs
Set a new parameter for initial precision of xprob and define some inputs

````@example index
set_parameters!(agent, ("x2", "initial_precision"), 0.9)
set_parameters!(agent, ("xprob", "initial_precision"), 0.9)
inputs = [1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0];
nothing #hide
````
Expand All @@ -75,23 +75,23 @@ actions = give_inputs!(agent, inputs)
using StatsPlots
using Plots
plot_trajectory(agent, ("u", "input_value"))
plot_trajectory!(agent, ("x1", "prediction"))
plot_trajectory!(agent, ("x", "prediction"))
````
![Image1](docs/src/images/readme/plot_trajectory.png)

Plot state trajectory of input value, action and prediction of x1
Plot state trajectory of input value, action and prediction of x

````@example index
plot_trajectory(agent, ("u", "input_value"))
plot_trajectory!(agent, "action")
plot_trajectory!(agent, ("x1", "prediction"))
plot_trajectory!(agent, ("x", "prediction"))
````
![Image1](docs/src/images/readme/plot_trajectory_2.png)
### Fitting parameters

````@example index
using Distributions
prior = Dict(("x2", "volatility") => Normal(1, 0.5))
prior = Dict(("xprob", "volatility") => Normal(1, 0.5))
model = fit_model(agent, prior, inputs, actions, n_iterations = 20)
````
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Glob = "c27321d9-0574-5035-807b-f59d2c89b15c"
HierarchicalGaussianFiltering = "63d42c3e-681c-42be-892f-a47f35336a79"
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd"
Turing = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"
14 changes: 7 additions & 7 deletions docs/src/Julia_src_files/index.jl → docs/julia_files/index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ using ActionModels
premade_agent("help")

# ### Create agent
agent = premade_agent("hgf_binary_softmax_action")
agent = premade_agent("hgf_binary_softmax")

# ### Get states and parameters
get_states(agent)
#-
get_parameters(agent)

# Set a new parameter for initial precision of x2 and define some inputs
set_parameters!(agent, ("x2", "initial_precision"), 0.9)
# Set a new parameter for initial precision of xprob and define some inputs
set_parameters!(agent, ("xprob", "initial_precision"), 0.9)
inputs = [1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0];

# ### Give inputs to the agent
Expand All @@ -42,18 +42,18 @@ actions = give_inputs!(agent, inputs)
using StatsPlots
using Plots
plot_trajectory(agent, ("u", "input_value"))
plot_trajectory!(agent, ("x1", "prediction"))
plot_trajectory!(agent, ("xbin", "prediction"))

# Plot state trajectory of input value, action and prediction of x1
# Plot state trajectory of input value, action and prediction of xbin
plot_trajectory(agent, ("u", "input_value"))
plot_trajectory!(agent, "action")
plot_trajectory!(agent, ("x1", "prediction"))
plot_trajectory!(agent, ("xbin", "prediction"))


# ### Fitting parameters

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

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

Expand Down
43 changes: 43 additions & 0 deletions docs/julia_files/tutorials/classic_JGET.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using ActionModels, HierarchicalGaussianFiltering
using CSV, DataFrames
using Plots, StatsPlots
using Distributions


# Get the path for the HGF superfolder
hgf_path = dirname(dirname(pathof(HierarchicalGaussianFiltering)))
# Add the path to the data files
data_path = hgf_path * "/docs/src/tutorials/data/"

#Load data
data = CSV.read(data_path * "classic_cannonball_data.csv", DataFrame)
inputs = data[(data.ID.==20).&(data.session.==1), :].outcome

#Create HGF
hgf = premade_hgf("JGET", verbose = false)
#Create agent
agent = premade_agent("hgf_gaussian", hgf)
#Set parameters
parameters = Dict(
"action_noise" => 1,
("u", "input_noise") => 0,
("x", "initial_mean") => first(inputs) + 2,
("x", "initial_precision") => 0.001,
("x", "volatility") => -8,
("xvol", "volatility") => -8,
("xnoise", "volatility") => -7,
("xnoise_vol", "volatility") => -2,
("x", "xvol", "coupling_strength") => 1,
("xnoise", "xnoise_vol", "coupling_strength") => 1,
)
set_parameters!(agent, parameters)
reset!(agent)

#Simulate updates and actions
actions = give_inputs!(agent, inputs);
#Plot belief trajectories
plot_trajectory(agent, "u")
plot_trajectory!(agent, "x")
plot_trajectory(agent, "xvol")
plot_trajectory(agent, "xnoise")
plot_trajectory(agent, "xnoise_vol")
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ using Distributions
# Get the path for the HGF superfolder
hgf_path = dirname(dirname(pathof(HierarchicalGaussianFiltering)))
# Add the path to the data files
data_path = hgf_path * "/docs/src/tutorials/data/"
data_path = hgf_path * "/docs/julia_files/tutorials/data/"

# Load the data
inputs = CSV.read(data_path * "classic_binary_inputs.csv", DataFrame)[!, 1];
Expand All @@ -23,59 +23,57 @@ inputs = CSV.read(data_path * "classic_binary_inputs.csv", DataFrame)[!, 1];
hgf_parameters = Dict(
("u", "category_means") => Real[0.0, 1.0],
("u", "input_precision") => Inf,
("x2", "volatility") => -2.5,
("x2", "initial_mean") => 0,
("x2", "initial_precision") => 1,
("x3", "volatility") => -6.0,
("x3", "initial_mean") => 1,
("x3", "initial_precision") => 1,
("x1", "x2", "value_coupling") => 1.0,
("x2", "x3", "volatility_coupling") => 1.0,
("xprob", "volatility") => -2.5,
("xprob", "initial_mean") => 0,
("xprob", "initial_precision") => 1,
("xvol", "volatility") => -6.0,
("xvol", "initial_mean") => 1,
("xvol", "initial_precision") => 1,
("xbin", "xprob", "coupling_strength") => 1.0,
("xprob", "xvol", "coupling_strength") => 1.0,
);

hgf = premade_hgf("binary_3level", hgf_parameters, verbose = false);

# Create an agent
agent_parameters = Dict("sigmoid_action_precision" => 5);
agent =
premade_agent("hgf_unit_square_sigmoid_action", hgf, agent_parameters, verbose = false);
agent_parameters = Dict("action_noise" => 0.2);
agent = premade_agent("hgf_unit_square_sigmoid", hgf, agent_parameters, verbose = false);

# Evolve agent and save actions
actions = give_inputs!(agent, inputs);

# Plot the trajectory of the agent
plot_trajectory(agent, ("u", "input_value"))
plot_trajectory!(agent, ("x1", "prediction"))

plot_trajectory!(agent, ("xbin", "prediction"))

# -

plot_trajectory(agent, ("x2", "posterior"))
plot_trajectory(agent, ("x3", "posterior"))
plot_trajectory(agent, ("xprob", "posterior"))
plot_trajectory(agent, ("xvol", "posterior"))

# Set fixed parameters
fixed_parameters = Dict(
"sigmoid_action_precision" => 5,
"action_noise" => 0.2,
("u", "category_means") => Real[0.0, 1.0],
("u", "input_precision") => Inf,
("x2", "initial_mean") => 0,
("x2", "initial_precision") => 1,
("x3", "initial_mean") => 1,
("x3", "initial_precision") => 1,
("x1", "x2", "value_coupling") => 1.0,
("x2", "x3", "volatility_coupling") => 1.0,
("x3", "volatility") => -6.0,
("xprob", "initial_mean") => 0,
("xprob", "initial_precision") => 1,
("xvol", "initial_mean") => 1,
("xvol", "initial_precision") => 1,
("xbin", "xprob", "coupling_strength") => 1.0,
("xprob", "xvol", "coupling_strength") => 1.0,
("xvol", "volatility") => -6.0,
);

# Set priors for parameter recovery
param_priors = Dict(("x2", "volatility") => Normal(-3.0, 0.5));
param_priors = Dict(("xprob", "volatility") => Normal(-3.0, 0.5));
#-
# Prior predictive plot
plot_predictive_simulation(
param_priors,
agent,
inputs,
("x1", "prediction_mean"),
("xbin", "prediction_mean"),
n_simulations = 100,
)
#-
Expand Down Expand Up @@ -104,6 +102,6 @@ plot_predictive_simulation(
fitted_model,
agent,
inputs,
("x1", "prediction_mean"),
("xbin", "prediction_mean"),
n_simulations = 3,
)
Loading

4 comments on commit f00c50c

@PTWaade
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@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/104963

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.5.0 -m "<description of version>" f00c50cb4cde7dfcc7e017c31baeb391057f90cb
git push origin v0.5.0

@PTWaade
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register

Release notes:

Breaking changes

  • New syntax for specifying HGF
  • nonlinear transforms, timed inputs, save_history and more

@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 updated: JuliaRegistries/General/104963

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.5.0 -m "<description of version>" f00c50cb4cde7dfcc7e017c31baeb391057f90cb
git push origin v0.5.0

Please sign in to comment.