Matrix multiplication error in conjugate transpose
Ältere Kommentare anzeigen
I get Incorrect dimensions for matrix multiplication error in step 4, line 75 and furthur, what can I do?
%Defining input parameters
function [chp] = dualaccumulatorahk(d,l,N,T,S1,S2,U1,V1,w)
%d is decay and is mostly considered as 1 in this model and would be open to more values in the extended version
%l is Lambda, N is the number of simulations of the deliberative process, T is the time range
%S1 is payoff matrix where self is the row player and S2 is payoff matrix where other is row player
%U1 and V1 are salience biases of players 1 and 2, respectively and in the
%absence of bias will set to 99
% w is trembling hand noise which is 0 here
%example: considering a two-strategy hide-and-seek game with player 1 as a hider and player 2 as a seeker we have:
%0,.5 1,0
%1,0 0,.5 as a full payoff matrix and the aforementioned parameters are:
d = 1;
S1 =[100,60,62,64;60,62,66,70];
S2 =[70,69,66,10;10,40,66,68];
l = 1;
T = 30;
U1 = 99;
V1 = 99;
N = 10000;
w = 0;
% Step 0 & 1
% possible number of strategies per player
ns1 = length(S1(:,1));
ns2 = length(S2(:,1));
chp = zeros(ns1,N)
% set a start for activation biases
if U1 == 99
U1 = zeros(1,ns1);
end
if V1 == 99
V1 = zeros(1,ns2);
end
%initiation of N simulations
for i = 1:N
U = zeros([ns1,T+1]); %as in the first column the time is 0
V = zeros([ns2,T+1]);
%Step 2: Leave initial preference and beliefs at 0
U(:,1) = U1;
V(:,1) = V1;
for t = 2:T+1
%Step 3: Sample one of the opponent's strategies
A = V(:,t-1) + V1';
P = exp(1*A)/sum(exp(1*A));
%See whether the definition of P is legit
if sum(isfinite(P)) < ns2
P = zeros(1,ns2)';
for k = 1:ns2
if A(k)== max(A)
P(k) = 1;
end
end
P = P/sum(P);
end
% Step 4: Update activations in preference node
U(:,t);
d*U(:,t-1);
S1*mnrnd(1,P)';
normrnd(0,w,ns1,1)
U1
U(:,t) = d*U(:,t-1) + S1*(mnrnd(1,P')') + normrnd(0,w,ns1,1);
% Step 5: Sample one of the decision maker’s own strategies
A = U(:,t) + U1';
P = exp(l*A)/sum(exp(l*A));
if sum(isfinite(P)) < ns1
P =zeros(1,ns1)';
for k = 1:ns1
if A(k) == max(A)
P(k) = 1;
end
end
P = P/sum(P);
end
% Step 6: Update activations in belief node
% V(:,t) = d*V(:,t-1) + S2*(mnrnd(1,P')') + normrnd(0,w,ns2,1);
end
% Step 7 & 8: making decision
for k = 1:ns1
if U(k,T+1) == max(U(:,T+1))
chp(k,i) = 1;
end
end
chp(:,i) = chp(:,i)/sum(chp(:,i));
end
% Step 9: Getting the average choice probabilities for each of the decision maker’s strategies
for k = 1:ns1
chp2(k) = mean(chp(k,:));
end
5 Kommentare
Geoff Hayes
am 23 Apr. 2020
Amir - please copy and paste the full error message to this question. Also, what are the inputs that you are using? You can attach them (in a *.mat file) to this question.
Amir Hossein K
am 23 Apr. 2020
Geoff Hayes
am 23 Apr. 2020
Amir - the problem is that you are trying to multiply two matrices with incompatible dimensions. S1 is a 2x4 array and mnrnd(1,P)' is a 2x1. Which one of these matrices is incorrect? Should P be a 1x4 array so that mnrnd(1,P)' is a 4x1?
Also, in this code
U(:,t);
d*U(:,t-1);
S1*(mnrnd(1,P)');
normrnd(0,w,ns1,1)
U1
there are no assignments to any local variables. Is this code really needed or are you missing something?
Amir Hossein K
am 23 Apr. 2020
Geoff Hayes
am 23 Apr. 2020
Amir - hopefully someone else will be able to comment on this. It isn't all that clear to me how the above pseudocode translates to your code.
Antworten (0)
Kategorien
Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
