本文整理汇总了Python中numpy.NINF属性的典型用法代码示例。如果您正苦于以下问题:Python numpy.NINF属性的具体用法?Python numpy.NINF怎么用?Python numpy.NINF使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类numpy
的用法示例。
在下文中一共展示了numpy.NINF属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_is_inf
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import NINF [as 别名]
def test_is_inf(self):
if legacy_opset_pre_ver(10):
raise unittest.SkipTest("ONNX version {} doesn't support IsInf.".format(
defs.onnx_opset_version()))
input = np.array([-1.2, np.nan, np.inf, 2.8, np.NINF, np.inf],
dtype=np.float32)
expected_output = {
"node_def": np.isinf(input),
"node_def_neg_false": np.isposinf(input),
"node_def_pos_false": np.isneginf(input)
}
node_defs = {
"node_def":
helper.make_node("IsInf", ["X"], ["Y"]),
"node_def_neg_false":
helper.make_node("IsInf", ["X"], ["Y"], detect_negative=0),
"node_def_pos_false":
helper.make_node("IsInf", ["X"], ["Y"], detect_positive=0)
}
for key in node_defs:
output = run_node(node_defs[key], [input])
np.testing.assert_equal(output["Y"], expected_output[key])
示例2: test_is_inf
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import NINF [as 别名]
def test_is_inf(self):
if legacy_opset_pre_ver(10):
raise unittest.SkipTest("ONNX version {} doesn't support IsInf.".format(
defs.onnx_opset_version()))
inp = np.array([-1.2, np.nan, np.inf, 2.8, np.NINF, np.inf],
dtype=np.float32)
expected_output = np.isinf(inp)
node_def = helper.make_node("IsInf", ["X"], ["Y"])
graph_def = helper.make_graph(
[node_def],
name="test_unknown_shape",
inputs=[
helper.make_tensor_value_info("X", TensorProto.FLOAT, [None]),
],
outputs=[helper.make_tensor_value_info("Y", TensorProto.BOOL, [None])])
tf_rep = onnx_graph_to_tensorflow_rep(graph_def)
output = tf_rep.run({"X": inp})
np.testing.assert_equal(output["Y"], expected_output)
示例3: ComputeEnabledAABB
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import NINF [as 别名]
def ComputeEnabledAABB(kinbody):
"""
Returns the AABB of the enabled links of a KinBody.
@param kinbody: an OpenRAVE KinBody
@returns: AABB of the enabled links of the KinBody
"""
from numpy import NINF, PINF
from openravepy import AABB
min_corner = numpy.array([PINF] * 3)
max_corner = numpy.array([NINF] * 3)
for link in kinbody.GetLinks():
if link.IsEnabled():
link_aabb = link.ComputeAABB()
center = link_aabb.pos()
half_extents = link_aabb.extents()
min_corner = numpy.minimum(center - half_extents, min_corner)
max_corner = numpy.maximum(center + half_extents, max_corner)
center = (min_corner + max_corner) / 2.
half_extents = (max_corner - min_corner) / 2.
return AABB(center, half_extents)
示例4: test_constants
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import NINF [as 别名]
def test_constants():
assert chainerx.Inf is numpy.Inf
assert chainerx.Infinity is numpy.Infinity
assert chainerx.NAN is numpy.NAN
assert chainerx.NINF is numpy.NINF
assert chainerx.NZERO is numpy.NZERO
assert chainerx.NaN is numpy.NaN
assert chainerx.PINF is numpy.PINF
assert chainerx.PZERO is numpy.PZERO
assert chainerx.e is numpy.e
assert chainerx.euler_gamma is numpy.euler_gamma
assert chainerx.inf is numpy.inf
assert chainerx.infty is numpy.infty
assert chainerx.nan is numpy.nan
assert chainerx.newaxis is numpy.newaxis
assert chainerx.pi is numpy.pi
示例5: normalize
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import NINF [as 别名]
def normalize(v):
if isinstance(v, numpy.bool_):
return bool(v)
elif isinstance(v, numpy.ndarray):
return [normalize(item) for item in v]
elif v == numpy.NaN:
return "NaN"
elif v == numpy.NINF:
return "-Infinity"
elif v == numpy.PINF:
return "Infinity"
elif isinstance(v, numpy.float):
return float(v)
elif isinstance(v, tuple):
return list(v)
else:
return v
示例6: _create_corpus_embed
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import NINF [as 别名]
def _create_corpus_embed(self):
"""
msg_embed: batch_size * max_n_days * max_n_msgs * msg_embed_size
=> corpus_embed: batch_size * max_n_days * corpus_embed_size
"""
with tf.name_scope('corpus_embed'):
with tf.variable_scope('u_t'):
proj_u = self._linear(self.msg_embed, self.msg_embed_size, 'tanh', use_bias=False)
w_u = tf.get_variable('w_u', shape=(self.msg_embed_size, 1), initializer=self.initializer)
u = tf.reduce_mean(tf.tensordot(proj_u, w_u, axes=1), axis=-1) # batch_size * max_n_days * max_n_msgs
mask_msgs = tf.sequence_mask(self.n_msgs_ph, maxlen=self.max_n_msgs, dtype=tf.bool, name='mask_msgs')
ninf = tf.fill(tf.shape(mask_msgs), np.NINF)
masked_score = tf.where(mask_msgs, u, ninf)
u = neural.softmax(masked_score) # batch_size * max_n_days * max_n_msgs
u = tf.where(tf.is_nan(u), tf.zeros_like(u), u) # replace nan with 0.0
u = tf.expand_dims(u, axis=-2) # batch_size * max_n_days * 1 * max_n_msgs
corpus_embed = tf.matmul(u, self.msg_embed) # batch_size * max_n_days * 1 * msg_embed_size
corpus_embed = tf.reduce_mean(corpus_embed, axis=-2) # batch_size * max_n_days * msg_embed_size
self.corpus_embed = tf.nn.dropout(corpus_embed, keep_prob=1-self.dropout_ce, name='corpus_embed')
示例7: lr_predict
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import NINF [as 别名]
def lr_predict(self, BV, data, num_sub):
BV = np.asarray(BV)
data = np.asarray(data)
fs = data.dot(BV)
n = data.shape[0]
n_class = int(fs.shape[1] / num_sub)
pres = np.ones((n, n_class)) * np.NINF
for j in range(num_sub):
f = fs[:, j: fs.shape[1]: num_sub]
assert (np.all(f.shape == pres.shape))
pres = np.fmax(pres, f)
labels = -np.ones((n, n_class - 1))
for line in range(n_class - 1):
gt = np.nonzero(pres[:, line] > pres[:, n_class - 1])[0]
labels[gt, line] = 1
return pres, labels
示例8: _get_proposal_function
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import NINF [as 别名]
def _get_proposal_function(self, model, space):
# Define proposal function for multi-fidelity
ei = ExpectedImprovement(model)
def proposal_func(x):
x_ = x[None, :]
# Map to highest fidelity
idx = np.ones((x_.shape[0], 1)) * self.high_fidelity
x_ = np.insert(x_, self.target_fidelity_index, idx, axis=1)
if space.check_points_in_domain(x_):
val = np.log(np.clip(ei.evaluate(x_)[0], 0., np.PINF))
if np.any(np.isnan(val)):
return np.array([np.NINF])
else:
return val
else:
return np.array([np.NINF])
return proposal_func
示例9: _get_proposal_function
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import NINF [as 别名]
def _get_proposal_function(self, model, space):
# Define proposal function for multi-fidelity
ei = ExpectedImprovement(model)
def proposal_func(x):
x_ = x[None, :]
# Add information source parameter into array
idx = np.ones((x_.shape[0], 1)) * self.target_information_source_index
x_ = np.insert(x_, self.source_idx, idx, axis=1)
if space.check_points_in_domain(x_):
val = np.log(np.clip(ei.evaluate(x_)[0], 0., np.PINF))
if np.any(np.isnan(val)):
return np.array([np.NINF])
else:
return val
else:
return np.array([np.NINF])
return proposal_func
示例10: test_df_rolling_corr
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import NINF [as 别名]
def test_df_rolling_corr(self):
all_data = [
list(range(10)), [1., -1., 0., 0.1, -0.1],
[1., np.inf, np.inf, -1., 0., np.inf, np.NINF, np.NINF],
[np.nan, np.inf, np.inf, np.nan, np.nan, np.nan, np.NINF, np.NZERO]
]
length = min(len(d) for d in all_data)
data = {n: d[:length] for n, d in zip(string.ascii_uppercase, all_data)}
df = pd.DataFrame(data)
for d in all_data:
other = pd.Series(d)
self._test_rolling_corr(df, other)
other_all_data = deepcopy(all_data) + [list(range(10))[::-1]]
other_all_data[1] = [-1., 1., 0., -0.1, 0.1, 0.]
other_length = min(len(d) for d in other_all_data)
other_data = {n: d[:other_length] for n, d in zip(string.ascii_uppercase, other_all_data)}
other = pd.DataFrame(other_data)
self._test_rolling_corr(df, other)
示例11: test_df_rolling_cov
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import NINF [as 别名]
def test_df_rolling_cov(self):
all_data = [
list(range(10)), [1., -1., 0., 0.1, -0.1],
[1., np.inf, np.inf, -1., 0., np.inf, np.NINF, np.NINF],
[np.nan, np.inf, np.inf, np.nan, np.nan, np.nan, np.NINF, np.NZERO]
]
length = min(len(d) for d in all_data)
data = {n: d[:length] for n, d in zip(string.ascii_uppercase, all_data)}
df = pd.DataFrame(data)
for d in all_data:
other = pd.Series(d)
self._test_rolling_cov(df, other)
other_all_data = deepcopy(all_data) + [list(range(10))[::-1]]
other_all_data[1] = [-1., 1., 0., -0.1, 0.1]
other_length = min(len(d) for d in other_all_data)
other_data = {n: d[:other_length] for n, d in zip(string.ascii_uppercase, other_all_data)}
other = pd.DataFrame(other_data)
self._test_rolling_cov(df, other)
示例12: value_bounds
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import NINF [as 别名]
def value_bounds(self, point):
"""
Returns the (lower_bound, upper_bound) tuple of a point implied by the reference set and the monotone relationship vector.
Use it to improve and understand the reference set without triggering a MonotoneError.
Returns np.inf as the second argument if there is no upper bound and np.NINF as the first argument if there is no lower bound.
Required argument:
point -- Point at which to assess upper and lower bounds.
"""
padj = point/self.scale
points_greater_than = filter(lambda x: np.allclose(x,padj) or self.__monotone_rel__(x,padj)==1, self.points.keys())
points_less_than = filter(lambda x: np.allclose(x,padj) or self.__monotone_rel__(padj,x)==1, self.points.keys())
gtbound = np.inf if self.maxval is None else self.maxval
ltbound = np.NINF if self.minval is None else self.minval
for p in points_greater_than:
gtbound = min(self.points[p],gtbound)
for p in points_less_than:
ltbound = max(self.points[p],ltbound)
return ltbound, gtbound
示例13: _norm
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import NINF [as 别名]
def _norm():
def _impl(inputs, input_types):
data = inputs[0]
dtype = input_types[0]
axis = None
keepdims = False
if len(inputs) > 3:
axis = list(_infer_shape(inputs[2]))
keepdims = bool(inputs[3])
order = inputs[1]
if order == np.inf:
return _op.reduce.max(_op.abs(data), axis=axis, keepdims=keepdims)
elif order == np.NINF:
return _op.reduce.min(_op.abs(data), axis=axis, keepdims=keepdims)
else:
reci_order = _expr.const(1.0 / order, dtype=dtype)
order = _expr.const(order)
return _op.power(_op.reduce.sum(_op.power(_op.abs(data), order),
axis=axis,
keepdims=keepdims),
reci_order)
return _impl
示例14: __init__
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import NINF [as 别名]
def __init__(self, word2index, index2word, argsDict, dataset,
data_generator, use_sourcelang=False, use_image=True):
super(Callback, self).__init__()
self.verbose = True
self.filename = "weights.hdf5"
self.save_best_only = True
self.val_loss = []
self.best_val_loss = np.inf
self.val_metric = []
self.best_val_metric = np.NINF
self.word2index = word2index
self.index2word = index2word
self.args = argsDict
# used to control early stopping on the validation data
self.wait = 0
self.patience = self.args.patience
# needed by model.predict in generate_sentences
self.use_sourcelang = use_sourcelang
self.use_image = use_image
# controversial assignment but it makes it much easier to
# do early stopping based on metrics
self.data_generator = data_generator
# this results in two file handlers for dataset (here and
# data_generator)
if not dataset:
logger.warn("No dataset given, using flickr8k")
self.dataset = h5py.File("flickr8k/dataset.h5", "r")
else:
self.dataset = h5py.File("%s/dataset.h5" % dataset, "r")
if self.args.source_vectors is not None:
self.source_dataset = h5py.File("%s/dataset.h5" % self.args.source_vectors, "r")
示例15: test_any_ninf
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import NINF [as 别名]
def test_any_ninf(self):
# atan2(+-y, -infinity) returns +-pi for finite y > 0.
assert_almost_equal(ncu.arctan2(1, np.NINF), np.pi)
assert_almost_equal(ncu.arctan2(-1, np.NINF), -np.pi)