利用torch.distributions生成一些满足不同分布的随机数
import torch.distributions.log_normal as log_normal
import torch.distributions.normal as normal
import torch.distributions.uniform as uniform
import torch.distributions.bernoulli as bernoulli
import matplotlib.pyplot as plt
log_nor_data = log_normal.LogNormal(torch.tensor([np.log(0.5)]),0.25)
print(type(log_nor_data))
log_nor_data = log_nor_data.sample(sample_shape=(1000,1)).flatten()
plt.hist(log_nor_data)
plt.xlabel('log_nor_data intervel')
plt.ylabel('log_nor_data frequency')
plt.show()
nor_data = normal.Normal(torch.tensor([0.5]),0.25)
print(type(nor_data))
nor_data = nor_data.sample(sample_shape=(1000,1)).flatten()
plt.hist(nor_data)
plt.xlabel('nor_data intervel')
plt.ylabel('nor_data frequency')
plt.show()
uni_data = uniform.Uniform(0,1)
print(type(uni_data))
uni_data = uni_data.sample(sample_shape=(1000,1)).flatten()
plt.hist(uni_data)
plt.xlabel('uni_data intervel')
plt.ylabel('uni_data frequency')
plt.show()
ber_data = bernoulli.Bernoulli(0.8)
print(type(ber_data))
ber_data = ber_data.sample(sample_shape=(1000,1)).flatten()
plt.hist(ber_data)
plt.xlabel('ber_data intervel')
plt.ylabel('ber_data frequency')
plt.show()