本文整理汇总了Python中tensorflow.python.ops.check_ops.assert_less_equal函数的典型用法代码示例。如果您正苦于以下问题:Python assert_less_equal函数的具体用法?Python assert_less_equal怎么用?Python assert_less_equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assert_less_equal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_doesnt_raise_when_both_empty
def test_doesnt_raise_when_both_empty(self):
larry = constant_op.constant([])
curly = constant_op.constant([])
with ops.control_dependencies(
[check_ops.assert_less_equal(larry, curly)]):
out = array_ops.identity(larry)
self.evaluate(out)
开发者ID:AbhinavJain13,项目名称:tensorflow,代码行数:7,代码来源:check_ops_test.py
示例2: calculate_reshape
def calculate_reshape(original_shape, new_shape, validate=False, name=None):
"""Calculates the reshaped dimensions (replacing up to one -1 in reshape)."""
batch_shape_static = tensor_util.constant_value_as_shape(new_shape)
if batch_shape_static.is_fully_defined():
return np.int32(batch_shape_static.as_list()), batch_shape_static, []
with ops.name_scope(name, "calculate_reshape", [original_shape, new_shape]):
original_size = math_ops.reduce_prod(original_shape)
implicit_dim = math_ops.equal(new_shape, -1)
size_implicit_dim = (
original_size // math_ops.maximum(1, -math_ops.reduce_prod(new_shape)))
new_ndims = array_ops.shape(new_shape)
expanded_new_shape = array_ops.where( # Assumes exactly one `-1`.
implicit_dim, array_ops.fill(new_ndims, size_implicit_dim), new_shape)
validations = [] if not validate else [
check_ops.assert_rank(
original_shape, 1, message="Original shape must be a vector."),
check_ops.assert_rank(
new_shape, 1, message="New shape must be a vector."),
check_ops.assert_less_equal(
math_ops.count_nonzero(implicit_dim, dtype=dtypes.int32),
1,
message="At most one dimension can be unknown."),
check_ops.assert_positive(
expanded_new_shape, message="Shape elements must be >=-1."),
check_ops.assert_equal(
math_ops.reduce_prod(expanded_new_shape),
original_size,
message="Shape sizes do not match."),
]
return expanded_new_shape, batch_shape_static, validations
开发者ID:Ajaycs99,项目名称:tensorflow,代码行数:30,代码来源:batch_reshape.py
示例3: test_doesnt_raise_when_equal
def test_doesnt_raise_when_equal(self):
with self.test_session():
small = constant_op.constant([1, 2], name="small")
with ops.control_dependencies(
[check_ops.assert_less_equal(small, small)]):
out = array_ops.identity(small)
out.eval()
开发者ID:1000sprites,项目名称:tensorflow,代码行数:7,代码来源:check_ops_test.py
示例4: test_doesnt_raise_when_less_equal_and_broadcastable_shapes
def test_doesnt_raise_when_less_equal_and_broadcastable_shapes(self):
with self.test_session():
small = constant_op.constant([1], name="small")
big = constant_op.constant([3, 1], name="big")
with ops.control_dependencies([check_ops.assert_less_equal(small, big)]):
out = array_ops.identity(small)
out.eval()
开发者ID:1000sprites,项目名称:tensorflow,代码行数:7,代码来源:check_ops_test.py
示例5: test_raises_when_less_equal_but_non_broadcastable_shapes
def test_raises_when_less_equal_but_non_broadcastable_shapes(self):
with self.test_session():
small = constant_op.constant([1, 1, 1], name="small")
big = constant_op.constant([3, 1], name="big")
with self.assertRaisesRegexp(ValueError, "must be"):
with ops.control_dependencies(
[check_ops.assert_less_equal(small, big)]):
out = array_ops.identity(small)
out.eval()
开发者ID:1000sprites,项目名称:tensorflow,代码行数:9,代码来源:check_ops_test.py
示例6: test_raises_when_greater
def test_raises_when_greater(self):
small = constant_op.constant([1, 2], name="small")
big = constant_op.constant([3, 4], name="big")
with self.assertRaisesOpError("fail"):
with ops.control_dependencies(
[check_ops.assert_less_equal(
big, small, message="fail")]):
out = array_ops.identity(small)
self.evaluate(out)
开发者ID:AbhinavJain13,项目名称:tensorflow,代码行数:9,代码来源:check_ops_test.py
示例7: _maybe_assert_valid_y
def _maybe_assert_valid_y(self, y):
if not self.validate_args:
return y
is_positive = check_ops.assert_non_negative(
y, message="Inverse transformation input must be greater than 0.")
less_than_one = check_ops.assert_less_equal(
y, constant_op.constant(1., y.dtype),
message="Inverse transformation input must be less than or equal to 1.")
return control_flow_ops.with_dependencies([is_positive, less_than_one], y)
开发者ID:AbhinavJain13,项目名称:tensorflow,代码行数:9,代码来源:weibull.py
示例8: _maybe_check_valid_shape
def _maybe_check_valid_shape(self, shape, validate_args):
"""Check that a shape Tensor is int-type and otherwise sane."""
if not shape.dtype.is_integer:
raise TypeError("{} dtype ({}) should be `int`-like.".format(
shape, shape.dtype.name))
assertions = []
ndims = array_ops.rank(shape)
ndims_ = tensor_util.constant_value(ndims)
if ndims_ is not None and ndims_ > 1:
raise ValueError("`{}` rank ({}) should be <= 1.".format(
shape, ndims_))
elif validate_args:
assertions.append(check_ops.assert_less_equal(
ndims, 1, message="`{}` rank should be <= 1.".format(shape)))
shape_ = tensor_util.constant_value_as_shape(shape)
if shape_.is_fully_defined():
es = np.int32(shape_.as_list())
if sum(es == -1) > 1:
raise ValueError(
"`{}` must have at most one `-1` (given {})"
.format(shape, es))
if np.any(es < -1):
raise ValueError(
"`{}` elements must be either positive integers or `-1`"
"(given {})."
.format(shape, es))
elif validate_args:
assertions.extend([
check_ops.assert_less_equal(
math_ops.reduce_sum(
math_ops.cast(math_ops.equal(shape, -1), dtypes.int32)),
1,
message="`{}` elements must have at most one `-1`."
.format(shape)),
check_ops.assert_greater_equal(
shape, -1,
message="`{}` elements must be either positive integers or `-1`."
.format(shape)),
])
return assertions
开发者ID:Ajaycs99,项目名称:tensorflow,代码行数:43,代码来源:reshape.py
示例9: _maybe_assert_valid_sample
def _maybe_assert_valid_sample(self, counts):
"""Check counts for proper shape, values, then return tensor version."""
if not self.validate_args:
return counts
counts = distribution_util.embed_check_nonnegative_integer_form(counts)
return control_flow_ops.with_dependencies([
check_ops.assert_less_equal(
counts, self.total_count,
message="counts are not less than or equal to n."),
], counts)
开发者ID:Jackiefan,项目名称:tensorflow,代码行数:10,代码来源:binomial.py
示例10: _maybe_assert_valid_sample
def _maybe_assert_valid_sample(self, event, check_integer=True):
if not self.validate_args:
return event
event = distribution_util.embed_check_nonnegative_discrete(
event, check_integer=check_integer)
return control_flow_ops.with_dependencies([
check_ops.assert_less_equal(
event, array_ops.ones_like(event),
message="event is not less than or equal to 1."),
], event)
开发者ID:LUTAN,项目名称:tensorflow,代码行数:10,代码来源:bernoulli.py
示例11: check_soundness
def check_soundness(ff, fp):
(sufficient_n1,
sufficient_n2) = st.min_num_samples_for_dkwm_mean_two_sample_test(
numbers, 0., 1., 0., 1.,
false_fail_rate=ff, false_pass_rate=fp)
d_fn = st.min_discrepancy_of_true_means_detectable_by_dkwm_two_sample
detectable_d = d_fn(
sufficient_n1, 0., 1., sufficient_n2, 0., 1.,
false_fail_rate=ff, false_pass_rate=fp)
return check_ops.assert_less_equal(detectable_d, numbers)
开发者ID:houhaichao830,项目名称:tensorflow,代码行数:10,代码来源:statistical_testing_test.py
示例12: _maybe_assert_valid
def _maybe_assert_valid(self, x):
if not self.validate_args:
return x
return control_flow_ops.with_dependencies([
check_ops.assert_non_negative(
x,
message="sample must be non-negative"),
check_ops.assert_less_equal(
x, array_ops.ones([], self.concentration0.dtype),
message="sample must be no larger than `1`."),
], x)
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:11,代码来源:kumaraswamy.py
示例13: test_dkwm_design_mean_one_sample_soundness
def test_dkwm_design_mean_one_sample_soundness(self):
numbers = [1e-5, 1e-2, 1.1e-1, 0.9, 1., 1.02, 2., 10., 1e2, 1e5, 1e10]
rates = [1e-6, 1e-3, 1e-2, 1.1e-1, 0.2, 0.5, 0.7, 1.]
with self.test_session() as sess:
for ff in rates:
for fp in rates:
sufficient_n = st.min_num_samples_for_dkwm_mean_test(
numbers, 0., 1., false_fail_rate=ff, false_pass_rate=fp)
detectable_d = st.min_discrepancy_of_true_means_detectable_by_dkwm(
sufficient_n, 0., 1., false_fail_rate=ff, false_pass_rate=fp)
sess.run(check_ops.assert_less_equal(detectable_d, numbers))
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:11,代码来源:statistical_testing_test.py
示例14: _check_counts
def _check_counts(self, counts):
counts = ops.convert_to_tensor(counts, name="counts_before_deps")
if not self.validate_args:
return counts
return control_flow_ops.with_dependencies([
check_ops.assert_non_negative(
counts, message="counts has negative components."),
check_ops.assert_less_equal(
counts, self._n, message="counts are not less than or equal to n."),
distribution_util.assert_integer_form(
counts, message="counts have non-integer components.")], counts)
开发者ID:ivankreso,项目名称:tensorflow,代码行数:11,代码来源:binomial.py
示例15: get_logits_and_prob
def get_logits_and_prob(
logits=None, p=None,
multidimensional=False, validate_args=False, name="GetLogitsAndProb"):
"""Converts logits to probabilities and vice-versa, and returns both.
Args:
logits: Numeric `Tensor` representing log-odds.
p: Numeric `Tensor` representing probabilities.
multidimensional: Given `p` a [N1, N2, ... k] dimensional tensor,
whether the last dimension represents the probability between k classes.
This will additionally assert that the values in the last dimension
sum to one. If `False`, will instead assert that each value is in
`[0, 1]`.
validate_args: `Boolean`, default `False`. Whether to assert `0 <= p <= 1`
if multidimensional is `False`, otherwise that the last dimension of `p`
sums to one.
name: A name for this operation (optional).
Returns:
Tuple with `logits` and `p`. If `p` has an entry that is `0` or `1`, then
the corresponding entry in the returned logits will be `-Inf` and `Inf`
respectively.
Raises:
ValueError: if neither `p` nor `logits` were passed in, or both were.
"""
with ops.name_scope(name, values=[p, logits]):
if p is None and logits is None:
raise ValueError("Must pass p or logits.")
elif p is not None and logits is not None:
raise ValueError("Must pass either p or logits, not both.")
elif p is None:
logits = array_ops.identity(logits, name="logits")
with ops.name_scope("p"):
p = math_ops.sigmoid(logits)
elif logits is None:
with ops.name_scope("p"):
p = array_ops.identity(p)
if validate_args:
one = constant_op.constant(1., p.dtype)
dependencies = [check_ops.assert_non_negative(p)]
if multidimensional:
dependencies += [assert_close(
math_ops.reduce_sum(p, reduction_indices=[-1]),
one, message="p does not sum to 1.")]
else:
dependencies += [check_ops.assert_less_equal(
p, one, message="p has components greater than 1.")]
p = control_flow_ops.with_dependencies(dependencies, p)
with ops.name_scope("logits"):
logits = math_ops.log(p) - math_ops.log(1. - p)
return (logits, p)
开发者ID:Nishant23,项目名称:tensorflow,代码行数:52,代码来源:distribution_util.py
示例16: test_raises_when_less_equal_but_non_broadcastable_shapes
def test_raises_when_less_equal_but_non_broadcastable_shapes(self):
small = constant_op.constant([3, 1], name="small")
big = constant_op.constant([1, 1, 1], name="big")
# The exception in eager and non-eager mode is different because
# eager mode relies on shape check done as part of the C++ op, while
# graph mode does shape checks when creating the `Operation` instance.
with self.assertRaisesRegexp(
(errors.InvalidArgumentError, ValueError),
(r"Incompatible shapes: \[2\] vs. \[3\]|"
r"Dimensions must be equal, but are 2 and 3")):
with ops.control_dependencies(
[check_ops.assert_less_equal(small, big)]):
out = array_ops.identity(small)
self.evaluate(out)
开发者ID:AbhinavJain13,项目名称:tensorflow,代码行数:14,代码来源:check_ops_test.py
示例17: _check_shape
def _check_shape(self, shape):
"""Check that the init arg `shape` defines a valid operator."""
shape = ops.convert_to_tensor(shape, name="shape")
if not self._verify_pd:
return shape
# Further checks are equivalent to verification that this is positive
# definite. Why? Because the further checks simply check that this is a
# square matrix, and combining the fact that this is square (and thus maps
# a vector space R^k onto itself), with the behavior of .matmul(), this must
# be the identity operator.
rank = array_ops.size(shape)
assert_matrix = check_ops.assert_less_equal(2, rank)
with ops.control_dependencies([assert_matrix]):
last_dim = array_ops.gather(shape, rank - 1)
second_to_last_dim = array_ops.gather(shape, rank - 2)
assert_square = check_ops.assert_equal(last_dim, second_to_last_dim)
return control_flow_ops.with_dependencies([assert_matrix, assert_square], shape)
开发者ID:kdavis-mozilla,项目名称:tensorflow,代码行数:18,代码来源:operator_pd_identity.py
示例18: _maximum_mean
def _maximum_mean(samples, envelope, high, name=None):
"""Returns a stochastic upper bound on the mean of a scalar distribution.
The idea is that if the true CDF is within an `eps`-envelope of the
empirical CDF of the samples, and the support is bounded above, then
the mean is bounded above as well. In symbols,
```none
sup_x(|F_n(x) - F(x)|) < eps
```
The 0th dimension of `samples` is interpreted as independent and
identically distributed samples. The remaining dimensions are
broadcast together with `envelope` and `high`, and operated on
separately.
Args:
samples: Floating-point tensor of samples from the distribution(s)
of interest. Entries are assumed IID across the 0th dimension.
The other dimensions must broadcast with `envelope` and `high`.
envelope: Floating-point tensor of sizes of admissible CDF
envelopes (i.e., the `eps` above).
high: Floating-point tensor of upper bounds on the distributions'
supports.
name: A name for this operation (optional).
Returns:
bound: Floating-point tensor of upper bounds on the true means.
Raises:
InvalidArgumentError: If some `sample` is found to be larger than
the corresponding `high`.
"""
with ops.name_scope(name, "maximum_mean", [samples, envelope, high]):
samples = ops.convert_to_tensor(samples, name="samples")
envelope = ops.convert_to_tensor(envelope, name="envelope")
high = ops.convert_to_tensor(high, name="high")
xmax = math_ops.reduce_max(samples, axis=[-1])
msg = "Given sample maximum value exceeds expectations"
check_op = check_ops.assert_less_equal(xmax, high, message=msg)
with ops.control_dependencies([check_op]):
return array_ops.identity(_do_maximum_mean(samples, envelope, high))
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:43,代码来源:statistical_testing.py
示例19: _make_runtime_assertions
def _make_runtime_assertions(
self, distribution, reduce_batch_ndims, validate_args):
assertions = []
static_reduce_batch_ndims = tensor_util.constant_value(reduce_batch_ndims)
batch_ndims = distribution.batch_shape.ndims
if batch_ndims is not None and static_reduce_batch_ndims is not None:
if static_reduce_batch_ndims > batch_ndims:
raise ValueError("reduce_batch_ndims({}) cannot exceed "
"distribution.batch_ndims({})".format(
static_reduce_batch_ndims, batch_ndims))
elif validate_args:
batch_shape = distribution.batch_shape_tensor()
batch_ndims = (
batch_shape.shape[0].value
if batch_shape.shape.with_rank_at_least(1)[0].value is not None
else array_ops.shape(batch_shape)[0])
assertions.append(check_ops.assert_less_equal(
reduce_batch_ndims, batch_ndims,
message="reduce_batch_ndims cannot exceed distribution.batch_ndims"))
return assertions
开发者ID:Crazyonxh,项目名称:tensorflow,代码行数:20,代码来源:independent.py
示例20: _init_clusters_random
def _init_clusters_random(self):
"""Does random initialization of clusters.
Returns:
Tensor of randomly initialized clusters.
"""
num_data = math_ops.add_n([array_ops.shape(inp)[0] for inp in self._inputs])
# Note that for mini-batch k-means, we should ensure that the batch size of
# data used during initialization is sufficiently large to avoid duplicated
# clusters.
with ops.control_dependencies(
[check_ops.assert_less_equal(self._num_clusters, num_data)]):
indices = random_ops.random_uniform(
array_ops.reshape(self._num_clusters, [-1]),
minval=0,
maxval=math_ops.cast(num_data, dtypes.int64),
seed=self._random_seed,
dtype=dtypes.int64)
clusters_init = embedding_lookup(
self._inputs, indices, partition_strategy='div')
return clusters_init
开发者ID:AliMiraftab,项目名称:tensorflow,代码行数:21,代码来源:clustering_ops.py
注:本文中的tensorflow.python.ops.check_ops.assert_less_equal函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论