Beispiel #1
0
def _uniform_weights(samples):
  """generate a nested list of N x 1D weights from a nested list of N x 1D
discrete measure positions, where the weights have norm 1.0 and are uniform.

>>> c.pos
[[1, 2, 3], [4, 5], [6]]
>>> _uniform_weights(c.pos)
[[0.333333333333333, 0.333333333333333, 0.333333333333333], [0.5, 0.5], [1.0]]
"""
  from mystic.math.measures import normalize
  return [normalize([1.]*len(xi)) for xi in samples]
Beispiel #2
0
def _uniform_weights(samples):
  """generate a nested list of N x 1D weights from a nested list of N x 1D
discrete measure positions, where the weights have norm 1.0 and are uniform.

>>> c.pos
[[1, 2, 3], [4, 5], [6]]
>>> _uniform_weights(c.pos)
[[0.333333333333333, 0.333333333333333, 0.333333333333333], [0.5, 0.5], [1.0]]
"""
  from mystic.math.measures import normalize
  return [normalize([1.]*len(xi), 1.0) for xi in samples]
 def norm(x):
     return normalize(x, mass=1.0)
Beispiel #4
0
def constraint(x):  # impose exactly
    return normalize(x, 1.0)
Beispiel #5
0
#
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
# Copyright (c) 1997-2016 California Institute of Technology.
# Copyright (c) 2016-2021 The Uncertainty Quantification Foundation.
# License: 3-clause BSD.  The full license text is available at:
#  - https://github.com/uqfoundation/mystic/blob/master/LICENSE

import numpy as np
import mystic.math.measures as mm
x = np.arange(1., 5)
y = np.array([-1., -2, 0, 3])
z = np.array([-1., -2, 0, 7])

# L1 and L2 norms

q = mm.normalize(x, mass='l1', zsum=True)
p = [0.10000000000000001, 0.20000000000000001, 0.29999999999999999, 0.40000000000000002]
assert np.sum(np.array(q) - p) <= 1e-15

q = mm.normalize(x, mass='l2', zsum=True)
p = [0.18257418583505536, 0.36514837167011072, 0.54772255750516607, 0.73029674334022143]
assert np.sum(np.array(q) - p) <= 1e-15

q = mm.normalize(y, mass='l2', zsum=True)
p = [-0.2672612419124244, -0.53452248382484879, 0.0, 0.80178372573727319]
assert np.sum(np.array(q) - p) <= 1e-15

q = mm.normalize(y, mass='l1', zsum=True)
p = [-0.16666666666666666, -0.33333333333333331, 0.0, 0.5]
assert np.sum(np.array(q) - p) <= 1e-15
Beispiel #6
0
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
# Copyright (c) 1997-2016 California Institute of Technology.
# Copyright (c) 2016-2017 The Uncertainty Quantification Foundation.
# License: 3-clause BSD.  The full license text is available at:
#  - http://trac.mystic.cacr.caltech.edu/project/mystic/browser/mystic/LICENSE

import numpy as np
import mystic.math.measures as mm

x = np.arange(1.0, 5)
y = np.array([-1.0, -2, 0, 3])
z = np.array([-1.0, -2, 0, 7])

# L1 and L2 norms

q = mm.normalize(x, mass="l1", zsum=True)
p = [0.10000000000000001, 0.20000000000000001, 0.29999999999999999, 0.40000000000000002]
assert np.sum(np.array(q) - p) <= 1e-15

q = mm.normalize(x, mass="l2", zsum=True)
p = [0.18257418583505536, 0.36514837167011072, 0.54772255750516607, 0.73029674334022143]
assert np.sum(np.array(q) - p) <= 1e-15

q = mm.normalize(y, mass="l2", zsum=True)
p = [-0.2672612419124244, -0.53452248382484879, 0.0, 0.80178372573727319]
assert np.sum(np.array(q) - p) <= 1e-15

q = mm.normalize(y, mass="l1", zsum=True)
p = [-0.16666666666666666, -0.33333333333333331, 0.0, 0.5]
assert np.sum(np.array(q) - p) <= 1e-15
Beispiel #7
0
def constraint(x): # impose exactly
    return normalize(x, 1.0)
Beispiel #8
0
#
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
# Copyright (c) 1997-2016 California Institute of Technology.
# Copyright (c) 2016-2019 The Uncertainty Quantification Foundation.
# License: 3-clause BSD.  The full license text is available at:
#  - https://github.com/uqfoundation/mystic/blob/master/LICENSE

import numpy as np
import mystic.math.measures as mm
x = np.arange(1., 5)
y = np.array([-1., -2, 0, 3])
z = np.array([-1., -2, 0, 7])

# L1 and L2 norms

q = mm.normalize(x, mass='l1', zsum=True)
p = [0.10000000000000001, 0.20000000000000001, 0.29999999999999999, 0.40000000000000002]
assert np.sum(np.array(q) - p) <= 1e-15

q = mm.normalize(x, mass='l2', zsum=True)
p = [0.18257418583505536, 0.36514837167011072, 0.54772255750516607, 0.73029674334022143]
assert np.sum(np.array(q) - p) <= 1e-15

q = mm.normalize(y, mass='l2', zsum=True)
p = [-0.2672612419124244, -0.53452248382484879, 0.0, 0.80178372573727319]
assert np.sum(np.array(q) - p) <= 1e-15

q = mm.normalize(y, mass='l1', zsum=True)
p = [-0.16666666666666666, -0.33333333333333331, 0.0, 0.5]
assert np.sum(np.array(q) - p) <= 1e-15
Beispiel #9
0
 def norm(x):
     return normalize(x, mass=1.0)