⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 decision_region.m

📁 最新的模式识别分类工具箱,希望对朋友们有用!
💻 M
字号:
function D = decision_region(m0, s0, w0, m1, s1, w1, p0, region)

%Function for making decision regions for Gaussians.
%Inputs are the means, std's and weights for the Gaussians.
%Output is the decision region matrix, based on a box of -5 to 5.

%If class probabilities are not specified, assume equal distribution
if ((nargin == 7) & (length(p0) > 1))
   region = p0;
   %region(1) = p0(1);
   %region(5) = 100;
   p0 = 0.5; 
end

N		= region(length(region));								%Number of points on the grid
x		= ones(N,1) * linspace (region(1),region(2),N);
y		= linspace (region(3),region(4),N)' * ones(1,N);
V0		= zeros(N,N);
V1		= zeros(N,N);

n0 = length(w0);
n1 = length(w1);
disp(['Detected ' num2str(n0) ' Gaussians for class 0 and ' num2str(n1) ' Gaussians for class 1'])

for i = 1:n0,
   if (length(size(s0))>2),
      sigma = squeeze(s0(i,:,:));
   else
      sigma = s0;
   end
   invsigma = inv(sigma);
   V0 = V0 + w0(i) ./ (2 * pi * sqrt(abs(det(sigma)))) .* ...
      exp(-0.5*(invsigma(1,1).*(x-m0(i,1)).^2 + ...
      2*invsigma(2,1).*(x-m0(i,1)).*(y-m0(i,2))+invsigma(2,2).*(y-m0(i,2)).^2));
end

for i = 1:n1,
   if (length(size(s1))>2),
      sigma = squeeze(s1(i,:,:));
   else
      sigma = s1;
   end
   invsigma = inv(sigma);
   V1 = V1 + w1(i) ./ (2 * pi * sqrt(abs(det(sigma)))) .* ...
        exp(-0.5*(invsigma(1,1).*(x-m1(i,1)).^2 + ...
          2*invsigma(2,1).*(x-m1(i,1)).*(y-m1(i,2))+invsigma(2,2).*(y-m1(i,2)).^2));
end
    
D = (V0*p0 < V1*(1-p0));

⌨️ 快捷键说明

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