QuantumContextEffectModels.QuantumModel
— TypeQuantumModel{T<:Real} <: AbstractQuantumModel
Fields
Ψ::Vector{T}
: initial state vectorθil::T
: parameter for rotating basis frominformative
tolikable
.θil ∈ [-1,1]
θpb::T
: parameter for rotating basis frombelievable
topersuasive
.θpb ∈ [-1,1]
Constructors
QuantumModel( Ψ, θil, θpb)
QuantumModel(; Ψ, θil, θpb)
Reference
Busemeyer, J. R., & Wang, Z. (2018). Hilbert space multidimensional theory. Psychological Review, 125(4), 572.
Base.rand
— Methodrand(
dist::AbstractQuantumModel,
n_trials::Int;
joint_func = get_ordered_joint_probs,
n_way
)
Simulates n_trials
of judgements per condition for all possible ordered collections of size n_way
.
Arguments
dist::AbstractQuantumModel
:an abstract quantum model objectn_trials::Int
: number of trials per condition
Keywords
joint_func = get_ordered_joint_probs
: joint probability function. The functionget_ordered_joint_probs
returns
all possible orders where as the function get_joint_probs
returns joint probabilities in the order specified in make_projectors
.
n_way
: the number of attributes simultaneously judged, forming an n_way-table.
Distributions.logpdf
— Methodlogpdf(
dist::AbstractQuantumModel,
data::Vector{Vector{Int}},
n_trials::Int;
n_way
)
Evaluates the log likelihood of all judgements for all possible joint probability tables with n_way
dimensionality.
Arguments
dist::AbstractQuantumModel
:an abstract quantum model objectdata::Vector{Vector{Int}}
: frequencies of yes responses for alln_way
tables (excluding order)n_trials::Int
: number of trials per condition
Keywords
n_way
: the number of attributes simultaneously judged, forming an n_way-table.
Distributions.logpdf
— Methodlogpdf(
dist::AbstractQuantumModel,
data::Vector{Vector{Vector{Int}}},
n_trials::Int;
n_way
)
Evaluates the log likelihood of all judgements per condition for all possible ordered collections of size n_way
.
Arguments
dist::AbstractQuantumModel
:an abstract quantum model objectdata::Vector{Vector{Vector{Int}}}
: frequencies of yes responses for alln_way
tables and ordersn_trials::Int
: number of trials per condition
Keywords
n_way
: the number of attributes simultaneously judged, forming an n_way-table.
QuantumContextEffectModels.get_joint_probs
— Methodget_joint_probs(model::AbstractQuantumModel, projectors, Ψ)
Computes joint probabilities for a distribution with an arbitrary number of dimensions and values per dimension. The total number of elements is n = Πᵢᵐ nᵢ
, where nᵢ
is the number of possible values for the ith dimension. For example, the joint probabilties for two binary variables is organized as follows:
yes yes
yes no
no yes
no no
Arguments
model::AbstractQuantumModel
:an abstract quantum model objectprojectors
: a vector of projectorsΨ
: superposition state vector
QuantumContextEffectModels.get_ordered_joint_probs
— Methodget_ordered_joint_probs(model::AbstractQuantumModel, projectors, Ψ)
Computes joint probabilities for all posible orders. The function works for a distribution with an arbitrary number of dimensions and values per dimension. The total number of elements is n = Πᵢᵐ nᵢ
, where nᵢ
is the number of possible values for the ith dimension.
Arguments
model::AbstractQuantumModel
:an abstract quantum model objectprojectors
: a vector of projectorsΨ
: superposition state vector
QuantumContextEffectModels.make_projectors
— Methodmake_projectors(model::QuantumModel)
Returns projectors for each value of each variable.
Arguments
model::AbstractQuantumModel
:an abstract quantum model object
Returns
projectors::Vector{Vector{Float64}}
: a nested vector of projectors
For this model, there are four variables corresponding to believable, infromative, persuasive, and likable which have binary values (e.g., yes, no). The projectors organized as follows [[Pby Pbn],[Piy Pin],[Ppy Ppn],[Ply Pln]]
, where the first index corresponds to the variable and the second index correspons to the binary value. For example, Pbn
, is the projector for responding "no" to the question about believable.
QuantumContextEffectModels.predict
— Methodpredict(
model::AbstractQuantumModel;
n_way,
joint_func = get_ordered_joint_probs
)
Computes response probabilities all possible n_way
joint probability tables. If get_ordered_joint_probs
is assigned to joint_func
, all orders within each n_way
table is included. If get_joint_probs
is assigned to joint_func
, the output will include only one order perh n_way
joint probability table. The order used is based on the projectors defined in make_projectors
.
Arguments
model::AbstractQuantumModel
:an abstract quantum model object
Keywords
n_way
: the number of attributes judged simultaneously to form an n-way joint probability tablejoint_func=get_ordered_joint_probs
: joint probability function. The functionget_ordered_joint_probs
returns
all possible orders where as the function get_joint_probs
returns joint probabilities in the order specified in make_projectors
.
QuantumContextEffectModels.to_dataframe
— Methodto_dataframe(
data::Vector{Vector{Vector{Float64}}},
attributes::T1,
values::T2,
n_way::Int
)
Arguments
data::Vector{Vector{Vector{T}}}:
a three-level nested data vector of vectors representing data or predictions. The first level contains different subsets ofn_way
joint probabilities (e.g., {B,I},{B,P},...). The second level contains all orders for a given subset (e.g., [B,I], [I,E]). The third level contains specific elemnts of then_way
joint probability table.attributes::T1
: a vector of attribute namesvalues::T2
: a vector of vectors where each sub-vector responses to possible values for a given attribute namen_way::Int
: the number of attributes defining then₁ × … × nₘ
joint probability table wherem=n_way
.
where T1
,T2
<:
Vector
.
Example output
48×6 DataFrame
Row │ group order attributes values val_idx preds
│ Int64 Int64 Array… Array… Int64 Float64
─────┼──────────────────────────────────────────────────────────────
1 │ 1 1 [:B, :I] [:yes, :yes] 1 0.3
2 │ 1 1 [:B, :I] [:no, :yes] 2 0.2
3 │ 1 1 [:B, :I] [:yes, :no] 3 0.1
4 │ 1 1 [:B, :I] [:no, :no] 4 0.4
5 │ 1 2 [:I, :B] [:yes, :yes] 1 0.3
6 │ 1 2 [:I, :B] [:yes, :no] 2 0.2
7 │ 1 2 [:I, :B] [:no, :yes] 3 0.1
8 │ 1 2 [:I, :B] [:no, :no] 4 0.4
9 │ 2 1 [:B, :P] [:yes, :yes] 1 0.329624
10 │ 2 1 [:B, :P] [:no, :yes] 2 0.624449
11 │ 2 1 [:B, :P] [:yes, :no] 3 0.0300594
12 │ 2 1 [:B, :P] [:no, :no] 4 0.0158673
13 │ 2 2 [:P, :B] [:yes, :yes] 1 0.138197
14 │ 2 2 [:P, :B] [:yes, :no] 2 0.392705
⋮
QuantumContextEffectModels.to_dataframe
— Methodto_dataframe(
data::Vector{Vector{Vector{T}}},
attributes::T1,
values::T2,
n_way::Int
)
Flattens input data
into a long form DataFrame.
Arguments
data::Vector{Vector{T}}:
a two-level nested data vector of vectors representing data or predictions. Each sub-vector is a different set of variables comprising then_way
joint probability table. Only one order of a given set of variables included, which is the order specified in the functionmake_projectors
.attributes::T1
: a vector of attribute namesvalues::T2
: a vector of vectors where each sub-vector responses to possible values for a given attribute namen_way::Int
: the number of attributes defining then₁ × … × nₘ
joint probability table wherem=n_way
.
where T1
,T2
<:
Vector
.
Output
24×4 DataFrame
Row │ group attributes values preds
│ Int64 Array… Array… Float64
─────┼──────────────────────────────────────────────
1 │ 1 [:B, :I] [:yes, :yes] 0.3
2 │ 1 [:B, :I] [:no, :yes] 0.2
3 │ 1 [:B, :I] [:yes, :no] 0.1
4 │ 1 [:B, :I] [:no, :no] 0.4
5 │ 2 [:B, :P] [:yes, :yes] 0.329624
6 │ 2 [:B, :P] [:no, :yes] 0.624449
7 │ 2 [:B, :P] [:yes, :no] 0.0300594
8 │ 2 [:B, :P] [:no, :no] 0.0158673
9 │ 3 [:B, :L] [:yes, :yes] 0.333826
10 │ 3 [:B, :L] [:no, :yes] 0.599901
11 │ 3 [:B, :L] [:yes, :no] 0.0661739
12 │ 3 [:B, :L] [:no, :no] 9.88958e-5
13 │ 4 [:I, :P] [:yes, :yes] 0.467509
14 │ 4 [:I, :P] [:no, :yes] 0.486564
15 │ 4 [:I, :P] [:yes, :no] 0.0324905
16 │ 4 [:I, :P] [:no, :no] 0.0134361
17 │ 5 [:I, :L] [:yes, :yes] 0.322595
18 │ 5 [:I, :L] [:no, :yes] 0.611132
19 │ 5 [:I, :L] [:yes, :no] 0.0433761
20 │ 5 [:I, :L] [:no, :no] 0.0228967
21 │ 6 [:P, :L] [:yes, :yes] 0.933579
22 │ 6 [:P, :L] [:no, :yes] 0.000148166
23 │ 6 [:P, :L] [:yes, :no] 0.0204943
24 │ 6 [:P, :L] [:no, :no] 0.0457785
QuantumContextEffectModels.to_tables
— Methodto_tables(
data::Vector{Vector{Vector{T}}},
attributes::T1,
values::T2,
n_way::Int
)
Returns a nested vector of DataFrames where each DataFrame is an n₁ × n₂
joint probability table. Each sub-vector of DataFrames contains a DataFrame for each order of a fixed set of attributes.
Example Output
The example output shows the two joint probability tables for attributes B
and I
–-one for each order.
julia> df[1]
2-element Vector{DataFrame}:
4×6 DataFrame
Row │ group order attributes values val_idx probs
│ Int64 Int64 Array… Array… Int64 Float64
─────┼──────────────────────────────────────────────────────────
1 │ 1 1 [:B, :I] [:yes, :yes] 1 0.3
2 │ 1 1 [:B, :I] [:no, :yes] 2 0.2
3 │ 1 1 [:B, :I] [:yes, :no] 3 0.1
4 │ 1 1 [:B, :I] [:no, :no] 4 0.4
4×6 DataFrame
Row │ group order attributes values val_idx probs
│ Int64 Int64 Array… Array… Int64 Float64
─────┼──────────────────────────────────────────────────────────
1 │ 1 2 [:I, :B] [:yes, :yes] 1 0.3
2 │ 1 2 [:I, :B] [:yes, :no] 2 0.2
3 │ 1 2 [:I, :B] [:no, :yes] 3 0.1
4 │ 1 2 [:I, :B] [:no, :no] 4 0.4
QuantumContextEffectModels.to_tables
— Methodto_tables(
data::Vector{Vector{Float64}},
attributes::T1,
values::T2,
n_way::Int
)
Returns a nested vector of DataFrames where each DataFrame is an n₁ × n₂
joint probability table. Each sub-vector of DataFrames contains a DataFrame for each order of a fixed set of attributes.
Example Output
julia> df[1:2]
2-element Vector{DataFrames.DataFrame}:
4×4 DataFrame
Row │ group attributes values preds
│ Int64 Array… Array… Float64
─────┼──────────────────────────────────────────
1 │ 1 [:B, :I] [:yes, :yes] 0.3
2 │ 1 [:B, :I] [:no, :yes] 0.2
3 │ 1 [:B, :I] [:yes, :no] 0.1
4 │ 1 [:B, :I] [:no, :no] 0.4
4×4 DataFrame
Row │ group attributes values preds
│ Int64 Array… Array… Float64
─────┼────────────────────────────────────────────
1 │ 2 [:B, :P] [:yes, :yes] 0.329624
2 │ 2 [:B, :P] [:no, :yes] 0.624449
3 │ 2 [:B, :P] [:yes, :no] 0.0300594
4 │ 2 [:B, :P] [:no, :no] 0.0158673