What should I do when fmincon returns exit flag -2 for all voxels?
3 次查看(过去 30 天)
显示 更早的评论
Hi all, I'm having troubles using fmincon to fit the function below:
function [out] = sm_signal_high(bvalues, Sig_high, perp, delta_lambda)
% bvalues and Sig_high are Nx1 column vectors.
% perp and delta_lambda are both scalars.
sig_high = exp(-bvalues*perp).*sqrt(pi./(4*bvalues*(delta_lambda))).*erf(sqrt(bvalues*(delta_lambda)));
out = sum((Sig_high - sig_high).^2);
end
For all voxels that are being fit, I'm receiving an exit flag of -2 meaning that no feasible point was found. What exactly does this mean? How can I resolve this issue? Here is the code that I have written to perform this:
lambda_perp = zeros(X, Y, Z);
deltaLambda = zeros(X, Y, Z);
opts = optimset('Display', 'off');
lambdas0 = [0.60e-4, 1.30e-3];
exit_flags_high = zeros(X, Y, Z);
for z = 1:Z % For every particular voxel...
for y = 1:Y
for x = 1:X
% As I am commenting this code for readability, I noticed it would be
% more efficient to write mask(x, y, slices(z)) == 1 since all
% values are by default 0. I'll change this later.
if mask(x, y, slices(z)) == 0 % Set all values outside of the mask to be 0.
lambda_par(x, y, z) = 0;
lambda_perp(x, y, z) = 0;
deltaLambda(x, y, z) = 0;
else
S_high_avg_formatted = zeros(high_num_unique, 1); % Reformat the average signal within a voxel.
for b = 1:high_num_unique % Vectorize eventually!!!
S_high_avg_formatted(b, 1) = S_avg_high(x, y, z, b);
end
% high_unique and S_high_avg_formatted are Nx1 column
% vectors. lam(1) and lam(2) are scalars representing
% lambda_perp and deltaLambda respectively.
[lambdas, ~, exit_reason_high, ~] = fmincon(@(lam) sm_signal_high(high_unique, S_high_avg_formatted, lam(1), lam(2)), ...
lambdas0, [], [], [], [], [0.40e-4, 0.92e-4], [0.80-4, 1.76e-3], [], opts);
% The bounds of our fit have been determined by biological constraints.
% ERROR: The function isn't actually fitting anything? It returns the values of lambda0 for all
% particular voxels.
% From lambdas, determine the eigenvalues within a particular voxel.
lambda_perp(x, y, z) = lambdas(1);
deltaLambda(x, y, z) = lambdas(2);
exit_flags_high(x, y, z) = exit_reason_high;
end
end
end
end
I'm aware that lsqcurvefit would perform a similar fitting and have already implemented that in a different script, however I wanted to try the different fitting algorithm to see if that would make a difference. Thank you!
-Warren
采纳的回答
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!