Skip to content

Commit bd15c49

Browse files
Merge pull request #85 from bayesml/release-0.3.0
Release 0.3.0
2 parents aa11ee8 + f8ce6be commit bd15c49

File tree

207 files changed

+8619
-26426
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

207 files changed

+8619
-26426
lines changed

README.md

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ Document Author
33
Yuta Nakahara <yuta.nakahara@aoni.waseda.jp>
44
Shota Saito <shota.s@gunma-u.ac.jp>
55
-->
6+
<div align="center">
7+
<b>Our algorithm for the meta-tree model is accepted at AISTATS 2025! Click <a href="https://bayesml.github.io/BayesML/examples/metatree_prediction_interval.html">here</a>!</b>
8+
</div>
9+
610
<img src="./doc/logos/BayesML_logo.png" width="600">
711

812
## Purpose
@@ -17,7 +21,11 @@ BayesML has the following characteristics.
1721
* Many of our learning algorithms are much faster than general-purpose Bayesian learning algorithms such as MCMC methods because they effectively use the conjugate property of a probabilistic data generative model and a prior distribution. Moreover, they are suitable for online learning.
1822
* All packages have methods to visualize the probabilistic data generative model, generated data from that model, and the posterior distribution learned from the data in 2~3 dimensional space. Thus, you can effectively understand the characteristics of probabilistic data generative models and algorithms through the generation of synthetic data and learning from them.
1923

