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

📄 demglm1.m

📁 有关PPCA的计算程序
💻 M
字号:
%DEMGLM1 Demonstrate simple classification using a generalized linear model.%%	Description%	 The problem consists of a two dimensional input matrix DATA and a%	vector of classifications T.  The data is  generated from two%	Gaussian clusters, and a generalized linear model with logistic%	output is trained using iterative reweighted least squares. A plot of%	the data together with the 0.1, 0.5 and 0.9 contour lines of the%	conditional probability is generated.%%	See also%	DEMGLM2, GLM, GLMTRAIN%%	Copyright (c) Ian T Nabney (1996-2001)% Generate data from two classes in 2dinput_dim = 2;% Fix seeds for reproducible resultsrandn('state', 42);rand('state', 42);ndata = 100;% Generate mixture of two Gaussians in two dimensional spacemix = gmm(2, 2, 'spherical');mix.priors = [0.4 0.6];              % Cluster priors mix.centres = [2.0, 2.0; 0.0, 0.0];  % Cluster centresmix.covars = [0.5, 1.0];[data, label] = gmmsamp(mix, ndata);targets = label - ones(ndata, 1);% Plot the resultclcdisp('This demonstration illustrates the use of a generalized linear model')disp('to classify data from two classes in a two-dimensional space. We')disp('begin by generating and plotting the data.')disp(' ')disp('Press any key to continue.')pausefh1 = figure;plot(data(label==1,1), data(label==1,2), 'bo');hold onaxis([-4 5 -4 5])set(gca, 'box', 'on')plot(data(label==2,1), data(label==2,2), 'rx')title('Data')clcdisp('Now we fit a model consisting of a logistic sigmoid function of')disp('a linear combination of the input variables.')disp(' ')disp('The model is trained using the IRLS algorithm for 5 iterations')disp(' ')disp('Press any key to continue.')pausenet = glm(input_dim, 1, 'logistic');options = foptions;options(1) = 1;options(14) = 5;net = glmtrain(net, options, data, targets);disp(' ')disp('We now plot some density contours given by this model.')disp('The contour labelled 0.5 is the decision boundary.')disp(' ')disp('Press any key to continue.')pausex = -4.0:0.2:5.0;y = -4.0:0.2:5.0;[X, Y] = meshgrid(x,y);X = X(:);Y = Y(:);grid = [X Y];Z = glmfwd(net, grid);Z = reshape(Z, length(x), length(y));v = [0.1 0.5 0.9];[c, h] = contour(x, y, Z, v);title('Generalized Linear Model')set(h, 'linewidth', 3)clabel(c, h);clcdisp('Note that the contours of constant density are straight lines.')disp(' ')disp('Press any key to end.')pauseclose(fh1);clear all;

⌨️ 快捷键说明

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