Skip to content

Commit 9cdfeb2

Browse files
committed
update docs and files
1 parent 0c1d5e2 commit 9cdfeb2

File tree

8 files changed

+59
-14
lines changed

8 files changed

+59
-14
lines changed

Examples/Delay_Discounting/Delay_Discounting.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ end
88

99
function loglike(κ, τ, t_ss, t_ll, r_ss, r_ll, data)
1010
p = prob(κ, τ, t_ss, t_ll, r_ss, r_ll)
11-
p = p == 1 ? 1 - eps() : p
12-
p = p == 0 ? eps() : p
11+
p = max(p, eps())
12+
p = min(1-eps(), p)
1313
LL = data ? log(p) : log(1 - p)
1414
# println(" choice ", data, " kappa ", κ, " tau ", τ, " t_ss ", t_ss,
1515
# " t_ll ", t_ll, " r_ss ", r_ss, " r_ll ", r_ll, " LL ", LL)

Examples/Delay_Discounting/Run_Delay_Discounting.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ cd(@__DIR__)
77
using Pkg
88
# activate the project environment
99
Pkg.activate("../../")
10-
using Revise, AdaptiveDesignOptimization, Random, UtilityModels, Distributions
11-
include("Delay_Discounting.jl")
10+
using Revise, AdaptiveDesignOptimization, Random, Distributions
11+
includet("Delay_Discounting.jl")
1212
#######################################################################################
13-
# Define Model
13+
# Define Experiment Design
1414
#######################################################################################
15-
Random.seed!(12034)
15+
Random.seed!(120341)
1616
prior = [Uniform(-5, 5), Uniform(-5, 50)]
1717

1818
model = Model(;prior, loglike)

Examples/Monetary_Gambles/Run_Monetary_Gamble.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ cd(@__DIR__)
77
using Pkg
88
# activate the project environment
99
Pkg.activate("../../")
10-
using AdaptiveDesignOptimization, Random, UtilityModels, Distributions
11-
include("TAX_Model.jl")
10+
using Revise, AdaptiveDesignOptimization, Random, UtilityModels, Distributions
11+
includet("TAX_Model.jl")
1212
Random.seed!(25974)
1313
#######################################################################################
14-
# Define Parameters
14+
# Define Experiment Design
1515
#######################################################################################
16-
1716
# model with default uniform prior
1817
model = Model(;loglike)
1918

Examples/Monetary_Gambles/TAX_Model.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function loglike(δ, β, γ, θ, pa, va, pb, vb, data)
2020
eua,eub = expected_utilities(δ, β, γ, θ, pa, va, pb, vb)
2121
p = choice_prob(eua, eub, θ)
2222
p = max(p, eps())
23+
p = min(1-eps(), p)
2324
return logpdf(Bernoulli(p), data)
2425
end
2526

Examples/Monetary_Gambles/results.png

17.9 KB
Loading

Project.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@ version = "0.1.0"
66
[deps]
77
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
88
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
9+
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"
910
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1011
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
1112
StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
12-
UtilityModels = "bddc258c-9485-48da-848b-3e4c1ee8966c"
1313

1414
[compat]
1515
Distributions = "v0.24.13"
1616
Parameters = "v0.12.2"
1717
SafeTestsets = "v0.0.1"
1818
StatsFuns = "v0.9.6"
19-
UtilityModels = "v0.2.2"
2019
julia = "1"
2120

2221
[extras]

README.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This package is a grid-based approach for performing Bayesian adaptive design optimization. After each observation, the optimizer chooses an experimental design that maximizes mutual information between model parameters and design parameters. In so doing, the optimizer selects designs that minimize the variance in the posterior distribution of model parameters.
44
# Example
55

6-
In this example, we will optimize a decision making experiment for the model called Transfer of Attention Exchange (TAX; Birnbaum, 2008). Additional examples can be found in the folder titled Examples. sds
6+
In this example, we will optimize a decision making experiment for the model called Transfer of Attention Exchange (TAX; Birnbaum, 2008). Additional examples can be found in the folder titled Examples.
77

88
```julia
99
using AdaptiveDesignOptimization, Random, UtilityModels, Distributions
@@ -73,6 +73,53 @@ data_list = (choice=[true, false],)
7373
```
7474
## Optimize Exeriment
7575

76+
In the following code blocks, we will run an optimized experiment and a random experiment. The first step is to generate the optimizer with the contructor `Optimizer`. Next, we specify true parameters for generating data from the model and initialize a `DataFrame` to collect the results on each simulated trial. In the experiment loop, data are generated with `simulate`. The data are passed to `update` in order to optimize the experiment for the next trial. Finally, the mean and standard deviation are added to the `DataFrame` for each parameter. A similar process is used to perform the random experiment.
77+
78+
```julia
79+
using DataFrames
80+
true_parms ==-1.0, β=1.0, γ=.7, θ=1.5)
81+
n_trials = 100
82+
optimizer = Optimizer(;design_list, parm_list, data_list, model)
83+
design = optimizer.best_design
84+
df = DataFrame(design=Symbol[], trial=Int[], mean_δ=Float64[], mean_β=Float64[],
85+
mean_γ=Float64[], mean_θ=Float64[], std_δ=Float64[], std_β=Float64[],
86+
std_γ=Float64[], std_θ=Float64[])
87+
new_data = [:optimal, 0, mean_post(optimizer)..., std_post(optimizer)...]
88+
push!(df, new_data)
89+
90+
for trial in 1:n_trials
91+
data = simulate(true_parms..., design...)
92+
design = update!(optimizer, data)
93+
new_data = [:optimal, trial, mean_post(optimizer)..., std_post(optimizer)...]
94+
push!(df, new_data)
95+
end
96+
```
97+
## Random Experiment
98+
```julia
99+
randomizer = Optimizer(;design_list, parm_list, data_list, model, design_type=Randomize);
100+
design = randomizer.best_design
101+
new_data = [:random, 0, mean_post(randomizer)..., std_post(randomizer)...]
102+
push!(df, new_data)
103+
104+
for trial in 1:n_trials
105+
data = simulate(true_parms..., design...)
106+
design = update!(randomizer, data)
107+
new_data = [:random, trial, mean_post(randomizer)..., std_post(randomizer)...]
108+
push!(df, new_data)
109+
end
110+
```
111+
112+
## Results
113+
114+
As expected, in the figure below, the posterior standard deviation of δ is smaller for the optimal experiment compared to the random experiment.
115+
116+
117+
```julia
118+
using StatsPlots
119+
@df df plot(:trial, :std_δ, xlabel="trial", ylabel="σ of δ", grid=false, group=:design, linewidth=2, ylims=(0,1.5), size=(600,400))
120+
```
121+
122+
<img src="Examples/Monetary_Gambles/results.png" alt="" width="500" height="300">
76123

77124
# References
78125

test/runtests.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ end
111111
@test std_post(randomizer)[1] std(Beta+1+2)) atol = 5e-3
112112
end
113113

114-
115114
@safetestset "Dimension Check" begin
116115
using Test, Distributions, AdaptiveDesignOptimization
117116

0 commit comments

Comments
 (0)