Compute the mean and variance of the latent function at some new points Xnew.
(
self, Xnew: InputData, full_cov: bool = False, full_output_cov: bool = False
)
| 488 | |
| 489 | @inherit_check_shapes |
| 490 | def predict_f( |
| 491 | self, Xnew: InputData, full_cov: bool = False, full_output_cov: bool = False |
| 492 | ) -> MeanAndVariance: |
| 493 | """ |
| 494 | Compute the mean and variance of the latent function at some new points |
| 495 | Xnew. |
| 496 | """ |
| 497 | assert_params_false(self.predict_f, full_output_cov=full_output_cov) |
| 498 | |
| 499 | _, _, Luu, L, _, _, gamma = self.common_terms() |
| 500 | Kus = Kuf(self.inducing_variable, self.kernel, Xnew) # [M, N] |
| 501 | |
| 502 | w = tf.linalg.triangular_solve(Luu, Kus, lower=True) # [M, N] |
| 503 | |
| 504 | tmp = tf.linalg.triangular_solve(tf.transpose(L), gamma, lower=False) |
| 505 | mean = tf.linalg.matmul(w, tmp, transpose_a=True) + self.mean_function(Xnew) |
| 506 | intermediateA = tf.linalg.triangular_solve(L, w, lower=True) |
| 507 | |
| 508 | if full_cov: |
| 509 | var = ( |
| 510 | self.kernel(Xnew) |
| 511 | - tf.linalg.matmul(w, w, transpose_a=True) |
| 512 | + tf.linalg.matmul(intermediateA, intermediateA, transpose_a=True) |
| 513 | ) |
| 514 | var = tf.tile(var[None, ...], [self.num_latent_gps, 1, 1]) # [P, N, N] |
| 515 | else: |
| 516 | var = ( |
| 517 | self.kernel(Xnew, full_cov=False) |
| 518 | - tf.reduce_sum(tf.square(w), 0) |
| 519 | + tf.reduce_sum(tf.square(intermediateA), 0) |
| 520 | ) # [N, P] |
| 521 | var = tf.tile(var[:, None], [1, self.num_latent_gps]) |
| 522 | |
| 523 | return mean, var |
| 524 | |
| 525 | |
| 526 | class SGPR_with_posterior(SGPR_deprecated): |
nothing calls this directly
no test coverage detected