Passing variable array in fmincon
이전 댓글 표시
Hi all,
I am trying to do a non linear optimization for a function which takes parameters and variables that come from my dataset.
function [q] = negloglike(x, e, c, G, spelldur1, j2u, j2j)
% e, c, G, spelldur1, j2u, j2j are variables from my data - all 2263 X 1 double arrays
%%lambda0 = x(3)
%lambda1 = x(1)
%delta = x(2)
a = x(1)/x(2)
b1 = 1 + a.*G
b2 = G + a.*G
F_emp = b2./b1
tempp = x(2) + x(1) - x(1).*F_emp
q1 = -e.*(log(x(3))-log(x(3) + x(2)) + (1-c) .*log(tempp) ...
- spelldur1.*tempp + j2u.*log(x(2)) - j2u.*log(tempp) + j2j.*log(x(1)) + ...
j2j.*log(1-F_emp) - j2j.*log(tempp)) - ...
(1-e).* (log(x(2)) - log(x(2) + x(3)) + (1-c).*log(x(3)) - spelldur1.* x(3))
q = sum(q1)
end
So, what I need is a negloglike as a function of just x, where then I can give initial values x = [0.1 0.1 0.1] and use fmincon to find the optimum values of parameter x.
Sorry if this is rudimentary. I am only a day old to Matlab! Thanks a lot in advance!
Yuvi
답변 (1개)
Alan Weiss
2015년 11월 12일
You are doing well for just a day with MATLAB! All you need to do is set your objective function as the following function handle:
fun = @(x) negloglike(x, e, c, G, spelldur1, j2u, j2j)
The variables e, c, G, spelldur1, j2u, and j2j must already be in your workspace before you call this assignment. Then you can use fmincon to optimize fun. For more information, see Passing Extra Parameters.
Alan Weiss
MATLAB mathematical toolbox documentation
카테고리
도움말 센터 및 File Exchange에서 Surrogate Optimization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!