pos python_Python numpy.isposinf() 使用实例

The following are code examples for showing how to use . They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don’t like. You can also save this page to your account.

Example 1

def __add__(self, other):

assert isinstance(other, ShapeFunction), "Can only add other shape function"

assert self.name == other.name, "Cannot add shapes of different features"

new_splits = self.splits.copy()

new_vals = self.values.copy()

for split, val in zip(other.splits, other.values):

idx = np.searchsorted(new_splits, split, side='right')

new_val = val

if split in new_splits:

idx_2 = np.argwhere(new_splits == split)

new_vals[idx_2] = new_vals[idx_2] + new_val

elif idx == len(new_splits) and (~np.isposinf(split)):

new_splits = np.append(new_splits, split)

new_vals = np.append(new_vals, new_val)

elif np.isposinf(split):

new_vals[-1] = new_vals[-1] + new_val

else:

new_splits = np.insert(new_splits, idx, split)

new_vals = np.insert(new_vals, idx, new_val)

return ShapeFunction(new_splits, new_vals, self.name)

Example 2

def get_mask_invalid(matrix):

mask = np.isposinf(matrix) + np.isneginf(matrix) + np.isnan(matrix)

return mask

Example 3

def set_logp_to_neg_inf(X, logp, bounds):

"""Set `logp` to negative infinity when `X` is outside the allowed bounds.

# Arguments

X: tensorflow.Tensor

The variable to apply the bounds to

logp: tensorflow.Tensor

The log probability corrosponding to `X`

bounds: list of `Region` objects

The regions corrosponding to allowed regions of `X`

# Returns

logp: tensorflow.Tensor

The newly bounded log probability

"""

conditions = []

for l, u in bounds:

lower_is_neg_inf = not isinstance(l, tf.Tensor) and np.isneginf(l)

upper_is_pos_inf = not isinstance(u, tf.Tensor) and np.isposinf(u)

if not lower_is_neg_inf and upper_is_pos_inf:

conditions.append(tf.greater(X, l))

elif lower_is_neg_inf and not upper_is_pos_inf:

conditions.append(tf.less(X, u))

elif not (lower_is_neg_inf or upper_is_pos_inf):

conditions.append(tf.logical_and(tf.greater(X, l), tf.less(X, u)))

if len(conditions) > 0:

is_inside_bounds = conditions[0]

for condition in conditions[1:]:

is_inside_bounds = tf.logical_or(is_inside_bounds, condition)

logp = tf.select(

is_inside_bounds,

logp,

tf.fill(tf.shape(X), config.dtype(-np.inf))

)

return logp

Example 4

def _numpy(self, data, weights, shape):

q = self.quantity(data)

self._checkNPQuantity(q, shape)

self._checkNPWeights(weights, shape)

weights = self._makeNPWeights(weights, shape)

newentries = weights.sum()

import numpy

selection = numpy.isnan(q)

numpy.bitwise_not(selection, selection)

subweights = weights.copy()

subweights[selection] = 0.0

self.nanflow._numpy(data, subweights, shape)

# switch to float here like in bin.py else numpy throws

# TypeError on trivial integer cases such as:

# >>> q = numpy.array([1,2,3,4])

# >>> np.divide(q,1,q)

# >>> np.floor(q,q)

q = numpy.array(q, dtype=numpy.float64)

neginfs = numpy.isneginf(q)

posinfs = numpy.isposinf(q)

numpy.subtract(q, self.origin, q)

numpy.divide(q, self.binWidth, q)

numpy.floor(q, q)

q = numpy.array(q, dtype=numpy.int64)

q[neginfs] = LONG_MINUSINF

q[posinfs] = LONG_PLUSINF

selected = q[weights > 0.0]

selection = numpy.empty(q.shape, dtype=numpy.bool)

for index in numpy.unique(selected):

if index != LONG_NAN:

bin = self.bins.get(index)

if bin is None:

bin = self.value.zero()

self.bins[index] = bin

numpy.not_equal(q, index, selection)

subweights[:] = weights

subweights[selection] = 0.0

bin._numpy(data, subweights, shape)

# no possibility of exception from here on out (for rollback)

self.entries += float(newentries)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值