gamean_distance.m

来自「一个启发式搜索算法  给初学者用的 随便参考着用  提供了多种策略」· M 代码 · 共 22 行

M
22
字号
% This function is used to determine the mean distance
% for uniform sampling over a hypercube.  Used for comparing the
% quality of initial conditions with other algorithms that use 
% only one iterative solution (i.e., can use mean distance here
% to set i.c. with same mean distance in single solution algorithm).
%
% 'thetatmax' and 'thetamin' represents px1 vectors of upper and lower
% bounds to theta elements.
%
p=10;
thetamax=2.047*ones(p,1);
thetamin=-2.048*ones(p,1);
thetatrue=ones(p,1); %must lie inside of hypercube defined by thetamax, thetamin
y=0;
N=200000;
rand('seed',31415927)
for i=1:N
   x=((thetamax-thetamin).*rand(p,1)+thetamin);
   dist=((x-thetatrue)'*(x-thetatrue))^.5;
   y=y+dist;
end
y=y/N

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?