- 阅读权限
- 255
- 威望
- 0 级
- 论坛币
- 50294 个
- 通用积分
- 83.8106
- 学术水平
- 253 点
- 热心指数
- 300 点
- 信用等级
- 208 点
- 经验
- 41518 点
- 帖子
- 3256
- 精华
- 14
- 在线时间
- 766 小时
- 注册时间
- 2006-5-4
- 最后登录
- 2022-11-6
|
|
Parzen Window Density Estimation
- close all; clc; clear;
- rand('seed',0);
- randn('seed',0);
- x_truth = linspace( -1, 3, 1000 );
- indsGT = x_truth>0.0;
- indsLT = x_truth<2.0;
- inds = find( indsGT & indsLT );
- p_truth = zeros( 1, 1000 );
- p_truth(inds) = 1/2;
- % Generate some data from the true distribution:
- %
- N_values = [ 32, 256, 5000 ];
- h_values = [ 0.05, 0.2 ];
- n_hs = length(h_values);
- colors = 'rb';
- for ni = 1:length(N_values)
- N = N_values(ni);
- X = unifrnd( 0, 2, N, 1 );
- figure;
- pt = plot( x_truth, p_truth, '-g' ); hold on;
- ph = zeros(n_hs,1); % handles for each Parzen density estimation
-
- for hi = 1:length(h_values)
- h = h_values(hi);
- % For each possible h plot the Parzen approximation on top of the truth:
- %
- x_grid = linspace(-1,3,100); % where we will sample our density \hat{p}
- p_hat = [];
- for xi = 1:length(x_grid)
- x = x_grid(xi);
- p = mean( normpdf( ( repmat( x, N, 1 ) - X ) / h ) )/h;
- p_hat = [ p_hat, p ];
- end
- ph(hi) = plot( x_grid, p_hat, ['-',colors(hi)] );
-
- end
-
- legend( [pt,ph(1),ph(2)], {'truth',['N=',num2str(N),'; h=0.05'],['N=',num2str(N), '; h=0.2']} );
- fn = ['chap_2_prob_31_N_',num2str(N),'.eps'];
- saveas(gcf,['../../WriteUp/Graphics/Chapter2/',fn],'epsc');
-
- end
- http://waxworksmath.com/Authors/N_Z/Theodoridis/WWW/chapter_2.html
复制代码
|
|