本文整理汇总了Python中chainer.functions.exp方法的典型用法代码示例。如果您正苦于以下问题:Python functions.exp方法的具体用法?Python functions.exp怎么用?Python functions.exp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chainer.functions
的用法示例。
在下文中一共展示了functions.exp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import exp [as 别名]
def __call__(self, state):
h = state
for layer in self.hidden_layers:
h = F.relu(layer(h))
v = self.v(h)
mu = self.mu(h)
if self.scale_mu:
mu = scale_by_tanh(mu, high=self.action_space.high,
low=self.action_space.low)
mat_diag = F.exp(self.mat_diag(h))
if hasattr(self, 'mat_non_diag'):
mat_non_diag = self.mat_non_diag(h)
tril = lower_triangular_matrix(mat_diag, mat_non_diag)
mat = F.matmul(tril, tril, transb=True)
else:
mat = F.expand_dims(mat_diag ** 2, axis=2)
return QuadraticActionValue(
mu, mat, v, min_action=self.action_space.low,
max_action=self.action_space.high)
示例2: _s_t_functions
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import exp [as 别名]
def _s_t_functions(self, x, adj):
y = self.rgcn(x, adj)
batch_size = x.shape[0]
if self.apply_batch_norm:
y = self.batch_norm(y)
y = self.lin1(y)
y = F.tanh(y)
y = self.lin2(y) * F.exp(self.scale_factor*2)
s = y[:, :self.out_size]
t = y[:, self.out_size:]
s = F.sigmoid(s + 2)
t = F.reshape(t, [batch_size, 1, self.out_size])
t = F.broadcast_to(t, [batch_size, int(self.num_nodes / self.num_masked_cols), self.out_size])
s = F.reshape(s, [batch_size, 1, self.out_size])
s = F.broadcast_to(s, [batch_size, int(self.num_nodes / self.num_masked_cols), self.out_size])
return s, t
示例3: predict
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import exp [as 别名]
def predict(self, input_x):
output = self.predictor(input_x)
batch_size, input_channel, input_h, input_w = input_x.shape
batch_size, _, grid_h, grid_w = output.shape
x, y, w, h, conf, prob = F.split_axis(F.reshape(output, (batch_size, self.predictor.n_boxes, self.predictor.n_classes+5, grid_h, grid_w)), (1, 2, 3, 4, 5), axis=2)
x = F.sigmoid(x) # xのactivation
y = F.sigmoid(y) # yのactivation
conf = F.sigmoid(conf) # confのactivation
prob = F.transpose(prob, (0, 2, 1, 3, 4))
prob = F.softmax(prob) # probablitiyのacitivation
prob = F.transpose(prob, (0, 2, 1, 3, 4))
# x, y, w, hを絶対座標へ変換
x_shift = Variable(np.broadcast_to(np.arange(grid_w, dtype=np.float32), x.shape))
y_shift = Variable(np.broadcast_to(np.arange(grid_h, dtype=np.float32).reshape(grid_h, 1), y.shape))
w_anchor = Variable(np.broadcast_to(np.reshape(np.array(self.anchors, dtype=np.float32)[:, 0], (self.predictor.n_boxes, 1, 1, 1)), w.shape))
h_anchor = Variable(np.broadcast_to(np.reshape(np.array(self.anchors, dtype=np.float32)[:, 1], (self.predictor.n_boxes, 1, 1, 1)), h.shape))
#x_shift.to_gpu(), y_shift.to_gpu(), w_anchor.to_gpu(), h_anchor.to_gpu()
box_x = (x + x_shift) / grid_w
box_y = (y + y_shift) / grid_h
box_w = F.exp(w) * w_anchor / grid_w
box_h = F.exp(h) * h_anchor / grid_h
return box_x, box_y, box_w, box_h, conf, prob
示例4: prob
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import exp [as 别名]
def prob(self, x):
return F.exp(self.log_prob(x))
示例5: _lossfun
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import exp [as 别名]
def _lossfun(self,
entropy, vs_pred, log_probs,
vs_pred_old, log_probs_old,
advs, vs_teacher):
prob_ratio = F.exp(log_probs - log_probs_old)
loss_policy = - F.mean(F.minimum(
prob_ratio * advs,
F.clip(prob_ratio, 1 - self.clip_eps, 1 + self.clip_eps) * advs))
if self.clip_eps_vf is None:
loss_value_func = F.mean_squared_error(vs_pred, vs_teacher)
else:
loss_value_func = F.mean(F.maximum(
F.square(vs_pred - vs_teacher),
F.square(_elementwise_clip(vs_pred,
vs_pred_old - self.clip_eps_vf,
vs_pred_old + self.clip_eps_vf)
- vs_teacher)
))
loss_entropy = -F.mean(entropy)
self.value_loss_record.append(float(loss_value_func.array))
self.policy_loss_record.append(float(loss_policy.array))
loss = (
loss_policy
+ self.value_func_coef * loss_value_func
+ self.entropy_coef * loss_entropy
)
return loss
示例6: __call__
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import exp [as 别名]
def __call__(self):
"""Return a temperature as a chainer.Variable."""
return F.exp(self.log_temperature)
示例7: _compute_gain
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import exp [as 别名]
def _compute_gain(self, log_prob, log_prob_old, entropy, advs):
"""Compute a gain to maximize."""
prob_ratio = F.exp(log_prob - log_prob_old)
mean_entropy = F.mean(entropy)
surrogate_gain = F.mean(prob_ratio * advs)
return surrogate_gain + self.entropy_coef * mean_entropy
示例8: forward
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import exp [as 别名]
def forward(self, x):
y1 = F.exp(x)
return y1
示例9: main
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import exp [as 别名]
def main():
np.random.seed(314)
x = np.random.rand(6, 4).astype(np.float32)
s_int = np.array(-10)
s_float = np.array(10.0)
testtools.generate_testcase(Sin(), [x], subname='sin')
testtools.generate_testcase(Sinh(), [x], subname='sinh')
testtools.generate_testcase(Sign(), [x], subname='sign')
testtools.generate_testcase(Cos(), [x], subname='cos')
testtools.generate_testcase(Cosh(), [x], subname='cosh')
testtools.generate_testcase(Tan(), [x], subname='tan')
testtools.generate_testcase(Tanh(), [x], subname='tanh')
testtools.generate_testcase(ArcSin(), [x], subname='arcsin')
testtools.generate_testcase(ArcCos(), [x], subname='arccos')
testtools.generate_testcase(ArcTan(), [x], subname='arctan')
testtools.generate_testcase(Exp(), [x], subname='exp')
testtools.generate_testcase(Log(), [x], subname='log')
testtools.generate_testcase(Clip(), [x], subname='clip')
testtools.generate_testcase(ClipNp(), [x], subname='clip_np')
testtools.generate_testcase(Abs(), [x], subname='abs')
testtools.generate_testcase(AbsNp(), [x], subname='abs_np')
testtools.generate_testcase(Sqrt(), [x], subname='sqrt')
testtools.generate_testcase(Round(), [x], subname='round')
testtools.generate_testcase(AbsBuiltin(), [x], subname='abs_builtin')
testtools.generate_testcase(AbsBuiltin(), [s_float], subname='abs_builtin_scalar_float')
testtools.generate_testcase(AbsBuiltin(), [s_int], subname='abs_builtin_scalar_int')
示例10: gaussian_kl
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import exp [as 别名]
def gaussian_kl(params0, params1):
(mean0, logstd0), (mean1, logstd1) = params0, params1
assert mean0.shape == logstd0.shape == mean1.shape == logstd1.shape
return F.sum(
logstd1 - logstd0 + (F.square(F.exp(logstd0)) + F.square(mean0 - mean1)) / (
2.0 * F.square(F.exp(logstd1))) - 0.5,
axis=1
)
示例11: categorical_kl
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import exp [as 别名]
def categorical_kl(params0, params1):
params0 = params0[0]
params1 = params1[0]
assert params0.shape == params1.shape
a0 = params0 - F.tile(F.max(params0, axis=1, keepdims=True), (1, 4))
a1 = params1 - F.tile(F.max(params1, axis=1, keepdims=True), (1, 4))
ea0 = F.exp(a0)
ea1 = F.exp(a1)
z0 = F.tile(F.sum(ea0, axis=1, keepdims=True), (1, 4))
z1 = F.tile(F.sum(ea1, axis=1, keepdims=True), (1, 4))
p0 = ea0 / z0
return F.sum(p0 * (a0 - F.log(z0) - a1 + F.log(z1)), axis=1)
示例12: _compute_ppo_loss
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import exp [as 别名]
def _compute_ppo_loss(self, obs, acts, at, vt, old_params):
params = self._pi_f(obs)
cv = F.flatten(self._vf_f(obs))
ratio = F.exp(self._logp(params, acts) - self._logp(old_params, acts))
surr1 = ratio * at
surr2 = F.clip(ratio, 1 - self._ppo_clipparam, 1 + self._ppo_clipparam) * at
ppo_surr_loss = (
-sym_mean(F.minimum(surr1, surr2))
+ self._ppo_klcoeff * sym_mean(self.kl(old_params, params))
+ sym_mean(F.square(cv - vt))
)
return ppo_surr_loss
示例13: _pi_logp
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import exp [as 别名]
def _pi_logp(self, obs, acts):
mean, logstd = self._pi_f(obs)
return (
- 0.5 * np.log(2.0 * np.pi) * acts.shape[1]
- 0.5 * F.sum(F.square((acts - mean) / (F.exp(logstd)) + 1e-8), axis=1)
- F.sum(logstd, axis=1)
)
示例14: _logp
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import exp [as 别名]
def _logp(self, params, acts):
mean, logstd = params
return (
- 0.5 * np.log(2.0 * np.pi) * acts.shape[1]
- 0.5 * F.sum(F.square((acts - mean) / (F.exp(logstd)) + 1e-8), axis=1)
- F.sum(logstd, axis=1)
)
示例15: setUp
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import exp [as 别名]
def setUp(self):
cuda.memory_pool.free_all_blocks()
self.h = function_hooks.CupyMemoryProfileHook()
f1 = functions.exp
f2 = functions.relu
self.x = numpy.random.uniform(-0.1, 0.1, (3, 5)).astype(numpy.float32)
x = cuda.to_gpu(self.x)
with self.h:
f1(chainer.Variable(x))
f1(chainer.Variable(x))
f2(chainer.Variable(x))
f2(chainer.Variable(x))