Skip to content

Commit 0e1dca7

Browse files
committed
add formatter
1 parent ffe54e9 commit 0e1dca7

9 files changed

Lines changed: 805 additions & 740 deletions

File tree

.JuliaFormatter.toml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
always_use_return = false
2+
annotate_untyped_fields_with_any = true
3+
conditional_to_if = false
4+
import_to_using = false
5+
join_lines_based_on_source = true
6+
normalize_line_endings = "unix"
7+
pipe_to_function_call = false
8+
remove_extra_newlines = true
9+
short_to_long_function_def = false
10+
long_to_short_function_def = false
11+
whitespace_in_kwargs = true
12+
whitespace_ops_in_indices = true
13+
whitespace_typedefs = true
14+
indent = 4
15+
margin = 92
16+
format_docstrings = false
17+
align_struct_field = false
18+
align_assignment = false
19+
align_conditional = false
20+
align_pair_arrow = false
21+
align_matrix = false
22+
trailing_comma = false
23+
trailing_zero = true
24+
indent_submodule = false
25+
separate_kwargs_with_semicolon = false
26+
surround_whereop_typeparameters = true
27+
variable_call_indent = []
28+
yas_style_nesting = false
29+
disallow_single_arg_nesting = true

sandbox/sandbox.jl

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22
# load packages
33
############################################################################################################
44
cd(@__DIR__)
5-
using Pkg
5+
using Pkg
66
Pkg.activate("..")
77
using CategorizationModels
8-
using Random
9-
using Test
8+
using Random
9+
using Test
1010

1111
Random.seed!(5)
1212

1313
# model predictions
1414
parms == 80.0,
15-
σ = 20.0,
16-
υ_k_k = 1.0,
17-
υ_s_k = 2.0,
18-
υ_k_s = 3.0,
19-
υ_s_s = 4.0,
20-
λ_k_k = .2,
21-
λ_s_k = .3,
22-
λ_k_s = .4,
23-
λ_s_s = .5)
15+
σ = 20.0,
16+
υ_k_k = 1.0,
17+
υ_s_k = 2.0,
18+
υ_k_s = 3.0,
19+
υ_s_s = 4.0,
20+
λ_k_k = 0.2,
21+
λ_s_k = 0.3,
22+
λ_k_s = 0.4,
23+
λ_s_s = 0.5)
2424

2525
# number of evidence states
2626
n_states = 96
@@ -29,7 +29,7 @@ n_states = 96
2929
n_options = 6
3030

3131
# create a model object
32-
model = QuantumModel(;parms..., n_states)
32+
model = QuantumModel(; parms..., n_states)
3333

3434
# generate predictions for all conditions
3535
preds = predict(model, n_options)
@@ -40,17 +40,15 @@ data = rand(model, preds, 100)
4040
# compute the logpdf of each data point
4141
LLs = logpdf(model, preds, data)
4242

43-
44-
4543
function make_hamiltonian1(n_states, υ, σ)
4644
mat = zeros(n_states, n_states)
4745
for c 1:n_states, r 1:n_states
4846
if (c - r) == 1
49-
mat[r,c] = σ
47+
mat[r, c] = σ
5048
elseif (c - r) == -1
51-
mat[r,c] = σ
49+
mat[r, c] = σ
5250
elseif r == c
53-
mat[r,c] = (r / n_states) * υ
51+
mat[r, c] = (r / n_states) * υ
5452
end
5553
end
5654
return mat
@@ -59,10 +57,10 @@ end
5957
function make_hamiltonian2(n_states, υ, σ)
6058
mat = zeros(n_states, n_states)
6159
for i 1:n_states
62-
mat[i,i] = (i / n_states) * υ
63-
i < n_states ? mat[i,i+1] = σ : nothing
64-
println(i > 1 )
65-
i > 1 ? (mat[i,i-1] = σ) : nothing
60+
mat[i, i] = (i / n_states) * υ
61+
i < n_states ? mat[i, i + 1] = σ : nothing
62+
println(i > 1)
63+
i > 1 ? (mat[i, i - 1] = σ) : nothing
6664
end
6765
return mat
68-
end
66+
end

