docstr: Pre-compute and cache some constants (at fixed time) for
  repeated computations of the alignment energy.
  
  The idea is to decompose the average temporal variance via:
  
  V = (n-1)/n V* + (n-1)/n^2 (x-m*)^2
  
  with x the considered volume at time t, and m* the mean of all
  resampled volumes but x. Only the second term is variable when
  
  one volumes while the others are fixed. A similar
  decomposition is used for the global variance, so we end up
  with:
  
  V/V0 = [nV* + (x-m*)^2] / [nV0* + (x-m0*)^2]
docstr_tok: ["Pre-compute","and","cache","some","constants","(","at","fixed","time",")","for","repeated","computations","of","the","alignment","energy",".","The","idea","is","to","decompose","the","average","temporal","variance","via",":","V","=","(","n-1",")","\/n","V","*","+","(","n-1",")","\/n^2","(","x-m","*",")","^2","with","x","the","considered","volume","at","time","t",",","and","m","*","the","mean","of","all","resampled","volumes","but","x",".","Only","the","second","term","is","variable","when","one","volumes","while","the","others","are","fixed",".","A","similar","decomposition","is","used","for","the","global","variance",",","so","we","end","up","with",":","V\/V0","=","[","nV","*","+","(","x-m","*",")","^2","]","\/","[","nV0","*","+","(","x-m0","*",")","^2","]"]
code: def init_instant_motion(self, t):
      """
      Pre-compute and cache some constants (at fixed time) for
      repeated computations of the alignment energy.
  
      The idea is to decompose the average temporal variance via:
  
      V = (n-1)/n V* + (n-1)/n^2 (x-m*)^2
  
      with x the considered volume at time t, and m* the mean of all
      resampled volumes but x. Only the second term is variable when
  
      one volumes while the others are fixed. A similar
      decomposition is used for the global variance, so we end up
      with:
  
      V/V0 = [nV* + (x-m*)^2] / [nV0* + (x-m0*)^2]
      """
      fixed = list(range(self.nscans))
      fixed.remove(t)
      aux = self.data[:, fixed]
      if self.optimize_template:
          self.mu = np.mean(aux, 1)
      self.offset = self.nscans * np.mean((aux.T - self.mu) ** 2)
      self.mu0 = np.mean(aux)
      self.offset0 = self.nscans * np.mean((aux - self.mu0) ** 2)
      self._t = t
      self._pc = None
  
imports: import os
  import warnings
  import numpy
  from nibabel import io_orientation
  from nibabel.affines import apply_affine
  from ...core.image.image_spaces import as_xyz_image, make_xyz_image, xyz_affine
  from ...io.nibcompat import get_header
  from ..slicetiming import timefuncs
  from ._registration import _cspline_sample3d, _cspline_sample4d, _cspline_transform
  from .affine import Affine, Rigid
  from .optimizer import configure_optimizer, use_derivatives
  from .type_check import check_type, check_type_and_shape
label_desc: Use image node_id 5 for calling the Realign4dAlgorithm obj's underlying member method code with example usage: obj.init_instant_motion(t) without return types