code: def get_moments(samples):
      reduced_vars = frozenset(["particle"])
      moments = OrderedDict()
  
      # Compute first moments.
      diffs = OrderedDict()
      for name, value in samples.items():
          mean = value.reduce(ops.mean, reduced_vars)
          moments[name] = mean
          diffs[name] = value - mean
  
      # Compute centered second moments.
      for i, (name1, diff1) in enumerate(diffs.items()):
          diff1_ = diff1.reshape((diff1.output.num_elements, 1))
          for name2, diff2 in list(diffs.items())[:i]:
              diff_2 = diff2.reshape((1, diff2.output.num_elements))
              diff12 = diff1_ * diff_2
              moments[name1, name2] = diff12.reduce(
                  ops.mean, reduced_vars
              )
  
      return moments
  
imports: from collections import OrderedDict
  from typing import Dict, Tuple
  import numpy
  import pytest
  import funsor.ops
  from funsor.domains import Bint, Real, Reals
  from funsor.interpretations import memoize
  from funsor.montecarlo import extract_samples
  from funsor.recipes import forward_filter_backward_precondition, forward_filter_backward_rsample
  from funsor.terms import Lambda, Variable
  from funsor.testing import Tensor, assert_close, randn, random_gaussian
  from funsor.util import get_backend
label_desc: Use image node_id 1 for calling a global function with example usage: get_moments(samples) and returns: moments