src/CategorizationModels.jl

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
module CategorizationModels
22

3-
using Distributions
4-
using LinearAlgebra
3+
using Distributions
4+
using LinearAlgebra
55

6-
import Distributions: ContinuousUnivariateDistribution
7-
import Distributions: rand
8-
import Distributions: logpdf
9-
10-
export BayesianModel
11-
export MarkovModel
12-
export QuantumModel
13-
export RationalModel
6+
import Distributions: ContinuousUnivariateDistribution
7+
import Distributions: rand
8+
import Distributions: logpdf
149

15-
export predict
16-
export logpdf
17-
export rand
18-
export sumlogpdf
19-
20-
include("common.jl")
21-
include("rational.jl")
22-
include("bayesian.jl")
23-
include("markov.jl")
24-
include("quantum.jl")
10+
export BayesianModel
11+
export MarkovModel
12+
export QuantumModel
13+
export RationalModel
14+
15+
export predict
16+
export logpdf
17+
export rand
18+
export sumlogpdf
19+
20+
include("common.jl")
21+
include("rational.jl")
22+
include("bayesian.jl")
23+
include("markov.jl")
24+
include("quantum.jl")
2525
end

src/bayesian.jl

Lines changed: 58 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ A model object for the Bayesian model.
1414
- `λ_sk_s`: diffusion for stimulus s when s is evaluated first
1515
- `n_states`: the number of evidence states
1616
"""
17-
struct BayesianModel{T<:Real} <: Model
17+
struct BayesianModel{T <: Real} <: Model
1818
μk::T
19-
μs::T
19+
μs::T
2020
σk::T
2121
σs::T
2222
υ_ks_k::T
@@ -26,48 +26,46 @@ struct BayesianModel{T<:Real} <: Model
2626
n_states::Int
2727
end
2828

29-
function BayesianModel(;μk,
30-
μs,
31-
σk,
32-
σs,
33-
υ_ks_k,
34-
υ_sk_s,
35-
λ_ks_k,
36-
λ_sk_s,
37-
n_states)
38-
29+
function BayesianModel(; μk,
30+
μs,
31+
σk,
32+
σs,
33+
υ_ks_k,
34+
υ_sk_s,
35+
λ_ks_k,
36+
λ_sk_s,
37+
n_states)
3938
return BayesianModel(μk,
40-
μs,
41-
σk,
42-
σs,
43-
υ_ks_k,
44-
υ_sk_s,
45-
λ_ks_k,
46-
λ_sk_s,
47-
n_states)
39+
μs,
40+
σk,
41+
σs,
42+
υ_ks_k,
43+
υ_sk_s,
44+
λ_ks_k,
45+
λ_sk_s,
46+
n_states)
4847
end
4948

5049
function BayesianModel(
5150
μk,
52-
μs,
53-
σk,
54-
σs,
55-
υ_ks_k,
51+
μs,
52+
σk,
53+
σs,
54+
υ_ks_k,
5655
υ_sk_s,
5756
λ_ks_k,
5857
λ_sk_s,
5958
n_states)
60-
61-
parms = promote(
59+
parms = promote(
6260
μk,
63-
μs,
64-
σk,
65-
σs,
66-
υ_ks_k,
61+
μs,
62+
σk,
63+
σs,
64+
υ_ks_k,
6765
υ_sk_s,
6866
λ_ks_k,
6967
λ_sk_s)
70-
68+
7169
return BayesianModel(parms..., n_states)
7270
end
7371

@@ -95,11 +93,11 @@ distribution of rating both stimuli in two orders. The joint distributions are a
9593
4. The joint probability distribution for k then s given stimulus s where element `pred[i,j]` is the probability of rating stimulus `s` as `i` and stimulus `k` as `j`
9694
"""
9795
function predict(model::BayesianModel{T}, n_options) where {T}
98-
(;μk,μs,σk,σs,n_states) = model
99-
(;υ_ks_k, υ_sk_s,λ_ks_k,λ_sk_s) = model
96+
(; μk, μs, σk, σs, n_states) = model
97+
(; υ_ks_k, υ_sk_s, λ_ks_k, λ_sk_s) = model
10098

