PyTorch torch.poisson 関数
torch.poissonPyTorch でポアソン分布から乱数を生成するための関数です。
関数定義
torch.poisson(lam, generator=None, out=None)
パラメータ説明
lam- ポアソン分布のパラメータ lambda(期待値/平均値)。非負の値である必要があります。generator- 乱数生成器(オプション)out- 出力テンソル(オプション)
使用例
実例
import torch
# 単一の lambda 値を使用してランダムテンソルを生成
result1 = torch.poisson(lam=5.0, size=(3, 3))
print("lambda=5 の 3x3 ポアソン分布ランダムテンソル:")
print(result1)
# テンソルを lambda パラメータとして使用
lam_tensor = torch.tensor([1.0, 2.0, 5.0, 10.0])
result2 = torch.poisson(lam_tensor)
print("nテンソル lambda を使用したサンプリング結果:")
print(result2)
# カウントデータをシミュレーション
lam = torch.tensor([0.5, 1.0, 2.0, 5.0, 10.0])
samples = torch.poisson(lam)
print("n異なる lambda 値のポアソンサンプリング:")
for i, (l, s) in enumerate(zip(lam.tolist(), samples.tolist())):
print(f" lambda={l}: {s}")
# 単一の lambda 値を使用してランダムテンソルを生成
result1 = torch.poisson(lam=5.0, size=(3, 3))
print("lambda=5 の 3x3 ポアソン分布ランダムテンソル:")
print(result1)
# テンソルを lambda パラメータとして使用
lam_tensor = torch.tensor([1.0, 2.0, 5.0, 10.0])
result2 = torch.poisson(lam_tensor)
print("nテンソル lambda を使用したサンプリング結果:")
print(result2)
# カウントデータをシミュレーション
lam = torch.tensor([0.5, 1.0, 2.0, 5.0, 10.0])
samples = torch.poisson(lam)
print("n異なる lambda 値のポアソンサンプリング:")
for i, (l, s) in enumerate(zip(lam.tolist(), samples.tolist())):
print(f" lambda={l}: {s}")
その他の拡張
Pytorch torch リファレンスマニュアル