20-
For more details, see our [website](https://yuta-nakahara.github.io/BayesML/ "BayesML's Documentation").
24+
For more details, see our [website](https://bayesml.github.io/BayesML/ "BayesML's Documentation").
25+
26+
## News
27+
28+
* Our algorithm for the meta-tree model is accepted at AISTATS 2025! A sample code is [here](https://bayesml.github.io/BayesML/examples/metatree_prediction_interval.html).
2129

2230
## Installation
2331

@@ -110,18 +118,18 @@ Different settings of a loss function yield different optimal estimates.
110118

111119
The following packages are currently available. In this library, a probabilistic data generative model, prior distribution, posterior distribution (or approximate posterior distribution), and predictive distribution (or approximate predictive distribution) are collectively called a model.
112120

113-
* [Bernoulli model](https://yuta-nakahara.github.io/BayesML/bayesml.bernoulli.html "Bayesml Bernoulli Model")
114-
* [Categorical model](https://yuta-nakahara.github.io/BayesML/bayesml.categorical.html "BayesML Categorical Model")
115-
* [Poisson model](https://yuta-nakahara.github.io/BayesML/bayesml.poisson.html "BayesML Poisson Model")
116-
* [Normal model](https://yuta-nakahara.github.io/BayesML/bayesml.normal.html "BayesML Normal Model")
117-
* [Multivariate normal model](https://yuta-nakahara.github.io/BayesML/bayesml.multivariate_normal.html "BayesML Multivariate Normal Model")
118-
* [Exponential model](https://yuta-nakahara.github.io/BayesML/bayesml.exponential.html "BayesML Exponential Model")
119-
* [Gaussian mixture model](https://yuta-nakahara.github.io/BayesML/bayesml.gaussianmixture.html "BayesML Gaussian Mixture Model")
120-
* [Linear regression model](https://yuta-nakahara.github.io/BayesML/bayesml.linearregression.html "BayesML Lenear Regression Model")
121-
* [Meta-tree model](https://yuta-nakahara.github.io/BayesML/bayesml.metatree.html "BayesML Meta-tree Model")
122-
* [Autoregressive model](https://yuta-nakahara.github.io/BayesML/bayesml.autoregressive.html "BayesML Autoregressive Model")
123-
* [Hidden Markov normal model](https://yuta-nakahara.github.io/BayesML/bayesml.hiddenmarkovnormal.html "BayesML Hidden Markov Normal Model")
124-
* [Context tree model](https://yuta-nakahara.github.io/BayesML/bayesml.contexttree.html "BayesML Context Tree Model")
121+
* [Bernoulli model](https://bayesml.github.io/BayesML/bayesml.bernoulli.html "Bayesml Bernoulli Model")
122+
* [Categorical model](https://bayesml.github.io/BayesML/bayesml.categorical.html "BayesML Categorical Model")
123+
* [Poisson model](https://bayesml.github.io/BayesML/bayesml.poisson.html "BayesML Poisson Model")
124+
* [Normal model](https://bayesml.github.io/BayesML/bayesml.normal.html "BayesML Normal Model")
125+
* [Multivariate normal model](https://bayesml.github.io/BayesML/bayesml.multivariate_normal.html "BayesML Multivariate Normal Model")
126+
* [Exponential model](https://bayesml.github.io/BayesML/bayesml.exponential.html "BayesML Exponential Model")
127+
* [Gaussian mixture model](https://bayesml.github.io/BayesML/bayesml.gaussianmixture.html "BayesML Gaussian Mixture Model")
128+
* [Linear regression model](https://bayesml.github.io/BayesML/bayesml.linearregression.html "BayesML Lenear Regression Model")
129+
* [Meta-tree model](https://bayesml.github.io/BayesML/bayesml.metatree.html "BayesML Meta-tree Model")
130+
* [Autoregressive model](https://bayesml.github.io/BayesML/bayesml.autoregressive.html "BayesML Autoregressive Model")
131+
* [Hidden Markov normal model](https://bayesml.github.io/BayesML/bayesml.hiddenmarkovnormal.html "BayesML Hidden Markov Normal Model")
132+
* [Context tree model](https://bayesml.github.io/BayesML/bayesml.contexttree.html "BayesML Context Tree Model")
125133

126134
In the future, we will add packages to deal with more complicated hierarchical models.
127135

@@ -137,8 +145,9 @@ Plain text
137145

138146
```
139147
Y. Nakahara, N. Ichijo, K. Shimada, Y. Iikubo,
140-
S. Saito, K. Kazama, T. Matsushima, BayesML Developers, ``BayesML 0.2.5,''
141-
[Online] https://github.com/yuta-nakahara/BayesML
148+
S. Saito, K. Kazama, T. Matsushima, BayesML Developers, ``BayesML,''
149+
Python package version 0.3.0,
150+
[Online] https://github.com/bayesml/BayesML
142151
```
143152

144153
BibTeX
@@ -148,8 +157,9 @@ BibTeX
148157
author = {Nakahara, Yuta and Ichijo, Naoki and Shimada, Koshi and
149158
Iikubo, Yuji and Saito, Shota and Kazama, Koki and
150159
Matsushima, Toshiyasu and {BayesML Developers}},
151-
title = {BayesML 0.2.5},
152-
howpublished = {\url{https://github.com/yuta-nakahara/BayesML}},
153-
year = {2022}
160+
title = {{BayesML}},
161+
howpublished = {Python package version 0.3.0},
162+
note = {\url{https://github.com/bayesml/BayesML}},
163+
year = {2025}
154164
}
155165
```

README_jp.md

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
Document Author
33
Yuta Nakahara <yuta.nakahara@aoni.waseda.jp>
44
-->
5+
<div align="center">
6+
<b>メタツリーモデルに対するアルゴリズムがAISTATS 2025に採択!詳細は<a href="https://bayesml.github.io/BayesML/examples/metatree_prediction_interval.html">こちら</a>!</b>
7+
</div>
8+
59
<img src="./doc/logos/BayesML_logo.png" width="600">
610

711
## 目的
@@ -16,7 +20,11 @@ BayesMLは以下の特徴を持っています.
1620
* 学習アルゴリズムの多くはデータ生成確率モデルと事前分布の共役性を効果的に用いているため,MCMC法などの汎用的なベイズ学習アルゴリズムと比べて非常に高速で,オンライン学習にも適しています.
1721
* 2~3次元空間上で,データ生成確率モデル,生成された人工データ,学習された事後分布を可視化するメソッドが全てのパッケージに備わっています.そのため,人工データの生成と学習を通じて確率モデル,アルゴリズムの特性を効果的に把握することができます.
1822

19-
詳細は[Webサイト](https://yuta-nakahara.github.io/BayesML/ "BayesML's Documentation")をご覧ください.
23+
詳細は[Webサイト](https://bayesml.github.io/BayesML/ "BayesML's Documentation")をご覧ください.
24+
25+
## ニュース
26+
27+
* メタツリーモデルに対するアルゴリズムがAISTATS 2025に採択されました.サンプルコードは[こちら](https://bayesml.github.io/BayesML/examples/metatree_prediction_interval.html)をご覧ください.
2028

2129
## インストール
2230

@@ -107,18 +115,18 @@ print(learn_model.estimate_params(loss='0-1'))
107115

108116
現在,以下のモデルに関するパッケージが利用可能です.本ライブラリでは,データ生成確率モデル,事前分布,事後分布(または近似事後分布),予測分布(または近似予測分布)を合わせてモデルと呼んでいます.
109117

110-
* [ベルヌーイモデル](https://yuta-nakahara.github.io/BayesML/bayesml.bernoulli.html "Bayesml Bernoulli Model")
111-
* [カテゴリカルモデル](https://yuta-nakahara.github.io/BayesML/bayesml.categorical.html "BayesML Categorical Model")
112-
* [ポアソンモデル](https://yuta-nakahara.github.io/BayesML/bayesml.poisson.html "BayesML Poisson Model")
113-
* [正規モデル](https://yuta-nakahara.github.io/BayesML/bayesml.normal.html "BayesML Normal Model")
114-
* [多変量正規モデル](https://yuta-nakahara.github.io/BayesML/bayesml.multivariate_normal.html "BayesML Multivariate Normal Model")
115-
* [指数モデル](https://yuta-nakahara.github.io/BayesML/bayesml.exponential.html "BayesML Exponential Model")
116-
* [混合正規モデル](https://yuta-nakahara.github.io/BayesML/bayesml.gaussianmixture.html "BayesML Gaussian Mixture Model")
117-
* [線形回帰モデル](https://yuta-nakahara.github.io/BayesML/bayesml.linearregression.html "BayesML Lenear Regression Model")
118-
* [メタツリーモデル](https://yuta-nakahara.github.io/BayesML/bayesml.metatree.html "BayesML Meta-tree Model")
119-
* [自己回帰モデル](https://yuta-nakahara.github.io/BayesML/bayesml.autoregressive.html "BayesML Autoregressive Model")
120-
* [隠れマルコフモデル](https://yuta-nakahara.github.io/BayesML/bayesml.hiddenmarkovnormal.html "BayesML Hidden Markov Normal Model")
121-
* [文脈木モデル](https://yuta-nakahara.github.io/BayesML/bayesml.contexttree.html "BayesML Context Tree Model")
118+
* [ベルヌーイモデル](https://bayesml.github.io/BayesML/bayesml.bernoulli.html "Bayesml Bernoulli Model")
119+
* [カテゴリカルモデル](https://bayesml.github.io/BayesML/bayesml.categorical.html "BayesML Categorical Model")
120+
* [ポアソンモデル](https://bayesml.github.io/BayesML/bayesml.poisson.html "BayesML Poisson Model")
121+
* [正規モデル](https://bayesml.github.io/BayesML/bayesml.normal.html "BayesML Normal Model")
122+
* [多変量正規モデル](https://bayesml.github.io/BayesML/bayesml.multivariate_normal.html "BayesML Multivariate Normal Model")
123+
* [指数モデル](https://bayesml.github.io/BayesML/bayesml.exponential.html "BayesML Exponential Model")
124+
* [混合正規モデル](https://bayesml.github.io/BayesML/bayesml.gaussianmixture.html "BayesML Gaussian Mixture Model")
125+
* [線形回帰モデル](https://bayesml.github.io/BayesML/bayesml.linearregression.html "BayesML Lenear Regression Model")
126+
* [メタツリーモデル](https://bayesml.github.io/BayesML/bayesml.metatree.html "BayesML Meta-tree Model")
127+
* [自己回帰モデル](https://bayesml.github.io/BayesML/bayesml.autoregressive.html "BayesML Autoregressive Model")
128+
* [隠れマルコフモデル](https://bayesml.github.io/BayesML/bayesml.hiddenmarkovnormal.html "BayesML Hidden Markov Normal Model")
129+
* [文脈木モデル](https://bayesml.github.io/BayesML/bayesml.contexttree.html "BayesML Context Tree Model")
122130

123131
また,今後はより複雑な階層的モデルを取り扱うパッケージを追加していく予定です.
124132

@@ -134,8 +142,9 @@ BayesMLへのコントリビューションを考えてくださってありが
134142

135143
```
136144
Y. Nakahara, N. Ichijo, K. Shimada, Y. Iikubo,
137-
S. Saito, K. Kazama, T. Matsushima, BayesML Developers, ``BayesML 0.2.5,''
138-
[Online] https://github.com/yuta-nakahara/BayesML
145+
S. Saito, K. Kazama, T. Matsushima, BayesML Developers, ``BayesML,''
146+
Python package version 0.3.0,
147+
[Online] https://github.com/bayesml/BayesML
139148
```
140149

141150
BibTeX
@@ -145,8 +154,9 @@ BibTeX
145154
author = {Nakahara, Yuta and Ichijo, Naoki and Shimada, Koshi and
146155
Iikubo, Yuji and Saito, Shota and Kazama, Koki and
147156
Matsushima, Toshiyasu and {BayesML Developers}},
148-
title = {BayesML 0.2.5},
149-
howpublished = {\url{https://github.com/yuta-nakahara/BayesML}},
150-
year = {2022}
157+
title = {{BayesML}},
158+
howpublished = {Python package version 0.3.0},
159+
note = {\url{https://github.com/bayesml/BayesML}},
160+
year = {2025}
151161
}
152162
```

bayesml/_check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Code Author
2-
# Yuta Nakahara <yuta.nakahara@aoni.waseda.jp>
2+
# Yuta Nakahara <y.nakahara@waseda.jp>
33
# Yuji Iikubo <yuji-iikubo.8@fuji.waseda.jp>
44
# Yasushi Esaki <esakiful@gmail.com>
55
# Jun Nishikawa <jun.b.nishikawa@gmail.com>

bayesml/_exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Code Author
2-
# Yuta Nakahara <yuta.nakahara@aoni.waseda.jp>
2+
# Yuta Nakahara <y.nakahara@waseda.jp>
33
class ParameterFormatError(Exception):
44
def __init__(self, value):
55
self.value = value

bayesml/autoregressive/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Document Author
2-
# Yuta Nakahara <yuta.nakahara@aoni.waseda.jp>
3-
# Koki Kazama <kokikazama@aoni.waseda.jp>
2+
# Yuta Nakahara <y.nakahara@waseda.jp>
3+
# Koki Kazama <kazama@info.shonan-it.ac.jp>
44
r"""
55
The linear autoregressive model with the normal-gamma prior distribution.
66

bayesml/autoregressive/_autoregressive.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Code Author
2-
# Yuta Nakahara <yuta.nakahara@aoni.waseda.jp>
2+
# Yuta Nakahara <y.nakahara@waseda.jp>
33
# Document Author
4-
# Yuta Nakahara <yuta.nakahara@aoni.waseda.jp>
4+
# Yuta Nakahara <y.nakahara@waseda.jp>
55
import warnings
66
import numpy as np
77
from scipy.stats import gamma as ss_gamma
@@ -475,31 +475,32 @@ def update_posterior(self,x,padding=None):
475475
If \"zeros\" is given, the zero vector is used as a initial value.
476476
"""
477477
_check.float_vec(x,'x',DataFormatError)
478-
if x.shape[0] <= self.c_degree:
478+
n = x.shape[0]
479+
if n <= self.c_degree:
479480
raise(DataFormatError("The length of x must greater than self.c_degree"))
480-
x_mat = np.zeros((x.shape[0],self.c_degree+1))
481+
x_mat = np.zeros((n,self.c_degree+1))
481482
x_mat[:,0] = 1.0
482-
for n in range(1,self.c_degree+1):
483-
x_mat[n,-n:] = x[:n]
484-
for n in range(self.c_degree+1,x.shape[0]):
485-
x_mat[n,1:] = x[n-self.c_degree:n]
483+
for i in range(1,self.c_degree+1):
484+
x_mat[i,-i:] = x[:i]
485+
for i in range(self.c_degree+1,n):
486+
x_mat[i,1:] = x[i-self.c_degree:i]
486487

487488
mu_tmp = np.array(self.hn_mu_vec)
488489
lambda_tmp = np.array(self.hn_lambda_mat)
489490
if padding == "zeros":
490491
self.hn_lambda_mat += x_mat.T @ x_mat
491492
self.hn_mu_vec[:] = np.linalg.solve(self.hn_lambda_mat,
492-
lambda_tmp @ mu_tmp[:,np.newaxis] + x_mat.T @ x[:,np.newaxis])[:,0]
493-
self.hn_alpha += x.shape[0] / 2.0
494-
self.hn_beta += (-self.hn_mu_vec[np.newaxis,:] @ self.hn_lambda_mat @ self.hn_mu_vec[:,np.newaxis]
495-
+ x @ x + mu_tmp[np.newaxis,:] @ lambda_tmp @ mu_tmp[:,np.newaxis])[0,0] / 2.0
493+
lambda_tmp @ mu_tmp + x_mat.T @ x)
494+
self.hn_alpha += n / 2.0
495+
self.hn_beta += (-self.hn_mu_vec @ self.hn_lambda_mat @ self.hn_mu_vec
496+
+ x @ x + mu_tmp @ lambda_tmp @ mu_tmp) / 2.0
496497
else:
497498
self.hn_lambda_mat += x_mat[self.c_degree:].T @ x_mat[self.c_degree:]
498499
self.hn_mu_vec[:] = np.linalg.solve(self.hn_lambda_mat,
499-
lambda_tmp @ mu_tmp[:,np.newaxis] + x_mat[self.c_degree:].T @ x[self.c_degree:,np.newaxis])[:,0]
500-
self.hn_alpha += (x.shape[0]-self.c_degree) / 2.0
501-
self.hn_beta += (-self.hn_mu_vec[np.newaxis,:] @ self.hn_lambda_mat @ self.hn_mu_vec[:,np.newaxis]
502-
+ x[self.c_degree:] @ x[self.c_degree:] + mu_tmp[np.newaxis,:] @ lambda_tmp @ mu_tmp[:,np.newaxis])[0,0] / 2.0
500+
lambda_tmp @ mu_tmp + x_mat[self.c_degree:].T @ x[self.c_degree:])
501+
self.hn_alpha += (n-self.c_degree) / 2.0
502+
self.hn_beta += (-self.hn_mu_vec @ self.hn_lambda_mat @ self.hn_mu_vec
503+
+ x[self.c_degree:] @ x[self.c_degree:] + mu_tmp @ lambda_tmp @ mu_tmp) / 2.0
503504
return self
504505

505506
def estimate_params(self,loss="squared"):

bayesml/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Code Author
2-
# Yuta Nakahara <yuta.nakahara@aoni.waseda.jp>
2+
# Yuta Nakahara <y.nakahara@waseda.jp>
33

44
from abc import ABCMeta, abstractmethod
55
import pickle

bayesml/bernoulli/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Document Author
2-
# Yuta Nakahara <yuta.nakahara@aoni.waseda.jp>
3-
# Koki Kazama <kokikazama@aoni.waseda.jp>
2+
# Yuta Nakahara <y.nakahara@waseda.jp>
3+
# Koki Kazama <kazama@info.shonan-it.ac.jp>
44
r"""
55
The Bernoulli distribution with the beta prior distribution.
66

bayesml/bernoulli/_bernoulli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Code Author
2-
# Yuta Nakahara <yuta.nakahara@aoni.waseda.jp>
2+
# Yuta Nakahara <y.nakahara@waseda.jp>
33
# Document Author
4-
# Yuta Nakahara <yuta.nakahara@aoni.waseda.jp>
4+
# Yuta Nakahara <y.nakahara@waseda.jp>
55
import warnings
66
import numpy as np
77
from scipy.stats import beta as ss_beta

bayesml/categorical/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Document Author
22
# Kohei Horinouchi <horinochi_18@toki.waseda.jp>
33
# Naoki Ichijo <1jonao@fuji.waseda.jp>
4-
# Yuta Nakahara <yuta.nakahara@aoni.waseda.jp>
5-
# Koki Kazama <kokikazama@aoni.waseda.jp>
4+
# Yuta Nakahara <y.nakahara@waseda.jp>
5+
# Koki Kazama <kazama@info.shonan-it.ac.jp>
66
r"""
77
The categorical distribution with the dirichlet prior distribution
88

0 commit comments

Comments
 (0)