Skip to content

Commit 214366b

Browse files
committed
added simple univariate splitting example to docs
1 parent 009101a commit 214366b

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

docs/examples.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,27 @@ Examples
33

44
This section provides examples of using PyEst for various applications.
55

6+
Splitting the Univariate Standard Normal Distribuion
7+
---------------------------------------------------------------------
8+
The PyEst library makes it easy to split a univariate standard normal distribution
9+
in an optimal way, which is fundamental to the formation of so-called
10+
"splitting libraries."
11+
12+
Each splitting solution is determined by the number of mixands :math:`L` and the
13+
regularization parameter :math:`\lambda`, which controls how large the resulting
14+
mixand variances are.
15+
16+
The first time PyEst generates an optimal split solution for an
17+
:math:`(L,\lambda)` pair that hasn't been used before, it will solve an
18+
optimization problem and cache the resulting solution to disk. All future calls
19+
with this parameter pair will simply reference the cached result and thus be much
20+
faster.
21+
22+
.. literalinclude:: ../examples/example_simple_gaussian_split.py
23+
:language: python
24+
25+
.. image:: image/univariate_split.png
26+
627
Splitting and Plotting PyEst Gaussian Mixtures
728
---------------------------------------------------------------------
829

docs/image/univariate_split.png

194 KB
Loading
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import pyest.gm as gm
2+
import matplotlib.pyplot as plt
3+
import numpy as np
4+
5+
# find the optimal standard normal split solutions for different mixture
6+
# sizes and regularization parameter values
7+
L = 5
8+
lam = 1e-3
9+
p = gm.split_1d_standard_gaussian(L, lam)
10+
11+
# we can now plot each of the mixands by using the iterable feature of GaussianMixture
12+
x = np.linspace(-4, 4, 100)
13+
fig, ax = plt.subplots()
14+
for wi, mi, Pi in p:
15+
ax.plot(x, wi*gm.eval_mvnpdf(x[:, np.newaxis], mi, Pi), linestyle='--')
16+
17+
# plot the GM approximation
18+
ax.plot(x, p(x[:, np.newaxis]), linestyle='-')
19+
ax.set_xlabel('x')
20+
ax.set_ylabel('p(x)')
21+
plt.show()
22+
# # save figure at high resolution with no extra whitespace
23+
# fig.savefig('univariate_split.png', dpi=400, bbox_inches='tight')

0 commit comments

Comments
 (0)