Matrix argument in Matlabs MLE function
이전 댓글 표시
Dear all,
I want to use Matlabs MLE function to find the maximum of a log-likelihood expression. The expression contains matrix multiplication of the unknown parameters (called theta here), so I want to submit a matrix. The matrix is of variable size, so I don't want to hard code any sizes.
What I've tried so far, with failed results, are seen below. First of all, I create some data that I use for all my trials:
global p b
p = [0.5 1 0.7; 0.4 0.5 0.2]'; %some matrix
b = [2 .6 .3 .1]; %some other matrix
theta0 = [1 1; 1 1; 1 1; 1 1]'; %initial guess of unknowns
y_meas = [2.32 3.17 2.53]; %measured values
Note that the matrix sizes above will not always be the same, they can vary.
Trial 1)
%Log-likelihood function
loglik = @(y_meas,theta) sum(sum(y_meas.*log( b*(p*theta)' ) - b*(p*theta)'));
%Maximum likelihood estimation
est = mle(y_meas,'logpdf',loglik,'start',theta0)
The above expression failes since I think you can only send and recieve individual arguments (not matrices or vectors) in MLE and the custom loglik function.
Trial 2)
%Create string argument with matrix indices like 'theta(1,1),theta(1,2),...'
[ro,co] = size(theta_true);
str = '';
for j = 1:co
for i = 1:ro
str = [str 'theta(' num2str(i) ',' num2str(j) '),'];
end
end
str = str(1:end-1); %Remove last comma
%Log-likelihood function
eval( ['loglik = @(y_meas,' str ') sum(sum(y_meas.*log( b*(p*theta)'' ) - b*(p*theta)''));'] );
%Maximum likelihood estimation
est = mle(y_meas,'logpdf',loglik,'start',theta0(:));
The above fails with unbalanced or unexpected parenthesis. I gather you cannot recieve arguments with indices in the custom function loglik?
Trial 3)
%Create string argument with matrix indices like 'theta11,theta12,...'
[ro,co] = size(theta_true);
str = '';
for j = 1:co
for i = 1:ro
str = [str 'theta' num2str(i) num2str(j) ','];;
end
end
str = str(1:end-1); %Remove last comma
Like the arguments above, I get no errors when passing them to the custom function, but I get the problem of how to perform the matrix multiplication.
Does anyone have an idea of how to use a variable number of arguments in MLE for a custom log-likelihood function containing matrix multiplication with the unknowns?
Thank you!
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!