class_docstr: This strategy sets all inducing point locations to observed inputs,
  and employs a :math:`k`-nearest-neighbor approximation. It was introduced as the
  `Variational Nearest Neighbor Gaussian Processes (VNNGP)` in `Wu et al (2022)`_.
  See the `VNNGP tutorial`_ for an example.
  
  VNNGP assumes a k-nearest-neighbor generative process for inducing points :math:`\mathbf u`,
  :math:`\mathbf q(\mathbf u) = \prod_{j=1}^M q(u_j | \mathbf u_{n(j)})`
  where :math:`n(j)` denotes the indices of :math:`k` nearest neighbors for :math:`u_j` among
  :math:`u_1, \cdots, u_{j-1}`. For any test observation :math:`\mathbf f`,
  VNNGP makes predictive inference conditioned on its :math:`k` nearest inducing points
  :math:`\mathbf u_{n(f)}`, i.e. :math:`p(f|\mathbf u_{n(f)})`.
  
  VNNGP's objective factorizes over inducing points and observations, making stochastic optimization over both
  immediately available. After a one-time cost of computing the :math:`k`-nearest neighbor structure,
  the training and inference complexity is :math:`O(k^3)`.
  Since VNNGP uses observations as inducing points, it is a user choice to either (1)
  use the same mini-batch of inducing points and observations (recommended),
  or (2) use different mini-batches of inducing points and observations. See the `VNNGP tutorial`_ for
  implementation and comparison.
  
  
  .. note::
  
      The current implementation only supports :obj:`~gpytorch.variational.MeanFieldVariationalDistribution`.
  
      We recommend installing the `faiss`_ library (requiring separate package installment)
      for nearest neighbor search, which is significantly faster than the `scikit-learn` nearest neighbor search.
      GPyTorch will automatically use `faiss` if it is installed, but will revert to `scikit-learn` otherwise.
  
      Different inducing point orderings will produce in different nearest neighbor approximations.
  
  
  :param ~gpytorch.models.ApproximateGP model: Model this strategy is applied to.
      Typically passed in when the VariationalStrategy is created in the
      __init__ method of the user defined model.
  :param inducing_points: Tensor containing a set of inducing
      points to use for variational inference.
  :param variational_distribution: A
      VariationalDistribution object that represents the form of the variational distribution :math:`q(\mathbf u)`
  :param k: Number of nearest neighbors.
  :param training_batch_size: The number of data points that will be in the training batch size.
  :param jitter_val: Amount of diagonal jitter to add for Cholesky factorization numerical stability
  
  .. _Wu et al (2022):
      https://arxiv.org/pdf/2202.01694.pdf
  .. _VNNGP tutorial:
      examples/04_Variational_and_Approximate_GPs/VNNGP.html
  .. _faiss:
      https://github.com/facebookresearch/faiss
