本文整理汇总了Python中autograd.numpy.power方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.power方法的具体用法?Python numpy.power怎么用?Python numpy.power使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类autograd.numpy
的用法示例。
在下文中一共展示了numpy.power方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Ixx
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import power [as 别名]
def Ixx(self):
# Returns the nondimensionalized Ixx moment of inertia, taken about the centroid.
x = self.coordinates[:, 0]
y = self.coordinates[:, 1]
x_n = np.roll(x, -1) # x_next, or x_i+1
y_n = np.roll(y, -1) # y_next, or y_i+1
a = x * y_n - x_n * y # a is the area of the triangle bounded by a given point, the next point, and the origin.
A = 0.5 * np.sum(a) # area
x_c = 1 / (6 * A) * np.sum(a * (x + x_n))
y_c = 1 / (6 * A) * np.sum(a * (y + y_n))
centroid = np.array([x_c, y_c])
Ixx = 1 / 12 * np.sum(a * (np.power(y, 2) + y * y_n + np.power(y_n, 2)))
Iuu = Ixx - A * centroid[1] ** 2
return Iuu
示例2: Iyy
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import power [as 别名]
def Iyy(self):
# Returns the nondimensionalized Iyy moment of inertia, taken about the centroid.
x = self.coordinates[:, 0]
y = self.coordinates[:, 1]
x_n = np.roll(x, -1) # x_next, or x_i+1
y_n = np.roll(y, -1) # y_next, or y_i+1
a = x * y_n - x_n * y # a is the area of the triangle bounded by a given point, the next point, and the origin.
A = 0.5 * np.sum(a) # area
x_c = 1 / (6 * A) * np.sum(a * (x + x_n))
y_c = 1 / (6 * A) * np.sum(a * (y + y_n))
centroid = np.array([x_c, y_c])
Iyy = 1 / 12 * np.sum(a * (np.power(x, 2) + x * x_n + np.power(x_n, 2)))
Ivv = Iyy - A * centroid[0] ** 2
return Ivv
示例3: J
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import power [as 别名]
def J(self):
# Returns the nondimensionalized polar moment of inertia, taken about the centroid.
x = self.coordinates[:, 0]
y = self.coordinates[:, 1]
x_n = np.roll(x, -1) # x_next, or x_i+1
y_n = np.roll(y, -1) # y_next, or y_i+1
a = x * y_n - x_n * y # a is the area of the triangle bounded by a given point, the next point, and the origin.
A = 0.5 * np.sum(a) # area
x_c = 1 / (6 * A) * np.sum(a * (x + x_n))
y_c = 1 / (6 * A) * np.sum(a * (y + y_n))
centroid = np.array([x_c, y_c])
Ixx = 1 / 12 * np.sum(a * (np.power(y, 2) + y * y_n + np.power(y_n, 2)))
Iyy = 1 / 12 * np.sum(a * (np.power(x, 2) + x * x_n + np.power(x_n, 2)))
J = Ixx + Iyy
return J
示例4: optimize
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import power [as 别名]
def optimize(self, angles0, target):
"""Calculate an optimum argument of an objective function."""
def new_objective(angles):
a = angles - angles0
if isinstance(self.smooth_factor, (np.ndarray, list)):
if len(a) == len(self.smooth_factor):
return (self.f(angles, target) +
np.sum(self.smooth_factor * np.power(a, 2)))
else:
raise ValueError('len(smooth_factor) != number of joints')
else:
return (self.f(angles, target) +
self.smooth_factor * np.sum(np.power(a, 2)))
return scipy.optimize.minimize(
new_objective,
angles0,
**self.optimizer_opt).x
示例5: constraint_c4_cylindrical
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import power [as 别名]
def constraint_c4_cylindrical(f, r): # cylindrical
l = anp.mean(f, axis=1)
l = anp.expand_dims(l, axis=1)
g = -anp.sum(anp.power(f - l, 2), axis=1) + anp.power(r, 2)
return g
示例6: obj_func
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import power [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
示例7: _evaluate
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import power [as 别名]
def _evaluate(self, x, out, *args, **kwargs):
X_, X_M = x[:, :self.n_obj - 1], x[:, self.n_obj - 1:]
g = anp.sum(anp.power(X_M, 0.1), axis=1)
theta = 1 / (2 * (1 + g[:, None])) * (1 + 2 * g[:, None] * X_)
theta = anp.column_stack([x[:, 0], theta[:, 1:]])
out["F"] = self.obj_func(theta, g)
示例8: get_scale
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import power [as 别名]
def get_scale(n, scale_factor):
return anp.power(anp.full(n, scale_factor), anp.arange(n))
示例9: _evaluate
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import power [as 别名]
def _evaluate(self, x, out, *args, **kwargs):
a = anp.sum(0.5 * anp.arange(1, self.n_var + 1) * x, axis=1)
out["F"] = anp.sum(anp.square(x), axis=1) + anp.square(a) + anp.power(a, 4)
示例10: _evaluate
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import power [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)
示例11: _evaluate
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import power [as 别名]
def _evaluate(self, x, out, *args, **kwargs):
f1 = x[:, 0]
g = 1 + 9.0 / (self.n_var - 1) * anp.sum(x[:, 1:], axis=1)
f2 = g * (1 - anp.power((f1 / g), 0.5))
out["F"] = anp.column_stack([f1, f2])
示例12: _calc_pareto_front
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import power [as 别名]
def _calc_pareto_front(self, n_pareto_points=100):
x = anp.linspace(0, 1, n_pareto_points)
return anp.array([x, 1 - anp.power(x, 2)]).T
示例13: _evaluate
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import power [as 别名]
def _evaluate(self, x, out, *args, **kwargs):
f1 = x[:, 0]
g = 1 + 9.0 / (self.n_var - 1) * np.sum(x[:, 1:], axis=1)
f2 = g * (1 - np.power((f1 / g), 0.5))
out["F"] = np.column_stack([f1, f2])
if "dF" in out:
dF = np.zeros([x.shape[0], self.n_obj, self.n_var], dtype=np.float)
dF[:, 0, 0], dF[:, 0, 1:] = 1, 0
dF[:, 1, 0] = -0.5 * np.sqrt(g / x[:, 0])
dF[:, 1, 1:] = ((9 / (self.n_var - 1)) * (1 - 0.5 * np.sqrt(x[:, 0] / g)))[:, None]
out["dF"] = dF
示例14: get_downsampled_mcl
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import power [as 别名]
def get_downsampled_mcl(self, mcl_fractions):
# Returns the mean camber line in downsampled form
mcl = self.mcl_coordinates
# Find distances along mcl, assuming linear interpolation
mcl_distances_between_points = np.sqrt(
np.power(mcl[:-1, 0] - mcl[1:, 0], 2) +
np.power(mcl[:-1, 1] - mcl[1:, 1], 2)
)
mcl_distances_cumulative = np.hstack((0, np.cumsum(mcl_distances_between_points)))
mcl_distances_cumulative_normalized = mcl_distances_cumulative / mcl_distances_cumulative[-1]
mcl_downsampled_x = np.interp(
x=mcl_fractions,
xp=mcl_distances_cumulative_normalized,
fp=mcl[:, 0]
)
mcl_downsampled_y = np.interp(
x=mcl_fractions,
xp=mcl_distances_cumulative_normalized,
fp=mcl[:, 1]
)
mcl_downsampled = np.column_stack((mcl_downsampled_x, mcl_downsampled_y))
return mcl_downsampled
示例15: grid
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import power [as 别名]
def grid(num, ndim, large=False):
"""Build a uniform grid with num points along each of ndim axes."""
if not large:
_check_not_too_large(np.power(num, ndim) * ndim)
x = np.linspace(0, 1, num, dtype='float64')
w = 1 / (num - 1)
points = np.stack(
np.meshgrid(*[x for _ in range(ndim)], indexing='ij'), axis=-1)
return points, w