Failure in initial objective function evaluation. FMINCON cannot continue.

Attaching my code, I am just not able to understand why this is not working. Gives the error, Failure in initial objective function evaluation. FMINCON cannot continue.
function new_hyp = max_likelihood(model)
problem.f = @(x) log_likelihood([x(1:model.nv), model.hyp(end)]',model); % calling the log likelihodd function, we maximize log likelihood the find the
% problem.f = @(x) log_likelihood( model.hyp(end)',model);
A = [];
b = [];
Aeq = [];
beq = [];
% model.hyper_bound = log([0.01, 50]); % bounds of hyperparamter
model.hyper_bound = log([0.35,2.73]); % bounds of hyperparamter
lb= model.hyper_bound(1)*ones(1,model.nv);
ub= model.hyper_bound(2)*ones(1,model.nv);
% lb = [-4.60517018598809,-4.60517018598809];
% ub = [3.91202300542815,3.91202300542815];
x0 = zeros(1,model.nv);%[0,0]; %Starting point
options = optimset('Display', 'off') ;
nonlcon=[];
new_hyp = fmincon(problem.f,x0,A,b,Aeq,beq,lb,ub,nonlcon, options)'; % compuatation of hyperparameter that maximizes the log likelihood
% new_hyp = fminsearch(problem.f,x0)';
end
function [lml] = log_likelihood(hyper_param, model)
K = model.cov_model(hyper_param, model.X(1:model.n,:), model.X(1:model.n,:)) + eye(model.n)*model.noise; % Covariance matrix using squared exponential kernel for the input points
Kchol = chol(K);
ALPHA = (Kchol\(Kchol'\model.f));
lml = model.f'*ALPHA + 2*sum(log(diag(Kchol))); % computation of log likelihood ,
end

3 件のコメント

Matt J
Matt J 2022 年 2 月 11 日
Before running fmincon, did you test your objective function at x0 to see if it works? (You should always do so).
Joshua Scott
Joshua Scott 2022 年 11 月 14 日
Hey Matt,
What is the best way to test the function at x0 in matlab? (my apologies if this is a dumb question.)
Alan Weiss
Alan Weiss 2022 年 11 月 15 日
Define your parameters hyper_param and model in your workspace. Then call
lml = log_likelihood(hyper_param, model)
Or set up your problem and x0 parameter, and call
problem.f(x0)
Alan Weiss
MATLAB mathematical toolbox documentation

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMultibody Modeling についてさらに検索

製品

リリース

R2020a

タグ

質問済み:

2022 年 2 月 11 日

コメント済み:

2022 年 11 月 15 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by