-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathplot_ood_results.py
142 lines (127 loc) · 4.88 KB
/
plot_ood_results.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import torch
import numpy as np
from matplotlib import pyplot as plt
## Blind SNR
# Target channel
target_channel = 'CDL-C'
our_stop_array = [1104, 1161, 1260] # Best 'N' in the paper
our_beta = 3e-4 # Best 'beta' in the paper
l1_stop_array = [291, 190, 248]
alpha_array = [1.0, 0.8, 0.6]
# Plot
plt.rcParams['font.size'] = 22
linewidth = 3.5
markersize = 12
colors = ['r', 'g', 'b']
markers = ['*', 'o', 's']
plt.figure(figsize=(24, 10))
plt.subplot(1, 2, 1)
# Plot a curve for each sparsity value 'alpha'
for target_alpha in range(3):
# Our results
our_dir = 'results_ours_saved_channels_seed9999'
our_file = our_dir + '/%s_noise%.1e.pt' % (target_channel, our_beta)
contents = torch.load(our_file)
snr_range = contents['snr_range']
our_log = contents['oracle_log'].squeeze()
# Downselect alpha, timestep and average
our_results = \
np.mean(our_log[target_alpha, :, our_stop_array[target_alpha]], axis=-1)
our_results = 10 * np.log10(our_results)
# L1 results
l1_dir = 'results_l1_saved_channels_seed9999'
l1_file = l1_dir + '/%s_spacing0.50/l1_results_lmbda3.00e-02.pt' % (
target_channel)
contents = torch.load(l1_file)
l1_log = contents['oracle_log'].squeeze()
# Downselect alpha, timestep and average
l1_results = \
np.mean(l1_log[target_alpha, :, l1_stop_array[target_alpha]-1], axis=-1)
l1_results = 10 * np.log10(l1_results)
# Plot
plt.plot(snr_range, our_results, linewidth=linewidth,
linestyle='solid', marker=markers[target_alpha],
color=colors[target_alpha],
label=r'Ours, CDL-C $\alpha=$%.1f' % alpha_array[target_alpha],
markersize=markersize)
plt.plot(snr_range, l1_results, linewidth=linewidth,
linestyle='dotted', marker=markers[target_alpha],
color=colors[target_alpha],
label=r'Lasso, CDL-C $\alpha=$%.1f' % alpha_array[target_alpha],
markersize=markersize)
# Plot
plt.grid()
plt.xlabel('SNR [dB]')
plt.ylabel('NMSE [dB]')
plt.title('Blind (Unknown SNR)')
plt.legend()
plt.ylim([-25, 6])
# Save plot
plt.savefig('CDL_C_SNRblind_results.png', bbox_inches = 'tight',
pad_inches = 0.05, dpi=300)
## Known SNR
# Target channel
target_channel = 'CDL-C'
alpha_array = [1.0, 0.8, 0.6]
step_snr_match = [
[ 525, 687, 816, 1000, 1137, 1435, 1623, 1765, 1938, 2141, 2270], # Best 'N' from Alpha = 1.0
[ 523, 612, 790, 995, 1122, 1437, 1538, 1843, 2028, 2246, 2437], # Best 'N' from Alpha = 0.8, CDL-D
[ 429, 583, 864, 885, 1213, 1353, 1541, 1652, 1870, 2216, 2328], # Best 'N' from Alpha = 0.6, CDL-D
]
our_beta = 1e-3 # Best 'beta' in the paper, using same for all SNR points
# Plot
plt.rcParams['font.size'] = 22
linewidth = 3.5
markersize = 12
colors = ['r', 'g', 'b']
markers = ['*', 'o', 's']
# plt.figure(figsize=(12, 10))
plt.subplot(1, 2, 2)
for target_alpha in range(3):
# Our results
our_dir = 'results_ours_saved_channels_SNR_known_seed9999'
our_file = our_dir + '/%s_noise%.1e.pt' % (target_channel, our_beta)
contents = torch.load(our_file)
snr_range = contents['snr_range']
our_log = contents['oracle_log'].squeeze()
# Downselect alpha, timestep and average
our_square_log = our_log[target_alpha, :, step_snr_match[target_alpha]]
# Downselect diagonals
our_diag_log = np.asarray([our_square_log[idx, idx] for idx in range(len(snr_range))])
our_results = np.mean(our_diag_log, axis=-1)
our_results = 10 * np.log10(our_results)
# L1 results
l1_dir = 'results_l1_saved_channels_seed9999'
l1_file = l1_dir + '/%s_spacing0.50/l1_results_lmbda3.00e-02.pt' % (
target_channel)
contents = torch.load(l1_file)
l1_log = contents['oracle_log'].squeeze()
# Pick best results here
avg_l1_log = np.mean(l1_log[target_alpha], axis=-1)
# Downselect alpha, timestep and average
l1_results = 10 * np.log10(np.min(avg_l1_log[
:, np.arange(l1_stop_array[target_alpha]-1)], axis=-1))
# Plot
plt.plot(snr_range, our_results, linewidth=linewidth,
linestyle='solid', marker=markers[target_alpha],
color=colors[target_alpha],
label=r'Ours, CDL-C $\alpha=$%.1f' % alpha_array[target_alpha],
markersize=markersize)
plt.plot(snr_range, l1_results, linewidth=linewidth,
linestyle='dotted', marker=markers[target_alpha],
color=colors[target_alpha],
label=r'Lasso, CDL-C $\alpha=$%.1f' % alpha_array[target_alpha],
markersize=markersize)
# Plot
plt.grid()
plt.xlabel('SNR [dB]')
plt.ylabel('NMSE [dB]')
plt.title('Known SNR')
plt.legend()
plt.ylim([-25, 6])
plt.subplots_adjust(wspace=0.36)
# Save-sausage
plt.savefig('CDL_C_SNRknown_results.png', bbox_inches = 'tight',
pad_inches = 0.05, dpi=300)