本文整理汇总了Python中autograd.numpy.hstack方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.hstack方法的具体用法?Python numpy.hstack怎么用?Python numpy.hstack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类autograd.numpy
的用法示例。
在下文中一共展示了numpy.hstack方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_mcl_normal_direction_at_chord_fraction
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import hstack [as 别名]
def get_mcl_normal_direction_at_chord_fraction(self, chord_fraction):
# Returns the normal direction of the mean camber line at a specified chord fraction.
# If you input a single value, returns a 1D numpy array with 2 elements (x,y).
# If you input a vector of values, returns a 2D numpy array. First index is the point number, second index is (x,y)
# Right now, does it by finite differencing camber values :(
# When I'm less lazy I'll make it do it in a proper, more efficient way
# TODO make this not finite difference
epsilon = np.sqrt(np.finfo(float).eps)
cambers = self.get_camber_at_chord_fraction(chord_fraction)
cambers_incremented = self.get_camber_at_chord_fraction(chord_fraction + epsilon)
dydx = (cambers_incremented - cambers) / epsilon
if dydx.shape == 1: # single point
normal = np.hstack((-dydx, 1))
normal /= np.linalg.norm(normal)
return normal
else: # multiple points vectorized
normal = np.column_stack((-dydx, np.ones(dydx.shape)))
normal /= np.expand_dims(np.linalg.norm(normal, axis=1), axis=1) # normalize
return normal
示例2: _make_A
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import hstack [as 别名]
def _make_A(self, eps_vec):
eps_vec_xx, eps_vec_yy = self._grid_average_2d(eps_vec)
eps_vec_xx_inv = 1 / (eps_vec_xx + 1e-5) # the 1e-5 is for numerical stability
eps_vec_yy_inv = 1 / (eps_vec_yy + 1e-5) # autograd throws 'divide by zero' errors.
indices_diag = npa.vstack((npa.arange(self.N), npa.arange(self.N)))
entries_DxEpsy, indices_DxEpsy = spsp_mult(self.entries_Dxb, self.indices_Dxb, eps_vec_yy_inv, indices_diag, self.N)
entires_DxEpsyDx, indices_DxEpsyDx = spsp_mult(entries_DxEpsy, indices_DxEpsy, self.entries_Dxf, self.indices_Dxf, self.N)
entries_DyEpsx, indices_DyEpsx = spsp_mult(self.entries_Dyb, self.indices_Dyb, eps_vec_xx_inv, indices_diag, self.N)
entires_DyEpsxDy, indices_DyEpsxDy = spsp_mult(entries_DyEpsx, indices_DyEpsx, self.entries_Dyf, self.indices_Dyf, self.N)
entries_d = 1 / EPSILON_0 * npa.hstack((entires_DxEpsyDx, entires_DyEpsxDy))
indices_d = npa.hstack((indices_DxEpsyDx, indices_DyEpsxDy))
entries_diag = MU_0 * self.omega**2 * npa.ones(self.N)
entries_a = npa.hstack((entries_d, entries_diag))
indices_a = npa.hstack((indices_d, indices_diag))
return entries_a, indices_a
示例3: _solve_fn
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import hstack [as 别名]
def _solve_fn(self, eps_vec, entries_a, indices_a, Mz_vec):
# convert the Mz current into Jx, Jy
eps_vec_xx, eps_vec_yy = self._grid_average_2d(eps_vec)
Jx_vec, Jy_vec = self._Hz_to_Ex_Ey(Mz_vec, eps_vec_xx, eps_vec_yy)
# lump the current sources together and solve for electric field
source_J_vec = npa.hstack((Jx_vec, Jy_vec))
E_vec = sp_solve(entries_a, indices_a, source_J_vec)
# strip out the x and y components of E and find the Hz component
Ex_vec = E_vec[:self.N]
Ey_vec = E_vec[self.N:]
Hz_vec = self._Ex_Ey_to_Hz(Ex_vec, Ey_vec)
return Ex_vec, Ey_vec, Hz_vec
示例4: _ntied_transmat_prior
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import hstack [as 别名]
def _ntied_transmat_prior(self, transmat_val): # TODO: document choices
transmat = np.empty((0, self.n_components))
for r in range(self.n_unique):
row = np.empty((self.n_chain, 0))
for c in range(self.n_unique):
if r == c:
subm = np.array(sp.diags([transmat_val[r, c],
1.0], [0, 1],
shape=(self.n_chain, self.n_chain)).todense())
else:
lower_left = np.zeros((self.n_chain, self.n_chain))
lower_left[self.n_tied, 0] = 1.0
subm = np.kron(transmat_val[r, c], lower_left)
row = np.hstack((row, subm))
transmat = np.vstack((transmat, row))
return transmat
示例5: add_data
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import hstack [as 别名]
def add_data(self, F, S):
T = F.shape[0]
assert S.shape == (T,) and S.dtype in (np.int, np.uint, np.uint32)
if F.shape[1] == self.K * self.B:
F = np.hstack([np.ones((T,)), F])
else:
assert F.shape[1] == 1 + self.K * self.B
self.data_list.append((F, S))
示例6: get_downsampled_mcl
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import hstack [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
示例7: repanel_current_airfoil
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import hstack [as 别名]
def repanel_current_airfoil(self, n_points_per_side=100):
# Returns a repaneled version of the airfoil with cosine-spaced coordinates on the upper and lower surfaces.
# Inputs:
# # n_points_per_side is the number of points PER SIDE (upper and lower) of the airfoil. 100 is a good number.
# Notes: The number of points defining the final airfoil will be n_points_per_side*2-1,
# since one point (the leading edge point) is shared by both the upper and lower surfaces.
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 distances between coordinates, assuming linear interpolation
upper_distances_between_points = np.sqrt(
np.power(upper_original_coors[:-1, 0] - upper_original_coors[1:, 0], 2) +
np.power(upper_original_coors[:-1, 1] - upper_original_coors[1:, 1], 2)
)
lower_distances_between_points = np.sqrt(
np.power(lower_original_coors[:-1, 0] - lower_original_coors[1:, 0], 2) +
np.power(lower_original_coors[:-1, 1] - lower_original_coors[1:, 1], 2)
)
upper_distances_from_TE = np.hstack((0, np.cumsum(upper_distances_between_points)))
lower_distances_from_LE = np.hstack((0, np.cumsum(lower_distances_between_points)))
upper_distances_from_TE_normalized = upper_distances_from_TE / upper_distances_from_TE[-1]
lower_distances_from_LE_normalized = lower_distances_from_LE / lower_distances_from_LE[-1]
# Generate a cosine-spaced list of points from 0 to 1
s = cosspace(n_points=n_points_per_side)
x_upper_func = sp_interp.PchipInterpolator(x=upper_distances_from_TE_normalized, y=upper_original_coors[:, 0])
y_upper_func = sp_interp.PchipInterpolator(x=upper_distances_from_TE_normalized, y=upper_original_coors[:, 1])
x_lower_func = sp_interp.PchipInterpolator(x=lower_distances_from_LE_normalized, y=lower_original_coors[:, 0])
y_lower_func = sp_interp.PchipInterpolator(x=lower_distances_from_LE_normalized, y=lower_original_coors[:, 1])
x_coors = np.hstack((x_upper_func(s), x_lower_func(s)[1:]))
y_coors = np.hstack((y_upper_func(s), y_lower_func(s)[1:]))
coordinates = np.column_stack((x_coors, y_coors))
self.coordinates = coordinates
示例8: concat_and_multiply
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import hstack [as 别名]
def concat_and_multiply(weights, *args):
cat_state = np.hstack(args + (np.ones((args[0].shape[0], 1)),))
return np.dot(cat_state, weights)
### Define recurrent neural net #######
示例9: test_hstack_1d
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import hstack [as 别名]
def test_hstack_1d(): combo_check(np.hstack, [0])([R(2), (R(2), R(2))])
示例10: test_hstack_2d
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import hstack [as 别名]
def test_hstack_2d(): combo_check(np.hstack, [0])([R(3, 2), (R(3, 4), R(3, 5))])
示例11: test_hstack_3d
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import hstack [as 别名]
def test_hstack_3d(): combo_check(np.hstack, [0])([R(2, 3, 4), (R(2, 1, 4), R(2, 5, 4))])
示例12: job_mmd_opt
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import hstack [as 别名]
def job_mmd_opt(p, data_source, tr, te, r):
"""
MMD test of Gretton et al., 2012 used as a goodness-of-fit test.
Require the ability to sample from p i.e., the UnnormalizedDensity p has
to be able to return a non-None from get_datasource()
With optimization. Gaussian kernel.
"""
data = tr + te
X = data.data()
with util.ContextTimer() as t:
# median heuristic
pds = p.get_datasource()
datY = pds.sample(data.sample_size(), seed=r+294)
Y = datY.data()
XY = np.vstack((X, Y))
med = util.meddistance(XY, subsample=1000)
# Construct a list of kernels to try based on multiples of the median
# heuristic
#list_gwidth = np.hstack( (np.linspace(20, 40, 10), (med**2)
# *(2.0**np.linspace(-2, 2, 20) ) ) )
list_gwidth = (med**2)*(2.0**np.linspace(-3, 3, 30) )
list_gwidth.sort()
candidate_kernels = [kernel.KGauss(gw2) for gw2 in list_gwidth]
mmd_opt = mgof.QuadMMDGofOpt(p, n_permute=300, alpha=alpha, seed=r+56)
mmd_result = mmd_opt.perform_test(data,
candidate_kernels=candidate_kernels,
tr_proportion=tr_proportion, reg=1e-3)
return { 'test_result': mmd_result, 'time_secs': t.secs}
# Define our custom Job, which inherits from base class IndependentJob
示例13: job_mmd_opt
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import hstack [as 别名]
def job_mmd_opt(p, data_source, tr, te, r):
"""
MMD test of Gretton et al., 2012 used as a goodness-of-fit test.
Require the ability to sample from p i.e., the UnnormalizedDensity p has
to be able to return a non-None from get_datasource()
With optimization. Gaussian kernel.
"""
data = tr + te
X = data.data()
with util.ContextTimer() as t:
# median heuristic
pds = p.get_datasource()
datY = pds.sample(data.sample_size(), seed=r+294)
Y = datY.data()
XY = np.vstack((X, Y))
med = util.meddistance(XY, subsample=1000)
# Construct a list of kernels to try based on multiples of the median
# heuristic
#list_gwidth = np.hstack( (np.linspace(20, 40, 10), (med**2)
# *(2.0**np.linspace(-2, 2, 20) ) ) )
list_gwidth = (med**2)*(2.0**np.linspace(-4, 4, 30) )
list_gwidth.sort()
candidate_kernels = [kernel.KGauss(gw2) for gw2 in list_gwidth]
mmd_opt = mgof.QuadMMDGofOpt(p, n_permute=300, alpha=alpha, seed=r)
mmd_result = mmd_opt.perform_test(data,
candidate_kernels=candidate_kernels,
tr_proportion=tr_proportion, reg=1e-3)
return { 'test_result': mmd_result, 'time_secs': t.secs}
示例14: optimize_auto_init
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import hstack [as 别名]
def optimize_auto_init(p, dat, J, **ops):
"""
Optimize parameters by calling optimize_locs_widths(). Automatically
initialize the test locations and the Gaussian width.
Return optimized locations, Gaussian width, optimization info
"""
assert J>0
# Use grid search to initialize the gwidth
X = dat.data()
n_gwidth_cand = 5
gwidth_factors = 2.0**np.linspace(-3, 3, n_gwidth_cand)
med2 = util.meddistance(X, 1000)**2
k = kernel.KGauss(med2*2)
# fit a Gaussian to the data and draw to initialize V0
V0 = util.fit_gaussian_draw(X, J, seed=829, reg=1e-6)
list_gwidth = np.hstack( ( (med2)*gwidth_factors ) )
besti, objs = GaussFSSD.grid_search_gwidth(p, dat, V0, list_gwidth)
gwidth = list_gwidth[besti]
assert util.is_real_num(gwidth), 'gwidth not real. Was %s'%str(gwidth)
assert gwidth > 0, 'gwidth not positive. Was %.3g'%gwidth
logging.info('After grid search, gwidth=%.3g'%gwidth)
V_opt, gwidth_opt, info = GaussFSSD.optimize_locs_widths(p, dat,
gwidth, V0, **ops)
# set the width bounds
#fac_min = 5e-2
#fac_max = 5e3
#gwidth_lb = fac_min*med2
#gwidth_ub = fac_max*med2
#gwidth_opt = max(gwidth_lb, min(gwidth_opt, gwidth_ub))
return V_opt, gwidth_opt, info
示例15: power_criterion
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import hstack [as 别名]
def power_criterion(p, dat, b, c, test_locs, reg=1e-2):
k = kernel.KIMQ(b=b, c=c)
return FSSD.power_criterion(p, dat, k, test_locs, reg)
#@staticmethod
#def optimize_auto_init(p, dat, J, **ops):
# """
# Optimize parameters by calling optimize_locs_widths(). Automatically
# initialize the test locations and the Gaussian width.
# Return optimized locations, Gaussian width, optimization info
# """
# assert J>0
# # Use grid search to initialize the gwidth
# X = dat.data()
# n_gwidth_cand = 5
# gwidth_factors = 2.0**np.linspace(-3, 3, n_gwidth_cand)
# med2 = util.meddistance(X, 1000)**2
# k = kernel.KGauss(med2*2)
# # fit a Gaussian to the data and draw to initialize V0
# V0 = util.fit_gaussian_draw(X, J, seed=829, reg=1e-6)
# list_gwidth = np.hstack( ( (med2)*gwidth_factors ) )
# besti, objs = GaussFSSD.grid_search_gwidth(p, dat, V0, list_gwidth)
# gwidth = list_gwidth[besti]
# assert util.is_real_num(gwidth), 'gwidth not real. Was %s'%str(gwidth)
# assert gwidth > 0, 'gwidth not positive. Was %.3g'%gwidth
# logging.info('After grid search, gwidth=%.3g'%gwidth)
# V_opt, gwidth_opt, info = GaussFSSD.optimize_locs_widths(p, dat,
# gwidth, V0, **ops)
# # set the width bounds
# #fac_min = 5e-2
# #fac_max = 5e3
# #gwidth_lb = fac_min*med2
# #gwidth_ub = fac_max*med2
# #gwidth_opt = max(gwidth_lb, min(gwidth_opt, gwidth_ub))
# return V_opt, gwidth_opt, info