本文整理汇总了Python中chainer.utils.force_array方法的典型用法代码示例。如果您正苦于以下问题:Python utils.force_array方法的具体用法?Python utils.force_array怎么用?Python utils.force_array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chainer.utils
的用法示例。
在下文中一共展示了utils.force_array方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp_configure
# 需要导入模块: from chainer import utils [as 别名]
# 或者: from chainer.utils import force_array [as 别名]
def setUp_configure(self):
from scipy import stats
self.dist = distributions.Gamma
self.scipy_dist = stats.gamma
self.test_targets = set(
['batch_shape', 'entropy', 'event_shape', 'log_prob', 'mean',
'sample', 'support', 'variance'])
k = utils.force_array(
numpy.random.uniform(0, 5, self.shape).astype(numpy.float32))
theta = utils.force_array(
numpy.random.uniform(0, 5, self.shape).astype(numpy.float32))
self.params = {'k': k, 'theta': theta}
self.scipy_params = {'a': k, 'scale': theta}
self.support = 'positive'
示例2: setUp_configure
# 需要导入模块: from chainer import utils [as 别名]
# 或者: from chainer.utils import force_array [as 别名]
def setUp_configure(self):
from scipy import stats
self.dist = distributions.Normal
self.scipy_dist = stats.norm
self.test_targets = set([
'batch_shape', 'cdf', 'entropy', 'event_shape', 'icdf', 'log_cdf',
'log_prob', 'log_survival', 'mean', 'prob', 'sample', 'stddev',
'support', 'survival', 'variance'])
loc = utils.force_array(
numpy.random.uniform(-1, 1, self.shape).astype(numpy.float32))
if self.log_scale_option:
log_scale = utils.force_array(
numpy.random.uniform(-1, 1, self.shape).astype(numpy.float32))
scale = numpy.exp(log_scale)
self.params = {'loc': loc, 'log_scale': log_scale}
self.scipy_params = {'loc': loc, 'scale': scale}
else:
scale = utils.force_array(numpy.exp(
numpy.random.uniform(-1, 1, self.shape)).astype(numpy.float32))
self.params = {'loc': loc, 'scale': scale}
self.scipy_params = {'loc': loc, 'scale': scale}
示例3: forward_expected
# 需要导入模块: from chainer import utils [as 别名]
# 或者: from chainer.utils import force_array [as 别名]
def forward_expected(self, inputs):
x, w = inputs
if not self.use_weights:
w = None
y_expect = numpy.average(x, axis=self.axis, weights=w)
if self.keepdims:
# numpy.average does not support keepdims
axis = self.axis
if axis is None:
axis = list(six.moves.range(x.ndim))
elif isinstance(axis, int):
axis = axis,
shape = list(x.shape)
for i in six.moves.range(len(shape)):
if i in axis or i - len(shape) in axis:
shape[i] = 1
y_expect = y_expect.reshape(shape)
y_expect = utils.force_array(y_expect, dtype=self.dtype)
return y_expect,
示例4: check_double_backward
# 需要导入模块: from chainer import utils [as 别名]
# 或者: from chainer.utils import force_array [as 别名]
def check_double_backward(self, x_data, t_data, y_grad, gx_grad,
normalize=True, reduce='mean'):
# Skip too large case. That requires a long time.
if self.shape[0] == 65536:
return
if reduce == 'mean':
y_grad = utils.force_array(y_grad.sum())
def f(x, t):
return chainer.functions.sigmoid_cross_entropy(
x, t, normalize=normalize, reduce=reduce)
gradient_check.check_double_backward(
f, (x_data, t_data), y_grad, (gx_grad,),
**self.check_double_backward_options)
示例5: forward_expected
# 需要导入模块: from chainer import utils [as 别名]
# 或者: from chainer.utils import force_array [as 别名]
def forward_expected(self, inputs):
x, t = inputs
count = 0
correct = 0
x_flatten = x.ravel()
t_flatten = t.ravel()
for i in six.moves.range(t_flatten.size):
if t_flatten[i] == -1:
continue
pred = int(x_flatten[i] >= 0)
if pred == t_flatten[i]:
correct += 1
count += 1
expected = float(correct) / count
expected = force_array(expected, self.dtype)
return expected,
示例6: forward
# 需要导入模块: from chainer import utils [as 别名]
# 或者: from chainer.utils import force_array [as 别名]
def forward(self, inputs):
logit, x = inputs
self.retain_inputs((0, 1))
xp = backend.get_array_module(x)
y = logit * (x - 1) - xp.log(xp.exp(-logit) + 1)
y = utils.force_array(y)
# extreme logit
logit_isinf = xp.isinf(logit)
self.logit_ispinf = xp.bitwise_and(logit_isinf, logit > 0)
self.logit_isminf = xp.bitwise_and(logit_isinf, logit <= 0)
with numpy.errstate(divide='ignore', invalid='raise'):
y = xp.where(self.logit_ispinf, xp.log(x), y)
y = xp.where(self.logit_isminf, xp.log(1 - x), y)
if self.binary_check:
self.invalid = utils.force_array(xp.bitwise_and(x != 0, x != 1))
y[self.invalid] = -xp.inf
return utils.force_array(y, logit.dtype),
示例7: floor
# 需要导入模块: from chainer import utils [as 别名]
# 或者: from chainer.utils import force_array [as 别名]
def floor(x):
"""Elementwise floor function.
.. math::
y_i = \\lfloor x_i \\rfloor
Args:
x (:class:`~chainer.Variable` or :ref:`ndarray`): Input variable.
Returns:
~chainer.Variable: Output variable.
"""
if isinstance(x, chainer.variable.Variable):
x = x.array
xp = backend.get_array_module(x)
return chainer.as_variable(utils.force_array(xp.floor(x), x.dtype))
示例8: forward_cpu
# 需要导入模块: from chainer import utils [as 别名]
# 或者: from chainer.utils import force_array [as 别名]
def forward_cpu(self, inputs):
y = sum(w * x for w, x in zip(self.weights, inputs))
return utils.force_array(y),
示例9: forward_cpu
# 需要导入模块: from chainer import utils [as 别名]
# 或者: from chainer.utils import force_array [as 别名]
def forward_cpu(self, inputs):
y = sum(inputs)
return utils.force_array(y),
示例10: forward
# 需要导入模块: from chainer import utils [as 别名]
# 或者: from chainer.utils import force_array [as 别名]
def forward(self, inputs):
self.retain_inputs((0,))
x, = inputs
xp = cuda.get_array_module(x)
y = xp.arctanh(x)
return utils.force_array(y, dtype=x.dtype),
示例11: forward
# 需要导入模块: from chainer import utils [as 别名]
# 或者: from chainer.utils import force_array [as 别名]
def forward(self, x):
self.retain_outputs((0,))
xp = cuda.get_array_module(*x)
return utils.force_array(xp.sqrt(x[0], dtype=x[0].dtype)),
示例12: setup_chainerx
# 需要导入模块: from chainer import utils [as 别名]
# 或者: from chainer.utils import force_array [as 别名]
def setup_chainerx(self, device_name='native:0'):
self._setup(chainer.get_device(device_name))
self.f.forward = mock.MagicMock(side_effect=lambda inputs: (
utils.force_array(inputs[0] * inputs[1]),
utils.force_array(inputs[0] + inputs[1])))
示例13: test_apply_single_return_value_chainerx_cpu
# 需要导入模块: from chainer import utils [as 别名]
# 或者: from chainer.utils import force_array [as 别名]
def test_apply_single_return_value_chainerx_cpu(self):
self.setup_chainerx()
self.f.forward.side_effect = lambda inputs: (
utils.force_array(inputs[0] * inputs[1]),)
self.check_apply_single_return_value_chainerx()
示例14: test_apply_single_return_value_chainerx_gpu
# 需要导入模块: from chainer import utils [as 别名]
# 或者: from chainer.utils import force_array [as 别名]
def test_apply_single_return_value_chainerx_gpu(self):
self.setup_chainerx('cuda:0')
self.f.forward.side_effect = lambda inputs: (
utils.force_array(inputs[0] * inputs[1]),)
self.check_apply_single_return_value_chainerx()
示例15: setUp_configure
# 需要导入模块: from chainer import utils [as 别名]
# 或者: from chainer.utils import force_array [as 别名]
def setUp_configure(self):
from scipy import stats
self.dist = distributions.Cauchy
self.scipy_dist = stats.cauchy
self.test_targets = set(['batch_shape', 'cdf', 'entropy',
'event_shape', 'icdf', 'log_prob',
'support'])
loc = utils.force_array(
numpy.random.uniform(-1, 1, self.shape).astype(numpy.float32))
scale = utils.force_array(numpy.exp(
numpy.random.uniform(-1, 1, self.shape)).astype(numpy.float32))
self.params = {'loc': loc, 'scale': scale}
self.scipy_params = {'loc': loc, 'scale': scale}