LoginSignup
0
1

More than 3 years have passed since last update.

【備忘録】いろいろ

Last updated at Posted at 2019-11-17

PyTorch

sampler

URL: SubsetRandomSampler, BatchSampler

list(BatchSampler(SequentialSampler(range(10)), batch_size=3, drop_last=False))
[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]
list(BatchSampler(SequentialSampler(range(10)), batch_size=3, drop_last=True))
[[0, 1, 2], [3, 4, 5], [6, 7, 8]]
from torch.utils.data.sampler import BatchSampler, SubsetRandomSampler
for indecies in BatchSampler(SubsetRandomSampler(range(50)), 10, False):
    print(indecies)

[5, 23, 10, 46, 49, 22, 13, 12, 24, 16]
[38, 15, 44, 39, 7, 1, 20, 41, 37, 47]
[48, 19, 25, 30, 43, 18, 4, 9, 27, 33]
[45, 31, 32, 26, 42, 28, 2, 35, 36, 3]
[11, 8, 40, 14, 21, 6, 34, 29, 0, 17]

数値計算

log-sum-exp

URL: Wikipedia

x = np.random.uniform(size=[100, 200])
expected = logsumexp(x)
max_x = np.max(x)
actual = max_x + np.log(np.sum(np.exp(x - max_x)))
self.assertEqual(expected, actual)
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1