-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.py
More file actions
84 lines (52 loc) · 2.61 KB
/
Copy pathexamples.py
File metadata and controls
84 lines (52 loc) · 2.61 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
84
from dataclasses import replace, asdict
import matplotlib.pyplot as plt
from optimization.gd_nesterov import gradient_descent_nesterov
from utils.env_utils import plotting_style, PATHS, print_bars
from utils.pattern_formation import initialize_u0_random
from params.opt_params import labyrinth_data_params, get_DataParameters, sim_config
from params.opt_params import pgd_sim_params as ngd_sim_params
from params.lipschitz import evaluate_lipschitz_constant
"""
functional with new dir layout
"""
if __name__ == "__main__":
EXAMPLE_1 = True
EXAMPLE_2 = False
plotting_style()
FOLDER_PATH = PATHS.PATH_EXAMPLES
LIVE_PLOT = False
DATA_LOG = False
labyrinth_data_params = replace(labyrinth_data_params, N = 100, gamma = 0.0008)
gridsize, N, th, epsilon, gamma = get_DataParameters(labyrinth_data_params)
ngd_sim_params = replace(ngd_sim_params, tau = evaluate_lipschitz_constant(gamma, epsilon, N, gridsize, th))
print_bars()
print(labyrinth_data_params)
print(ngd_sim_params)
print_bars()
u0 = initialize_u0_random(N)
if EXAMPLE_1:
u, e = gradient_descent_nesterov(u0, LIVE_PLOT, DATA_LOG, FOLDER_PATH, **asdict(labyrinth_data_params),**asdict(ngd_sim_params),**asdict(sim_config) )
u = u[30:70, :]
im = plt.imshow(u.cpu(), cmap="managua", origin="lower")
plt.axis("off")
plt.colorbar(label = r"$m_z$", shrink = 0.4) #ax=ax, fraction=0.046, pad=0.04
plt.tight_layout()
plt.savefig(FOLDER_PATH / "pattern_example_with_colobar.png", dpi = 300)
plt.show()
u_ls = []
fig, axs = plt.subplots(1, 5)
if EXAMPLE_2:
for ii, th in enumerate([0.1, 0.5, 1.0, 10, 100]):
labyrinth_data_params = replace(labyrinth_data_params, th = th)
eta = evaluate_lipschitz_constant(labyrinth_data_params.gamma,
labyrinth_data_params.epsilon,
labyrinth_data_params.N,
labyrinth_data_params.gridsize,
labyrinth_data_params.th)
ngd_sim_params = replace(ngd_sim_params, tau = eta)
u, e = gradient_descent_nesterov(u0, LIVE_PLOT, DATA_LOG, FOLDER_PATH, **asdict(labyrinth_data_params),**asdict(ngd_sim_params),**asdict(sim_config) )
axs[ii].imshow(u, cmap='managua', extent=(0,1,0,1))
axs[ii].axes.get_xaxis().set_ticks([])
axs[ii].axes.get_yaxis().set_ticks([])
axs[ii].set_title(f"$\\delta = {th}$")
plt.show()