File Exchange

image thumbnail

Differential Evolution

version 1.16 (89 KB) by

Optimization using the evolutionary algorithm of Differential Evolution.

4.71053
40 Ratings

85 Downloads

Updated

View License

This contribution provides functions for finding an optimum parameter set using the evolutionary algorithm of Differential Evolution. Simply speaking: If you have some complicated function of which you are unable to compute a derivative, and you want to find the parameter set minimizing the output of the function, using this package is one possible way to go.
The core of the optimization is the Differential Evolution algorithm. However, this package provides much more than the code available on the Differential Evolution homepage:
http://www.icsi.berkeley.edu/~storn/code.html
Here is a list of some features:
* Optimization can run in parallel on multiple cores/computers.
* Extensive and configurable progress information during optimization.
* Intermediate results are stored for later review of optimization progress.
* Progress information can be sent by E-mail.
* Optimization toolbox is not needed.
* Quick start with demo functions.
* Intermediate results are displayed after the optimization.
* Different end conditions can be chosen (maximum time, value to reach etc.).
* Each parameter value can be constrained to an interval.
* Each parameter value can be quantized (for example for parameters of integer nature).
* Code can easily be extended to use the evolutionary algorithm of your choice.
I have spent many hours to develop this package. If you would like to let me know that you appreciate my work, you can do so by leaving a donation:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KAECWD2H7EJFN
Keywords: Optimization, evolutionary algorithm, genetic algorithm, differential evolution, parallel processing, distributed computing, multiple core.

Comments and Ratings (57)

Ryan Rosario

Krishanu Nath

How are you able to use this function including constraints?

I tried to create a new script with all the constraints and call it through validChkHandle parameter in getDefaultParams.m. But it seems to be wrong somehow. It says that apparently there are too many input parameters. What on Earth could be wrong?

I just did

DEParamsDefault.validChkHandle = @(param)NonLinearConstraints({param,k,N,D,perror,divisions})

And cannot see what is wrong with it.

Thank you all in advance for the attention, and BR!!

2MASS

2MASS (view profile)

saw

saw (view profile)

Hi, thanks for the code.From the demo1, it only pass one number. I'm trying to pass 3 additional vectors to the cost function but it doesnt work. may i know how to do that? Would appreciate much if you could help. Thanks.
Below is how the code.

optimInfo.title = 'Fung model using DE';

objFctHandle = @cost_Fung_v3_brute;
% Define parameter names, ranges and quantization:

paramDefCell = {
'c0', [0.1 10], 0.001
'c1', [0.1 10], 0.001
'c2', [0.1 10], 0.001
};

% Set initial parameter values in struct objFctParams
objFctParams.c0 = 0.1;
objFctParams.c1 = 0.1;
objFctParams.c2 = 0.1;
% Set single additional function parameter
Mycell = {lamda, c_stress11, c_stress22};
objFctSettings = {Mycell};
% objFctSettings.lamda = lamda;
% objFctSettings.c_stress11 = c_stress11;
% objFctSettings.c_stress22 = c_stress22;

DEParams = getdefaultparams;

% Set number of population members (often 10*D is suggested)
DEParams.NP = 30;

% Do not use slave processes here. If you want to, set feedSlaveProc to 1 and
% run startmulticoreslave.m in at least one additional Matlab session.
DEParams.feedSlaveProc = 0;

% Set times
DEParams.maxiter = 20;
DEParams.maxtime = 30; % in seconds
DEParams.maxclock = [];

% Set display options
DEParams.infoIterations = 1;
DEParams.infoPeriod = 10; % in seconds

% Do not send E-mails
emailParams = [];

% Set random state in order to always use the same population members here
setrandomseed(1);

% Start differential evolution
[bestmem, bestval, bestFctParams, nrOfIterations, resultFileName] = differentialevolution(...
DEParams, paramDefCell, objFctHandle, objFctSettings, objFctParams, emailParams, optimInfo);

The cost function:

function P_error_top = cost_Fung_v3_brute(objFctSettings, objFctParams)
% Initialize values

