Beispiel #1
0
def test_flatten_unflatten():
    # 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)])

    # build a collection
    c = collection([sx, sy, sz])

    # flatten and unflatten
    from mystic.math.discrete import flatten, unflatten
    d = unflatten(flatten(c), c.pts)

    # check if the same
    assert c.npts == d.npts
    assert c.weights == d.weights
    assert c.positions == d.positions

    # flatten() and load(...)
    e = collection().load(c.flatten(), c.pts)

    # check if the same
    assert c.npts == e.npts
    assert c.weights == e.weights
    assert c.positions == e.positions

    # decompose and compose
    from mystic.math.discrete import decompose, compose
    b = compose(*decompose(c))

    # check if the same
    assert c.npts == b.npts
    assert c.weights == b.weights
    assert c.positions == b.positions
    return
def test_flatten_unflatten():
  # 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)])

  # build a collection
  c = collection([sx,sy,sz])

  # flatten and unflatten
  from mystic.math.discrete import flatten, unflatten
  d = unflatten(flatten(c), c.pts)

  # check if the same
  assert c.npts == d.npts
  assert c.weights == d.weights
  assert c.positions == d.positions

  # flatten() and load(...)
  e = collection().load(c.flatten(), c.pts)

  # check if the same
  assert c.npts == e.npts
  assert c.weights == e.weights
  assert c.positions == e.positions

  # decompose and compose
  from mystic.math.discrete import decompose, compose
  b = compose(*decompose(c))

  # check if the same
  assert c.npts == b.npts
  assert c.weights == b.weights
  assert c.positions == b.positions
  return
Beispiel #3
0
 def constraints(x, w):
   from mystic.math.discrete import compose, decompose
   c = compose(x,w)
   E = float(c[0].mean)
   if not (E <= float(h_mean+h_error)) or not (float(h_mean-h_error) <= E):
     c[0].mean = h_mean
   E = float(c[2].mean)
   if not (E <= float(v_mean+v_error)) or not (float(v_mean-v_error) <= E):
     c[2].mean = v_mean
   return decompose(c)[0]
Beispiel #4
0
 def constraints(x, w):
   from mystic.math.discrete import compose, decompose
   c = compose(x,w)
   E = float(c[0].mean)
   if not (E <= float(h_mean+h_error)) or not (float(h_mean-h_error) <= E):
     c[0].mean = h_mean
   E = float(c[2].mean)
   if not (E <= float(v_mean+v_error)) or not (float(v_mean-v_error) <= E):
     c[2].mean = v_mean
   return decompose(c)[0]