@@ -26,33 +26,132 @@ Functions
26
26
Module Contents
27
27
---------------
28
28
29
- .. py :function :: average_rom(autoencoder, physics, latent_dynamics, gp_dictionary, param_grid)
29
+ .. py :function :: average_rom(autoencoder: lasdi.latent_space.Autoencoder, physics: lasdi.physics.Physics, latent_dynamics: lasdi.latent_dynamics.LatentDynamics, gp_list: list[sklearn.gaussian_process.GaussianProcessRegressor], param_grid: numpy.ndarray)
30
+
31
+ This function simulates the latent dynamics for a collection of testing parameters by using
32
+ the mean of the posterior distribution for each coefficient's posterior distribution.
33
+ Specifically, for each parameter combination, we determine the mean of the posterior
34
+ distribution for each coefficient. We then use this mean to simulate the latent dynamics
35
+ forward in time (starting from the latent encoding of the fom initial condition for that
36
+ combination of coefficients).
37
+
38
+
39
+ -----------------------------------------------------------------------------------------------
40
+ :Parameters: * **autoencoder ** (*The actual autoencoder object that we use to map the ICs into the latent space. *)
41
+ * **physics ** (*A "Physics" object that stores the datasets for each parameter combination. *)
42
+ * **latent_dynamics ** (*A LatentDynamics object which describes how we specify the dynamics in the *)
43
+ * **Autoencoder's latent space. **
44
+ * **gp_list ** (*a list of trained GP regressor objects. The number of elements in this list should *)
45
+ * **match the number of columns in param_grid. The i'th element of this list is a GP regressor **
46
+ * **object that predicts the i'th coefficient. **
47
+ * **param_grid ** (*A 2d numpy.ndarray object of shape (number of parameter combination) x (number of *)
48
+ * **parameters). The i,j element of this array holds the value of the j'th parameter in the i'th **
49
+ * **combination of parameters. **
50
+
51
+ -----------------------------------------------------------------------------------------------
52
+ :returns: * *A 3d numpy ndarray whose i, j, k element holds the k'th component of the j'th time step of *
53
+ * *the solution to the latent dynamics when we use the latent encoding of the initial condition *
54
+ * *from the i'th combination of parameter values *
55
+
56
+
57
+ .. py :function :: sample_roms(autoencoder: lasdi.latent_space.Autoencoder, physics: lasdi.physics.Physics, latent_dynamics: lasdi.latent_dynamics.LatentDynamics, gp_list: list[sklearn.gaussian_process.GaussianProcessRegressor], param_grid: numpy.ndarray, n_samples: int ) -> numpy.ndarray
58
+
59
+ This function samples the latent coefficients, solves the corresponding latent dynamics, and
60
+ then returns the resulting latent solutions.
61
+
62
+ Specifically, for each combination of parameter values in the param_grid, we draw n_samples
63
+ samples of the latent coefficients (from the coefficient posterior distributions evaluated at
64
+ that parameter value). This gives us a set of n_samples latent dynamics coefficients. For each
65
+ set of coefficients, we solve the corresponding latent dynamics forward in time and store the
66
+ resulting solution frames. We do this for each sample and each combination of parameter values,
67
+ resulting in an (n_param, n_sample, n_t, n_z) array of solution frames, which is what we
68
+ return.
69
+
70
+
71
+ -----------------------------------------------------------------------------------------------
72
+ :Parameters: * **autoencoder ** (*An autoencoder. We use this to map the fom IC's (stored in Physics) to the *)
73
+ * **latent space using the autoencoder's encoder. **
74
+ * **physics ** (*A "Physics" object that stores the ICs for each parameter combination. *)
75
+ * **latent_dynamics ** (*A LatentDynamics object which describes how we specify the dynamics in the *)
76
+ * **Autoencoder's latent space. We use this to simulate the latent dynamics forward in time. **
77
+ * **gp_list ** (*a list of trained GP regressor objects. The number of elements in this list should *)
78
+ * **match the number of columns in param_grid. The i'th element of this list is a GP regressor **
79
+ * **object that predicts the i'th coefficient. **
80
+ * **param_grid ** (*A 2d numpy.ndarray object of shape (number of parameter combination) x (number of *)
81
+ * **parameters). The i,j element of this array holds the value of the j'th parameter in the i'th **
82
+ * **combination of parameters. **
83
+ * **n_samples ** (*The number of samples we want to draw from each posterior distribution for each *)
84
+ * **coefficient evaluated at each combination of parameter values. **
85
+
86
+ -----------------------------------------------------------------------------------------------
87
+ :returns: * *A np.array of size [n_test, n_samples, physics.nt, autoencoder.n_z]. The i, j, k, l element *
88
+ * *holds the l'th component of the k'th frame of the solution to the latent dynamics when we use *
89
+ * *the j'th sample of latent coefficients drawn from the posterior distribution for the i'th *
90
+ * *combination of parameter values (i'th row of param_grid). *
91
+
92
+
93
+ .. py :function :: get_fom_max_std(autoencoder: lasdi.latent_space.Autoencoder, Zis: numpy.ndarray) -> int
94
+
95
+ Computes the maximum standard deviation across the trajectories in Zis and returns the
96
+ corresponding parameter index. Specifically, Zis is a 4d tensor of shape (n_test, n_samples,
97
+ n_t, n_z). The first axis specifies which parameter combination we're using. For each
98
+ combination of parameters, we assume that we drew n_samples of the posterior distribution of
99
+ the coefficients at that parameter value, simulated the corresponding dynamics for n_t time
100
+ steps, and then recorded the results in Zis[i]. Thus, Zis[i, j, k, :] represents the k'th
101
+ time step of the solution to the latent dynamics when we use the coefficients from the j'th
102
+ sample of the posterior distribution for the i'th set of parameters.
103
+
104
+ Let i \i n {1, 2, ... , n_test} and k \i n {1, 2, ... , n_t}. For each j, we map the k'th frame
105
+ of the j'th solution trajectory for the i'th parameter combination (Zi[i, j, k, :]) to a fom
106
+ frame. We do this for each j (the set of samples), which gives us a collection of n_sample
107
+ fom frames, representing samples of the distribution of fom frames at the k'th time step
108
+ when we use the posterior distribution for the i'th set of parameters. For each l \i n {1, 2,
109
+ ... , n_fom}, we compute the STD of the set of l'th components of these n_sample fom frames.
110
+ We do this for each i and k and then figure out which i, k, l combination gives the largest
111
+ STD. We return the corresponding i index.
112
+
113
+
114
+ -----------------------------------------------------------------------------------------------
115
+ :Parameters: * **autoencoder ** (*The autoencoder. We assume the solved dynamics (whose frames are stored in Zis) *)
116
+ * **take place in the autoencoder's latent space. We use this to decode the solution frames. **
117
+ * **Zis ** (*A 4d numpy array of shape (n_test, n_samples, n_t, n_z) whose i, j, k, l element holds *)
118
+ * **the l'th component of the k'th frame of the solution to the latent dynamics when we use the **
119
+ * **j'th sample of latent coefficients drawn from the posterior distribution for the i'th testing **
120
+ * **parameter. **
121
+
122
+ -----------------------------------------------------------------------------------------------
123
+ Returns:
124
+ -----------------------------------------------------------------------------------------------
125
+
126
+ An integer. The index of the testing parameter that gives the largest standard deviation.
127
+ Specifically, for each testing parameter, we compute the STD of each component of the fom
128
+ solution at each frame generated by samples from the posterior coefficient distribution for
129
+ that parameter. We compute the maximum of these STDs and pair that number with the parameter.
130
+ We then return the index of the parameter whose corresponding maximum std (the number we pair
131
+ with it) is greatest.
132
+
133
+
134
+ .. py :function :: optimizer_to(optim: torch.optim.Optimizer, device: str ) -> None
135
+
136
+ This function moves an optimizer object to a specific device.
137
+
138
+
139
+ -----------------------------------------------------------------------------------------------
140
+ :Parameters: * **optim ** (*The optimizer whose device we want to change. *)
141
+ * **device ** (*The device we want to move optim onto. *)
142
+
143
+ -----------------------------------------------------------------------------------------------
144
+ :rtype: Nothing.
145
+
30
146
31
- .. py :function :: sample_roms(autoencoder, physics, latent_dynamics, gp_dictionary, param_grid, n_samples)
32
-
33
- Collect n_samples of ROM trajectories on param_grid.
34
- gp_dictionary: list of Gaussian process regressors (size of n_test)
35
- param_grid: numpy 2d array
36
- n_samples: integer
37
- assert(len(gp_dictionnary) == param_grid.shape[0])
38
-
39
- output: np.array of size [n_test, n_samples, physics.nt, autoencoder.n_z]
40
-
41
-
42
- .. py :function :: get_fom_max_std(autoencoder, Zis)
43
-
44
- Computes the maximum standard deviation accross the parameter space grid and finds the corresponding parameter location
45
-
46
-
47
-
48
- .. py :function :: optimizer_to(optim, device)
49
-
50
- .. py :class :: BayesianGLaSDI(physics, autoencoder, latent_dynamics, param_space, config)
147
+ .. py :class :: BayesianGLaSDI(physics: lasdi.physics.Physics, autoencoder: lasdi.latent_space.Autoencoder, latent_dynamics: lasdi.latent_dynamics.LatentDynamics, param_space: lasdi.param.ParameterSpace, config: dict )
51
148
52
149
.. py :attribute :: X_train
150
+ :type: torch.Tensor
53
151
54
152
55
153
.. py :attribute :: X_test
154
+ :type: torch.Tensor
56
155
57
156
58
157
.. py :attribute :: autoencoder
@@ -71,60 +170,119 @@ Module Contents
71
170
72
171
73
172
.. py :attribute :: n_samples
173
+ :type: int
74
174
75
175
76
176
.. py :attribute :: lr
177
+ :type: float
77
178
78
179
79
180
.. py :attribute :: n_iter
181
+ :type: int
80
182
81
183
82
184
.. py :attribute :: max_iter
185
+ :type: int
83
186
84
187
85
188
.. py :attribute :: max_greedy_iter
189
+ :type: int
86
190
87
191
88
192
.. py :attribute :: ld_weight
193
+ :type: float
89
194
90
195
91
196
.. py :attribute :: coef_weight
197
+ :type: float
92
198
93
199
94
200
.. py :attribute :: optimizer
201
+ :type: torch.optim.Optimizer
95
202
96
203
97
204
.. py :attribute :: MSE
98
205
99
206
100
207
.. py :attribute :: path_checkpoint
208
+ :type: str
101
209
102
210
103
211
.. py :attribute :: path_results
212
+ :type: str
104
213
105
214
106
215
.. py :attribute :: best_loss
216
+ :type: float
107
217
108
218
109
219
.. py :attribute :: best_coefs
220
+ :type: numpy.ndarray
110
221
:value: None
111
222
112
223
113
224
114
225
.. py :attribute :: restart_iter
226
+ :type: int
115
227
:value: 0
116
228
117
229
118
230
119
- .. py :method :: train()
231
+ .. py :method :: train() -> None
232
+
233
+ Runs a round of training on the autoencoder.
234
+
235
+ -------------------------------------------------------------------------------------------
236
+ :Parameters: **None! **
237
+
238
+ -------------------------------------------------------------------------------------------
239
+ :rtype: Nothing!
240
+
241
+
242
+
243
+ .. py :method :: get_new_sample_point() -> numpy.ndarray
244
+
245
+ This function uses a greedy process to sample a new parameter value. Specifically, it runs
246
+ through each combination of parameters in in self.param_space. For the i'th combination of
247
+ parameters, we generate a collection of samples of the coefficients in the latent dynamics.
248
+ We draw the k'th sample of the j'th coefficient from the posterior distribution for the
249
+ j'th coefficient at the i'th combination of parameters. We map the resulting solution back
250
+ into the real space and evaluate the standard deviation of the fom frames. We return the
251
+ combination of parameters which engenders the largest standard deviation (see the function
252
+ get_fom_max_std).
253
+
254
+
255
+ -------------------------------------------------------------------------------------------
256
+ :Parameters: **None! **
257
+
258
+ -------------------------------------------------------------------------------------------
259
+ :returns: * *a 2d numpy ndarray object of shape (1, n_param) whose (0, j) element holds the value of *
260
+ * *the j'th parameter in the new sample. *
261
+
262
+
263
+
264
+ .. py :method :: export() -> dict
265
+
266
+ -------------------------------------------------------------------------------------------
267
+ :returns: * *A dictionary housing most of the internal variables in self. You can pass this dictionary *
268
+ * *to self (after initializing it using ParameterSpace, Autoencoder, and LatentDynamics *
269
+ * *objects) to make a GLaSDI object whose internal state matches that of self. *
270
+
271
+
120
272
273
+ .. py :method :: load(dict_: dict ) -> None
121
274
122
- .. py :method :: get_new_sample_point()
275
+ Modifies self's internal state to match the one whose export method generated the dict _
276
+ dictionary.
123
277
124
278
125
- .. py :method :: export()
279
+ -------------------------------------------------------------------------------------------
280
+ :Parameters: * **dict_ ** (*This should be a dictionary returned by calling the export method on another *)
281
+ * **GLaSDI object. We use this to make self hav the same internal state as the object that **
282
+ * **generated dict_. **
126
283
284
+ -------------------------------------------------------------------------------------------
285
+ :rtype: Nothing!
127
286
128
- .. py :method :: load(dict_)
129
287
130
288
0 commit comments