Skip to content

Commit e0ff7c1

Browse files
committed
deploy: 7341d37
1 parent e0ed080 commit e0ff7c1

File tree

20 files changed

+470
-250
lines changed

20 files changed

+470
-250
lines changed
964 Bytes
Binary file not shown.
58.5 KB
Binary file not shown.
87 Bytes
Binary file not shown.
2 Bytes
Binary file not shown.
2.18 KB
Binary file not shown.
3.64 KB
Binary file not shown.

.doctrees/environment.pickle

124 KB
Binary file not shown.

_sources/autoapi/lasdi/gp/index.rst.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ Module Contents
2828
We assume each target coefficient is independent with each other.
2929

3030

31-
3231
-----------------------------------------------------------------------------------------------
3332
:Parameters: * **X** (*A 2d numpy array of shape (n_train, input_dim), where n_train is the number of training*)
3433
* **examples and input_dim is the number of components in each input (e.g., the number of**
@@ -42,12 +41,11 @@ Module Contents
4241
* *columns of X and whose corresponding target values are the elements of the i'th column of Y.*
4342

4443

45-
.. py:function:: eval_gp(gp_list: list[sklearn.gaussian_process.GaussianProcessRegressor], param_grid: numpy.ndarray) -> tuple
44+
.. py:function:: eval_gp(gp_list: list[sklearn.gaussian_process.GaussianProcessRegressor], param_grid: numpy.ndarray) -> tuple[numpy.ndarray, numpy.ndarray]
4645
4746
Computes the GPs predictive mean and standard deviation for points of the parameter space grid
4847

4948

50-
5149
-----------------------------------------------------------------------------------------------
5250
:Parameters: * **gp_list** (*a list of trained GP regressor objects. The number of elements in this list should*)
5351
* **match the number of columns in param_grid. The i'th element of this list is a GP regressor**
@@ -74,7 +72,6 @@ Module Contents
7472
when param is the parameter.
7573

7674

77-
7875
-----------------------------------------------------------------------------------------------
7976
:Parameters: * **gp_list** (*a list of trained GP regressor objects. The number of elements in this list should*)
8077
* **match the number of columns in param_grid. The i'th element of this list is a GP regressor**

_sources/autoapi/lasdi/gplasdi/index.rst.txt

Lines changed: 183 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,132 @@ Functions
2626
Module Contents
2727
---------------
2828

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 \in {1, 2, ... , n_test} and k \in {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 \in {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+
30146

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)
51148
52149
.. py:attribute:: X_train
150+
:type: torch.Tensor
53151

54152

55153
.. py:attribute:: X_test
154+
:type: torch.Tensor
56155

57156

58157
.. py:attribute:: autoencoder
@@ -71,60 +170,119 @@ Module Contents
71170
72171
73172
.. py:attribute:: n_samples
173+
:type: int
74174

75175

76176
.. py:attribute:: lr
177+
:type: float
77178

78179

79180
.. py:attribute:: n_iter
181+
:type: int
80182

81183

82184
.. py:attribute:: max_iter
185+
:type: int
83186

84187

85188
.. py:attribute:: max_greedy_iter
189+
:type: int
86190

87191

88192
.. py:attribute:: ld_weight
193+
:type: float
89194

90195

91196
.. py:attribute:: coef_weight
197+
:type: float
92198

93199

94200
.. py:attribute:: optimizer
201+
:type: torch.optim.Optimizer
95202

96203

97204
.. py:attribute:: MSE
98205
99206
100207
.. py:attribute:: path_checkpoint
208+
:type: str
101209

102210

103211
.. py:attribute:: path_results
212+
:type: str
104213

105214

106215
.. py:attribute:: best_loss
216+
:type: float
107217

108218

109219
.. py:attribute:: best_coefs
220+
:type: numpy.ndarray
110221
:value: None
111222

112223

113224

114225
.. py:attribute:: restart_iter
226+
:type: int
115227
:value: 0
116228

117229

118230

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+
120272

273+
.. py:method:: load(dict_: dict) -> None
121274
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.
123277

124278

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_.**
126283

284+
-------------------------------------------------------------------------------------------
285+
:rtype: Nothing!
127286

128-
.. py:method:: load(dict_)
129287

130288

_sources/autoapi/lasdi/latent_space/index.rst.txt

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ Module Contents
4545

4646
-----------------------------------------------------------------------------------------------
4747
:Parameters: * **param_grid** (*A 2d numpy.ndarray object of shape (number of parameter combination) x (number of*)
48-
* **parameters).**
49-
* **physics** (*A "Physics" object that stores the datasets for each parameter combination.*)
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+
* **physics** (*A "Physics" object that, among other things, stores the IC for each combination of*)
51+
* **parameters.**
5052
* **autoencoder** (*The actual autoencoder object that we use to map the ICs into the latent space.*)
5153

5254
-----------------------------------------------------------------------------------------------
@@ -105,14 +107,8 @@ Module Contents
105107

106108
.. py:method:: init_weight() -> None
107109
108-
This function initializes the weight matrices and bias vectors in self's layers.
109-
110-
111-
-------------------------------------------------------------------------------------------
112-
:Parameters: **None!**
113-
114-
-------------------------------------------------------------------------------------------
115-
:rtype: Nothing!
110+
This function initializes the weight matrices and bias vectors in self's layers. It takes
111+
no arguments and returns nothing!
116112

117113

118114

@@ -155,14 +151,11 @@ Module Contents
155151

156152
.. py:method:: export() -> dict
157153
158-
This function extracts self's parameters and returns them in a dictionary.
159-
160-
161-
-------------------------------------------------------------------------------------------
162-
:Parameters: **None!**
163-
164154
-------------------------------------------------------------------------------------------
165-
:rtype: The A dictionary housing self's state dictionary.
155+
:returns: * *This function extracts self's parameters and returns them in a dictionary. You can pass*
156+
* *the dictionary returned by this function to the load method of another Autoencoder object*
157+
* *(that you initialized to have the same architecture as self) to make the other autoencoder*
158+
* *identical to self.*
166159

167160

168161

0 commit comments

Comments
 (0)