📄 generate_data_set.m
字号:
function [features, targets] = generate_data_set(m0, m1, s0, s1, w0, w1, p0, region)
% Generate a new data set given it's Gaussian parameters
% Inputs:
% m0, m1 - Means of the gaussians for both classes
% s0, s1 - Standard deviations of the gaussians for both classes
% w0, w1 - Weights of the gaussians for both classes
% p0 - Probability of class 0
% region - Decision region vector: [-x x -y y number_of_points]
%
% Outputs:
% features - New features
% targets - New targets
n0 = size(s0,1);
n1 = size(s1,1);
%Get the number of points from the user
N = str2num(char(inputdlg('Enter the number of points in data set:','Generate Data set')));
set(gcf,'pointer','watch');
%First, select the indices for class0 and the indices for class 1
N0 = round(p0*N);
N1 = N - N0;
indices = randperm(N);
indices0 = indices(1:N0);
indices1 = indices(N0+1:N);
targets = zeros(1,N);
targets(indices1) = 1;
features = zeros(2,N);
%Now, make the points for class 0
%First, divide N0 to n0 pieces according to w0
w0 = round(N0 * w0);
if (sum(w0) ~= N0),
w0(1) = w0(1) - (sum(w0) - N0);
end
cw0 = [0 ; cumsum(w0)];
for i = 1:n0,
%Make w0(i) data points according to the distribution
if (length(size(s0))>2),
sigma = squeeze(s0(i,:,:));
else
sigma = s0;
end
A = sigma;
dist = A'*randn(2,w0(i));
dist = dist + m0(i,:)' * ones(1,w0(i));
%Place them in one of the remaining places of indices0
features(:,indices0(1+cw0(i):cw0(i+1))) = dist;
end
%Do the same for class 1
%First, divide N1 to n1 pieces according to w1
w1 = round(N1 * w1);
if (sum(w1) ~= N1),
w1(1) = w1(1) - (sum(w1) - N1);
end
cw1 = [0 ; cumsum(w1)];
for i = 1:n1,
%Make w1(i) data points according to the distribution
if (length(size(s1))>2),
sigma = squeeze(s1(i,:,:));
else
sigma = s1;
end
A = sigma;
dist = A'*randn(2,w1(i));
dist = dist + m1(i,:)' * ones(1,w1(i));
%Place them in one of the remaining places of indices1
features(:,indices1(1+cw1(i):cw1(i+1))) = dist;
end
N = region(5);
param = max(max(abs(features)));
plot_scatter(features, targets)
axis([-param,param,-param,param])
set(gcf,'pointer','arrow');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -