-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_all_experiments.py
More file actions
83 lines (70 loc) · 2.67 KB
/
run_all_experiments.py
File metadata and controls
83 lines (70 loc) · 2.67 KB
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
import numpy as np
import matplotlib.pyplot as plt
import perturbations
import estimators
from statistical_problems import GaussianLocation, UniformLocation, LinearRegression
from simulation import Simulation
#################################
##### SIMULATION PARAMETERS #####
#################################
alpha_values = np.linspace(-2.5, 0, 40)
num_copies = 10000
#################################
# Define problem parameters
gaussian_params = {
'n': 10,
'p': 3,
'theta': np.array([0.0, 0.0, 0.0]),
'sigma': np.diag([1/6, 2/6, 3/6]),
'perturbation_class' : 'JDS'
}
uniform_params = {
'n':50,
'p':1,
'theta' : np.array([3]),
'perturbation_class' : 'JDS'
}
linear_regression_params = {
'n':10,
'p':5,
'theta' : np.ones(5),
'perturbation_class' : 'JDS'
}
def get_statistical_problem(problem_type, loss_type = "squared_error", sigma = None):
new_params = {"loss": loss_type}
if sigma is not None:
new_params["sigma"] = sigma
if problem_type == "Gaussian":
# Create a GaussianMean problem instance
problem = GaussianLocation(**(gaussian_params | new_params))
elif problem_type == "Uniform":
# Create a UniformMean problem instance
problem = UniformLocation(**(uniform_params | new_params))
elif problem_type == "Linear Regression":
# Create a Linear Regression problem instance
n,p = linear_regression_params['n'],linear_regression_params['p']
X = np.random.normal(size = (n,p))/np.sqrt(n)
linear_regression_params['X'] = X
problem = LinearRegression(**(linear_regression_params | new_params))
else:
raise NotImplementedError
return problem
# Define epsilon values
display_est = "best"
for problem_type in ["Gaussian","Linear Regression","Uniform"]:
all_sigma = [None]
losses = ["squared_error"]
if problem_type == "Linear Regression":
all_sigma = [np.eye(10)/100, np.diag([(i+1)/200 for i in range(10)])]
losses.append("prediction_error")
for loss in losses:
for i, sigma in enumerate(all_sigma):
print(f"Running {problem_type} with {loss} loss and sigma num {i+1}/{len(all_sigma)}")
problem = get_statistical_problem(problem_type, sigma=sigma, loss_type=loss)
epsilon_values = np.power(problem.n, alpha_values)
# Create and run the simulation
simulation = Simulation(problem, epsilon_values, num_copies, display_est)
results = simulation.run_simulation()
plt.rcParams['figure.figsize'] = [8, 6]
simulation.display_est = display_est
simulation.generate_plot(results,show=False)