annotate toolboxes/FullBNT-1.0.7/bnt/examples/static/HME/gen_data.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, ndata1, ndata2, targets]=gen_data(ndata, seed)
Daniel@0 2 % Generate data from three classes in 2d
Daniel@0 3 % Setting 'seed' for reproducible results
Daniel@0 4 % OUTPUT
Daniel@0 5 % data : data set
Daniel@0 6 % ndata1, ndata2: separator
Daniel@0 7
Daniel@0 8 if nargin<1,
Daniel@0 9 error('Missing data size');
Daniel@0 10 end
Daniel@0 11
Daniel@0 12 input_dim = 2;
Daniel@0 13 num_classes = 3;
Daniel@0 14
Daniel@0 15 if nargin==2,
Daniel@0 16 % Fix seeds for reproducible results
Daniel@0 17 randn('state', seed);
Daniel@0 18 rand('state', seed);
Daniel@0 19 end
Daniel@0 20
Daniel@0 21 % Generate mixture of three Gaussians in two dimensional space
Daniel@0 22 data = randn(ndata, input_dim);
Daniel@0 23 targets = zeros(ndata, 3);
Daniel@0 24
Daniel@0 25 % Priors for the clusters
Daniel@0 26 prior(1) = 0.4;
Daniel@0 27 prior(2) = 0.3;
Daniel@0 28 prior(3) = 0.3;
Daniel@0 29
Daniel@0 30 % Cluster centres
Daniel@0 31 c = [2.0, 2.0; 0.0, 0.0; 1, -1];
Daniel@0 32
Daniel@0 33 ndata1 = round(prior(1)*ndata);
Daniel@0 34 ndata2 = round((prior(1) + prior(2))*ndata);
Daniel@0 35 % Put first cluster at (2, 2)
Daniel@0 36 data(1:ndata1, 1) = data(1:ndata1, 1) * 0.5 + c(1,1);
Daniel@0 37 data(1:ndata1, 2) = data(1:ndata1, 2) * 0.5 + c(1,2);
Daniel@0 38 targets(1:ndata1, 1) = 1;
Daniel@0 39
Daniel@0 40 % Leave second cluster at (0,0)
Daniel@0 41 data((ndata1 + 1):ndata2, :) = data((ndata1 + 1):ndata2, :);
Daniel@0 42 targets((ndata1+1):ndata2, 2) = 1;
Daniel@0 43
Daniel@0 44 data((ndata2+1):ndata, 1) = data((ndata2+1):ndata,1) *0.6 + c(3, 1);
Daniel@0 45 data((ndata2+1):ndata, 2) = data((ndata2+1):ndata,2) *0.6 + c(3, 2);
Daniel@0 46 targets((ndata2+1):ndata, 3) = 1;
Daniel@0 47
Daniel@0 48 if 0
Daniel@0 49 ndata = 1;
Daniel@0 50 data = x;
Daniel@0 51 targets = [1 0 0];
Daniel@0 52 end