本文整理汇总了Python中theano.tensor.round方法的典型用法代码示例。如果您正苦于以下问题:Python tensor.round方法的具体用法?Python tensor.round怎么用?Python tensor.round使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类theano.tensor
的用法示例。
在下文中一共展示了tensor.round方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: compute_output
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import round [as 别名]
def compute_output(self, network, in_vw):
zero_ratio = network.find_hyperparameter(["zero_ratio"])
axis = network.find_hyperparameter(["axis"], 1)
in_var = in_vw.variable
size = treeano.utils.as_fX(in_var.shape[axis])
num_zeros = T.round(zero_ratio * size).astype("int32")
idxs = [None] * (axis - 1) + [slice(-num_zeros, None)]
out_var = T.set_subtensor(in_var[idxs], 0)
network.create_vw(
"default",
variable=out_var,
shape=in_vw.shape,
tags={"output"},
)
示例2: get_output
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import round [as 别名]
def get_output(self, train=False):
p = self.get_input(train)
if self.mode == 'maximum_likelihood':
# draw maximum likelihood sample from Bernoulli distribution
# x* = argmax_x p(x) = 1 if p(x=1) >= 0.5
# 0 otherwise
return T.round(p, mode='half_away_from_zero')
elif self.mode == 'random':
# draw random sample from Bernoulli distribution
# x* = x ~ p(x) = 1 if p(x=1) > uniform(0, 1)
# 0 otherwise
return self.srng.binomial(size=p.shape, n=1, p=p, dtype=theano.config.floatX)
elif self.mode == 'mean_field':
# draw mean-field approximation sample from Bernoulli distribution
# x* = E[p(x)] = E[Bern(x; p)] = p
return p
else:
raise NotImplementedError('Unknown sample mode!')
示例3: create_oct_level_dense
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import round [as 别名]
def create_oct_level_dense(self, unique_val, grid):
uv_3d = T.cast(T.round(unique_val[0, :T.prod(self.regular_grid_res)].reshape(self.regular_grid_res, ndim=3)),
'int32')
new_shape = T.concatenate([self.regular_grid_res, T.stack([3])])
xyz = grid[:T.prod(self.regular_grid_res)].reshape(new_shape, ndim=4)
shift_x = uv_3d[1:, :, :] - uv_3d[:-1, :, :]
shift_x_select = T.neq(shift_x, 0)
x_edg = (xyz[:-1, :, :][shift_x_select] + xyz[1:, :, :][shift_x_select])/2
shift_y = uv_3d[:, 1:, :] - uv_3d[:, :-1, :]
shift_y_select = T.neq(shift_y, 0)
y_edg = (xyz[:, :-1, :][shift_y_select] + xyz[:, 1:, :][shift_y_select])/2
shift_z = uv_3d[:, :, 1:] - uv_3d[:, :, :-1]
shift_z_select = T.neq(shift_z, 0)
z_edg = (xyz[:, :, :-1][shift_z_select] + xyz[:, :, 1:][shift_z_select])/2
new_xyz_edg = T.vertical_stack(x_edg, y_edg, z_edg)
return self.create_oct_voxels(new_xyz_edg)
示例4: create_oct_level_sparse
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import round [as 别名]
def create_oct_level_sparse(self, unique_val, grid):
xyz_8 = grid.reshape((-1, 8, 3))
# uv_8 = T.round(unique_val[0, :-2 * self.len_points].reshape((-1, 8)))
uv_8 = T.round(unique_val[0, :].reshape((-1, 8)))
shift_x = uv_8[:, :4] - uv_8[:, 4:]
shift_x_select = T.neq(shift_x, 0)
x_edg = (xyz_8[:, :4, :][shift_x_select] + xyz_8[:, 4:, :][shift_x_select])/2
shift_y = uv_8[:, [0,1,4,5]] - uv_8[:, [2,3,6,7]]
shift_y_select = T.neq(shift_y, 0)
y_edg = (xyz_8[:, [0, 1, 4, 5], :][shift_y_select] + xyz_8[:, [2, 3, 6, 7], :][shift_y_select])/2
shift_z = uv_8[:, ::2] - uv_8[:, 1::2]
shift_z_select = T.neq(shift_z, 0)
z_edg = (xyz_8[:, ::2, :][shift_z_select] + xyz_8[:, 1::2, :][shift_z_select])/2
new_xyz_edg = T.vertical_stack(x_edg, y_edg, z_edg)
return self.create_oct_voxels(new_xyz_edg, level=2)
示例5: round
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import round [as 别名]
def round(x):
return T.round(x)
示例6: get_pseudo_likelihood_cost
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import round [as 别名]
def get_pseudo_likelihood_cost(self, updates):
bit_i_idx = theano.shared(value=0, name='bit_i_idx')
xi = T.round(self.input)
fe_xi = self.free_energy(xi)
xi_flip = T.set_subtensor(xi[:, bit_i_idx], 1 - xi[:, bit_i_idx])
fe_xi_flip = self.free_energy(xi_flip)
cost = T.mean(self.n_visible * T.log(T.nnet.sigmoid(fe_xi_flip - fe_xi)))
updates[bit_i_idx] = (bit_i_idx + 1) % self.n_visible
return cost
示例7: round
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import round [as 别名]
def round(x):
return T.round(x, mode='half_to_even')
示例8: fixed_point
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import round [as 别名]
def fixed_point(X,NOB, NOIB):
power = T.cast(2.**(NOB - NOIB), theano.config.floatX) # float !
max = T.cast((2.**NOB)-1, theano.config.floatX)
value = X*power
value = T.round(value) # rounding
value = T.clip(value, -max, max) # saturation arithmetic
value = value/power
return value
# compute the new range of the dynamic fixed point representation
示例9: binarize_conv_filters
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import round [as 别名]
def binarize_conv_filters(W):
"""Binarize convolution weights and find the weight scaling factor
W : theano tensor : convolution layer weight of dimension no_filters x no_feat_maps x h x w
"""
# symbolic binary weight
Wb = T.cast(T.switch(T.ge(W, 0),1,-1), theano.config.floatX)
# BinaryNet method
#Wb = T.cast(T.switch(T.round(hard_sigmoid(W),1,-1)), theano.config.floatX)
# weight scaling factor
# FIXME: directly compute the mean along axis 1,2,3 instead of reshaping
alpha = T.mean( T.reshape(T.abs_(W), (W.shape[0], W.shape[1]*W.shape[2]*W.shape[3])), axis=1)
return Wb, alpha
示例10: binarize_fc_weights
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import round [as 别名]
def binarize_fc_weights(W):
# symbolic binary weight
Wb = T.cast(T.switch(T.ge(W, 0),1,-1), theano.config.floatX)
# BinaryNet method
#Wb = T.cast(T.switch(T.round(hard_sigmoid(W)),1,-1), theano.config.floatX)
alpha = T.mean(T.abs_(W), axis=0)
return Wb, alpha
示例11: to_fixed_point_theano
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import round [as 别名]
def to_fixed_point_theano(input, no_bits, no_int_bits):
scale =T.cast(2.**(no_bits - no_int_bits), theano.config.floatX)
max_val = T.cast((2.**no_bits) - 1, theano.config.floatX)
scaled = input * scale
scaled = T.round(scaled)
scaled = T.clip(scaled, -max_val, max_val)
return scaled/scale
示例12: fixed_point
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import round [as 别名]
def fixed_point(array, no_mag_bits, no_int_bits):
"""Convert to fixed point and convert it back to float
"""
factor = 2.0 ** (no_mag_bits - no_int_bits)
max_val = 2. ** no_mag_bits - 1
scaled_arr = array * factor
# round to the nearest value
scaled_arr = np.around(scaled_arr)
# saturation
scaled_arr = np.clip(scaled_arr, -max_val, max_val)
return scaled_arr/factor
示例13: get_pseudo_likelihood_cost
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import round [as 别名]
def get_pseudo_likelihood_cost(self, updates):
"""Stochastic approximation to the pseudo-likelihood"""
# index of bit i in expression p(x_i | x_{\i})
bit_i_idx = theano.shared(value=0, name='bit_i_idx')
# binarize the input image by rounding to nearest integer
xi = T.round(self.input)
# calculate free energy for the given bit configuration
fe_xi = self.free_energy(xi)
# flip bit x_i of matrix xi and preserve all other bits x_{\i}
# Equivalent to xi[:,bit_i_idx] = 1-xi[:, bit_i_idx], but assigns
# the result to xi_flip, instead of working in place on xi.
xi_flip = T.set_subtensor(xi[:, bit_i_idx], 1 - xi[:, bit_i_idx])
# calculate free energy with bit flipped
fe_xi_flip = self.free_energy(xi_flip)
# equivalent to e^(-FE(x_i)) / (e^(-FE(x_i)) + e^(-FE(x_{\i})))
cost = T.mean(self.n_visible * T.log(T.nnet.sigmoid(fe_xi_flip -
fe_xi)))
# increment bit_i_idx % number as part of updates
updates[bit_i_idx] = (bit_i_idx + 1) % self.n_visible
return cost
示例14: get_boundary_voxels
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import round [as 别名]
def get_boundary_voxels(self, unique_val):
uv_3d = T.cast(T.round(unique_val[0, :T.prod(self.regular_grid_res)].reshape(self.regular_grid_res, ndim=3)),
'int32')
uv_l = T.horizontal_stack(uv_3d[1:, :, :].reshape((1, -1)),
uv_3d[:, 1:, :].reshape((1, -1)),
uv_3d[:, :, 1:].reshape((1, -1)))
uv_r = T.horizontal_stack(uv_3d[:-1, :, :].reshape((1, -1)),
uv_3d[:, :-1, :].reshape((1, -1)),
uv_3d[:, :, :-1].reshape((1, -1)))
shift = uv_l - uv_r
select_edges = T.neq(shift.reshape((1, -1)), 0)
select_edges_dir = select_edges.reshape((3, -1))
select_voxels = T.zeros_like(uv_3d)
select_voxels = T.inc_subtensor(select_voxels[1:, :, :],
select_edges_dir[0].reshape((self.regular_grid_res - np.array([1, 0, 0])),
ndim=3))
select_voxels = T.inc_subtensor(select_voxels[:-1, :, :],
select_edges_dir[0].reshape((self.regular_grid_res - np.array([1, 0, 0])),
ndim=3))
select_voxels = T.inc_subtensor(select_voxels[:, 1:, :],
select_edges_dir[1].reshape((self.regular_grid_res - np.array([0, 1, 0])),
ndim=3))
select_voxels = T.inc_subtensor(select_voxels[:, :-1, :],
select_edges_dir[1].reshape((self.regular_grid_res - np.array([0, 1, 0])),
ndim=3))
select_voxels = T.inc_subtensor(select_voxels[:, :, 1:],
select_edges_dir[2].reshape((self.regular_grid_res - np.array([0, 0, 1])),
ndim=3))
select_voxels = T.inc_subtensor(select_voxels[:, :, :-1],
select_edges_dir[2].reshape((self.regular_grid_res - np.array([0, 0, 1])),
ndim=3))
return select_voxels
# region Geometry