diff --git a/CEopt-1.0/CEopt.m b/CEopt-1.0/CEopt.m index 4c5806e..5474293 100644 --- a/CEopt-1.0/CEopt.m +++ b/CEopt-1.0/CEopt.m @@ -1,11 +1,11 @@ % ----------------------------------------------------------------- % CEopt.m % ----------------------------------------------------------------- -% programmer: Americo Cunha Jr +% Programmer: Americo Cunha Jr % americo.cunhajr@gmail.com % % 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 . % ----------------------------------------------------------------- function [Xopt,Fopt,ExitFlag,CEstr] = ... CEopt(fun,xmean0,sigma0,lb,ub,nonlcon,CEstr) diff --git a/CEopt-1.0/MainCEoptExample1Ext.m b/CEopt-1.0/MainCEoptExample1Ext.m index cb5b5df..aa980b6 100644 --- a/CEopt-1.0/MainCEoptExample1Ext.m +++ b/CEopt-1.0/MainCEoptExample1Ext.m @@ -33,7 +33,7 @@ % CE optimizer tic -[Xopt,Fopt,ExitFlag,CEobj] = CEopt(F,mu0,sigma0,lb,ub) +[Xopt,Fopt,ExitFlag,CEstr] = CEopt(F,mu0,sigma0,lb,ub) toc % domain for plotting diff --git a/CEopt-1.0/MainCEoptExample2.m b/CEopt-1.0/MainCEoptExample2.m index b759eb4..ea08052 100644 --- a/CEopt-1.0/MainCEoptExample2.m +++ b/CEopt-1.0/MainCEoptExample2.m @@ -28,7 +28,7 @@ % CE optimizer tic -[X_opt,F_opt,ExitFlag,CEstr] = CEopt(F,mu0,sigma0,lb,ub,[],CEstr) +[Xopt,Fopt,ExitFlag,CEstr] = CEopt(F,mu0,sigma0,lb,ub,[],CEstr) toc % objective function diff --git a/CEopt-1.0/MainCEoptExample5.m b/CEopt-1.0/MainCEoptExample5.m index d694ee5..a695c81 100644 --- a/CEopt-1.0/MainCEoptExample5.m +++ b/CEopt-1.0/MainCEoptExample5.m @@ -30,7 +30,7 @@ thetaA = p(3,:); a0 = 1; b0 = x(1); - c0 = b0; + c0 = x(1); d0 = x(2); gamma = x(3); thetaD = x(4); @@ -49,5 +49,7 @@ xEc1 = (xEc0 - mean(xEc0))/(max(xEc0) - min(xEc0)); yEc1 = (yEc0 - mean(yEc0))/(max(xEc0) - min(xEc0)); - F = sum(abs(xE1 - xEc1) + abs(yE1 - yEc1)); + F1 = sum((xE1 - real(xEc1)).^2 + (yE1 - real(yEc1)).^2); + F2 = sum(abs(imag(xEc1).^2) + abs(imag(yEc1).^2) + abs(imag(thetaB).^2)); + F = F1 + F2; end \ No newline at end of file diff --git a/CEopt-1.0/MainCEoptExample7.m b/CEopt-1.0/MainCEoptExample7.m new file mode 100644 index 0000000..8301508 --- /dev/null +++ b/CEopt-1.0/MainCEoptExample7.m @@ -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 \ No newline at end of file