本文整理汇总了Python中theano.tensor.isnan方法的典型用法代码示例。如果您正苦于以下问题:Python tensor.isnan方法的具体用法?Python tensor.isnan怎么用?Python tensor.isnan使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类theano.tensor
的用法示例。
在下文中一共展示了tensor.isnan方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: answer_probabilities
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import isnan [as 别名]
def answer_probabilities(self, *args, **kwargs):
"""
normalise the answer groups for each question.
"""
input = self.input_layer.output(*args, **kwargs)
input_clipped = T.maximum(input, 0) # T.clip(input, 0, 1) # T.maximum(input, 0)
normalisation_denoms = T.dot(input_clipped, self.normalisation_mask) + 1e-12 # small constant to prevent division by 0
input_normalised = input_clipped / normalisation_denoms
return input_normalised
# return [input_normalised[:, s] for s in self.question_slices]
# def weighted_answer_probabilities(self, *args, **kwargs):
# answer_probabilities = self.answer_probabilities(*args, **kwargs)
# log_scale_factors = T.dot(T.log(answer_probabilities), self.scaling_mask)
# scale_factors = T.exp(T.switch(T.isnan(log_scale_factors), -np.inf, log_scale_factors)) # need NaN shielding here because 0 * -inf = NaN.
# return answer_probabilities * scale_factors
示例2: compute_ortho_grid
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import isnan [as 别名]
def compute_ortho_grid(self, res):
"""Compute the polynomial basis on the plane of the sky."""
# NOTE: I think there's a bug in Theano related to
# tt.mgrid; I get different results depending on whether the
# function is compiled using `theano.function()` or if it
# is evaluated using `.eval()`. The small perturbation to `res`
# is a hacky fix that ensures that `y` and `x` are of the
# correct length in all cases I've tested.
dx = 2.0 / (res - 0.01)
y, x = tt.mgrid[-1:1:dx, -1:1:dx]
z = tt.sqrt(1 - x ** 2 - y ** 2)
y = tt.set_subtensor(y[tt.isnan(z)], np.nan)
x = tt.reshape(x, [1, -1])
y = tt.reshape(y, [1, -1])
z = tt.reshape(z, [1, -1])
lat = tt.reshape(0.5 * np.pi - tt.arccos(y), [1, -1])
lon = tt.reshape(tt.arctan(x / z), [1, -1])
return tt.concatenate((lat, lon)), tt.concatenate((x, y, z))
示例3: compute_ortho_grid_inc_obl
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import isnan [as 别名]
def compute_ortho_grid_inc_obl(self, res, inc, obl):
"""Compute the polynomial basis on the plane of the sky, accounting
for the map inclination and obliquity."""
# See NOTE on tt.mgrid bug in `compute_ortho_grid`
dx = 2.0 / (res - 0.01)
y, x = tt.mgrid[-1:1:dx, -1:1:dx]
z = tt.sqrt(1 - x ** 2 - y ** 2)
y = tt.set_subtensor(y[tt.isnan(z)], np.nan)
x = tt.reshape(x, [1, -1])
y = tt.reshape(y, [1, -1])
z = tt.reshape(z, [1, -1])
Robl = self.RAxisAngle(tt.as_tensor_variable([0.0, 0.0, 1.0]), -obl)
Rinc = self.RAxisAngle(
tt.as_tensor_variable([tt.cos(obl), tt.sin(obl), 0.0]),
-(0.5 * np.pi - inc),
)
R = tt.dot(Robl, Rinc)
xyz = tt.dot(R, tt.concatenate((x, y, z)))
x = tt.reshape(xyz[0], [1, -1])
y = tt.reshape(xyz[1], [1, -1])
z = tt.reshape(xyz[2], [1, -1])
lat = tt.reshape(0.5 * np.pi - tt.arccos(y), [1, -1])
lon = tt.reshape(tt.arctan2(x, z), [1, -1])
return tt.concatenate((lat, lon)), tt.concatenate((x, y, z))
示例4: compute_step
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import isnan [as 别名]
def compute_step(self, parameter, previous_step):
step_sum = tensor.sum(previous_step)
not_finite = (tensor.isnan(step_sum) +
tensor.isinf(step_sum))
step = tensor.switch(
not_finite > 0, (1 - self.scaler) * parameter, previous_step)
return step, []
示例5: intensity
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import isnan [as 别名]
def intensity(self, mu, u):
"""Compute the intensity at a set of points."""
if self.udeg == 0:
mu_f = tt.reshape(mu, (-1,))
intensity = tt.ones_like(mu_f)
intensity = tt.set_subtensor(intensity[tt.isnan(mu_f)], np.nan)
return intensity
else:
basis = tt.reshape(1.0 - mu, (-1, 1)) ** np.arange(self.udeg + 1)
return -tt.dot(basis, u)