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

📄 gmmsamp.m

📁 模式识别的主要工具集合
💻 M
字号:
function [data, label] = gmmsamp(mix, n)%GMMSAMP Sample from a Gaussian mixture distribution.%%	Description%%	DATA = GSAMP(MIX, N) generates a sample of size N from a Gaussian%	mixture distribution defined by the MIX data structure. The matrix X%	has N rows in which each row represents a MIX.NIN-dimensional sample%	vector.%%	[DATA, LABEL] = GMMSAMP(MIX, N) also returns a column vector of%	classes (as an index 1..N) LABEL.%%	See also%	GSAMP, GMM%%	Copyright (c) Ian T Nabney (1996-2001)% Check input argumentserrstring = consist(mix, 'gmm');if ~isempty(errstring)  error(errstring);endif n < 1  error('Number of data points must be positive')end% Determine number to sample from each componentpriors = rand(1, n);% Pre-allocate data arraydata = zeros(n, mix.nin);if nargout > 1  label = zeros(n, 1);endcum_prior = 0;		% Cumulative sum of priorstotal_samples = 0;	% Cumulative sum of number of sampled pointsfor j = 1:mix.ncentres  num_samples = sum(priors >= cum_prior & ...    priors < cum_prior + mix.priors(j));  % Form a full covariance matrix  switch mix.covar_type    case 'spherical'      covar = mix.covars(j) * eye(mix.nin);    case 'diag'      covar = diag(mix.covars(j, :));    case 'full'      covar = mix.covars(:, :, j);    case 'ppca'      covar = mix.covars(j) * eye(mix.nin) + ...        mix.U(:, :, j)* ...        (diag(mix.lambda(j, :))-(mix.covars(j)*eye(mix.ppca_dim)))* ...        (mix.U(:, :, j)');    otherwise      error(['Unknown covariance type ', mix.covar_type]);  end  data(total_samples+1:total_samples+num_samples, :) = ...    gsamp(mix.centres(j, :), covar, num_samples);  if nargout > 1    label(total_samples+1:total_samples+num_samples) = j;  end  cum_prior = cum_prior + mix.priors(j);  total_samples = total_samples + num_samples;end  

⌨️ 快捷键说明

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