c0=objFctParams.c0(1); %p(1) ;
c1=objFctParams.c1(1); % p(2);
c2=objFctParams.c2(1); %p(3);
c3=c2;
c4=0; %p(5);
c5=0; %p(6);
c6=0; %p(7);

% load at fiber orientation
Mycell = objFctSettings{:}
[lamda11, c_stress11, c_stress22] = Mycell{:};
lamda22 = sqrt(1./lamda11);
lamda33 = lamda22;

E11=0.5*(lamda11.^2-1);
E22=0.5*(lamda22.^2-1);
E33=0.5*(lamda33.^2-1);

Q = c1*E22.^2 + c2*E11.^2 + c3*E33.^2;
H = -c0*(1+2*E22).*(c1*E22).*exp(Q);

stress_top_comp = c0*(1+2*E11).*(c2*E11).*exp(Q) + H;

P_error1= stress_top_comp - c_stress11;

P_error_top =sum(sqrt((P_error1).^2))/length(lamda11);

end

Hello everyone,

I'd be very pleased if you are so kind to tell me which parts you need to comment out to make the script work. I am also having problems with the wavread declaration, but after I try to comment its corresponding lines, the whole script stops working.

Many thanks in advance and may you have a nice day.

Samuel Käser

Thanks for your work. I also changed the not working parts (addbuttons & wavread), after tat it was alright and workinf fine :)

Halil Bilal

qiang zhang

yukun ding

Thanks very much for your work and sharing, it helps me a lot. Although there seems to be some problems with the new version (addbuttons and wavread), but it works well after I comment them out.

yukun ding

yukun ding

yalan Zhao

adba

adba (view profile)

Namit Sharma

Thank you for this submission.It is working well for my problem.

However, I have noticed that for constrained optimization problems the evaluations of constraint function take place in only one MATLAB session(i.e. sequentially rather than in parallel) while the objective function evaluations are carried out in parallel(i.e. on multiple MATLAB sessions).
So, is there any way that I can also parallelize my constraint function evaluations? (since my constraint function is as computationally expensive as the objective function)

Jakob Sievers

Jakob Sievers (view profile)

I cannot overstate how pleased I have been with this code. That being said, I have had to make a few relatively simple alterations for use with my specific problem and I feel some of them might be good to add for a future release:
1) I have added an input parameter DEParams.infoOutput which, if set to 0, suppresses ALL visual output. This is handy for serial application after an initial testing phase. I myself am running the code for a very large number of cases and I prefer that the screen is left for more general output like progress reports and estimated time left, etc.
2) I have added a parameter DEParams.saveHistoryFilename which allows the user to save the history to a specific path. Again this is useful for serial application in which one wants to do statistics on the performance of the algorithm.
3) I have added a parameter DEParams.maxiterStablebest which defines the number of allowed iterations with a stable "best solution". That is: if for X iterations the solution has been stable, terminate optimization.
4) Finally, and perhaps most importantly, I have had to add support for vectorized functions. That is: in the current code evaluation of the NP members is done in a for-loop. For functions which can be vectorized (i.e.: calling the function with all NP members at once rather than sequentially) a significant reduction in computation time can be attained. In my case the computation time dropped to ~60% relative to before when using a vectorized function evaluation instead. Support should be added such that users can alternate between sequential and vectorized application depending on their type of problem.

Liqun

Liqun (view profile)

Trying to figure out how to use this package these days, and had some emails back and forth with the author. But still have two questions.

The fist is: in the demo files, it has the following codes:

% set times
DEParams.maxiter = 20;
DEParams.maxtime = 30; % in seconds
DEParams.maxclock = [];

What is the proper way to set the time parameters (maxiter and maxtime) for DE? or what is the the theory behind this?

The second questions is: how to use this package on a cluster (Linux based)? I can access to a cluster, but have to submit the job to the cluster from within the Matlab on my local laptop or desktop, using job = batch(......)

How to open as many as matlab sessions on the cluster, using job = batch(......)?

Hope can hear some feedback!

Thanks!

Pijian Cheng

gon

gon (view profile)

