大神请看如下代码,NW核估计窗宽选择问题,用CV准则选取窗宽,为什么我的结果一直是CV值会随着h的增大而增大,这样怎么选窗宽呢?求高手帮忙解决,谢谢!
clc;clear all;
% Generate some noisy data.
x = linspace(0, 4 * pi,100);
y = sin(x) + 0.75*randn(size(x));
% Create an inline function to evaluate the weights.
mystrg='(2*pi*h^2)^(-1/2)*exp(-0.5*((x - mu)/h).^2)';
wfun = inline(mystrg);
% Set up the space to store the estimated values.
% We will get the estimate at all values of x.
yhatnw = zeros(size(x));
n = length(x);
% Set the window width.
% h = 1;
hGarry = [0.1:0.1:10];
for j=1:numel(H)
h=hGarry(j);
% find smooth at each value in x
for i = 1:n
w = wfun(h,x(i),x);
yhatnw(i) = sum(w.*y)/sum(w);
end
%CV准则选取窗宽
CV(j) = sum((y- yhatnw).^2)/numel(x);
end