zoukankan      html  css  js  c++  java
  • parzen 窗的matlab实现

    用一下程序简单实现使用parzen窗对正态分布的概率密度估计:

    (其中核函数选用高斯核)

    %run for parzen 
    close all;clear all;clc;
    x=normrnd(0,1,1,10000);%从正态分布中产生样本
    f=-5:0.01:5;%确定横坐标范
    
    % N=100   h= 0.25 , 1, 4
    p1=Parzen(x,0.25,10,f); 
    p2 = Parzen(x,1,10,f);
    p3 = Parzen(x,4,10,f);
    subplot(331)
    plot(f,p1)
    subplot(332)
    plot(f,p2)
    subplot(333)
    plot(f,p3)
    
    hold on
    % N=100   h= 0.25 , 1, 4
    p1=Parzen(x,0.25,100,f); 
    p2 = Parzen(x,1,100,f);
    p3 = Parzen(x,4,100,f);
    subplot(334)
    plot(f,p1)
    subplot(335)
    plot(f,p2)
    subplot(336)
    plot(f,p3)
    
    hold on
    % N=1000   h= 0.25 , 1, 4
    p1=Parzen(x,0.25,1000,f); 
    p2 = Parzen(x,1,1000,f);
    p3 = Parzen(x,4,1000,f);
    subplot(337)
    plot(f,p1)
    subplot(338)
    plot(f,p2)
    subplot(339)
    plot(f,p3)
    
    function  p =  Parzen(x,h,N,f)
    %  高斯函数Parzen 窗  统计落在parzen窗内的估计概率
    %  h - 窗长度
    %  N -采样点数
    b=0;
    h1 =  h/sqrt(N);
    for i=1:length(f)
        for j=1:N
        b= b+ exp(((f(i)-x(j))/h1).^2/(-2))/sqrt(2*pi)/h1;
        end
        p(i) =  b/N;
        b=0;
    end
    end
    
  • 相关阅读:
    时间日期date/cal
    chown命令
    su命令
    which命令和bin目录
    python基础之文件操作
    python之模块之shutil模块
    python基础之面向对象01
    python基础之面向对象02
    python基础之map/reduce/filter/sorted
    python基础之模块之序列化
  • 原文地址:https://www.cnblogs.com/simayuhe/p/5360119.html
Copyright © 2011-2022 走看看