Hi Markus, May I enquire if this algorithm works if multi objective optimization? So far, it appears that it can only maximize a function with a single output.

Paulo Branco

Hi Markus, thanks for the response. I am sorry to intrude, but I do have another question. There is a test problem in <http://www-optima.amp.i.kyoto-u.ac.jp/member/student/hedar/Hedar_files/TestGO_files/Page506.htm>. I used the constraint function you pointed me to. I defined a matrix Ain(dimension 9x13) and the vector bin(dimension 9x1) to write the function return value: valid all(Ain*x<=bin). However, the optimum parameters stray by a huge amount from the expected results. The problem has hard boundaries, as well as linear inequality constraints (9 of them to be precise). I hope you can briefly walk me through the correct formulation of the problem in your files, as I suspect my constraints are at the core of the problem.

Paulo Branco

Hi Markus, does your algorithm allow the inclusion of linear constraints? I am trying to optimize an instance of density evolution, and the parameters must add up to 1. Also, a linear combination of the parameters must yield a given rate. Do you have anything similar to the tools provided by Matlab's global optimization toolbox or do I just have to work around with the parameters, taking the linear constraints into account as I go along?

Joe

Joe (view profile)

very helpful tool for those who cannot afford toolboxes.

Behnam seyedi

Hi dear Markus Buehren
i just wana ask about the simple Differential Evolution algorithm (single objective ) , how can i use your code for this propose ?

chen

chen (view profile)

Jakob Sievers

Jakob Sievers (view profile)

I am very happy with this submission. I have probably misunderstood something though, but isn't it possible to stop optimization before maxiter if the function has been optimized within a user-defined threshold? Currently I am only tuning maxiter to achieve proper results but I suspect I am loosing a lot of processing time and accuracy when a fixed maxiter is insufficient (either too many or too few).
Cheers

This is a wonderful method and implementation that I have used frequently, and always successfully. If I had one "feature request" it would be the option to restart a prior optimization by reading the optimResult file and starting with the current population in that file. I have, on occasion, had a problem terminate prematurely for reasons having nothing to do with differentialevoluion.m. It would be nice to continue such problems where I had left off.

vijay pandit

DEAR SIR,
I am using this techniques for my optimizaion technique.would u please help me i am facing lots of problem..

AfanSveta

Joe Hays

Very helpful tool. Loved having the parallel implementation too!

Joe Ajay

Hi Markus, does it solve discrete optimization problems? if not is there any differential evolution solver which solves discrete problems

deng

deng (view profile)

Thank you very much!

Hi, I have to call a variable in the objectfunction, where I have to call it in order to pass it to the function?

Matthias Thul

john

john (view profile)

Where can I find Multi objective version of the Differential evolution algorithms?

thanks

Evi Daems

William Chang

Very Good,Thanks

Mahmud Iwan

This is an excellent code..
However, i am wondering how to use this code for constrained optimization problem (inequality constraint).?? It was given in the demo for such problem, but the code needs the initial values not to violate the constraint. in the real practice, we do not need to know whether the initial value violate it or not.Just give any initial values..right?...pls, enlighten! thanks,,

ardian mohib

thank u for sharing markus, but can u tell me why when I run the codes in my computer, the codes is always error. and one more question for u, would u like to help me to explain Differential evolution algorithm. i 'm a student that interest to Differential evolution algorithm and would like to use this algorithm for solve optimization inventory supply chain for my research.
thank b4

RMS Danaraj

RMS Danaraj (view profile)

Very nice algorithm .I have implemented this to solve three non linear optimization problems which I will upload shrtly in the file exchange.Thank you very much.

James Pullen

James Pullen

I'm normally way too lazy to bother rating code and submissions, but this deserves to be an exception to the rule. Very minor quibble: I'd have liked one of the demo files to have incorporated the use of external vectors/matrices. Otherwise a very concise and usable (and, more importantly, utterly useful) piece of code. Thank you Markus.

saradha devi

