annotate toolboxes/FullBNT-1.0.7/netlab3.3/dem2ddat.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function [data, c, prior, sd] = dem2ddat(ndata)
Daniel@0 2 %DEM2DDAT Generates two dimensional data for demos.
Daniel@0 3 %
Daniel@0 4 % Description
Daniel@0 5 % The data is drawn from three spherical Gaussian distributions with
Daniel@0 6 % priors 0.3, 0.5 and 0.2; centres (2, 3.5), (0, 0) and (0,2); and
Daniel@0 7 % standard deviations 0.2, 0.5 and 1.0. DATA = DEM2DDAT(NDATA)
Daniel@0 8 % generates NDATA points.
Daniel@0 9 %
Daniel@0 10 % [DATA, C] = DEM2DDAT(NDATA) also returns a matrix containing the
Daniel@0 11 % centres of the Gaussian distributions.
Daniel@0 12 %
Daniel@0 13 % See also
Daniel@0 14 % DEMGMM1, DEMKMEAN, DEMKNN1
Daniel@0 15 %
Daniel@0 16
Daniel@0 17 % Copyright (c) Ian T Nabney (1996-2001)
Daniel@0 18
Daniel@0 19 input_dim = 2;
Daniel@0 20
Daniel@0 21 % Fix seed for reproducible results
Daniel@0 22 randn('state', 42);
Daniel@0 23
Daniel@0 24 % Generate mixture of three Gaussians in two dimensional space
Daniel@0 25 data = randn(ndata, input_dim);
Daniel@0 26
Daniel@0 27 % Priors for the three clusters
Daniel@0 28 prior(1) = 0.3;
Daniel@0 29 prior(2) = 0.5;
Daniel@0 30 prior(3) = 0.2;
Daniel@0 31
Daniel@0 32 % Cluster centres
Daniel@0 33 c = [2.0, 3.5; 0.0, 0.0; 0.0, 2.0];
Daniel@0 34
Daniel@0 35 % Cluster standard deviations
Daniel@0 36 sd = [0.2 0.5 1.0];
Daniel@0 37
Daniel@0 38 % Put first cluster at (2, 3.5)
Daniel@0 39 data(1:prior(1)*ndata, 1) = data(1:prior(1)*ndata, 1) * 0.2 + c(1,1);
Daniel@0 40 data(1:prior(1)*ndata, 2) = data(1:prior(1)*ndata, 2) * 0.2 + c(1,2);
Daniel@0 41
Daniel@0 42 % Leave second cluster at (0,0)
Daniel@0 43 data((prior(1)*ndata + 1):(prior(2)+prior(1))*ndata, :) = ...
Daniel@0 44 data((prior(1)*ndata + 1):(prior(2)+prior(1))*ndata, :) * 0.5;
Daniel@0 45
Daniel@0 46 % Put third cluster at (0,2)
Daniel@0 47 data((prior(1)+prior(2))*ndata +1:ndata, 2) = ...
Daniel@0 48 data((prior(1)+prior(2))*ndata+1:ndata, 2) + c(3, 2);