-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
57a1749
commit 7ef5b0c
Showing
5 changed files
with
80 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
% ----------------------------------------------------------------- | ||
% CEopt.m | ||
% ----------------------------------------------------------------- | ||
% programmer: Americo Cunha Jr | ||
% Programmer: Americo Cunha Jr | ||
% [email protected] | ||
% | ||
% Originally programmed in: Jun 18, 2021 | ||
% Last updated in: Apr 10, 2024 | ||
% Last updated in: Aug 15, 2024 | ||
% ----------------------------------------------------------------- | ||
% This routine employs the Cross-entropy (CE) method to solve the | ||
% following optimization problem: | ||
|
@@ -106,12 +106,32 @@ | |
% CEstr - The updated Cross-Entropy object struct containing the final | ||
% state of the algorithm and possibly additional diagnostic | ||
% information. | ||
% ----------------------------------------------------------------- | ||
% References: | ||
% | ||
% Reference: | ||
% Reuven Y. Rubinstein, Dirk P. Kroese | ||
% The Cross-Entropy Method: A Unified Approach to Combinatorial | ||
% Optimization, Monte-Carlo Simulation, and Machine Learning | ||
% Springer-Verlag, 2004. | ||
% [1] Reuven Y. Rubinstein, Dirk P. Kroese, | ||
% The Cross-Entropy Method: A Unified Approach to Combinatorial | ||
% Optimization, Monte-Carlo Simulation, and Machine Learning, | ||
% Springer-Verlag, 2004. | ||
% | ||
% [2] A. Cunha Jr, M. V. Issa, J. C. Basilio, J. G. Telles Ribeiro, | ||
% CEopt: A MATLAB Package for Non-convex Optimization with the | ||
% Cross-Entropy Method, ArXiv, 2024 | ||
% ----------------------------------------------------------------- | ||
% Copyright (C) 2024 Americo Cunha Jr et al. | ||
% | ||
% This program is free software: you can redistribute it and/or modify | ||
% it under the terms of the GNU General Public License as published by | ||
% the Free Software Foundation, either version 3 of the License, or | ||
% (at your option) any later version. | ||
% | ||
% This program is distributed in the hope that it will be useful, | ||
% but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
% GNU General Public License for more details. | ||
% | ||
% You should have received a copy of the GNU General Public License | ||
% along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
% ----------------------------------------------------------------- | ||
function [Xopt,Fopt,ExitFlag,CEstr] = ... | ||
CEopt(fun,xmean0,sigma0,lb,ub,nonlcon,CEstr) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
clc; clear; close all; | ||
|
||
disp(' ------------------- ') | ||
disp(' MainCEoptExample6Ext.m ') | ||
disp(' ------------------- ') | ||
|
||
% bound for design variables | ||
lb = [-6 -4]; | ||
ub = [ 2 4]; | ||
|
||
% objective function and constraints | ||
F = @PatternSearchFunc; | ||
nonlcon = @ConicConstraints; | ||
|
||
% cross-entropy optimizer struct | ||
CEobj.isVectorized = 1; % vectorized function | ||
CEobj.TolCon = 1.0e-6; % relative tolerance | ||
|
||
tic | ||
[Xopt,Fopt,ExitFlag,CEobj] = CEopt(F,[],[],lb,ub,nonlcon,CEobj) | ||
toc | ||
|
||
% objective function | ||
function F = PatternSearchFunc(x) | ||
x1 = x(:,1); | ||
x2 = x(:,2); | ||
F = zeros(size(x1,1),1); | ||
for i = 1:size(x,1) | ||
if x1(i) < -5 | ||
F(i) = (x1(i)+5).^2 + abs(x2(i)); | ||
elseif x1(i) < -3 | ||
F(i) = -2*sin(x1(i)) + abs(x2(i)); | ||
elseif x1(i) < 0 | ||
F(i) = 0.5*x1(i) + 2 + abs(x2(i)); | ||
elseif x1 >= 0 | ||
F(i) = .3*sqrt(x1(i)) + 5/2 + abs(x2(i)); | ||
end | ||
end | ||
end | ||
|
||
% equality and inequality constraints | ||
function [G,H] = ConicConstraints(x) | ||
x1 = x(:,1); | ||
x2 = x(:,2); | ||
G = 2*x1.^2 + x2.^2 - 3; | ||
H = (x1+1).^2 - (x2/2).^4; | ||
end |