本文整理汇总了Python中autograd.numpy.cos方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.cos方法的具体用法?Python numpy.cos怎么用?Python numpy.cos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类autograd.numpy
的用法示例。
在下文中一共展示了numpy.cos方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import cos [as 别名]
def __init__(self, n_var=2, n_constr=1, option="linear"):
super().__init__(n_var=n_var, n_obj=2, n_constr=n_constr, xl=0, xu=1, type_var=anp.double)
def g_linear(x):
return 1 + anp.sum(x, axis=1)
def g_multimodal(x):
A = 10
return 1 + A * x.shape[1] + anp.sum(x ** 2 - A * anp.cos(2 * anp.pi * x), axis=1)
if option == "linear":
self.calc_g = g_linear
elif option == "multimodal":
self.calc_g = g_multimodal
self.xl[:, 1:] = -5.12
self.xu[:, 1:] = 5.12
else:
print("Unknown option for CTP single.")
示例2: test_multigrad
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import cos [as 别名]
def test_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
def complicated_fun_3_1(d_b):
d, b = d_b
return complicated_fun(A, b, C, d, E, f=F, g=G)
A = 0.5
B = -0.3
C = 0.2
D = -1.1
E = 0.7
F = 0.6
G = -0.1
wrapped = grad(complicated_fun, argnum=[3, 1])(A, B, C, D, E, f=F, g=G)
explicit = grad(complicated_fun_3_1)((D, B))
check_equivalent(wrapped, explicit)
示例3: test_value_and_multigrad
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import cos [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 cos [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: __init__
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import cos [as 别名]
def __init__(self, n_var=2, n_constr=1, option="linear"):
super().__init__(n_var=n_var, n_obj=2, n_constr=n_constr, xl=0, xu=1, type_var=anp.double)
def g_linear(x):
return 1 + anp.sum(x, axis=1)
def g_multimodal(x):
A = 10
return 1 + A * x.shape[1] + anp.sum(x ** 2 - A * anp.cos(2 * anp.pi * x), axis=1)
if option == "linear":
self.calc_g = g_linear
elif option == "multimodal":
self.calc_g = g_multimodal
self.xl[:, 1:] = -5.12
self.xu[:, 1:] = 5.12
else:
print("Unknown option for CTP problems.")
示例6: g1
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import cos [as 别名]
def g1(self, X_M):
return 100 * (self.k + anp.sum(anp.square(X_M - 0.5) - anp.cos(20 * anp.pi * (X_M - 0.5)), axis=1))
示例7: obj_func
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import cos [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
示例8: _evaluate
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import cos [as 别名]
def _evaluate(self, x, out, *args, **kwargs):
z = anp.power(x, 2) - self.A * anp.cos(2 * anp.pi * x)
out["F"] = self.A * self.n_var + anp.sum(z, axis=1)
示例9: calc_constraint
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import cos [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)
示例10: _evaluate
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import cos [as 别名]
def _evaluate(self, x, out, *args, **kwargs):
f1 = x[:, 0]
g = 1.0
g += 10 * (self.n_var - 1)
for i in range(1, self.n_var):
g += x[:, i] * x[:, i] - 10.0 * anp.cos(4.0 * anp.pi * x[:, i])
h = 1.0 - anp.sqrt(f1 / g)
f2 = g * h
out["F"] = anp.column_stack([f1, f2])
示例11: _evaluate
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import cos [as 别名]
def _evaluate(self, x, out, *args, **kwargs):
# define an objective function to be evaluated using var1
f = anp.sum(anp.power(x, 2) - self.const_1 * anp.cos(2 * anp.pi * x), axis=1)
# !!! only if a constraint value is positive it is violated !!!
# set the constraint that x1 + x2 > var2
g1 = (x[:, 0] + x[:, 1]) - self.const_2
# set the constraint that x3 + x4 < var2
g2 = self.const_2 - (x[:, 2] + x[:, 3])
out["F"] = f
out["G"] = anp.column_stack([g1, g2])
示例12: _state_eq
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import cos [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])
示例13: xyz_te
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import cos [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
示例14: add_control_surface
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import cos [as 别名]
def add_control_surface(self, deflection=0., hinge_point=0.75):
# Returns a version of the airfoil with a control surface added at a given point.
# Inputs:
# # deflection: the deflection angle, in degrees. Downwards-positive.
# # hinge_point: the location of the hinge, as a fraction of chord.
# Make the rotation matrix for the given angle.
sintheta = np.sin(np.radians(-deflection))
costheta = np.cos(np.radians(-deflection))
rotation_matrix = np.array(
[[costheta, -sintheta],
[sintheta, costheta]]
)
# Find the hinge point
hinge_point = np.array(
(hinge_point, self.get_camber_at_chord_fraction(hinge_point))) # Make hinge_point a vector.
# Split the airfoil into the sections before and after the hinge
split_index = np.where(self.mcl_coordinates[:, 0] > hinge_point[0])[0][0]
mcl_coordinates_before = self.mcl_coordinates[:split_index, :]
mcl_coordinates_after = self.mcl_coordinates[split_index:, :]
upper_minus_mcl_before = self.upper_minus_mcl[:split_index, :]
upper_minus_mcl_after = self.upper_minus_mcl[split_index:, :]
# Rotate the mean camber line (MCL) and "upper minus mcl"
new_mcl_coordinates_after = np.transpose(
rotation_matrix @ np.transpose(mcl_coordinates_after - hinge_point)) + hinge_point
new_upper_minus_mcl_after = np.transpose(rotation_matrix @ np.transpose(upper_minus_mcl_after))
# Do blending
# Assemble airfoil
new_mcl_coordinates = np.vstack((mcl_coordinates_before, new_mcl_coordinates_after))
new_upper_minus_mcl = np.vstack((upper_minus_mcl_before, new_upper_minus_mcl_after))
upper_coordinates = np.flipud(new_mcl_coordinates + new_upper_minus_mcl)
lower_coordinates = new_mcl_coordinates - new_upper_minus_mcl
coordinates = np.vstack((upper_coordinates, lower_coordinates[1:, :]))
new_airfoil = Airfoil(name=self.name + " flapped", coordinates=coordinates, repanel=False)
return new_airfoil # TODO fix self-intersecting airfoils at high deflections
示例15: cosspace
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import cos [as 别名]
def cosspace(min=0, max=1, n_points=50):
mean = (max + min) / 2
amp = (max - min) / 2
return mean + amp * np.cos(np.linspace(np.pi, 0, n_points))