本文整理汇总了Python中autograd.numpy.sin方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.sin方法的具体用法?Python numpy.sin怎么用?Python numpy.sin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类autograd.numpy
的用法示例。
在下文中一共展示了numpy.sin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _calc_pareto_front
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import sin [as 别名]
def _calc_pareto_front(self, n_points=100, flatten=True):
regions = [[0, 0.0830015349],
[0.182228780, 0.2577623634],
[0.4093136748, 0.4538821041],
[0.6183967944, 0.6525117038],
[0.8233317983, 0.8518328654]]
pf = []
for r in regions:
x1 = anp.linspace(r[0], r[1], int(n_points / len(regions)))
x2 = 1 - anp.sqrt(x1) - x1 * anp.sin(10 * anp.pi * x1)
pf.append(anp.array([x1, x2]).T)
if not flatten:
pf = anp.concatenate([pf[None,...] for pf in pf])
else:
pf = anp.row_stack(pf)
return pf
示例2: test_const_graph
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import sin [as 别名]
def test_const_graph():
L = []
def foo(x, y):
L.append(None)
return grad(lambda x: np.sin(x) + x * 2)(x * y)
foo_wrapped = const_graph(foo)
assert len(L) == 0
assert scalar_close(foo(0., 0.),
foo_wrapped(0., 0.))
assert len(L) == 2
assert scalar_close(foo(1., 0.5),
foo_wrapped(1., 0.5))
assert len(L) == 3
assert scalar_close(foo(1., 0.5),
foo_wrapped(1., 0.5))
assert len(L) == 4
示例3: test_value_and_multigrad
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import sin [as 别名]
def test_value_and_multigrad():
def complicated_fun(a,b,c,d,e,f=1.1, g=9.0):
return a + np.sin(b) + np.cosh(c) + np.cos(d) + np.tan(e) + f + g
A = 0.5
B = -0.3
C = 0.2
D = -1.1
E = 0.7
F = 0.6
G = -0.1
dfun = grad(complicated_fun, argnum=[3, 1])
dfun_both = value_and_grad(complicated_fun, argnum=[3, 1])
check_equivalent(complicated_fun(A, B, C, D, E, f=F, g=G),
dfun_both(A, B, C, D, E, f=F, g=G)[0])
check_equivalent(dfun(A, B, C, D, E, f=F, g=G),
dfun_both(A, B, C, D, E, f=F, g=G)[1])
示例4: compute_f
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import sin [as 别名]
def compute_f(theta, lambda0, dL, shape):
""" Compute the 'vacuum' field vector """
# get plane wave k vector components (in units of grid cells)
k0 = 2 * npa.pi / lambda0 * dL
kx = k0 * npa.sin(theta)
ky = -k0 * npa.cos(theta) # negative because downwards
# array to write into
f_src = npa.zeros(shape, dtype=npa.complex128)
# get coordinates
Nx, Ny = shape
xpoints = npa.arange(Nx)
ypoints = npa.arange(Ny)
xv, yv = npa.meshgrid(xpoints, ypoints, indexing='ij')
# compute values and insert into array
x_PW = npa.exp(1j * xpoints * kx)[:, None]
y_PW = npa.exp(1j * ypoints * ky)[:, None]
f_src[xv, yv] = npa.outer(x_PW, y_PW)
return f_src.flatten()
示例5: obj_func
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import sin [as 别名]
def obj_func(self, X_, g, alpha=1):
f = []
for i in range(0, self.n_obj):
_f = (1 + g)
_f *= anp.prod(anp.cos(anp.power(X_[:, :X_.shape[1] - i], alpha) * anp.pi / 2.0), axis=1)
if i > 0:
_f *= anp.sin(anp.power(X_[:, X_.shape[1] - i], alpha) * anp.pi / 2.0)
f.append(_f)
f = anp.column_stack(f)
return f
示例6: _evaluate
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import sin [as 别名]
def _evaluate(self, x, out, *args, **kwargs):
f = []
for i in range(0, self.n_obj - 1):
f.append(x[:, i])
f = anp.column_stack(f)
g = 1 + 9 / self.k * anp.sum(x[:, -self.k:], axis=1)
h = self.n_obj - anp.sum(f / (1 + g[:, None]) * (1 + anp.sin(3 * anp.pi * f)), axis=1)
out["F"] = anp.column_stack([f, (1 + g) * h])
示例7: _evaluate
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import sin [as 别名]
def _evaluate(self, x, out, *args, **kwargs):
out["F"] = 1 - anp.exp(-x ** 2) * anp.sin(2 * anp.pi * x) ** 2
示例8: _evaluate
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import sin [as 别名]
def _evaluate(self, x, out, *args, **kwargs):
f = 3 * x[:, 0] + (10 ** -6) * x[:, 0] ** 3 + 2 * x[:, 1] + (2 * 10 ** (-6)) / 3 * x[:, 1] ** 3
# Constraints
g1 = x[:, 2] - x[:, 3] - 0.55
g2 = x[:, 3] - x[:, 2] - 0.55
g3 = anp.absolute(1000 * (anp.sin(-x[:, 2] - 0.25) + anp.sin(-x[:, 3] - 0.25)) + 894.8 - x[:, 0]) - 10 ** (-4)
g4 = anp.absolute(
1000 * (anp.sin(x[:, 2] - 0.25) + anp.sin(x[:, 2] - x[:, 3] - 0.25)) + 894.8 - x[:, 1]) - 10 ** (-4)
g5 = anp.absolute(1000 * (anp.sin(x[:, 3] - 0.25) + anp.sin(x[:, 3] - x[:, 2] - 0.25)) + 1294.8) - 10 ** (-4)
out["F"] = f
out["G"] = anp.column_stack([g1, g2, g3, g4, g5])
示例9: _evaluate
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import sin [as 别名]
def _evaluate(self, x, out, *args, **kwargs):
out["F"] = 418.9829 * self.n_var - np.sum(x * np.sin(np.sqrt(np.abs(x))), axis=1)
示例10: _evaluate
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import sin [as 别名]
def _evaluate(self, x, out, *args, **kwargs):
l = []
for i in range(2):
l.append(-10 * anp.exp(-0.2 * anp.sqrt(anp.square(x[:, i]) + anp.square(x[:, i + 1]))))
f1 = anp.sum(anp.column_stack(l), axis=1)
f2 = anp.sum(anp.power(anp.abs(x), 0.8) + 5 * anp.sin(anp.power(x, 3)), axis=1)
out["F"] = anp.column_stack([f1, f2])
示例11: calc_constraint
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import sin [as 别名]
def calc_constraint(self, theta, a, b, c, d, e, f1, f2):
return - (anp.cos(theta) * (f2 - e) - anp.sin(theta) * f1 -
a * anp.abs(anp.sin(b * anp.pi * (anp.sin(theta) * (f2 - e) + anp.cos(theta) * f1) ** c)) ** d)
示例12: _evaluate
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import sin [as 别名]
def _evaluate(self, x, out, *args, **kwargs):
f1 = x[:, 0]
c = anp.sum(x[:, 1:], axis=1)
g = 1.0 + 9.0 * c / (self.n_var - 1)
f2 = g * (1 - anp.power(f1 * 1.0 / g, 0.5) - (f1 * 1.0 / g) * anp.sin(10 * anp.pi * f1))
out["F"] = anp.column_stack([f1, f2])
示例13: f
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import sin [as 别名]
def f(x):
return x*np.sin(4*np.pi*x)
示例14: _state_eq
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import sin [as 别名]
def _state_eq(self, st, u):
x, x_dot, theta, theta_dot = st
force = u[0]
costheta = np.cos(theta)
sintheta = np.sin(theta)
temp = (force + self.polemass_length * theta_dot * theta_dot * sintheta) / self.total_mass
thetaacc = (self.gravity * sintheta - costheta* temp) / (self.length * (4.0/3.0 - self.masspole * costheta * costheta / self.total_mass))
xacc = temp - self.polemass_length * thetaacc * costheta / self.total_mass
x = x + self.tau * x_dot
x_dot = x_dot + self.tau * xacc
theta = theta + self.tau * theta_dot
theta_dot = theta_dot + self.tau * thetaacc
return np.array([x, x_dot, theta, theta_dot])
示例15: xyz_te
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import sin [as 别名]
def xyz_te(self):
xyz_te = self.xyz_le + self.chord * np.array(
[np.cos(np.radians(self.twist)),
0,
-np.sin(np.radians(self.twist))
])
return xyz_te