-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathburgers_article.py
More file actions
170 lines (133 loc) · 6.15 KB
/
Copy pathburgers_article.py
File metadata and controls
170 lines (133 loc) · 6.15 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
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 19 15:51:40 2022
@author: maslyaev
"""
import numpy as np
import pandas as pd
'''
You can install EPDE directly from our github repo:
pip install git+https://github.com/ITMO-NSS-team/EPDE@main
'''
import epde.interface.interface as epde_alg
from epde.interface.prepared_tokens import TrigonometricTokens, CacheStoredTokens
import os
import sys
sys.path.append('../')
sys.path.pop()
sys.path.append(os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..')))
# from epde.evaluators import CustomEvaluator, simple_function_evaluator, inverse_function_evaluator
# TODO^ caching of the pre-calculated derivatives
def run_burg_eq_search(multiobjective_mode, derivs):
epde_search_obj = epde_alg.EpdeSearch(multiobjective_mode=multiobjective_mode, use_solver=False,
dimensionality=dimensionality, boundary=boundary,
coordinate_tensors = grids)
epde_search_obj.set_preprocessor(default_preprocessor_type='poly', # use_smoothing = True
preprocessor_kwargs={'use_smoothing' : False})
popsize = 7
if multiobjective_mode:
epde_search_obj.set_moeadd_params(population_size = popsize,
training_epochs=40)
else:
epde_search_obj.set_singleobjective_params(population_size = popsize,
training_epochs=40)
custom_grid_tokens = CacheStoredTokens(token_type = 'grid',
# boundary = boundary,
token_labels = ['t', 'x'],
token_tensors={'t' : grids[0], 'x' : grids[1]},
params_ranges = {'power' : (1, 1)},
params_equality_ranges = None)
trig_tokens = TrigonometricTokens(dimensionality = dimensionality)
factors_max_number = {'factors_num' : [1, 2], 'probas' : [0.7, 0.3]}
opt_val = 1e-1
bounds = (1e-8, 1e0) if multiobjective_mode else (opt_val, opt_val)
epde_search_obj.fit(data=[u, ], variable_names=['u',], max_deriv_order=(2, 1), derivs = [derivs,],
equation_terms_max_number=4, data_fun_pow = 2,
additional_tokens=[trig_tokens, custom_grid_tokens], #custom_grid_tokens
equation_factors_max_number = factors_max_number,
eq_sparsity_interval = bounds)
epde_search_obj.equation_search_results(only_print = True, num = 1)
if multiobjective_mode:
metric = epde_search_obj.get_equations_by_complexity(complexity = 3)[0].obj_fun[0]
else:
metric = epde_search_obj.equation_search_results(only_print = False, num = 1)[0].obj_fun[0]
print(f'Obtained metric is {metric}')
return epde_search_obj.equation_search_results(only_print = False, num = 1), metric
if __name__ == "__main__":
'''
Ensure the correctness of the paths!
'''
path = '/home/maslyaev/epde/GECCO_experiments/data/Burgers/'
try:
u_file = os.path.join(os.path.dirname( __file__ ), 'data/KdV/burgers_sln_256.csv')
u = np.loadtxt(u_file, delimiter=',').T
except (FileNotFoundError, OSError):
u_file = '/home/maslyaev/epde/GECCO_experiments/data/Burgers/burgers_sln_256.csv'
u = np.loadtxt(u_file, delimiter=',').T
derives = None
dx = pd.read_csv(f'{path}burgers_sln_dx_256.csv', header=None)
d_x = dx.values
d_x = np.transpose(d_x)
dt = pd.read_csv(f'{path}burgers_sln_dt_256.csv', header=None)
d_t = dt.values
d_t = np.transpose(d_t)
dtt = pd.read_csv(f'{path}burgers_sln_dtt_256.csv', header=None)
d_tt = dtt.values
d_tt = np.transpose(d_tt)
# derives = np.zeros(shape=(data.shape[0], data.shape[1], 3))
# derives[:, :, 0] = d_t
# derives[:, :, 1] = d_tt
# derives[:, :, 2] = d_x
derives = np.zeros(shape=(u.shape[0], u.shape[1], 3))
derives[:, :, 0] = d_t
derives[:, :, 1] = d_tt
derives[:, :, 2] = d_x
derives = derives.reshape((-1, 3))
# u = np.moveaxis(u, 1, 0)
t = np.linspace(0, 4, u.shape[0])
x = np.linspace(-4000, 4000, u.shape[1])
grids = np.meshgrid(t, x, indexing = 'ij')
dimensionality = u.ndim - 1; boundary = 20
paretos_mo = []
paretos_so = []
exp_num = 10
for exp_run in range(exp_num):
paretos_mo.append(run_burg_eq_search(multiobjective_mode = True, derivs=derives))
paretos_so.append(run_burg_eq_search(multiobjective_mode = False, derivs=derives))
obj_funs_mo = [elem[1] for elem in paretos_mo]
obj_funs_so = [elem[1] for elem in paretos_so]
'''
obj_funs_mo = [1.8602792969132718e-07,
15.151537975821995,
1.8602792969132718e-07,
6.045698413857898e-12,
6.045877564414611e-12,
6.045698413857898e-12,
6.045698413857898e-12,
1.8602792969132718e-07,
6.045698413857898e-12,
6.045877564414611e-12]
obj_funs_so = [52.55367840511059,
50.92569285913047,
4.751400052693273e-10,
68.07398197293008,
22168.84900209751,
68.07398197293008,
6.045877564414611e-12,
1.00755257337613e-09,
55.32605105695978,
1.0707313482856096e-09]
'''
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['pdf.fonttype'] = 42
matplotlib.rcParams['ps.fonttype'] = 42
plt.rcParams["figure.figsize"] = (3.0, 3.5)
my_dict = {'Single Objective': obj_funs_so, 'Multi-Objective': obj_funs_mo}
fig, ax = plt.subplots()
ax.set_yscale('log')
ax.grid(alpha = 0.5)
ax.boxplot(my_dict.values(), whis=[5, 95])
ax.set_xticklabels(my_dict.keys())
plt.savefig('boxplot_burgers.png', dpi = 300, format = 'png', bbox_inches = 'tight')