-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRR_NoisyPD_0SNR.m
36 lines (27 loc) · 953 Bytes
/
RR_NoisyPD_0SNR.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
clear; clc;
% Generate data
load SpectrumNPD_AWGN_0.mat
data = SpectrumNPD_AWGN_0;
X = data(:,1:end-1);
y = data(:,end);
% Standardize features to have mean of 0 and variance of 1
X = standardizeCols(X);
% Add bias variable
[n, d] = size(X); % dimesnions of X
X = [ones(n,1) X];
d = d+1; % number of columns of X
p = 1; % norm
lambdaValues = 10.^[3:-0.2:-1];
lambda = lambdaValues(9);
w = zeros(1, d); % Initialization for the weight vector
% Solving the optimization problem to find the optimal weight vector (w)
cvx_begin
variable w(d)
minimize( norm( X * w - y, p ) + lambda * norm( w, p ) )
cvx_end
Wsparse = w; % The solution is sparse
threshold = 1e-4;
ind = find(abs(Wsparse)>threshold); % Indices of non-zero elements
Nonzeros = length(ind) % Number of Non-Zero elements
SpectrumNPD_AWGN_0_Sparse = SpectrumNPD_AWGN_0(:,ind);
csvwrite('SpectrumNPD_AWGN_0_Sparse.csv', SpectrumNPD_AWGN_0_Sparse,1,0);