-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharticle_num_experiments_random_large.py
154 lines (132 loc) · 4.26 KB
/
article_num_experiments_random_large.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
"""
Created on 7/18/2021
Author: Joost Berkhout (VU, email: joost.berkhout@vu.nl)
Description: This script is used to do the numerical experiments for the
random instances.
WARNING: The following values were used in TSDP_optimization.py for the
experiments
PRECISION = 10 ** (-8)
BINSEARCH_PRECISION = 10 ** (-8)
"""
from tabulate import tabulate
from TSDP_optimization import *
from utilities import (
store_results, calc_stationary_distribution,
ergodic_project,
)
np.random.seed(0)
# user init
timeLimit = 5 * 60
normType = 'inf'
n = 1000 # size random instances
numb_exp = 25
verbose = False
# technical init
results_dict = {}
for random_seed in range(numb_exp):
np.random.seed(random_seed)
print(f'Start experiment with seed {random_seed}')
# random instance
P = np.random.rand(n, n)
P = np.diag(1 / np.sum(P, 1)).dot(P)
mu = calc_stationary_distribution(P)
# random mu_goal
mu_goal = np.random.rand(n, 1)
mu_goal /= sum(mu_goal)
fraction_random = 0.01
mu_goal = fraction_random * mu_goal + (1 - fraction_random) * mu
method_name = 'min_norm_rank_1()'
start_time = time.time()
DeltaSol = min_norm_rank_1(P, mu_goal, normType)
run_time = time.time() - start_time
store_results(
results_dict, method_name, P, DeltaSol, mu_goal, normType,
run_time, calc_norm=True
)
method_name = 'min_norm_rank_1_pert_pres_stoch()'
start_time = time.time()
alpha, soft_mu_goal = max_convex_softened_mu_goal(P, mu, mu_goal)
if alpha > 0:
DeltaSol = min_norm_rank_1_pert_pres_stoch(
P, mu, soft_mu_goal,
normtype=normType
)
else:
DeltaSol = np.zeros((n, n))
run_time = time.time() - start_time
store_results(
results_dict, method_name, P, DeltaSol, mu_goal, normType,
run_time
)
method_name = 'R1SH(2)'
start_time = time.time()
DeltaSol = RISH_K(
P, mu, mu_goal, normType=normType,
verbose=False, sequence='descending',
jumpDirectlyToGoalIfPossible=False,
considerDeltaHistory=True,
numbIntervals=2
)
run_time = time.time() - start_time
store_results(
results_dict, method_name, P, DeltaSol, mu_goal, normType,
run_time
)
method_name = 'R1SH(4)'
start_time = time.time()
DeltaSol = RISH_K(
P, mu, mu_goal, normType=normType,
verbose=False, sequence='descending',
jumpDirectlyToGoalIfPossible=False,
considerDeltaHistory=True,
numbIntervals=4
)
run_time = time.time() - start_time
store_results(
results_dict, method_name, P, DeltaSol, mu_goal, normType,
run_time
)
method_name = 'R1SH(8)'
start_time = time.time()
DeltaSol = RISH_K(
P, mu, mu_goal, normType=normType,
verbose=False, sequence='descending',
jumpDirectlyToGoalIfPossible=False,
considerDeltaHistory=True,
numbIntervals=8
)
run_time = time.time() - start_time
store_results(
results_dict, method_name, P, DeltaSol, mu_goal, normType,
run_time
)
method_name = 'R1SH(16)'
start_time = time.time()
DeltaSol = RISH_K(
P, mu, mu_goal, normType=normType,
verbose=False, sequence='descending',
jumpDirectlyToGoalIfPossible=False,
considerDeltaHistory=True,
numbIntervals=16
)
run_time = time.time() - start_time
store_results(
results_dict, method_name, P, DeltaSol, mu_goal, normType,
run_time
)
method_name = 'Riesz projector'
start_time = time.time()
DeltaSol = DeltaSolErgProj = ergodic_project(mu_goal) - P
run_time = time.time() - start_time
store_results(
results_dict, method_name, P, DeltaSol, mu_goal, normType,
run_time
)
# print table of results
results_table = [[method] + [np.round(np.nanmean(results[k]), 6)
for k, v in results.items()]
for method, results in results_dict.items()]
column_labels = ['Method', f'mean(\|Delta\|_{normType})', 'Fraction feasible',
'mean run time', 'mean rank']
print(tabulate(results_table, column_labels))
print(tabulate(results_table, column_labels, tablefmt="latex"))