本文整理汇总了Python中autograd.numpy.max方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.max方法的具体用法?Python numpy.max怎么用?Python numpy.max使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类autograd.numpy
的用法示例。
在下文中一共展示了numpy.max方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _evaluate
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import max [as 别名]
def _evaluate(self, x, out, *args, **kwargs):
# variable names for convenient access
x1 = x[:, 0]
x2 = x[:, 1]
y = x[:, 2]
# first objectives
f1 = x1 * anp.sqrt(16 + anp.square(y)) + x2 * anp.sqrt((1 + anp.square(y)))
# measure which are needed for the second objective
sigma_ac = 20 * anp.sqrt(16 + anp.square(y)) / (y * x1)
sigma_bc = 80 * anp.sqrt(1 + anp.square(y)) / (y * x2)
# take the max
f2 = anp.max(anp.column_stack((sigma_ac, sigma_bc)), axis=1)
# define a constraint
g1 = f2 - self.Smax
out["F"] = anp.column_stack([f1, f2])
out["G"] = g1
示例2: get_thickness_at_chord_fraction_legacy
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import max [as 别名]
def get_thickness_at_chord_fraction_legacy(self, chord_fraction):
# Returns the (interpolated) camber at a given location(s). The location is specified by the chord fraction, as measured from the leading edge. Thickness is nondimensionalized by chord (i.e. this function returns t/c at a given x/c).
chord = np.max(self.coordinates[:, 0]) - np.min(
self.coordinates[:, 0]) # This should always be 1, but this is just coded for robustness.
x = chord_fraction * chord + min(self.coordinates[:, 0])
upperCoors = self.upper_coordinates()
lowerCoors = self.lower_coordinates()
y_upper_func = sp_interp.interp1d(x=upperCoors[:, 0], y=upperCoors[:, 1], copy=False, fill_value='extrapolate')
y_lower_func = sp_interp.interp1d(x=lowerCoors[:, 0], y=lowerCoors[:, 1], copy=False, fill_value='extrapolate')
y_upper = y_upper_func(x)
y_lower = y_lower_func(x)
thickness = np.maximum(y_upper - y_lower, 0)
return thickness
示例3: get_camber_at_chord_fraction_legacy
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import max [as 别名]
def get_camber_at_chord_fraction_legacy(self, chord_fraction):
# Returns the (interpolated) camber at a given location(s). The location is specified by the chord fraction, as measured from the leading edge. Camber is nondimensionalized by chord (i.e. this function returns camber/c at a given x/c).
chord = np.max(self.coordinates[:, 0]) - np.min(
self.coordinates[:, 0]) # This should always be 1, but this is just coded for robustness.
x = chord_fraction * chord + min(self.coordinates[:, 0])
upperCoors = self.upper_coordinates()
lowerCoors = self.lower_coordinates()
y_upper_func = sp_interp.interp1d(x=upperCoors[:, 0], y=upperCoors[:, 1], copy=False, fill_value='extrapolate')
y_lower_func = sp_interp.interp1d(x=lowerCoors[:, 0], y=lowerCoors[:, 1], copy=False, fill_value='extrapolate')
y_upper = y_upper_func(x)
y_lower = y_lower_func(x)
camber = (y_upper + y_lower) / 2
return camber
示例4: accel_gradient
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import max [as 别名]
def accel_gradient(eps_arr, mode='max'):
# set the permittivity of the FDFD and solve the fields
F.eps_r = eps_arr.reshape((Nx, Ny))
Ex, Ey, Hz = F.solve(source)
# compute the gradient and normalize if you want
G = npa.sum(Ey * eta / Ny)
if mode == 'max':
return -np.abs(G) / Emax(Ex, Ey, eps_r)
elif mode == 'avg':
return -np.abs(G) / Eavg(Ex, Ey)
else:
return -np.abs(G / E0)
# define the gradient for autograd
示例5: bound_by_data
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import max [as 别名]
def bound_by_data(Z, Data):
"""
Determine lower and upper bound for each dimension from the Data, and project
Z so that all points in Z live in the bounds.
Z: m x d
Data: n x d
Return a projected Z of size m x d.
"""
n, d = Z.shape
Low = np.min(Data, 0)
Up = np.max(Data, 0)
LowMat = np.repeat(Low[np.newaxis, :], n, axis=0)
UpMat = np.repeat(Up[np.newaxis, :], n, axis=0)
Z = np.maximum(LowMat, Z)
Z = np.minimum(UpMat, Z)
return Z
示例6: _decode_map
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import max [as 别名]
def _decode_map(self, data): # adapted hmmlearn
flp = self._compute_log_likelihood(data)
flp_rep = np.zeros((flp.shape[0], self.n_components))
for u in range(self.n_unique):
for c in range(self.n_chain):
flp_rep[:, u*self.n_chain+c] = flp[:, u]
logprob, fwdlattice = self._do_forward_pass(flp_rep)
bwdlattice = self._do_backward_pass(flp_rep)
gamma = fwdlattice + bwdlattice
# gamma is guaranteed to be correctly normalized by logprob at
# all frames, unless we do approximate inference using pruning.
# So, we will normalize each frame explicitly in case we
# pruned too aggressively.
posteriors = np.exp(gamma.T - logsumexp(gamma, axis=1)).T
posteriors += np.finfo(np.float64).eps
posteriors /= np.sum(posteriors, axis=1).reshape((-1, 1))
state_sequence = np.argmax(posteriors, axis=1)
map_logprob = np.max(posteriors, axis=1).sum()
return map_logprob, state_sequence
示例7: _calc_pareto_front
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import max [as 别名]
def _calc_pareto_front(self, ref_dirs, *args, **kwargs):
F = super()._calc_pareto_front(ref_dirs, *args, **kwargs)
a = anp.sqrt(anp.sum(F ** 2, 1) - 3 / 4 * anp.max(F ** 2, axis=1))
a = anp.expand_dims(a, axis=1)
a = anp.tile(a, [1, ref_dirs.shape[1]])
F = F / a
return F
示例8: __init__
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import max [as 别名]
def __init__(self, sampled_pops, conf_arr, sampled_n=None,
ascertainment_pop=None):
"""Use build_config_list() instead of calling this constructor directly"""
# If sampled_n=None, ConfigList.sampled_n will be the max number of
# observed individuals/alleles per population.
self.sampled_pops = tuple(sampled_pops)
self.value = conf_arr
if ascertainment_pop is None:
ascertainment_pop = [True] * len(sampled_pops)
self.ascertainment_pop = np.array(ascertainment_pop)
self.ascertainment_pop.setflags(write=False)
if all(not a for a in self.ascertainment_pop):
raise ValueError(
"At least one of the populations must be used for "
"ascertainment of polymorphic sites")
max_n = np.max(np.sum(self.value, axis=2), axis=0)
if sampled_n is None:
sampled_n = max_n
sampled_n = np.array(sampled_n)
if np.any(sampled_n < max_n):
raise ValueError("config greater than sampled_n")
self.sampled_n = sampled_n
if not np.sum(sampled_n[self.ascertainment_pop]) >= 2:
raise ValueError("The total sample size of the ascertainment "
"populations must be >= 2")
config_sampled_n = np.sum(self.value, axis=2)
self.has_missing_data = np.any(config_sampled_n != self.sampled_n)
if np.any(np.sum(self.value[:, self.ascertainment_pop, :], axis=1)
== 0):
raise ValueError("Monomorphic sites not allowed. In addition, all"
" sites must be polymorphic when restricted to"
" the ascertainment populations")
示例9: test_underflow_robustness
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import max [as 别名]
def test_underflow_robustness(folded):
num_runs = 1000
sampled_pops = (1, 2, 3)
sampled_n = (5, 5, 5)
n_bases = int(1e3)
demo = momi.DemographicModel(1.0, .25, muts_per_gen=2.5 / n_bases)
for p in sampled_pops:
demo.add_leaf(p)
demo.add_time_param("t0")
demo.add_time_param("t1", lower_constraints=["t0"])
demo.move_lineages(1, 2, "t0")
demo.move_lineages(2, 3, "t1")
true_params = np.array([0.5, 0.7])
demo.set_params(true_params)
data = demo.simulate_data(
length=n_bases,
recoms_per_gen=0.0,
num_replicates=num_runs,
sampled_n_dict=dict(zip(sampled_pops, sampled_n)))
sfs = data.extract_sfs(1)
if folded:
sfs = sfs.fold()
demo.set_data(sfs)
demo.set_params({"t0": 0.1, "t1": 100.0})
optimize_res = demo.optimize()
print(optimize_res)
inferred_params = np.array(list(demo.get_params().values()))
error = (true_params - inferred_params) / true_params
print("# Truth:\n", true_params)
print("# Inferred:\n", inferred_params)
print("# Max Relative Error: %f" % max(abs(error)))
print("# Relative Error:", "\n", error)
assert max(abs(error)) < .1
示例10: span
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import max [as 别名]
def span(self):
# Returns the span (y-distance between the root of the wing and the tip).
# If symmetric, this is doubled to obtain the full span.
spans = []
for i in range(len(self.xsecs)):
spans.append(np.abs(self.xsecs[i].xyz_le[1] - self.xsecs[0].xyz_le[1]))
span = np.max(spans)
if self.symmetric:
span *= 2
return span
示例11: get_sharp_TE_airfoil
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import max [as 别名]
def get_sharp_TE_airfoil(self):
# Returns a version of the airfoil with a sharp trailing edge.
upper_original_coors = self.upper_coordinates() # Note: includes leading edge point, be careful about duplicates
lower_original_coors = self.lower_coordinates() # Note: includes leading edge point, be careful about duplicates
# Find data about the TE
# Get the scale factor
x_mcl = self.mcl_coordinates[:, 0]
x_max = np.max(x_mcl)
x_min = np.min(x_mcl)
scale_factor = (x_mcl - x_min) / (x_max - x_min) # linear contraction
# Do the contraction
upper_minus_mcl_adjusted = self.upper_minus_mcl - self.upper_minus_mcl[-1, :] * np.expand_dims(scale_factor, 1)
# Recreate coordinates
upper_coordinates_adjusted = np.flipud(self.mcl_coordinates + upper_minus_mcl_adjusted)
lower_coordinates_adjusted = self.mcl_coordinates - upper_minus_mcl_adjusted
coordinates = np.vstack((
upper_coordinates_adjusted[:-1, :],
lower_coordinates_adjusted
))
# Make a new airfoil with the coordinates
name = self.name + ", with sharp TE"
new_airfoil = Airfoil(name=name, coordinates=coordinates, repanel=False)
return new_airfoil
示例12: logsumexp
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import max [as 别名]
def logsumexp(X, axis, keepdims=False):
max_X = np.max(X)
return max_X + np.log(np.sum(np.exp(X - max_X), axis=axis, keepdims=keepdims))
示例13: forward_pass
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import max [as 别名]
def forward_pass(self, inputs, param_vector):
new_shape = inputs.shape[:2]
for i in [0, 1]:
pool_width = self.pool_shape[i]
img_width = inputs.shape[i + 2]
new_shape += (img_width // pool_width, pool_width)
result = inputs.reshape(new_shape)
return np.max(np.max(result, axis=3), axis=4)
示例14: defaultmax
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import max [as 别名]
def defaultmax(x, default=-np.inf):
if x.size == 0:
return default
return np.max(x)
示例15: logsumexp
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import max [as 别名]
def logsumexp(x):
"""Numerically stable log(sum(exp(x))), also defined in scipy.special"""
max_x = np.max(x)
return max_x + np.log(np.sum(np.exp(x - max_x)))
# Next, we write a function that specifies the gradient with a closure.
# The reason for the closure is so that the gradient can depend
# on both the input to the original function (x), and the output of the
# original function (ans).