张量流2.1中最大似然拟合多高斯分布的采样
multigaussampler的Python项目详细描述
多高斯采样
条件概率密度函数的参数化起着至关重要的作用 用于快速生成大样本数据仿真的模拟中的角色 真实的数据集。在
一种非常简单的技术是基于概率的显式建模 目标数据集的密度函数作为通过条件的函数 核函数之和。在
包multigaussampler
提供了一个简单的Python3实现
简单算法。pdf
的模型是通过一个极大值得到的
概率密度函数的似然拟合
Gaussians,使用Adam优化器的TensorFlow实现进行优化。在
pdf
的采样也在TensorFlow中实现,以提供
CPU和GPU基础设施上的高效采样。在
示例代码
下面的代码片段在随机数据集上训练一个采样器并生成 在用于训练的相同X变量之上的y变量的随机抽样。在
import numpy as np
## Generate a random dataset as an example
nSamples = 1000
X = np.random.uniform ( -20, 10, (nSamples,4)).astype (np.float32)
y = np.random.uniform ( 0, 1, (nSamples,2)).astype (np.float32)
#from multigaussampler import MGSampler
## Creates and configure the MGSampler object
gp = MGSampler(X,y)
## Train the MGSampler on the training dataset
from tqdm import trange
progress_bar = trange ( 100 )
for iEpoch in progress_bar:
l = gp.train ( X,y )
progress_bar.set_description ( "Loss: %.1f " % l )
## Sample the obtained parametrization
gp.sample (X)
作者
卢西奥·安德里尼(法国核研究所)
- 项目
标签: