@@ -96,23 +96,31 @@ class HSGPParams(NamedTuple):
96
96
97
97
98
98
def approx_hsgp_hyperparams (
99
- x : np . ndarray , lengthscale_range : list [float ], cov_func : str
99
+ x_range : list [ float ] , lengthscale_range : list [float ], cov_func : str
100
100
) -> HSGPParams :
101
101
"""Utility function that uses heuristics to recommend minimum `m` and `c` values,
102
102
based on recommendations from Ruitort-Mayol et. al.
103
103
104
104
In practice, you need to choose `c` large enough to handle the largest lengthscales,
105
- and `m` large enough to accommodate the smallest lengthscales.
105
+ and `m` large enough to accommodate the smallest lengthscales. Use your prior on the
106
+ lengthscale as guidance for setting the prior range. For example, if you believe
107
+ that 95% of the prior mass of the lengthscale is between 1 and 5, set the
108
+ `lengthscale_range` to be [1, 5], or maybe a touch wider.
109
+
110
+ Also, be sure to pass in an `x` that is exemplary of the domain not just of your
111
+ training data, but also where you intend to make predictions. For instance, if your
112
+ training x values are from [0, 10], and you intend to predict from [7, 15], you can
113
+ pass in `x_range = [0, 15]`.
106
114
107
115
NB: These recommendations are based on a one-dimensional GP.
108
116
109
117
Parameters
110
118
----------
111
- x : np.ndarray
112
- The input variable on which the GP is going to be evaluated.
113
- Careful: should be the X values you want to predict over, not *only* the training X .
119
+ x_range : list[float]
120
+ The range of the x values you intend to both train and predict over. Should be a list with
121
+ two elements, [x_min, x_max] .
114
122
lengthscale_range : List[float]
115
- The range of the lengthscales. Should be a list with two elements [lengthscale_min, lengthscale_max].
123
+ The range of the lengthscales. Should be a list with two elements, [lengthscale_min, lengthscale_max].
116
124
cov_func : str
117
125
The covariance function to use. Supported options are "expquad", "matern52", and "matern32".
118
126
@@ -126,7 +134,7 @@ def approx_hsgp_hyperparams(
126
134
Scaling factor such that L = c * S, where L is the boundary of the approximation.
127
135
Increasing it helps approximate larger lengthscales, but may require increasing m.
128
136
- `S` : float
129
- The value of `S`, which is half the range of `x`.
137
+ The value of `S`, which is half the range, or radius, of `x`.
130
138
131
139
Raises
132
140
------
@@ -139,11 +147,12 @@ def approx_hsgp_hyperparams(
139
147
Practical Hilbert Space Approximate Bayesian Gaussian Processes for Probabilistic Programming
140
148
"""
141
149
if lengthscale_range [0 ] >= lengthscale_range [1 ]:
142
- raise ValueError ("One of the boundaries out of order" )
150
+ raise ValueError ("One of the `lengthscale_range` boundaries is out of order." )
151
+
152
+ if x_range [0 ] >= x_range [1 ]:
153
+ raise ValueError ("One of the `x_range` boundaries is out of order." )
143
154
144
- X_center = (np .max (x , axis = 0 ) - np .min (x , axis = 0 )) / 2
145
- Xs = x - X_center
146
- S = np .max (np .abs (Xs ), axis = 0 )
155
+ S = (x_range [1 ] - x_range [0 ]) / 2.0
147
156
148
157
if cov_func .lower () == "expquad" :
149
158
a1 , a2 = 3.2 , 1.75
@@ -394,7 +403,7 @@ def prior_linearized(self, Xs: TensorLike):
394
403
# Important: fix the computation of the midpoint of X.
395
404
# If X is mutated later, the training midpoint will be subtracted, not the testing one.
396
405
if self ._X_center is None :
397
- self ._X_center = (pt .max (Xs , axis = 0 ) - pt .min (Xs , axis = 0 )).eval () / 2
406
+ self ._X_center = (pt .max (Xs , axis = 0 ) + pt .min (Xs , axis = 0 )).eval () / 2
398
407
Xs = Xs - self ._X_center # center for accurate computation
399
408
400
409
# Index Xs using input_dim and active_dims of covariance function
0 commit comments