📄 randsph.m
字号:
function x = randsph(n,d)
%RANDSPH generate objects in hypersphere
%
% x = randsph(n,d)
%
% Generate n data objects uniformly drawn from a d-dimensional hypersphere
% with zero mean and unit radius.
% Copyright: D. Tax, R.P.W. Duin, davidt@ph.tn.tudelft.nl
% Faculty of Applied Physics, Delft University of Technology
% P.O. Box 5046, 2600 GA Delft, The Netherlands
% Gaussian data:
x = randn(n,d);
% squared norms of the vectors:
nx = sum(x.*x,2);
% make squared norms uniformly distributed:
if exist('mychi2cdf') % necessary when you have your own copy of
% chi2cdf
rx = mychi2cdf(nx,d);
else
rx = chi2cdf(nx,d);
end
% change uniform to r^d
newrx = rx.^(2/d);
% renormalize the original data x:
x = sqrt(newrx./nx)*ones(1,d).*x;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -