@@ -96,23 +96,31 @@ class HSGPParams(NamedTuple):
9696
9797
9898def 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
100100) -> HSGPParams :
101101 """Utility function that uses heuristics to recommend minimum `m` and `c` values,
102102 based on recommendations from Ruitort-Mayol et. al.
103103
104104 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]`.
106114
107115 NB: These recommendations are based on a one-dimensional GP.
108116
109117 Parameters
110118 ----------
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] .
114122 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].
116124 cov_func : str
117125 The covariance function to use. Supported options are "expquad", "matern52", and "matern32".
118126
@@ -126,7 +134,7 @@ def approx_hsgp_hyperparams(
126134 Scaling factor such that L = c * S, where L is the boundary of the approximation.
127135 Increasing it helps approximate larger lengthscales, but may require increasing m.
128136 - `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`.
130138
131139 Raises
132140 ------
@@ -139,11 +147,12 @@ def approx_hsgp_hyperparams(
139147 Practical Hilbert Space Approximate Bayesian Gaussian Processes for Probabilistic Programming
140148 """
141149 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." )
143154
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
147156
148157 if cov_func .lower () == "expquad" :
149158 a1 , a2 = 3.2 , 1.75
@@ -394,7 +403,7 @@ def prior_linearized(self, Xs: TensorLike):
394403 # Important: fix the computation of the midpoint of X.
395404 # If X is mutated later, the training midpoint will be subtracted, not the testing one.
396405 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
398407 Xs = Xs - self ._X_center # center for accurate computation
399408
400409 # Index Xs using input_dim and active_dims of covariance function
0 commit comments