helo,
based on the above comments im overwhelmed in using the code posted buy markus.ive been working on genetic algorithms n optimization toolbox for my problem on alkylation.Differential Evolution can also be applied to this prob but im not sure of how to handle the code. So could u plz give insights on how to work on it. i ve been using matlab-GA only n am a new user so i request to plz help me in dis regard.Im highly interested in workin on dis.

Un package vraiment complet.
Un programme qui marche de suite sans avoir à retoucher quoi que ce soit. Je l'utilise pour du recalage de modèles éléments finis et ca fonctionne du tonnerre.
Bravo

Markus Buehren

Markus Buehren (view profile)

Thanks for pointing that out, Scott. I have corrected the link.

Scott

Scott (view profile)

Markus,

I think the point Andrew Koh was making is that for some reason the ")" is part of the URL in your abstract, but not in Andrew's URL, so your URL does not get to Storn's website, but Andrew's does.

Scott

STTAR WDAA

THANK YOU VERY MUCH

Hom Gharti

Thanks for the very very useful code. I wanted to apply this code for 4-D, 3 space dimension and 1 time dimension. I got the error 'error in bestmem ~= lastbestmem', when I checked, obviously these two vectors have different lengths, then I changed parGridVector = cell2mat(paramDefCell(:,3));
to
parGridVector = cell2mat(paramDefCell(:,4));
and code seems to be working fine. Am I doing right?

many thanks,

James Yong

One of the best optimizers I've used. The speedy support from Markus was invaluable and greatly appreciated. An amazing package. Straightforward to implement, flexible and provides results!

David Brown

This package is unbelievably powerful. In addition Markus is always available to answer tons of questions about how to use it properly. He's even responded to fix small quirks I found in lightning fast time. This thing CHOPS hard problems to bits.

Markus Buehren

As it is written in the description, exactly that code is used as the core algorithm! However, this packages offers much much more than the core algorithm.

ANDREW KOH

I think the better DE code appears at

http://www.icsi.berkeley.edu/~storn/code.html

Marcelo P.

Hi Markues, This is a great submission, thanks for sharing it.

I think it is just missing documentation regarding the method, not the code. For instance, which algo are you using? did u got it from a book or a paper? If so, can you provide the reference?

Updates

1.16

Deactivated pushbutton generation which causes error in late Matlab versions.

1.15

New feature: A previous optimization run can be continued. Set DEParams.saveHistory to true for saving intermediate results, then call differentialevolution.m with the name of the intermediate result file as an extra input argument.

1.14

Bugfix: File needed by setfilesemaphore.m was missing.

1.13

Performance optimization for multicore processing.

1.12

Bugfix: Results computed by slave processes were set to NaN when maxMasterEvals was not equal to Inf.

1.11

New feature: Now the objective function may return NaN, Inf or -Inf.

1.10

New feature: Now the objective function may return NaN, Inf or -Inf.

1.7

Only E-mail changed in html file.

1.6

Bugfix: Constraint function was called with empty matrix as input argument. blat.exe no longer contained in the package due to restrictions on Matlab Central.

1.5

Bugfix: Constraint function was called with empty matrix.

1.4

Paths are now built using the system-dependent file separator.

1.3

Semaphore mechanism improved.

1.2

Link in package description corrected.

1.1

File datenum2 was not needed.

Fixed another bug.

Bug fixed: Using a scalar parameter without name now works.

Added two new features: 1. Additional function can be used to test parameter constraints (parameter validChkHandle), 2. Evaluation value can be maximized or minimized now (parameter minimizeValue).

Now saving less intermediate results if saveHistory is off.

Fixed a bug in checking the maximum time parameters "maxtime" and "maxclock".

Added a FAQ summarizing E-mail conversations with David Brown, who excessively applied and tested the package.

Added features:
* Number of function evaluations of the master process can now be limited (parameter maxMasterEvals).
* Sound output can be turned on/off (parameter playSound).

Link to DE homepage added to description.

A file that is seldom called was missing.

Another update of the documentation.

Small documentation update.

MATLAB Release
MATLAB 7.9 (R2009b)
Acknowledgements

Inspired: Ogive optimization toolbox

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video