Hi everyone,
I know there are similar topics but I couldn’t fix my issue by reading them.
I get this error:
MethodError: no method matching *(::Vector{Float64}, ::Vector{Float64})
And here is my code:
function Qbandit(params, data)
Beta = params[1]
LR = 0.5 + 0.5 * erf(params[2] / sqrt(2))
W = params[3]
r1::Array{Int64,1} = data.r1
r2::Array{Int64,1} = data.r2
C::Array{Int64,1} = data.Choice
TrialType::Array{Int64,1} = data.TrialType
Feedback::Array{Int64,1} = data.Feedback
Condition::Array{Int64,1} = data.Condition
# Initialize Q values
Q = zeros(typeof(Beta),4, 4)
conditions = ["condition1", "condition2", "condition3", "condition4"]
rownames = ["QA1", "QB1", "QA2", "QB2"]
Q = NamedArray(Q, (rownames, conditions), ("rows", "conditions"))
# Initialize lik
lik = 0
# loop over trials
for t in 1:length(C)
QC = Condition[t]
#increment likelihood according to log probability of making their actual choice
QATotal = (1-W)*(Q["QA1",QC]) - W*Q["QA2",QC]
QBTotal = (1-W)*(Q["QB1",QC]) - W*Q["QB2",QC]
if C[t] == 1
lik += lik + (Beta*QATotal - log(sum(exp.(Beta*c(QATotal, QBTotal)))))
elseif C[t] == 2
lik += lik + (Beta*QBTotal - log(sum(exp.(Beta*c(QATotal, QBTotal)))))
end
# Learning
if TrialType[t] == 1 && Feedback[t] == 1
if C[t] == 1
Q["QA1", QC] = (1 - LR) * Q["QA1", QC] + LR * r1[t]
elseif C[t] == 2
Q["QB1", QC] = (1 - LR) * Q["QB1", QC] + LR * r2[t]
end
elseif TrialType[t] == 1 && Feedback[t] == 0
if C[t] == 1
Q["QB1", QC] = (1 - LR) * Q["QB1", QC] + LR * r2[t]
elseif C[t] == 2
Q["QA1", QC] = (1 - LR) * Q["QA1", QC] + LR * r1[t]
end
elseif TrialType[t] == 0 && Feedback[t] == 1
if C[t] == 1
Q["QA2", QC] = (1 - LR) * Q["QA2", QC] + LR * r1[t]
elseif C[t] == 2
Q["QB2", QC] = (1 - LR) * Q["QB2", QC] + LR * r2[t]
end
elseif TrialType[t] == 0 && Feedback[t] == 0
if C[t] == 1
Q["QB2", QC] = (1 - LR) * Q["QB2", QC] + LR * r2[t]
elseif C[t] == 2
Q["QA2", QC] = (1 - LR) * Q["QA2", QC] + LR * r1[t]
end
end
end
return -lik
end
(betas,sigma,x,l,h) = em(data,subs,X,startbetas,startsigma,Qbandit; emtol=emtol, full=full);
I’m not sure which line the error refers to, but I assumed this one:
lik += lik + (BetaQATotal - log(sum(exp.(Betac(QATotal, QBTotal)))))
I tried writing it in different ways but to no avail.