class_docstr_tok: ["This","strategy","sets","all","inducing","point","locations","to","observed","inputs",",","and","employs","a",":","math",":","`","k","`","-nearest-neighbor","approximation",".","It","was","introduced","as","the","`","Variational","Nearest","Neighbor","Gaussian","Processes","(","VNNGP",")","`","in","`","Wu","et","al","(","2022",")","`","_",".","See","the","`","VNNGP","tutorial","`","_","for","an","example",".","VNNGP","assumes","a","k-nearest-neighbor","generative","process","for","inducing","points",":","math",":","`","\\mathbf","u","`",",",":","math",":","`","\\mathbf","q","(","\\mathbf","u",")","=","\\prod_","{","j=1","}","^M","q","(","u_j","|","\\mathbf","u_","{","n","(","j",")","}",")","`","where",":","math",":","`","n","(","j",")","`","denotes","the","indices","of",":","math",":","`","k","`","nearest","neighbors","for",":","math",":","`","u_j","`","among",":","math",":","`","u_1",",","\\cdots",",","u_","{","j-1","}","`",".","For","any","test","observation",":","math",":","`","\\mathbf","f","`",",","VNNGP","makes","predictive","inference","conditioned","on","its",":","math",":","`","k","`","nearest","inducing","points",":","math",":","`","\\mathbf","u_","{","n","(","f",")","}","`",",","i.e",".",":","math",":","`","p","(","f|\\mathbf","u_","{","n","(","f",")","}",")","`",".","VNNGP","'s","objective","factorizes","over","inducing","points","and","observations",",","making","stochastic","optimization","over","both","immediately","available",".","After","a","one-time","cost","of","computing","the",":","math",":","`","k","`","-nearest","neighbor","structure",",","the","training","and","inference","complexity","is",":","math",":","`","O","(","k^3",")","`",".","Since","VNNGP","uses","observations","as","inducing","points",",","it","is","a","user","choice","to","either","(","1",")","use","the","same","mini-batch","of","inducing","points","and","observations","(","recommended",")",",","or","(","2",")","use","different","mini-batches","of","inducing","points","and","observations",".","See","the","`","VNNGP","tutorial","`","_","for","implementation","and","comparison",".","..","note",":",":","The","current","implementation","only","supports",":","obj",":","`","~gpytorch.variational.MeanFieldVariationalDistribution","`",".","We","recommend","installing","the","`","faiss","`","_","library","(","requiring","separate","package","installment",")","for","nearest","neighbor","search",",","which","is","significantly","faster","than","the","`","scikit-learn","`","nearest","neighbor","search",".","GPyTorch","will","automatically","use","`","faiss","`","if","it","is","installed",",","but","will","revert","to","`","scikit-learn","`","otherwise",".","Different","inducing","point","orderings","will","produce","in","different","nearest","neighbor","approximations",".",":","param","~gpytorch.models.ApproximateGP","model",":","Model","this","strategy","is","applied","to",".","Typically","passed","in","when","the","VariationalStrategy","is","created","in","the","__init__","method","of","the","user","defined","model",".",":","param","inducing_points",":","Tensor","containing","a","set","of","inducing","points","to","use","for","variational","inference",".",":","param","variational_distribution",":","A","VariationalDistribution","object","that","represents","the","form","of","the","variational","distribution",":","math",":","`","q","(","\\mathbf","u",")","`",":","param","k",":","Number","of","nearest","neighbors",".",":","param","training_batch_size",":","The","number","of","data","points","that","will","be","in","the","training","batch","size",".",":","param","jitter_val",":","Amount","of","diagonal","jitter","to","add","for","Cholesky","factorization","numerical","stability","..","_Wu","et","al","(","2022",")",":","https",":","\/\/arxiv.org\/pdf\/2202.01694.pdf","..","_VNNGP","tutorial",":","examples\/04_Variational_and_Approximate_GPs\/VNNGP.html","..","_faiss",":","https",":","\/\/github.com\/facebookresearch\/faiss"]
code: def _compute_nn(self) -> "NNVariationalStrategy":
      with torch.no_grad():
          inducing_points_fl = self.inducing_points.data.float()
          self.nn_util.set_nn_idx(inducing_points_fl)
          self.nn_xinduce_idx = self.nn_util.build_sequential_nn_idx(
              inducing_points_fl
          )
      return self
  
imports: from typing import Any, Optional
  import torch
  from linear_operator import to_dense
  from linear_operator.operators import DiagLinearOperator, LinearOperator, TriangularLinearOperator
  from linear_operator.utils.cholesky import psd_safe_cholesky
  from torch import LongTensor, Tensor
  from ..distributions import MultivariateNormal
  from ..models import ApproximateGP, ExactGP
  from ..module import Module
  from ..utils.errors import CachingError
  from ..utils.memoize import add_to_cache, cached, pop_from_cache
  from ..utils.nearest_neighbors import NNUtil
  from ._variational_distribution import _VariationalDistribution
  from .mean_field_variational_distribution import MeanFieldVariationalDistribution
  from .unwhitened_variational_strategy import UnwhitenedVariationalStrategy
label_desc: Use image node_id 13 for calling the NNVariationalStrategy obj's underlying member method code with example usage: obj._compute_nn() and returns: self