Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- close all
- clear all
- c = [1; 0.2; 0.5]; % coéfficients du canal
- %c = [0.4048; 0.8164; 0.4084];
- M = length(c);
- sigv = 0.01; % variance bruit additif pour .001 1e-3 pour 0.01 1e-30
- N = 10000; % nombre de données
- d = sign(randn(1, N)); % séquence binaire générée
- dbuffer = zeros(M, 1); % Buffer
- y = zeros(1, N);
- for n = 1 : N,
- dbuffer = [d(n); dbuffer(1 : M - 1)];
- y(n) = c' * dbuffer + sqrt(sigv) * randn; % entrée récepteur
- end
- P = 3;
- ybuffer = zeros(P, 1);
- y2 = zeros(P, N);
- for n = 1 : N,
- ybuffer = [y(n); ybuffer(1 : P - 1)];
- y2(:,n) = ybuffer;
- %y(n) = wopt' ? ybuffer;
- if (n <= (N/2)) && (mod(n, 5) == 0),
- if d(n) == 1,
- plot3(ybuffer(1), ybuffer(2), ybuffer(3), 'O');
- hold on;
- else
- plot3(ybuffer(1), ybuffer(2), ybuffer(3), 'X');
- hold on;
- end
- pause(0.0001);
- end
- end
- disp('ok pour affichage des motifs pour les deux classes')
- trainset = transpose(y2(:,1:N/2));
- trainsetclass = transpose(d(1:N/2));
- testset = transpose(y2(:,N/2+1:N));
- testsetclass = transpose(d(N/2+1:N));
- %% CV partition
- c = cvpartition(trainsetclass, 'k', 5);
- %% Feature selection
- opts = statset('display', 'iter');
- fun = @(train_data, train_labels, test_data, test_labels) ...
- sum(predict(fitcsvm(train_data, train_labels, 'KernelFunction', 'rbf'), test_data) ~= test_labels);
- [fs, history] = sequentialfs(fun, trainset, trainsetclass, 'cv', c, 'options', opts, 'nfeatures', 3);
- %% Best hyperparameters
- BF = trainset(:, fs);
- mdl = fitcsvm(BF, trainsetclass, 'KernelFunction', 'rbf');
- %% Ploting
- %Gather support vectors from ClassificationSVM struct
- sv = mdl.SupportVectors;
- %set step size for finer sampling
- dd = 0.05;
- %generate grid for predictions at finer sample rate
- [x, y, z] = meshgrid(min(trainset(:,1)):dd:max(trainset(:,1)),...
- min(trainset(:,2)):dd:max(trainset(:,2)),...
- min(trainset(:,3)):dd:max(trainset(:,3)));
- xGrid = [x(:),y(:),z(:)];
- %get scores, f
- [ ~ , f] = predict(mdl,xGrid);
- %reshape to same grid size as the input
- f = reshape(f(:,2), size(x));
- % Assume class labels are 1 and 0 and convert to logical
- t = logical(trainsetclass);
- %plot data points, color by class label
- figure
- plot3(trainset(t, 1), trainset(t, 2), trainset(t, 3), 'b.');
- hold on
- plot3(trainset(~t, 1), trainset(~t, 2), trainset(~t, 3), 'r.');
- hold on
- % load unscaled support vectors for plotting
- plot3(sv(:, 1), sv(:, 2), sv(:, 3), 'go');
- %plot decision surface
- [faces,verts,~] = isosurface(x, y, z, f, 0, x);
- patch('Vertices', verts, 'Faces', faces, 'FaceColor','k','edgecolor', 'none', 'FaceAlpha', 0.2);
- grid on
- box on
- view(3)
- hold off
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement