dejong_f4_noise.m
来自「C++实现的PSO算法,很有用写关于PSO算法的论文少不了他」· M 代码 · 共 30 行
M
30 行
% DeJong_f4_noise.m
% De Jong's f4 function, ND, includes a normally distributed noise term
%
% f(x) = sum( [1:N].*(in.^4), 2) + randn(tlen,1)
%
% x = N element row vector containing [ x0, x1,..., xN ]
% each row is processed independently,
% you can feed in matrices of timeXN no prob
%
% example: cost = DeJong_f4([1,2;3,4;5,6])
% note minimum @ x= all zeros
% Brian Birge
% Rev 1.0
% 9/12/04
function [out]=DeJong_f4_noise(in)
persistent D tlen d randterm
% this speeds routine up a lot, if called from PSO these won't change from
% call to call (repmat is a cpu hog)
Dx=length(in(1,:));
tlenx=length(in(:,1));
if isempty(D) | D~=Dx | tlen~=tlenx
D=Dx; % dimension of prob
tlen=tlenx; % how many separate states
d=repmat([1:D],tlen,1); % needed to vectorize this
% makes sure the function stays the same for the whole PSO run
randterm=randn(tlen,1);
end
out = sum( d.*(in.^4), 2) + randterm;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?