【问题标题】:plotting contours according to distribution variance根据分布方差绘制等高线
【发布时间】:2019-06-20 13:49:43
【问题描述】:

我正在运行一个实验,我得到一组二维点形式的数据作为输出

# read csv file
samples = csvread('results.csv');

假设它们是正态分布的,我可以计算它们的均值和协方差并评估 pdf

mu = mean(samples);
sigma = cov(samples);
y = mvnpdf(X,mu,sigma);

其中X 是使用meshgrid 计算的二维网格。

我现在想做的是用等值线绘制这个分布为here

而且,我想选择与协方差相关的特定值的轮廓,如下图所示:

例如,我应该知道点 = (X: mu(1)+sigma(1,1), Y: mu(1)+sigma(1,1)) 中的分布值。我的猜测是我可以这样使用 normpdf 函数

value = normpdf(point,mu,sigma)

但我将其作为输出:

value =

   116.39   297.63
   297.63   409.88

我真的不知道如何解释它。

谁能告诉我怎么做?

谢谢。

【问题讨论】:

    标签: octave contour gaussian


    【解决方案1】:

    在您开始谈论 normpdf 时,我已经失去了您。你有一个多元正态,这就是你需要处理的。不确定您希望从这里的单变量法线中得到什么。

    如果您想获得马氏距离为 1 的多元正态分布的概率值(即与分布均值相差一个标准差),您可以通过在值 [m+s,0] 处评估 mvnpdf 来做到这一点,其中、m = mu(1)s = sqrt( sigma(1,1) )

    然后,您可以将其与适当的轮廓函数一起使用以获得所需的轮廓。

    编辑:这是一个例子。

      pkg load statistics
    
    % create 1000 samples from a known multivariate normal
      Observations     = mvnrnd( [0,0], [4, 1; 1 ,2], 1000 );
    
    % Get mean and covariance estimates from sample
      SampleMean       = mean( Observations, 1 ) % average along rows
      SampleCovariance = cov( Observations )
    
    % Get mean and standard deviation in first dimension (i.e. "x-axis")
      Mean_firstDimension   = SampleMean(1)
      StdDev_firstDimension = sqrt( SampleCovariance(1,1) )
    
    % Get gaussian values at malanobis distance of 1, 2, and 3
      MVN_value_at_mahalanobis_distance_of_one   = mvnpdf( [ Mean_firstDimension +     StdDev_firstDimension, 0], SampleMean, SampleCovariance )
      MVN_value_at_mahalanobis_distance_of_two   = mvnpdf( [ Mean_firstDimension + 2 * StdDev_firstDimension, 0], SampleMean, SampleCovariance )    
      MVN_value_at_mahalanobis_distance_of_three = mvnpdf( [ Mean_firstDimension + 3 * StdDev_firstDimension, 0], SampleMean, SampleCovariance )    
    
    % Define grid:
      [GridX, GridY] = ndgrid( -8:0.1:8, -8:0.1:8 );
      GridValues = mvnpdf( [GridX(:), GridY(:)], SampleMean, SampleCovariance );
      GridValues = reshape( GridValues, size( GridX ) );
    
    % Plot Observations
      plot( Observations(:,1), Observations(:,2), 'o', 'markerfacecolor', 'g', 'markeredgecolor', [0,0.5,0], 'linewidth', 1.5 );
      hold on;
    
    % Plot contours over grid
      contour( GridX, GridY, GridValues,   ...
               [ MVN_value_at_mahalanobis_distance_of_three, ...
                 MVN_value_at_mahalanobis_distance_of_two, ...
                 MVN_value_at_mahalanobis_distance_of_one ...
               ],
               'linewidth', 2
      )
      hold off;
    
    % Set nice limits and colours for background
      axis([-8, +8, -8, +8]); axis equal square;
      set(gca, 'color', 'k');
      set(gcf, 'color', [0.75, 0.75, 0.75]);
    

    【讨论】:

      猜你喜欢
      • 2021-09-05
      • 2016-10-19
      • 2012-03-02
      • 1970-01-01
      • 1970-01-01
      • 2014-12-02
      • 2021-05-19
      • 2017-11-30
      • 1970-01-01
      相关资源
      最近更新 更多