-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtesting_superresolution.py
185 lines (141 loc) · 4.49 KB
/
testing_superresolution.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 13 09:07:51 2018
@author: Yohann DE CASTRO (yohann.decastro "at" gmail)
This code reproduces some numerical experiments of the paper entitled
"Testing Gaussian Process with Applications to Super-Resolution"
by J.-M. Azaïs and Y. De Castro
"""
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from aux import generate_stat, generate_tstat
#%%
"""
The known variance case
"""
"""
We begin with the distribution of S under the null
"""
sample_size = 5
sparsity = 0
amplitude = 0
sigma = 1
iterations = 500
emp = np.zeros(iterations)
for k in range(0,iterations):
temp = generate_stat(sample_size, sparsity, amplitude, sigma)
emp[k] = temp
np.save('fig1_1', [emp, sample_size, sparsity, amplitude, sigma, iterations])
"""
We continue with the distribution of S under an alternative
"""
sparsity = 1
amplitude = np.log(2*sample_size+1)
emp2 = np.zeros(iterations)
for k in range(0,iterations):
temp = generate_stat(sample_size, sparsity, amplitude, sigma)
emp2[k] = temp
np.save('fig1_2', [emp2, sample_size, sparsity, amplitude, sigma, iterations])
"""
We continue with the distribution of S under an other alternative
"""
sparsity = 1
amplitude = np.sqrt(2*sample_size+1)
emp3 = np.zeros(iterations)
for k in range(0,iterations):
temp = generate_stat(sample_size, sparsity, amplitude, sigma)
emp3[k] = temp
np.save('fig1_3', [emp3, sample_size, sparsity, amplitude, sigma, iterations])
"""
We plot the results
"""
#%
sns.set_style("dark")
a =emp
b =emp2
c =emp3
plt.figure(figsize=(6,6))
x = np.linspace(0,1,2000)
plt.plot(x, x, color="dimgray", linestyle="--", lw=2)
plt.plot(np.sort(a), np.linspace(0, 1, len(a)), color="royalblue", lw=3)
plt.plot(np.sort(b), np.linspace(0, 1, len(b)), color="darkseagreen", lw=3)
plt.plot(np.sort(c), np.linspace(0, 1, len(c)), color="indianred", lw=3)
plt.grid()
plt.xlim(-0.01,1.01)
plt.ylim(-0.01,1.01)
#plt.xlabel("x")
#plt.ylabel("F(x)")
plt.legend(["CDF of Uniform Law", "CDF of $S$ under the null",\
"CDF of $S$ under $\log(N)$ alt.", "CDF of $S$ under $\sqrt{N}$ alt."])
plt.title ("Emp. CDFs with $f_c=$%s over %s iterations" %(sample_size, iterations))
plt.tight_layout()
plt.savefig('fig1.png', format='png', dpi=300)
plt.show()
#%%
"""
The unknown variance case
"""
"""
We begin with the distribution of T under the null
"""
sample_size = 5
sparsity = 0
amplitude = 0
sigma = 1
iterations = 5000
emp = np.zeros(iterations)
var_emp = np.zeros(iterations)
for k in range(0,iterations):
temp = generate_tstat(sample_size, sparsity, amplitude, sigma)
emp[k] = temp[0]
var_emp[k] = temp[1]
np.save('fig2_1', [emp, var_emp, sample_size, sparsity, amplitude, sigma, iterations])
"""
We continue with the distribution of S under an alternative
"""
sparsity = 1
amplitude = np.log(2*sample_size+1)
emp2 = np.zeros(iterations)
var_emp2 = np.zeros(iterations)
for k in range(0,iterations):
temp = generate_tstat(sample_size, sparsity, amplitude, sigma)
emp2[k] = temp[0]
var_emp2[k] = temp[1]
np.save('fig2_2', [emp2, var_emp2, sample_size, sparsity, amplitude, sigma, iterations])
"""
We continue with the distribution of S under an other alternative
"""
sparsity = 1
amplitude = np.sqrt(2*sample_size+1)
emp3 = np.zeros(iterations)
var_emp3 = np.zeros(iterations)
for k in range(0,iterations):
temp = generate_tstat(sample_size, sparsity, amplitude, sigma)
emp3[k] = temp[0]
var_emp3[k] = temp[1]
np.save('fig2_3', [emp3, var_emp3, sample_size, sparsity, amplitude, sigma, iterations])
"""
We plot the results
"""
#%
sns.set_style("dark")
a =emp
b =emp2
c =emp3
plt.figure(figsize=(6,6))
x = np.linspace(0,1,2000)
plt.plot(x, x, color="dimgray", linestyle="--", lw=2)
plt.plot(np.sort(a), np.linspace(0, 1, len(a)), color="royalblue", lw=3)
plt.plot(np.sort(b), np.linspace(0, 1, len(b)), color="darkseagreen", lw=3)
plt.plot(np.sort(c), np.linspace(0, 1, len(c)), color="indianred", lw=3)
plt.grid()
plt.xlim(-0.01,1.01)
plt.ylim(-0.01,1.01)
plt.legend(["CDF of Uniform Law", "CDF of $T$ under the null",\
"CDF of $T$ under $\log(N)$ alt.", "CDF of $T$ under $\sqrt{N}$ alt."])
plt.title ("Emp. CDFs with $f_c=$%s over %s iterations" %(sample_size, iterations))
plt.tight_layout()
plt.savefig('fig2.png', format='png', dpi=300)
plt.show()