problem using GA to optimize an image processing index in MATLAB?

2 views (last 30 days)
Hi everyone, I have a problem using GA to optimize an image processing index. the GA optimization works but does not respond to stop criteria and seems to be running forever no matter what i do.
So, I wanted to fit two graphs using SSIM index. The function that i wrote creates the model in another program, used for nonlinear structural engineering (OpenSEES), then plots and saves the model as a .png file. like the one below:
The general idea of the code is to give the function MIK a set of parameters P (in this case 14 parameters) and calculate and minimize the error value using SSIM index.
function error = MIK2(P)
. % this part opens opensees runs the model
. % plots the model and saves it as a .png file
A = imread('Model_Output.png');
B = imread('Experimet_Data.png');
error = 1-ssim(A,B);
end
After opening the GA toolbox and setting the stop criteria to only run for 10 populations i noticed that GA does not even count the steps and basically reports nothing and responds to nothing I literally have to close MATLAB to stop the optimization! :)
Any help would be appreciated... tnx :)

Answers (1)

Alan Weiss
Alan Weiss on 13 Oct 2021
I suspect that the problem is your objective function takes too long, possibly it does not even finish.
I assume that you have defined the nvar and lb and ub argumentts for ga. (I assume that you have finite bounds.) If so, see how long it takes to run your objective function on a random point:
pt = lb + rand(size(lb)).*(ub - lb);
% Or, if you have no bounds, pt = randn(1,nvar);
tic
error = MIK2(pt);
toc
If this returns in a reasonable amount of time, then to help us understand what is going on, please show your ga call and any options that you are passing.
Alan Weiss
MATLAB mathematical toolbox documentation
  2 Comments
farbod safi
farbod safi on 19 Oct 2021
Thanks for the response
Actually the code runs pretty smoothly and it only takes about 15 seconds to run the MIK function for a set of parameters.
I use the GA through optimization toolbox from the apps menu in MATLAB
I am not changing anything special I only enter the upper, lower and initial values. the configurations are mostly the default values.
What happens when i run the GA is that it plots the output that i want and calculates the error value, But doesn't count the steps or perhaps there is something in the process of saving the plots that makes GA unable to understand the steps.
Any insight would be appreciated tnx in advance...
Alan Weiss
Alan Weiss on 19 Oct 2021
This is strange. In order to have more control over what is happening, I wonder if you can try running the optimization at the command line instead of using the Optimization App. Something like this:
options = gaoptimset('Generations',10,'Display','iter');
nvar = 14;
options = gaoptimset(options,'InitialPopulation',randn(1,nvar)); % Put in the real init pop here
lb = zeros(1,nvar); % Put in your real bounds here
ub = ones(1,nvar); % Put in your real bounds here
[x,fval,exitflag] = ga(@MIK2,nvar,[],[],[],[],lb,ub,[],options)
Running this way you can put break points in the code and see what is going on more easily.
Alan Weiss
MATLAB mathematical toolbox documentation

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!