What should I do when fmincon returns exit flag -2 for all voxels?

1 vue (au cours des 30 derniers jours)
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
  1 commentaire
Warren Boschen
Warren Boschen le 1 Fév 2023
Modifié(e) : Warren Boschen le 1 Fév 2023
Turning off opts reveals the following message:
Exiting due to infeasibility: 1 lower bound exceeds the corresponding upper bound.
What does this mean exactly? My bounds are set correctly unless I'm missing something incredibly obvious.

Connectez-vous pour commenter.

Réponse acceptée

Warren Boschen
Warren Boschen le 1 Fév 2023
I was missing something incredibly obvious. I had an upper bound written as 0.80-4 instead of 0.80e-4.

Plus de réponses (0)

Catégories

En savoir plus sur Curve Fitting Toolbox dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by