10199
n = div(n_states, n_options)
102-
initial_states = Vector{Vector{T}}(undef,4)
100+
initial_states = Vector{Vector{T}}(undef, 4)
103101
# initial state k then s for k stimulus
104102
initial_states[1] = compute_initial_state(model, μk, σk, n_states)
105103
# initial state s then k for s stimulus
@@ -110,7 +108,7 @@ function predict(model::BayesianModel{T}, n_options) where {T}
110108
# intensity matrix s then k for s stimulus
111109
κ_sk_s = make_intensity_matrix(model, n_states, υ_sk_s)
112110

113-
transitions = Vector{Matrix{T}}(undef,4)
111+
transitions = Vector{Matrix{T}}(undef, 4)
114112
# transition matrix k then s for k stimulus
115113
transitions[1] = exp(λ_ks_k * κ_ks_k)
116114
# transition matrix s then k for s stimulus
@@ -122,27 +120,27 @@ function predict(model::BayesianModel{T}, n_options) where {T}
122120
initial_states[4] = transitions[3] * initial_states[3]
123121

124122
# transition matrix s then k for k stimulus
125-
transitions[2] = make_transition_matrix(model,
126-
initial_states[2],
127-
initial_states[1],
128-
transitions[1])
123+
transitions[2] = make_transition_matrix(model,
124+
initial_states[2],
125+
initial_states[1],
126+
transitions[1])
129127

130128
# transition matrix k then s for s stimulus
131-
transitions[4] = make_transition_matrix(model,
132-
initial_states[4],
133-
initial_states[3],
134-
transitions[3])
129+
transitions[4] = make_transition_matrix(model,
130+
initial_states[4],
131+
initial_states[3],
132+
transitions[3])
135133

136134
# a projector for each option
137-
projectors = map(i ->
138-
make_projector(n_states, n * (i - 1) + 1, i * n),
139-
1:n_options)
140-
141-
preds = map((s,t) ->
142-
make_joint_dist(model, s, projectors, t),
143-
initial_states,
144-
transitions)
145-
return preds
135+
projectors = map(i ->
136+
make_projector(n_states, n * (i - 1) + 1, i * n),
137+
1:n_options)
138+
139+
preds = map((s, t) ->
140+
make_joint_dist(model, s, projectors, t),
141+
initial_states,
142+
transitions)
143+
return preds
146144
end
147145

148146
"""
@@ -173,15 +171,15 @@ function make_intensity_matrix(model::BayesianModel, n_states, υ)
173171
mat = zeros(n_states, n_states)
174172
for c 1:n_states, r 1:n_states
175173
if r == (c - 1)
176-
mat[r,c] = 1 - υ
174+
mat[r, c] = 1 - υ
177175
elseif c == (r - 1)
178-
mat[r,c] = 1 + υ
176+
mat[r, c] = 1 + υ
179177
elseif r == c
180-
mat[r,c] = -2
178+
mat[r, c] = -2
181179
end
182180
end
183-
mat[1,1] = -1 - υ
184-
mat[end,end] = υ - 1
181+
mat[1, 1] = -1 - υ
182+
mat[end, end] = υ - 1
185183
return mat
186184
end
187185

@@ -201,7 +199,7 @@ function make_transition_matrix(model::BayesianModel, s0_sk, s0_ks, T)
201199
n = length(s0_sk)
202200
probs = fill(0.0, n, n)
203201
for k 1:n, j 1:n
204-
probs[j,k] = s0_ks[j] * T[k,j] / s0_sk[k]
202+
probs[j, k] = s0_ks[j] * T[k, j] / s0_sk[k]
205203
end
206-
return probs
207-
end
204+
return probs
205+
end

0 commit comments

Comments
 (0)