% Odd Square function L. LAURENT -- 21/03/2017 -- luc.laurent@lecnam.net
0001 %% Odd Square function 0002 %L. LAURENT -- 21/03/2017 -- luc.laurent@lecnam.net 0003 0004 % sources available here: 0005 % https://bitbucket.org/luclaurent/optigtest/ 0006 % https://github.com/luclaurent/optigtest/ 0007 0008 % optiGTest - set of testing functions A toolbox to easy manipulate functions. 0009 % Copyright (C) 2017 Luc LAURENT <luc.laurent@lecnam.net> 0010 % 0011 % This program is free software: you can redistribute it and/or modify 0012 % it under the terms of the GNU General Public License as published by 0013 % the Free Software Foundation, either version 3 of the License, or 0014 % (at your option) any later version. 0015 % 0016 % This program is distributed in the hope that it will be useful, 0017 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0018 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0019 % GNU General Public License for more details. 0020 % 0021 % You should have received a copy of the GNU General Public License 0022 % along with this program. If not, see <http://www.gnu.org/licenses/>. 0023 0024 % 0025 %global minimum : f(x)=-1.0084 for xi=pi 0026 % 0027 %Design space: -5*pi<xi<5*pi 0028 % 0029 %nbvar<20 0030 0031 0032 function [p,dp]=funOddSquare(xx) 0033 %constants 0034 a=2*pi; 0035 b=pi; 0036 c=1; 0037 e=0.02; 0038 f=0.01; 0039 BV=[1, 1.3, 0.8, -0.4, -1.3, 1.6, -0.2, -0.6, 0.5, 1.4... 0040 1, 1.3, 0.8, -0.4, -1.3, 1.6, -0.2, -0.6, 0.5, 1.4]; 0041 BV=reshape(BV,1,1,20); 0042 0043 %evaluation and derivatives 0044 sX=[size(xx,1) size(xx,2) size(xx,3)]; 0045 % 0046 xb=xx-BV(:,:,1:sX(3)); 0047 % 0048 [vX,IXm]=max(xb.^2,[],3); 0049 maxD=sX(3)*vX; 0050 h=sum(xb.^2,3); 0051 % 0052 pa=exp(-maxD./a); 0053 pb=cos(b*maxD); 0054 pc=c+e*h./(maxD+f); 0055 % 0056 p=-pa.*pb.*pc; 0057 % 0058 if nargout==2 0059 % 0060 dD=zeros(sX); 0061 % 0062 %compute linear index 0063 rowSub=(1:sX(1))'; 0064 colSub=1:sX(2); 0065 LI=sub2ind(sX,rowSub(:,ones(1,sX(2))),colSub(ones(1,sX(1)),:),IXm); 0066 % 0067 dD(LI)=2*sX(3).*xb(LI); 0068 % 0069 dh=2*xb; 0070 % 0071 dp=1/a*dD.*pa.*pb.*pc ... 0072 +b.*dD.*sin(b*maxD).*pa.*pc ... 0073 -e*(dh.*(maxD+f)-h.*dD)./(maxD+f).^2.*pa.*pb; 0074 % 0075 end