You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://julialang.zulipchat.com/#narrow/stream/279055-sciml-bridged)
[](https://github.com/SciML/ColPrac)
`s(xs)`, where `xs` is a `Vector` of input points and `ys` is a `Vector` of corresponding evaluations.
25
-
26
-
Calling `update!(s, xs, ys)` refits the surrogate `s` to include evaluations `ys` at points `xs`.
27
-
The result of `s(xs)` is a `Vector` of evaluations of the surrogate at points `xs`, corresponding to approximations of the underlying function at points `xs` respectively.
28
-
29
-
For single points `x` and `y`, call these methods via `update!(s, [x], [y])`
30
-
and `s([x])`.
31
-
32
-
### Optional methods
33
-
34
-
If the surrogate `s` wants to expose current parameter values, the method `parameters(s)`**must** be implemented.
35
-
36
-
If the surrogate `s` has tunable hyperparameters, the methods
37
-
`update_hyperparameters!(s, prior)` and `hyperparameters(s)`**must** be implemented.
38
-
39
-
Calling `update_hyperparameters!(s, prior)` updates the hyperparameters of the surrogate `s` by performing hyperparameter optimization using the information in `prior`. After the hyperparameters of `s` are updated, `s` is fit to past evaluations.
40
-
Calling `hyperparameters(s)` returns current values of hyperparameters.
function SurrogatesBase.update_hyperparameters!(rbf::RBF, prior)
67
-
# update rbf.scale and fit the surrogate by adapting rbf.weights
68
-
return rbf
69
-
end
70
-
```
71
-
72
-
## Stochastic Surrogates
73
-
74
-
Stochastic surrogates `s` are subtypes of `SurrogatesBase.AbstractStochasticSurrogate`.
75
-
76
-
### Required methods
77
-
78
-
The methods `update!(s, xs, ys)` and `finite_posterior(s, xs)`**must** be implemented, where `xs` is a `Vector` of input points and `ys` is a `Vector` of corresponding observed samples.
79
-
80
-
Calling `update!(s, xs, ys)` refits the surrogate `s` to include observations `ys` at points `xs`.
81
-
82
-
For single points `x` and `y`, call the `update!(s, xs, ys)` via `update!(s, [x], [y])`.
83
-
84
-
Calling `finite_posterior(s, xs)` returns an object that provides methods for working with the finite
85
-
dimensional posterior distribution at points `xs`.
86
-
The following methods might be supported:
87
-
88
-
-`mean(finite_posterior(s,xs))` returns a `Vector` of posterior means at `xs`
89
-
-`var(finite_posterior(s,xs))` returns a `Vector` of posterior variances at `xs`
90
-
-`mean_and_var(finite_posterior(s,xs))` returns a `Tuple` consisting of a `Vector`
91
-
of posterior means and a `Vector` of posterior variances at `xs`
92
-
-`rand(finite_posterior(s,xs))` returns a `Vector`, which is a sample from the joint posterior at points `xs`
93
-
94
-
### Optional methods
95
-
96
-
If the surrogate `s` wants to expose current parameter values, the method `parameters(s)`**must** be implemented.
97
-
98
-
If the surrogate `s` has tunable hyper-parameters, the methods
99
-
`update_hyperparameters!(s, prior)` and `hyperparameters(s)`**must** be implemented.
100
-
101
-
Calling `update_hyperparameters!(s, prior)` updates the hyperparameters of the surrogate `s` by performing hyperparameter optimization using the information in `prior`. After the hyperparameters of `s` are updated, `s` is fit to past samples.
102
-
Calling `hyperparameters(s)` returns current values of hyperparameters.
103
-
104
-
105
-
### Example
106
-
107
-
```julia
108
-
using SurrogatesBase
109
-
110
-
mutable struct GaussianProcessSurrogate{D, R, GP, H <:NamedTuple} <:AbstractStochasticSurrogate
111
-
xs::Vector{D}
112
-
ys::Vector{R}
113
-
gp_process::GP
114
-
hyperparameters::H
115
-
end
116
-
117
-
function SurrogatesBase.update!(g::GaussianProcessSurrogate, new_xs, new_ys)
118
-
append!(g.xs, new_xs)
119
-
append!(g.ys, new_ys)
120
-
# condition the prior `g.gp_process` on new data to obtain a posterior
121
-
# update g.gp_process to the posterior process
122
-
return g
123
-
end
124
-
125
-
function SurrogatesBase.finite_posterior(g::GaussianProcessSurrogate, xs)
126
-
# Return a finite dimensional projection of g.gp_process at points xs.
127
-
# The returned object GP_finite supports methods mean(GP_finite) and
128
-
# var(GP_finite) for obtaining the vector of means and variances at points xs.
0 commit comments