Skip to content

Commit

Permalink
Merge pull request #12 from itsdfish/auto-juliaformatter-pr
Browse files Browse the repository at this point in the history
Automatic JuliaFormatter.jl run
  • Loading branch information
itsdfish authored Jul 27, 2024
2 parents 2d619e5 + 3e5f07c commit ae31e2b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/ExpectedUtility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ function compute_utility(model::ExpectedUtility, gamble::Gamble)
(; v) = gamble
utility = @. sign(v) * abs(v)^α
return utility
end
end
4 changes: 2 additions & 2 deletions src/UtilityModel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,6 @@ Generates a simulated choice
function rand(model::UtilityModel, gambles::Vector{<:Gamble})
utility = mean.(model, gambles)
util_exp = exp.(model.θ .* utility)
probs = util_exp ./ sum(util_exp)
probs = util_exp ./ sum(util_exp)
return sample(1:length(gambles), Weights(probs))
end
end
85 changes: 42 additions & 43 deletions test/distributions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,72 +2,71 @@
@safetestset "1" begin
using Test
using UtilityModels
gamble1 = Gamble(;
p = [.50, .50],
v = [-10, 10]
)
gamble2 = Gamble(;
p = [1],

gamble1 = Gamble(;
p = [0.50, 0.50],
v = [-10, 10]
)

gamble2 = Gamble(;
p = [1],
v = [0]
)
gambles = [gamble1,gamble2]

gambles = [gamble1, gamble2]

model = ExpectedUtility(; α = 1.0, θ = 1.0)

prob = pdf(model, gambles, 1)
@test prob .50

@test prob 0.50
end

@safetestset "2" begin
using Test
using UtilityModels
gamble1 = Gamble(;
p = [.50, .50],
v = [-11, 10]
)
gamble2 = Gamble(;
p = [1],

gamble1 = Gamble(;
p = [0.50, 0.50],
v = [-11, 10]
)

gamble2 = Gamble(;
p = [1],
v = [0]
)
gambles = [gamble1,gamble2]

gambles = [gamble1, gamble2]

model = ExpectedUtility(; α = 1.0, θ = 2.0)

prob = pdf(model, gambles, 1)
@test prob 1 / (1 + exp(-2 * -.5))

@test prob 1 / (1 + exp(-2 * -0.5))
end
end


@safetestset "logpdf" begin
@safetestset "1" begin
using Test
using UtilityModels
gamble1 = Gamble(;
p = [.50, .50],
v = [-11, 10]
)
gamble2 = Gamble(;
p = [1],

gamble1 = Gamble(;
p = [0.50, 0.50],
v = [-11, 10]
)

gamble2 = Gamble(;
p = [1],
v = [0]
)
gambles = [gamble1,gamble2]

gambles = [gamble1, gamble2]

model = ExpectedUtility(; α = 1.0, θ = 2.0)

log_prob = pdf(model, gambles, 1) |> log

@test log_prob logpdf(model, gambles, 1)
end
end
end

0 comments on commit ae31e2b

Please sign in to comment.