code: def test_collection_behavior():
      from mystic.math import almostEqual
      from numpy import inf
  
      def f(x):
          return sum(x)  # a test function for expectation value
  
      # build three sets (x,y,z)
      sx = set([point(1.0, 1.0), point(2.0, 1.0), point(3.0, 2.0)])
      sy = set([point(0.0, 1.0), point(3.0, 2.0)])
      sz = set([point(1.0, 1.0), point(2.0, 3.0)])
      # NOTE: for marc_surr(x,y,z), we must have x > 0.0
      sx.normalize()
      sy.normalize()
      sz.normalize()
      assert sx.mass == sy.mass == sz.mass == 1.0
  
      # build a collection
      c = collection([sx, sy, sz])
      xpos = c[0].positions
      ypos = c[1].positions
      zpos = c[2].positions
      xwts = c[0].weights
      ywts = c[1].weights
      zwts = c[2].weights
      if disp:
          print("x_positions: %s" % xpos)
          print("y_positions: %s" % ypos)
          print("z_positions: %s" % zpos)
          print("x_weights: %s" % xwts)
          print("y_weights: %s" % ywts)
          print("z_weights: %s" % zwts)
      assert xpos == sx.positions
      assert ypos == sy.positions
      assert zpos == sz.positions
      assert xwts == sx.weights
      assert ywts == sy.weights
      assert zwts == sz.weights
      tol = 0.2
      supp = c.support(tol)
      positions = c.positions
      weights = c.weights
      assert supp == [
          p for (p, w) in zip(positions, weights) if w > tol
      ]
      if disp:
          print("support points:\n %s" % supp)
          print("npts: %s (i.e. %s)" % (c.npts, c.pts))
          print("weights: %s" % weights)
          print("positions: %s" % positions)
      assert c.npts == sx.npts * sy.npts * sz.npts
      assert len(weights) == len(positions) == c.npts
      assert sx.positions in c.pos
      assert sy.positions in c.pos
      assert sz.positions in c.pos
      assert sx.weights in c.wts
      assert sy.weights in c.wts
      assert sz.weights in c.wts
  
      c_exp = c.expect(f)
      if disp:
          print("mass: %s" % c.mass)
          print("expect: %s" % c_exp)
      assert c.mass == [sx.mass, sy.mass, sz.mass]
      assert c_exp == expectation(f, c.positions, c.weights)
  
      # print("center: %s" % c.center)
      # print("delta: %s" % c.delta)
  
      # change the positions in the collection
      points = [list(i) for i in positions[::3]]
      for i in range(len(points)):
          points[i][0] = 0.5
      positions[::3] = points
      c.positions = positions
  
      _xpos = c[0].positions
      _ypos = c[1].positions
      _zpos = c[2].positions
      _cexp = c.expect(f)
      if disp:
          print("x_positions: %s" % _xpos)
          print("y_positions: %s" % _ypos)
          print("z_positions: %s" % _zpos)
          print("expect: %s" % _cexp)
      assert _xpos == [0.5] + xpos[1:]
      assert _ypos == ypos
      assert _zpos == zpos
      assert _cexp < c_exp  # due to _xpos[0] is 0.5 and less than 1.0
  
      _mean = 85.0
      _range = 0.25
  
      c.set_expect(_mean, f, npop=40, maxiter=200, tol=_range)
      _exp = c.expect(f)
      if disp:
          print("mean: %s" % _mean)
          print("range: %s" % _range)
          print("expect: %s" % _exp)
      assert almostEqual(_mean, _exp, tol=_mean * 0.01)
  
      # a test function for probability of failure
      def g(x):
          if f(x) <= 0.0:
              return False
          return True
  
      pof = c.pof(g)
      spof = c.sampled_pof(g, npts=10000)
      if disp:
          print("pof: %s" % pof)
          print("sampled_pof: %s" % spof)
      assert almostEqual(pof, spof, tol=0.02)
      return
  
file_path: mystic/mystic/tests/test_dirac_measure.py
imports: from mystic.math.discrete import point_mass
  from mystic.math.discrete import measure
  from mystic.math.discrete import product_measure
  from mystic.math.samples import random_samples
  from mystic.math.grid import samplepts
  from mystic.math import almostEqual
  from mystic.math.measures import *
  from mystic.math.measures import _pack, _unpack
label_desc: Use image node_id 4 for calling a global function with example usage: test_collection_behavior() and returns: sum, True, False