MCPcopy
hub / github.com/GPflow/GPflow / predict_f_samples

Method predict_f_samples

gpflow/models/model.py:232–280  ·  view source on GitHub ↗

Produce samples from the posterior latent function(s) at the input points. Currently, the method does not support `full_output_cov=True` and `full_cov=True`. :param Xnew: Input locations at which to draw samples. :param num_samples: Number o

(
        self,
        Xnew: InputData,
        num_samples: Optional[int] = None,
        full_cov: bool = True,
        full_output_cov: bool = False,
    )

Source from the content-addressed store, hash-verified

230 "return: [batch..., S, N, P] if (num_samples is not None)",
231 )
232 def predict_f_samples(
233 self,
234 Xnew: InputData,
235 num_samples: Optional[int] = None,
236 full_cov: bool = True,
237 full_output_cov: bool = False,
238 ) -> tf.Tensor:
239 """
240 Produce samples from the posterior latent function(s) at the input points.
241
242 Currently, the method does not support `full_output_cov=True` and `full_cov=True`.
243
244 :param Xnew:
245 Input locations at which to draw samples.
246 :param num_samples:
247 Number of samples to draw.
248 If `None`, a single sample is drawn and the return shape is [..., N, P],
249 for any positive integer the return shape contains an extra batch
250 dimension, [..., S, N, P], with S = num_samples and P is the number of outputs.
251 :param full_cov:
252 If True, draw correlated samples over the inputs. Computes the Cholesky over the
253 dense covariance matrix of size [num_data, num_data].
254 If False, draw samples that are uncorrelated over the inputs.
255 :param full_output_cov:
256 If True, draw correlated samples over the outputs.
257 If False, draw samples that are uncorrelated over the outputs.
258 """
259 if full_cov and full_output_cov:
260 raise NotImplementedError(
261 "The combination of both `full_cov` and `full_output_cov` is not supported."
262 )
263
264 # check below for shape info
265 mean, cov = self.predict_f(Xnew, full_cov=full_cov, full_output_cov=full_output_cov)
266 if full_cov:
267 # mean: [..., N, P]
268 # cov: [..., P, N, N]
269 mean_for_sample = tf.linalg.adjoint(mean) # [..., P, N]
270 samples = sample_mvn(
271 mean_for_sample, cov, full_cov, num_samples=num_samples
272 ) # [..., (S), P, N]
273 samples = tf.linalg.adjoint(samples) # [..., (S), N, P]
274 else:
275 # mean: [..., N, P]
276 # cov: [..., N, P] or [..., N, P, P]
277 samples = sample_mvn(
278 mean, cov, full_output_cov, num_samples=num_samples
279 ) # [..., (S), N, P]
280 return samples # [..., (S), N, P]
281
282 @check_shapes(
283 "Xnew: [batch..., N, D]",

Callers 10

test_predict_f_samplesFunction · 0.80
my_imageFunction · 0.80
my_image_2Function · 0.80
plot_kernel_samplesFunction · 0.80
plot_2d_kernel_samplesFunction · 0.80
plot_from_samplesFunction · 0.80
mcmc.pct.pyFile · 0.80

Calls 2

predict_fMethod · 0.95
sample_mvnFunction · 0.85

Tested by 3

test_predict_f_samplesFunction · 0.64