matlab中二元正态分布函数.docx

上传人:小飞机 文档编号:3161193 上传时间:2023-03-11 格式:DOCX 页数:4 大小:37.14KB
返回 下载 相关 举报
matlab中二元正态分布函数.docx_第1页
第1页 / 共4页
matlab中二元正态分布函数.docx_第2页
第2页 / 共4页
matlab中二元正态分布函数.docx_第3页
第3页 / 共4页
matlab中二元正态分布函数.docx_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《matlab中二元正态分布函数.docx》由会员分享,可在线阅读,更多相关《matlab中二元正态分布函数.docx(4页珍藏版)》请在三一办公上搜索。

1、matlab中二元正态分布函数matlab中二元正态分布函数 function data1, data2 = twogaussian(n1,mu1,cov1,n2,mu2,cov2); % % data1, data2 = twogaussian(n1,mu1,sigma1,n2,mu2,sigma2); % % Function to simulate data from 2 Gaussian densities in d dimensions % and to plot the data in the first 2 dimensions % % INPUTS: % n1, n2: two

2、 integers, size of data set 1 and 2 respectively % mu1, mu2: two vectors of dimension 1 x d, means % for data set 1 and 2 % cov1, cov2: two matrices of dimension d x d, covariance % matrices for data set 1 and 2 respectively % % OUTPUTS: % data1: n1 x d matrix of data for data set 1 % data2: n2 x d

3、matrix of data for data set 2 % check that the dimensionality of the mus and sigmas are consistent d1 = length(mu1); d2 = length(mu2); if (d1=d2) error(means are of different lengths); end; d = length(mu1); % d is the dimensionality of the data d1 d2 = size(cov1); if (d1=d2) error(cov1 is a non-squa

4、re covariance matrix); end; if (d1=d) error(cov1 is of different dimensionality to mu1); end; d1 d2 = size(cov2); if (d1=d2) error(cov2 is a non-square covariance matrix); end; if (d1=d) error(cov2 is of different dimensionality to mu2); end; % Call the function mvnrnd.m to generate the two data set

5、s data1 = mvnrnd(mu1,cov1,n1); data2 = mvnrnd(mu2,cov2,n2); % Now plot the two data sets as a two-dimensional scatter plot % if d = 2: plot dimension1 on the xaxis and dimension 2 on the % yaxis. Plot the points from data1 as green circles o, and the % points from data2 as red crosses x. if . figure

6、 % open a figure window plot(data1(:,1),data1(:,2),b.);. % now plot data1 axis(-6 6 -6 6); % fix the lengths of the axes hold % hold the figure to overlay a 2nd plot plot(data2(:,1),data2(:,2),rx);% now plot data 2 xlabel(Dimension 1); ylabel(Dimension 2); title(Simulation of two-class Gaussian data

7、 in two dimensions); end function r = mvnrnd(mu,sigma,cases); %MVNRND Random matrices from the multivariate normal distribution. % R = MVNRND(MU,SIGMA,CASES) returns a matrix of random numbers % chosen from the multivariate normal distribution with mean vector, % MU, and covariance matrix, SIGMA. CA

8、SES is the number of rows in R. % % SIGMA is a square positive definite matrix with size equal to % the length of MU % Adapted from Mathworks function m1 n1 = size(mu); c = max(m1 n1); if m1 .* n1 = c error(Mu must be a vector.); end m n = size(sigma); if m = n error(Sigma must be square); end if m = c error(The length of mu must equal the number of rows in sigma.); end T p = chol(sigma); if p = 0 error(Sigma must be a positive definite matrix.); end if m1 = c mu = mu; end mu = mu(ones(cases,1),:); r = randn(cases,c) * T + mu;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号