Skip to content

Commit de39d88

Browse files
authored
Update predict api docs (#414)
* rm transform_to_real from exaples * rm transform_to_real from docs examples * update docstring * format * typo
1 parent 3f63106 commit de39d88

21 files changed

Lines changed: 54 additions & 50 deletions

docs/src/data_processing.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ The framework works as follows
77
- An `encoder_schedule` defines the type of processing to be applied to input and/or output spaces
88
- The `encoder_schedule` is passed into the `Emulator` where it is initialized and stored. Sometimes it will require additional information, passed in as `encoder_kwargs`.
99
- The encoder will be used automatically to encode training data, covariance matrices, and predictions within the Emulate and Sample routines.
10+
- Users can predict to/from encoded space with `predict(...; encode=X)` with `X` being `"in"`, `"out"`, or `"in_and_out"` if needed.
1011

11-
An external API is also available using the `encode_data`, and `encode_structure_matrix` methods if needed.
12+
An external API is also available using the `encode_data`, and `encode_structure_matrix` methods if needed to encode new data, or new covariance-type matrices.
1213

1314
## Defaults and recommendations
1415
### Default schedule (no explicit dimension reduction)

docs/src/emulate.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,16 @@ optimize_hyperparameters!(emulator)
3333
For some machine learning packages however, this may be completed during construction automatically, and for others this will not. If automatic construction took place, the `optimize_hyperparameters!` line does not perform any new task, so may be safely called. In the Lorenz example, this line learns the hyperparameters of the Gaussian process, which depend on the choice of [kernel](https://clima.github.io/CalibrateEmulateSample.jl/dev/GaussianProcessEmulator/#kernels), and the choice of GP package.
3434
Predictions at new inputs can then be made using
3535
```julia
36-
y, cov = Emulator.predict(emulator, new_inputs)
36+
em_mean, em_cov = Emulator.predict(emulator, new_inputs)
37+
```
38+
This returns both a mean value and a covariance. The emulator is subject to encoding (see [Data processing and Dimension reduction](@ref data-proc)), and so we provide the `encode` and `add_obs_noise_cov` to enable users to predict in different spaces, and with different inflation.
39+
```julia
40+
# produce output in encoded space
41+
em_mean_enc, em_cov_enc = Emulator.predict(emulator, new_inputs; encode="out")
42+
43+
# given encoded inputs, produce outputs in real space, and inflate the emulator uncertainty with observational noise
44+
em_mean, em_and_obs_noise_cov = Emulator.predict(emulator, new_encoded_inputs; encode="in", add_obs_noise_cov=true)
3745
```
38-
This returns both a mean value and a covariance.
3946

4047
## [Modular interface](@id modular-interface)
4148

docs/src/examples/Cloudy_example.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,7 @@ on them).
417417
# Check how well the emulator predicts on the true parameters
418418
y_mean, y_var = Emulators.predict(
419419
emulator,
420-
reshape(θ_true, :, 1);
421-
transform_to_real = true
420+
reshape(θ_true, :, 1)
422421
)
423422

424423
println("Emulator ($(case)) prediction on true parameters: ")

docs/src/examples/emulators/global_sens_analysis.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ optimize_hyperparameters!(emulator) # (only needed for some Emulator packages)
127127

128128
### Results and plots
129129

130-
We validate the emulator by evaluating it on the entire Sobol sequence, and calculating the Sobol indices (presenting mean and std if using multiple repeats.
130+
We validate the emulator by evaluating it on the entire Sobol sequence, and calculating the Sobol indices (presenting mean and std if using multiple repeats).
131131

132132
```julia
133133
# predict on all Sobol points with emulator (example)
134-
y_pred, y_var = predict(emulator, samples', transform_to_real = true)
134+
y_pred, y_var = predict(emulator, samples')
135135

136136
# obtain emulated Sobol indices
137137
result_pred = analyze(data, y_pred')

docs/src/examples/emulators/lorenz_integrator_3d_3d.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ u_test_tmp = zeros(3, length(xspan_test))
151151
u_test_tmp[:, 1] = sol_test.u[1] # initialize at the final-time solution of the training period
152152

153153
for i in 1:(length(xspan_test) - 1)
154-
rf_mean, _ = predict(emulator, u_test_tmp[:, i:i], transform_to_real = true) # 3x1 matrix
154+
rf_mean, _ = predict(emulator, u_test_tmp[:, i:i]) # 3x1 matrix
155155
u_test_tmp[:, i + 1] = rf_mean
156156
end
157157
```

docs/src/examples/emulators/regression_2d_2d.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ x2 = range(0.0, stop = 2 * π, length = n_pts)
139139
X1, X2 = meshgrid(x1, x2)
140140
inputs = permutedims(hcat(X1[:], X2[:]), (2, 1))
141141
```
142-
We predict using the emulators at the new inputs, and `transform_to_real` inverts the data processing back to physical values
142+
We predict using the emulators at the new inputs,
143143
```julia
144-
em_mean, em_cov = predict(emulator, inputs, transform_to_real = true)
144+
em_mean, em_cov = predict(emulator, inputs)
145145
```
146146
We then plot the predicted mean and pointwise variances, and calculate the errors from the three highlighted cases:
147147

docs/src/examples/lorenz_example.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ The emulator is checked for accuracy by evaluating its predictions on the true p
230230
```julia
231231
# Check how well the Gaussian Process regression predicts on the
232232
# true parameters
233-
y_mean, y_var = Emulators.predict(emulator, reshape(truth_params, :, 1), transform_to_real = true)
234-
y_mean_test, y_var_test = Emulators.predict(emulator, get_inputs(input_output_pairs_test), transform_to_real = true)
233+
y_mean, y_var = Emulators.predict(emulator, reshape(truth_params, :, 1))
234+
y_mean_test, y_var_test = Emulators.predict(emulator, get_inputs(input_output_pairs_test))
235235

236236
println("ML prediction on true parameters: ")
237237
println(vec(y_mean))

examples/Cloudy/Cloudy_emulate_sample.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ function main()
181181
optimize_hyperparameters!(emulator)
182182

183183
# Check how well the emulator predicts on the true parameters
184-
y_mean, y_var = Emulators.predict(emulator, reshape(θ_true, :, 1); transform_to_real = true)
185-
y_mean_test, y_var_test = Emulators.predict(emulator, get_inputs(test_pairs); transform_to_real = true)
184+
y_mean, y_var = Emulators.predict(emulator, reshape(θ_true, :, 1))
185+
y_mean_test, y_var_test = Emulators.predict(emulator, get_inputs(test_pairs))
186186
println("Emulator ($(case)) prediction on true parameters: ")
187187
println(vec(y_mean))
188188
println("true data: ")

examples/Darcy/emulate_sample.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,8 @@ function main()
105105
# Check how well the Gaussian Process regression predicts on the
106106
# true parameters
107107
#if retained_svd_frac==1.0
108-
y_mean, y_var = Emulators.predict(emulator, reshape(truth_params, :, 1), transform_to_real = true)
109-
y_mean_test, y_var_test =
110-
Emulators.predict(emulator, get_inputs(input_output_pairs_test), transform_to_real = true)
108+
y_mean, y_var = Emulators.predict(emulator, reshape(truth_params, :, 1))
109+
y_mean_test, y_var_test = Emulators.predict(emulator, get_inputs(input_output_pairs_test))
111110

112111
println("ML prediction on true parameters: ")
113112
println(vec(y_mean))

examples/EDMF_data/emulator-rank-test.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,15 @@ function main()
268268
# error of emulator on the training points: (no denoised training data)
269269
train_err_tmp = [0.0]
270270
for i in 1:size(train_inputs, 2)
271-
train_mean, _ = Emulators.predict(emulator, train_inputs[:, i:i], transform_to_real = true) # 3x1
271+
train_mean, _ = Emulators.predict(emulator, train_inputs[:, i:i]) # 3x1
272272
train_err_tmp[1] += norm(train_mean - train_outputs[:, i])
273273
end
274274
train_err[rank_id, rep_idx] = 1 / size(train_inputs, 2) * train_err_tmp[1]
275275

276276
# error of emulator on test points:
277277
test_err_tmp = [0.0]
278278
for i in 1:size(test_inputs, 2)
279-
test_mean, _ = Emulators.predict(emulator, test_inputs[:, i:i], transform_to_real = true) # 3x1
279+
test_mean, _ = Emulators.predict(emulator, test_inputs[:, i:i]) # 3x1
280280
test_err_tmp[1] += norm(test_mean - test_outputs[:, i])
281281
end
282282
test_err[rank_id, rep_idx] = 1 / size(test_inputs, 2) * test_err_tmp[1]

0 commit comments

Comments
 (0)