本文整理汇总了Python中theano.tensor.min方法的典型用法代码示例。如果您正苦于以下问题:Python tensor.min方法的具体用法?Python tensor.min怎么用?Python tensor.min使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类theano.tensor
的用法示例。
在下文中一共展示了tensor.min方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: contains_nan
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import min [as 别名]
def contains_nan(arr):
"""
Test whether a numpy.ndarray contains any `np.nan` values.
Parameters
----------
arr : np.ndarray
Returns
-------
contains_nan : bool
`True` if the array contains any `np.nan` values, `False` otherwise.
Notes
-----
Tests for the presence of `np.nan`'s using `np.isnan(np.min(ndarray))`.
This approach is faster and more memory efficient than the obvious
alternative, calling `np.any(np.isnan(ndarray))`, which requires the
construction of a boolean array with the same shape as the input array.
"""
if isinstance(arr, theano.gof.type.CDataType._cdata_type):
return False
elif isinstance(arr, np.random.mtrand.RandomState):
return False
return np.isnan(np.min(arr))
示例2: learn_mini_batch
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import min [as 别名]
def learn_mini_batch(self, X):
"""
.. todo::
WRITEME
"""
self.learn_func(X)
if self.momentum_saturation_example is not None:
alpha = float(self.monitor.get_examples_seen()) / float(self.momentum_saturation_example)
alpha = min(alpha, 1.0)
self.momentum.set_value(np.cast[config.floatX]( (1.-alpha) * self.init_momentum + alpha * self.final_momentum))
if self.monitor.get_examples_seen() % self.print_interval == 0:
self.print_status()
if self.debug_m_step:
if self.energy_functional_diff.get_value() < 0.0:
warnings.warn( "m step decreased the em functional" )
if self.debug_m_step != 'warn':
quit(-1)
示例3: select_finite_faults
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import min [as 别名]
def select_finite_faults(self):
fault_points = T.vertical_stack(T.stack([self.ref_layer_points[0]], axis=0), self.rest_layer_points).T
ctr = T.mean(fault_points, axis=1)
x = fault_points - ctr.reshape((-1, 1))
M = T.dot(x, x.T)
U = T.nlinalg.svd(M)[2]
rotated_x = T.dot(self.x_to_interpolate(), U)
rotated_fault_points = T.dot(fault_points.T, U)
rotated_ctr = T.mean(rotated_fault_points, axis=0)
a_radius = (rotated_fault_points[:, 0].max() - rotated_fault_points[:, 0].min()) / 2 + self.inf_factor[
self.n_surface_op[0] - 1]
b_radius = (rotated_fault_points[:, 1].max() - rotated_fault_points[:, 1].min()) / 2 + self.inf_factor[
self.n_surface_op[0] - 1]
sel = T.lt((rotated_x[:, 0] - rotated_ctr[0]) ** 2 / a_radius ** 2 + (
rotated_x[:, 1] - rotated_ctr[1]) ** 2 / b_radius ** 2,
1)
if "select_finite_faults" in self.verbose:
sel = theano.printing.Print("scalar_field_iter")(sel)
return sel
示例4: select_finite_faults
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import min [as 别名]
def select_finite_faults(self, grid):
fault_points = T.vertical_stack(T.stack([self.ref_layer_points[0]], axis=0), self.rest_layer_points).T
ctr = T.mean(fault_points, axis=1)
x = fault_points - ctr.reshape((-1, 1))
M = T.dot(x, x.T)
U, D, V = T.nlinalg.svd(M)
rotated_x = T.dot(T.dot(grid, U), V)
rotated_fault_points = T.dot(T.dot(fault_points.T, U), V)
rotated_ctr = T.mean(rotated_fault_points, axis=0)
a_radius = (rotated_fault_points[:, 0].max() - rotated_fault_points[:, 0].min()) / 2
b_radius = (rotated_fault_points[:, 1].max() - rotated_fault_points[:, 1].min()) / 2
ellipse_factor = (rotated_x[:, 0] - rotated_ctr[0])**2 / a_radius**2 + \
(rotated_x[:, 1] - rotated_ctr[1])**2 / b_radius**2
if "select_finite_faults" in self.verbose:
ellipse_factor = theano.printing.Print("h")(ellipse_factor)
return ellipse_factor
示例5: min
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import min [as 别名]
def min(x, axis=None, keepdims=False):
return T.min(x, axis=axis, keepdims=keepdims)
示例6: test_optimization_max
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import min [as 别名]
def test_optimization_max(self):
data = numpy.asarray(numpy.random.rand(2, 3), dtype=config.floatX)
n = tensor.matrix()
for axis in [0, 1, -1]:
f = function([n], tensor.max(n, axis), mode=self.mode)
topo = f.maker.fgraph.toposort()
assert len(topo) == 1
assert isinstance(topo[0].op, CAReduce)
f(data)
f = function([n], tensor.max(-n, axis), mode=self.mode)
topo = f.maker.fgraph.toposort()
assert len(topo) == 2
assert isinstance(topo[0].op, Elemwise)
assert isinstance(topo[0].op.scalar_op, scalar.Neg)
assert isinstance(topo[1].op, CAReduce)
f(data)
f = function([n], -tensor.max(n, axis), mode=self.mode)
topo = f.maker.fgraph.toposort()
assert len(topo) == 2
assert isinstance(topo[0].op, CAReduce)
assert isinstance(topo[1].op, Elemwise)
assert isinstance(topo[1].op.scalar_op, scalar.Neg)
f(data)
f = function([n], -tensor.max(-n, axis), mode=self.mode)
topo = f.maker.fgraph.toposort()
assert len(topo) == 1
assert isinstance(topo[0].op, CAReduce) # min
f(data)
示例7: test_optimization_min
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import min [as 别名]
def test_optimization_min(self):
data = numpy.asarray(numpy.random.rand(2, 3), dtype=config.floatX)
n = tensor.matrix()
for axis in [0, 1, -1]:
f = function([n], tensor.min(n, axis), mode=self.mode)
topo = f.maker.fgraph.toposort()
assert len(topo) == 1
assert isinstance(topo[0].op, CAReduce)
f(data)
# test variant with neg to make sure we optimize correctly
f = function([n], tensor.min(-n, axis), mode=self.mode)
topo = f.maker.fgraph.toposort()
assert len(topo) == 2
assert isinstance(topo[0].op, CAReduce) # max
assert isinstance(topo[1].op, Elemwise)
assert isinstance(topo[1].op.scalar_op, scalar.Neg)
f(data)
f = function([n], -tensor.min(n, axis), mode=self.mode)
topo = f.maker.fgraph.toposort()
assert len(topo) == 2
assert isinstance(topo[0].op, Elemwise)
assert isinstance(topo[0].op.scalar_op, scalar.Neg)
assert isinstance(topo[1].op, CAReduce) # max
f(data)
f = function([n], -tensor.min(-n, axis), mode=self.mode)
topo = f.maker.fgraph.toposort()
assert len(topo) == 1
assert isinstance(topo[0].op, CAReduce) # max
f(data)
示例8: contains_nan
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import min [as 别名]
def contains_nan(arr, node=None):
"""
Test whether a numpy.ndarray contains any `np.nan` values.
Parameters
----------
arr : np.ndarray or output of any Theano op
node : None or an Apply instance.
If arr is the output of a Theano op, the node associated to it.
Returns
-------
contains_nan : bool
`True` if the array contains any `np.nan` values, `False` otherwise.
Notes
-----
Tests for the presence of `np.nan`'s using `np.isnan(np.min(ndarray))`.
This approach is faster and more memory efficient than the obvious
alternative, calling `np.any(np.isnan(ndarray))`, which requires the
construction of a boolean array with the same shape as the input array.
"""
if isinstance(arr, theano.gof.type.CDataType._cdata_type):
return False
elif isinstance(arr, np.random.mtrand.RandomState):
return False
elif arr.size == 0:
return False
elif cuda.cuda_available and isinstance(arr, cuda.CudaNdarray):
if (hasattr(theano.sandbox, 'rng_mrg') and
isinstance(
node.op,
# It store ints in float container
theano.sandbox.rng_mrg.GPU_mrg_uniform)):
return False
else:
compile_gpu_func(True, False, False)
return np.isnan(f_gpumin(arr.reshape(arr.size)))
return np.isnan(np.min(arr))
示例9: compile_gpu_func
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import min [as 别名]
def compile_gpu_func(nan_is_error, inf_is_error, big_is_error):
""" compile utility function used by contains_nan and contains_inf
"""
global f_gpumin, f_gpumax, f_gpuabsmax
if not cuda.cuda_available:
return
guard_input = cuda.fvector('nan_guard')
cuda_compile_failed = False
if (nan_is_error or inf_is_error) and f_gpumin is None:
try:
f_gpumin = theano.function(
[guard_input], T.min(guard_input),
mode='FAST_RUN'
)
except RuntimeError:
# This can happen if cuda is available, but the
# device is in exclusive mode and used by another
# process.
cuda_compile_failed = True
if inf_is_error and not cuda_compile_failed and f_gpumax is None:
try:
f_gpumax = theano.function(
[guard_input], T.max(guard_input),
mode='FAST_RUN'
)
except RuntimeError:
# This can happen if cuda is available, but the
# device is in exclusive mode and used by another
# process.
cuda_compile_failed = True
if big_is_error and not cuda_compile_failed and f_gpuabsmax is None:
try:
f_gpuabsmax = theano.function(
[guard_input], T.max(T.abs_(guard_input)),
mode='FAST_RUN'
)
except RuntimeError:
# This can happen if cuda is available, but the
# device is in exclusive mode and used by another
# process.
cuda_compile_failed = True
示例10: get_stats
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import min [as 别名]
def get_stats(input, stat=None):
"""
Returns a dictionary mapping the name of the statistic to the result on the input.
Currently gets mean, var, std, min, max, l1, l2.
Parameters
----------
input : tensor
Theano tensor to grab stats for.
Returns
-------
dict
Dictionary of all the statistics expressions {string_name: theano expression}
"""
stats = {
'mean': T.mean(input),
'var': T.var(input),
'std': T.std(input),
'min': T.min(input),
'max': T.max(input),
'l1': input.norm(L=1),
'l2': input.norm(L=2),
#'num_nonzero': T.sum(T.nonzero(input)),
}
stat_list = raise_to_list(stat)
compiled_stats = {}
if stat_list is None:
return stats
for stat in stat_list:
if isinstance(stat, string_types) and stat in stats:
compiled_stats.update({stat: stats[stat]})
return compiled_stats
示例11: reghess
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import min [as 别名]
def reghess(self, Hc):
'''Regularize the Hessian to avoid ill-conditioning and to escape saddle
points.
'''
# compute eigenvalues and condition number
w = self.eigh(Hc)
rcond = np.min(np.abs(w)) / np.max(np.abs(w))
if rcond <= self.eps or (self.neq + self.nineq) != np.sum(w < -self.eps):
# if the Hessian is ill-conditioned or the matrix inertia is undesireable, regularize the Hessian
if rcond <= self.eps and self.neq:
# if the Hessian is ill-conditioned, regularize by replacing some zeros with a small magnitude diagonal
# matrix
ind1 = self.nvar + self.nineq
ind2 = ind1 + self.neq
Hc[ind1:ind2, ind1:ind2] -= self.reg_coef * self.eta * (self.mu_host ** self.beta) * np.eye(self.neq)
if self.delta == 0.0:
# if the diagonal shift coefficient is zero, set to initial value
self.delta = self.delta0
else:
# prevent the diagonal shift coefficient from becoming too small
self.delta = np.max([self.delta / 2, self.delta0])
# regularize Hessian with diagonal shift matrix (delta*I) until matrix inertia condition is satisfied
Hc[:self.nvar, :self.nvar] += self.delta * np.eye(self.nvar)
w = self.eigh(Hc)
while (self.neq + self.nineq) != np.sum(w < -self.eps):
Hc[:self.nvar, :self.nvar] -= self.delta * np.eye(self.nvar)
self.delta *= 10.0
Hc[:self.nvar, :self.nvar] += self.delta * np.eye(self.nvar)
w = self.eigh(Hc)
# return regularized Hessian
return Hc
示例12: _layer_stats
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import min [as 别名]
def _layer_stats(self, state_below, layer_output):
"""
DESCRIPTION:
This method is called every batch whereby the examples from test or valid set
is pass through, the final result will be the mean of all the results from all
the batches in an epoch from the test set or valid set.
PARAM:
layer_output: the output from the layer
RETURN:
A list of tuples of [('name_a', var_a), ('name_b', var_b)] whereby var is scalar
"""
w_len = T.sqrt((self.W ** 2).sum(axis=0))
max_length = T.max(w_len)
mean_length = T.mean(w_len)
min_length = T.min(w_len)
max_output = T.max(layer_output)
mean_output = T.mean(T.abs_(layer_output))
min_output = T.min(layer_output)
max_state = T.max(state_below)
mean_state = T.mean(T.abs_(state_below))
min_state = T.min(state_below)
return [('max_W', T.max(self.W)),
('mean_W', T.mean(self.W)),
('min_W', T.min(self.W)),
('max_b', T.max(self.b)),
('mean_b', T.mean(self.b)),
('min_b', T.min(self.b)),
('max_layer_output', max_output),
('mean_layer_output', mean_output),
('min_layer_output', min_output),
('max_col_length', max_length),
('mean_col_length', mean_length),
('min_col_length', min_length),
('max_state_below', max_state),
('mean_state_below', mean_state),
('min_state_below', min_state)]