kde.m

来自「patten regnization source从1-14章能运行」· M 代码 · 共 27 行

M
27
字号
function [f_est,x_est]=kde(x,h,ker,par)%% [f_est,x_est]=kde(x,h,'ker','par')%----------------------------------------------------------------------% The kernel density estimator (1 dimension)% INPUT:% x      a row vector containing the data% h      smoothing parameter % ker    a string containing the chosen kernel. For example 'ker1'% par    a string containing the chosen plot element. For example 'r--'%OUTPUT:% f_est  a row vector containing the estimates calculated at the%        evaluation points x_est% x_est  a row vector containing the evaluation points  %---------------------------------------------------------------------n=length(x);x_est=linspace(min(x),max(x),200);n_est=length(x_est);f_est=zeros(1,n_est);for i=1:n_est  ero_i=x_est(i)-x;                  eval(['Ki_h=',ker,'(ero_i/h);'])           f_est(i)=(1/(n*h))*sum(Ki_h);endplot(x_est,f_est,par)

⌨️ 快捷键说明

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