本文整理汇总了Python中mystic.math.measures.impose_mean函数的典型用法代码示例。如果您正苦于以下问题:Python impose_mean函数的具体用法?Python impose_mean怎么用?Python impose_mean使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了impose_mean函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bounded_mean
def bounded_mean(mean_x, samples, xmin, xmax, wts=None):
from mystic.math.measures import impose_mean, impose_spread
from mystic.math.measures import spread, mean
from numpy import asarray
a = impose_mean(mean_x, samples, wts)
if min(a) < xmin: # maintain the bound
#print "violate lo(a)"
s = spread(a) - 2*(xmin - min(a)) #XXX: needs compensation (as below) ?
a = impose_mean(mean_x, impose_spread(s, samples, wts), wts)
if max(a) > xmax: # maintain the bound
#print "violate hi(a)"
s = spread(a) + 2*(xmax - max(a)) #XXX: needs compensation (as below) ?
a = impose_mean(mean_x, impose_spread(s, samples, wts), wts)
return asarray(a)
示例2: constraints
def constraints(x):
# constrain the last x_i to be the same value as the first x_i
x[-1] = x[0]
# constrain x such that mean(x) == target
if not almostEqual(mean(x), target):
x = impose_mean(target, x)
return x
示例3: test_proxified_constraint
def test_proxified_constraint():
from mystic.math.measures import impose_mean
@inner_proxy(inner=impose_mean)
def mean_then_squared(x): #XXX: proxy doesn't preserve function signature
return [i**2 for i in x]
from numpy import array
x = array([1,2,3,4,5])
assert mean_then_squared(5,x) == [i**2 for i in impose_mean(5,x)]
示例4: test_with_mean
def test_with_mean():
from mystic.math.measures import mean, impose_mean
@with_mean(5.0)
def mean_of_squared(x):
return [i**2 for i in x]
from numpy import array
x = array([1,2,3,4,5])
y = impose_mean(5, [i**2 for i in x])
assert mean(y) == 5.0
assert mean_of_squared(x) == y
示例5: test_with_constraint
def test_with_constraint():
from mystic.math.measures import mean, impose_mean
@with_constraint(inner, kwds={'target':5.0})
def mean_of_squared(x, target):
return impose_mean(target, [i**2 for i in x])
from numpy import array
x = array([1,2,3,4,5])
y = impose_mean(5, [i**2 for i in x])
assert mean(y) == 5.0
assert mean_of_squared(x) == y
示例6: test_inner_constraint
def test_inner_constraint():
from mystic.math.measures import impose_mean
def impose_constraints(x, mean, weights=None):
return impose_mean(mean, x, weights)
@inner(inner=impose_constraints, kwds={'mean':5.0})
def mean_then_squared(x):
return [i**2 for i in x]
from numpy import array
x = array([1,2,3,4,5])
assert mean_then_squared(x) == [i**2 for i in impose_mean(5,x)]
示例7: test_with_mean_spread
def test_with_mean_spread():
from mystic.math.measures import mean, spread, impose_mean, impose_spread
@with_spread(50.0)
@with_mean(5.0)
def constrained_squared(x):
return [i**2 for i in x]
from numpy import array
x = array([1,2,3,4,5])
y = impose_spread(50.0, impose_mean(5.0,[i**2 for i in x]))
assert almostEqual(mean(y), 5.0, tol=1e-15)
assert almostEqual(spread(y), 50.0, tol=1e-15)
assert constrained_squared(x) == y
示例8: test_outer_constraint
def test_outer_constraint():
from mystic.math.measures import impose_mean, mean
def impose_constraints(x, mean, weights=None):
return impose_mean(mean, x, weights)
@outer(outer=impose_constraints, kwds={'mean':5.0})
def mean_of_squared(x):
return [i**2 for i in x]
from numpy import array
x = array([1,2,3,4,5])
y = impose_mean(5, [i**2 for i in x])
assert mean(y) == 5.0
assert mean_of_squared(x) == y
示例9: test_inner_constraints
def test_inner_constraints():
from mystic.math.measures import impose_mean, impose_spread
def impose_constraints(x, mean=0.0, spread=1.0):
x = impose_mean(mean, x)
x = impose_spread(spread, x)
return x
@inner(inner=impose_constraints, kwds={'mean':5.0, 'spread':50.0})
def constrained_squared(x):
return [i**2 for i in x]
from numpy import array
x = array([1,2,3,4,5])
y = impose_spread(50.0, impose_mean(5.0,x))
assert constrained_squared(x) == [i**2 for i in y]
示例10: constrain
def constrain(rv):
"constrain: y >= m and sum(wi)_{k} = 1 for each k in K"
pm = scenario()
pm.load(rv, pts) # here rv is param: w,x,y
#impose: sum(wi)_{k} = 1 for each k in K
norm = 1.0
for i in range(len(pm)):
w = pm[i].weights
w[-1] = norm - sum(w[:-1])
pm[i].weights = w
#impose: y >= m
values, weights = pm.values, pm.weights
y = float(mean(values, weights))
if not (y >= float(target[0])):
pm.values = impose_mean(target[0]+target[1], values, weights)
rv = pm.flatten(all=True)
return rv
示例11: test_proxified_constraints
def test_proxified_constraints():
from mystic.math.measures import impose_mean, impose_spread
def impose_constraints(x, mean=0.0, spread=1.0):
x = impose_mean(mean, x)
x = impose_spread(spread, x)
return x
@inner_proxy(inner=impose_constraints)
def constrained_squared(x): #XXX: proxy doesn't preserve function signature
return [i**2 for i in x]
from numpy import array
x = array([1,2,3,4,5])
y = impose_spread(50.0, impose_mean(5.0,x))
assert constrained_squared(x, 5.0, 50.0) == [i**2 for i in y]
示例12: mean_of_squared
def mean_of_squared(x, target):
return impose_mean(target, [i**2 for i in x])
示例13: impose_constraints
def impose_constraints(x, mean, weights=None):
return impose_mean(mean, x, weights)
示例14: mean_constraint
def mean_constraint(x, mean=0.0):
return impose_mean(mean, x)
示例15: __set_mean
def __set_mean(self, m):
self.positions = impose_mean(m, self.positions, self.weights)
return