/Pydpm

A Python Library for Deep Probabilistic Models

Primary LanguagePythonApache License 2.0Apache-2.0

Pydpm

PyPI GitHub

A python library focuses on constructing deep probabilistic models on GPU. Pydpm provides efficient distribution sampling functions and has included lots of implemented probabilistic models.

Image text

Install

This library can be installed under both Windows and Linux systems.

$ pip install pydpm

Under Windows system, we recommed to install Visual Studio 2019 and latest CUDA Toolkit. The combination of VS2019(with MSVC v142) and CUDA 11.5 has been tested in pydpm2.0.

Create Probabilistic Model

Model list

Model list is as following:

Probabilistic Model Name Abbreviation Paper Link
Latent Dirichlet Allocation LDA Link
Poisson Factor Analysis PFA Link
Poisson Gamma Belief Network PGBN Link
Convolutional Poisson Factor Analysis CPFA Link
Convolutional Poisson Gamma Belief Network CPGBN Link
Poisson Gamma Dynamical Systems PGDS Link
Deep Poisson Gamma Dynamical Systems DPGDS Link
Dirichlet Belief Networks DirBN Link
Deep Poisson Factor Analysis DPFA Link
Word Embeddings Deep Topic Model WEDTM Link

More probabilistic models will be further included in pydpm/_model/...

Demo

Create a PGBN model:

from pydpm._model import PGBN

# create the model and deploy it on gpu or cpu
model = PGBN([128, 64, 32], device='gpu')
model.initial(train_data)
train_local_params = model.train(100, train_data)
train_local_params = model.test(100, train_data)
test_local_params = model.test(100, test_data)

# evaluate the model with classification accuracy
# the demo accuracy can achieve 0.8549
results = ACC(train_local_params.Theta[0], test_local_params.Theta[0], train_label, test_label, 'SVM')

# save the model after training
model.save()

More model demos can be found in pydpm/examples/...

Source data can be found in Link

Sample on GPU

Function list

The parameters of partial distribution functions are as following:

Function Parameters List
Normal mean, std, times
Multinomial count, prob, times
Poisson lambda, times
Gamma shape, scale, times
Beta alpha, beta, times
F n1, n2, times
StudentT n, times
Dirichlet alpha, times
Crt point, p, times
Weibull shape, scale, times
Chisquare n, times
Geometric p, times
... ...

Example

from pydpm._sampler import Basic_Sampler

sampler = Basic_Sampler('gpu')
a = sampler.gamma(np.ones(100)*5, 1, times=10)
b = sampler.gamma(np.ones([100, 100])*5, 1, times=10)

More sampler demos can be found in pydpm/_sampler/...

Compare

Compare the sampling speed of distribution functions with numpy: Image text
The compared code can be found in pydpm/example/Sampler_Speed_Demo.py

Compare the sampling speed of distribution functions with tensorflow and torch: Image text
The compared code can be found in pydpm/example/Sampler_Speed_Demo.py

Contact

License: Apache License Version 2.0

Contact: Chaojie Wang xd_silly@163.com, Wei Zhao 13279389260@163.com, Jiawen Wu wjw19960807@163.com

Copyright (c), 2020, Chaojie Wang, Wei Zhao, Jiawen Wu, Xinyang Liu, Jie Ren, Yewen Li, Hao Zhang, Bo Chen and Mingyuan Zhou