dmx-learn 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dmx_learn-1.0.0/LICENSE +27 -0
- dmx_learn-1.0.0/MANIFEST.in +10 -0
- dmx_learn-1.0.0/PKG-INFO +81 -0
- dmx_learn-1.0.0/README.md +55 -0
- dmx_learn-1.0.0/pyproject.toml +53 -0
- dmx_learn-1.0.0/setup.cfg +4 -0
- dmx_learn-1.0.0/src/dmx/__init__.py +3 -0
- dmx_learn-1.0.0/src/dmx/arithmetic.py +28 -0
- dmx_learn-1.0.0/src/dmx/bexamples/dpm_auto_example1.py +19 -0
- dmx_learn-1.0.0/src/dmx/bexamples/dpm_auto_example2.py +39 -0
- dmx_learn-1.0.0/src/dmx/bstats/__init__.py +491 -0
- dmx_learn-1.0.0/src/dmx/bstats/bernoulli.py +253 -0
- dmx_learn-1.0.0/src/dmx/bstats/bestimation.py +267 -0
- dmx_learn-1.0.0/src/dmx/bstats/beta.py +69 -0
- dmx_learn-1.0.0/src/dmx/bstats/catdirichlet.py +84 -0
- dmx_learn-1.0.0/src/dmx/bstats/categorical.py +293 -0
- dmx_learn-1.0.0/src/dmx/bstats/composite.py +294 -0
- dmx_learn-1.0.0/src/dmx/bstats/conditional.py +298 -0
- dmx_learn-1.0.0/src/dmx/bstats/dirac.py +134 -0
- dmx_learn-1.0.0/src/dmx/bstats/dirichlet.py +335 -0
- dmx_learn-1.0.0/src/dmx/bstats/dmvn.py +278 -0
- dmx_learn-1.0.0/src/dmx/bstats/dpm.py +428 -0
- dmx_learn-1.0.0/src/dmx/bstats/exponential.py +209 -0
- dmx_learn-1.0.0/src/dmx/bstats/gamma.py +172 -0
- dmx_learn-1.0.0/src/dmx/bstats/gaussian.py +292 -0
- dmx_learn-1.0.0/src/dmx/bstats/geometric.py +259 -0
- dmx_learn-1.0.0/src/dmx/bstats/ignored.py +122 -0
- dmx_learn-1.0.0/src/dmx/bstats/intrange.py +329 -0
- dmx_learn-1.0.0/src/dmx/bstats/mixture.py +382 -0
- dmx_learn-1.0.0/src/dmx/bstats/mvngamma.py +108 -0
- dmx_learn-1.0.0/src/dmx/bstats/normgamma.py +96 -0
- dmx_learn-1.0.0/src/dmx/bstats/nulldist.py +154 -0
- dmx_learn-1.0.0/src/dmx/bstats/optional.py +287 -0
- dmx_learn-1.0.0/src/dmx/bstats/pdist.py +194 -0
- dmx_learn-1.0.0/src/dmx/bstats/poisson.py +259 -0
- dmx_learn-1.0.0/src/dmx/bstats/sequence.py +340 -0
- dmx_learn-1.0.0/src/dmx/bstats/setdist.py +230 -0
- dmx_learn-1.0.0/src/dmx/bstats/symdirichlet.py +49 -0
- dmx_learn-1.0.0/src/dmx/mpi4py/bstats/__init__.py +285 -0
- dmx_learn-1.0.0/src/dmx/mpi4py/stats/__init__.py +309 -0
- dmx_learn-1.0.0/src/dmx/mpi4py/utils/automatic.py +69 -0
- dmx_learn-1.0.0/src/dmx/mpi4py/utils/bestimation.py +177 -0
- dmx_learn-1.0.0/src/dmx/mpi4py/utils/estimation.py +296 -0
- dmx_learn-1.0.0/src/dmx/mpi4py/utils/humap.py +87 -0
- dmx_learn-1.0.0/src/dmx/mpi4py/utils/optsutil.py +16 -0
- dmx_learn-1.0.0/src/dmx/stats/__init__.py +692 -0
- dmx_learn-1.0.0/src/dmx/stats/binomial.py +608 -0
- dmx_learn-1.0.0/src/dmx/stats/categorical.py +515 -0
- dmx_learn-1.0.0/src/dmx/stats/catmultinomial.py +731 -0
- dmx_learn-1.0.0/src/dmx/stats/composite.py +569 -0
- dmx_learn-1.0.0/src/dmx/stats/conditional.py +839 -0
- dmx_learn-1.0.0/src/dmx/stats/dirac_length.py +803 -0
- dmx_learn-1.0.0/src/dmx/stats/dirichlet.py +711 -0
- dmx_learn-1.0.0/src/dmx/stats/dmvn.py +606 -0
- dmx_learn-1.0.0/src/dmx/stats/dmvn_mixture.py +887 -0
- dmx_learn-1.0.0/src/dmx/stats/exponential.py +454 -0
- dmx_learn-1.0.0/src/dmx/stats/gamma.py +511 -0
- dmx_learn-1.0.0/src/dmx/stats/gaussian.py +504 -0
- dmx_learn-1.0.0/src/dmx/stats/geometric.py +455 -0
- dmx_learn-1.0.0/src/dmx/stats/gmm.py +780 -0
- dmx_learn-1.0.0/src/dmx/stats/heterogeneous_mixture.py +817 -0
- dmx_learn-1.0.0/src/dmx/stats/hidden_association.py +424 -0
- dmx_learn-1.0.0/src/dmx/stats/hidden_markov.py +1859 -0
- dmx_learn-1.0.0/src/dmx/stats/hmixture.py +785 -0
- dmx_learn-1.0.0/src/dmx/stats/icltree.py +407 -0
- dmx_learn-1.0.0/src/dmx/stats/ignored.py +300 -0
- dmx_learn-1.0.0/src/dmx/stats/int_edit_setdist.py +560 -0
- dmx_learn-1.0.0/src/dmx/stats/int_edit_stepsetdist.py +470 -0
- dmx_learn-1.0.0/src/dmx/stats/int_hidden_association.py +886 -0
- dmx_learn-1.0.0/src/dmx/stats/int_markovchain.py +707 -0
- dmx_learn-1.0.0/src/dmx/stats/int_plsi.py +870 -0
- dmx_learn-1.0.0/src/dmx/stats/int_spike.py +483 -0
- dmx_learn-1.0.0/src/dmx/stats/intmultinomial.py +639 -0
- dmx_learn-1.0.0/src/dmx/stats/intrange.py +495 -0
- dmx_learn-1.0.0/src/dmx/stats/intsetdist.py +404 -0
- dmx_learn-1.0.0/src/dmx/stats/jmixture.py +649 -0
- dmx_learn-1.0.0/src/dmx/stats/lda.py +822 -0
- dmx_learn-1.0.0/src/dmx/stats/log_gaussian.py +357 -0
- dmx_learn-1.0.0/src/dmx/stats/look_back_hmm.py +874 -0
- dmx_learn-1.0.0/src/dmx/stats/markovchain.py +826 -0
- dmx_learn-1.0.0/src/dmx/stats/mixture.py +696 -0
- dmx_learn-1.0.0/src/dmx/stats/mvn.py +404 -0
- dmx_learn-1.0.0/src/dmx/stats/null_dist.py +297 -0
- dmx_learn-1.0.0/src/dmx/stats/optional.py +518 -0
- dmx_learn-1.0.0/src/dmx/stats/pdist.py +435 -0
- dmx_learn-1.0.0/src/dmx/stats/poisson.py +336 -0
- dmx_learn-1.0.0/src/dmx/stats/rdd_sampler.py +99 -0
- dmx_learn-1.0.0/src/dmx/stats/select.py +224 -0
- dmx_learn-1.0.0/src/dmx/stats/sequence.py +624 -0
- dmx_learn-1.0.0/src/dmx/stats/setdist.py +396 -0
- dmx_learn-1.0.0/src/dmx/stats/sparse_markov_transform.py +606 -0
- dmx_learn-1.0.0/src/dmx/stats/spearman_rho.py +312 -0
- dmx_learn-1.0.0/src/dmx/stats/ss_mixture.py +544 -0
- dmx_learn-1.0.0/src/dmx/stats/tree_hmm.py +1602 -0
- dmx_learn-1.0.0/src/dmx/stats/vmf.py +498 -0
- dmx_learn-1.0.0/src/dmx/stats/weighted.py +247 -0
- dmx_learn-1.0.0/src/dmx/utils/__init__.py +1 -0
- dmx_learn-1.0.0/src/dmx/utils/automatic.py +436 -0
- dmx_learn-1.0.0/src/dmx/utils/builder.py +83 -0
- dmx_learn-1.0.0/src/dmx/utils/estimation.py +459 -0
- dmx_learn-1.0.0/src/dmx/utils/htsne.py +496 -0
- dmx_learn-1.0.0/src/dmx/utils/humap.py +69 -0
- dmx_learn-1.0.0/src/dmx/utils/metrics.py +173 -0
- dmx_learn-1.0.0/src/dmx/utils/optsutil.py +242 -0
- dmx_learn-1.0.0/src/dmx/utils/pvalues.py +102 -0
- dmx_learn-1.0.0/src/dmx/utils/special.py +148 -0
- dmx_learn-1.0.0/src/dmx/utils/vector.py +688 -0
- dmx_learn-1.0.0/src/dmx_learn.egg-info/PKG-INFO +81 -0
- dmx_learn-1.0.0/src/dmx_learn.egg-info/SOURCES.txt +111 -0
- dmx_learn-1.0.0/src/dmx_learn.egg-info/dependency_links.txt +1 -0
- dmx_learn-1.0.0/src/dmx_learn.egg-info/not-zip-safe +1 -0
- dmx_learn-1.0.0/src/dmx_learn.egg-info/requires.txt +13 -0
- dmx_learn-1.0.0/src/dmx_learn.egg-info/top_level.txt +1 -0
dmx_learn-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Copyright (c) 2025, Adam Walder
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this
|
|
8
|
+
list of conditions and the following disclaimer.
|
|
9
|
+
|
|
10
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
|
12
|
+
and/or other materials provided with the distribution.
|
|
13
|
+
|
|
14
|
+
* Neither the name of the copyright holder nor the names of its
|
|
15
|
+
contributors may be used to endorse or promote products derived from
|
|
16
|
+
this software without specific prior written permission.
|
|
17
|
+
|
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
19
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
20
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
21
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
22
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
23
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
24
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
25
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
26
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
27
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
dmx_learn-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dmx-learn
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A package for estimating heterogeneous probability density functions.
|
|
5
|
+
Author: Adam Walder
|
|
6
|
+
License: BSD
|
|
7
|
+
Keywords: machine learning,density estimation,statistics,heterogeneous data
|
|
8
|
+
Classifier: Programming Language :: Python
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Requires-Python: >=3.10
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: mpmath
|
|
15
|
+
Requires-Dist: numba
|
|
16
|
+
Requires-Dist: numpy
|
|
17
|
+
Requires-Dist: pandas
|
|
18
|
+
Requires-Dist: pyspark
|
|
19
|
+
Requires-Dist: scipy
|
|
20
|
+
Provides-Extra: test
|
|
21
|
+
Requires-Dist: pytest; extra == "test"
|
|
22
|
+
Provides-Extra: optional
|
|
23
|
+
Requires-Dist: mpi4py; extra == "optional"
|
|
24
|
+
Requires-Dist: umap-learn; extra == "optional"
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
dmx-learn - (Distributed Mixture Learning) A package for distributed heterogeneous density estimation. With only a few lines of code you can specify and fit complex models on variable-length heterogenous data.
|
|
28
|
+
|
|
29
|
+
--------------------------------------------------------------------------------
|
|
30
|
+
|
|
31
|
+
## 📚 Documentation
|
|
32
|
+
View the full documentation on **Read the Docs**:
|
|
33
|
+
|
|
34
|
+
👉 [https://dmx-learn.readthedocs.io/en/latest/](https://dmx-learn.readthedocs.io/en/latest/)
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
User installation with pip
|
|
39
|
+
```
|
|
40
|
+
> pip install --user /path/to/package
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
## Building with mpi4py and umap-learn
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
> cd /path/to/package
|
|
48
|
+
> pip install --user .[optional]
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Stats Examples
|
|
52
|
+
Examples using `stats` distributions that run locally are located in ./dmx/examples/
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
> export PYHONPATH=$PYTHONPATH:/path./to/dmx-learn
|
|
56
|
+
> PYTHONPATH=/path/to/package/ python ./dmx/examples/stats_examples/mixture_example.py
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Running with Spark
|
|
60
|
+
Examples that run with Apache Spark are located in./dmx/examples_spark/
|
|
61
|
+
|
|
62
|
+
First build a wheel
|
|
63
|
+
```
|
|
64
|
+
> cd /path/to/dmx-learn
|
|
65
|
+
> pip install setuptools wheel
|
|
66
|
+
> python setup.py bdist_wheel
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Run the example with below
|
|
70
|
+
```
|
|
71
|
+
> /path/to/spark/bin/spark-submit --master local[*] --py-files /path/to/package/dist/dmx-learn-0.1.8.4-py3-none-any.whl ./dmx/examples_spark/mixture_example.py
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Running with MPI4PY
|
|
75
|
+
Examples that run with mpi4py are located in ./dmx/mpi4py/examples/
|
|
76
|
+
|
|
77
|
+
Below will run the example ./dmx/mpi4py/examples/estimation_example.py with 4 cores.
|
|
78
|
+
```
|
|
79
|
+
> export PYHONPATH=$PYTHONPATH:/path./to/dmx-learn
|
|
80
|
+
> mpiexec -n 4 python /path/to/package/dmx/mpi4py/examples/estimation_example.py
|
|
81
|
+
```
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
dmx-learn - (Distributed Mixture Learning) A package for distributed heterogeneous density estimation. With only a few lines of code you can specify and fit complex models on variable-length heterogenous data.
|
|
2
|
+
|
|
3
|
+
--------------------------------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
## 📚 Documentation
|
|
6
|
+
View the full documentation on **Read the Docs**:
|
|
7
|
+
|
|
8
|
+
👉 [https://dmx-learn.readthedocs.io/en/latest/](https://dmx-learn.readthedocs.io/en/latest/)
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
User installation with pip
|
|
13
|
+
```
|
|
14
|
+
> pip install --user /path/to/package
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
## Building with mpi4py and umap-learn
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
> cd /path/to/package
|
|
22
|
+
> pip install --user .[optional]
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Stats Examples
|
|
26
|
+
Examples using `stats` distributions that run locally are located in ./dmx/examples/
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
> export PYHONPATH=$PYTHONPATH:/path./to/dmx-learn
|
|
30
|
+
> PYTHONPATH=/path/to/package/ python ./dmx/examples/stats_examples/mixture_example.py
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Running with Spark
|
|
34
|
+
Examples that run with Apache Spark are located in./dmx/examples_spark/
|
|
35
|
+
|
|
36
|
+
First build a wheel
|
|
37
|
+
```
|
|
38
|
+
> cd /path/to/dmx-learn
|
|
39
|
+
> pip install setuptools wheel
|
|
40
|
+
> python setup.py bdist_wheel
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Run the example with below
|
|
44
|
+
```
|
|
45
|
+
> /path/to/spark/bin/spark-submit --master local[*] --py-files /path/to/package/dist/dmx-learn-0.1.8.4-py3-none-any.whl ./dmx/examples_spark/mixture_example.py
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Running with MPI4PY
|
|
49
|
+
Examples that run with mpi4py are located in ./dmx/mpi4py/examples/
|
|
50
|
+
|
|
51
|
+
Below will run the example ./dmx/mpi4py/examples/estimation_example.py with 4 cores.
|
|
52
|
+
```
|
|
53
|
+
> export PYHONPATH=$PYTHONPATH:/path./to/dmx-learn
|
|
54
|
+
> mpiexec -n 4 python /path/to/package/dmx/mpi4py/examples/estimation_example.py
|
|
55
|
+
```
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dmx-learn"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "A package for estimating heterogeneous probability density functions."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { text = "BSD" }
|
|
12
|
+
authors = [
|
|
13
|
+
{ name="Adam Walder" }
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Programming Language :: Python",
|
|
18
|
+
"Development Status :: 4 - Beta",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
keywords = [
|
|
23
|
+
"machine learning",
|
|
24
|
+
"density estimation",
|
|
25
|
+
"statistics",
|
|
26
|
+
"heterogeneous data"
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
dependencies = [
|
|
30
|
+
"mpmath",
|
|
31
|
+
"numba",
|
|
32
|
+
"numpy",
|
|
33
|
+
"pandas",
|
|
34
|
+
"pyspark",
|
|
35
|
+
"scipy"
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[project.optional-dependencies]
|
|
39
|
+
test = [
|
|
40
|
+
"pytest"
|
|
41
|
+
]
|
|
42
|
+
optional = [
|
|
43
|
+
"mpi4py",
|
|
44
|
+
"umap-learn"
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
[tool.setuptools]
|
|
48
|
+
zip-safe = false
|
|
49
|
+
include-package-data = true
|
|
50
|
+
|
|
51
|
+
[tool.setuptools.packages.find]
|
|
52
|
+
where = ["src"]
|
|
53
|
+
include = ["dmx"]
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module defines mathematical constants and imports commonly used functions from NumPy.
|
|
3
|
+
|
|
4
|
+
The constants and functions provided here can be used for various mathematical operations
|
|
5
|
+
such as logarithms, exponentiation, and calculations involving pi, square roots, or infinity.
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from numpy import (
|
|
10
|
+
log, # Natural logarithm
|
|
11
|
+
exp, # Exponential function
|
|
12
|
+
pi, # Mathematical constant π
|
|
13
|
+
sqrt, # Square root function
|
|
14
|
+
abs, # Absolute value function
|
|
15
|
+
dot, # Dot product of two arrays
|
|
16
|
+
isnan, # Check for NaN values
|
|
17
|
+
isinf # Check for infinite values
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
# Constants
|
|
21
|
+
maxint = 2**31 - 1 # Maximum value for a signed 32-bit integer
|
|
22
|
+
maxrandint = 2**31 - 1 # Maximum random integer value for signed 32-bit range
|
|
23
|
+
one = 1.0 # Floating-point representation of 1
|
|
24
|
+
zero = 0.0 # Floating-point representation of 0
|
|
25
|
+
two = 2.0 # Floating-point representation of 2
|
|
26
|
+
half = 0.5 # Floating-point representation of 0.5
|
|
27
|
+
inf = float('inf') # Floating-point representation of infinity
|
|
28
|
+
eps = 1.0e-8 # Small value for numerical precision
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Fitting a DPM with an automatic estimator determined from the data."""
|
|
2
|
+
from dmx.utils.automatic import get_dpm_mixture, get_estimator
|
|
3
|
+
from dmx.bstats import *
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
if __name__ == '__main__':
|
|
8
|
+
|
|
9
|
+
d1 = DiagonalGaussianDistribution([-1, -1, -1], [5, 5, 5])
|
|
10
|
+
d2 = DiagonalGaussianDistribution([0, 0, 0], [0.1, 0.1, 0.1])
|
|
11
|
+
d3 = DiagonalGaussianDistribution([2, 2, 2], [1, 1, 1])
|
|
12
|
+
d4 = DiagonalGaussianDistribution([4, 4, 4], [1, 1, 1])
|
|
13
|
+
dist1 = MixtureDistribution([d1, d2, d3, d4], [0.3, 0.3, 0.2, 0.2])
|
|
14
|
+
|
|
15
|
+
data = dist1.sampler(seed=1).sample(1000)
|
|
16
|
+
est = get_estimator(data, use_bstats=True)
|
|
17
|
+
model = get_dpm_mixture(data, rng=np.random.RandomState(1))
|
|
18
|
+
|
|
19
|
+
print(str(model))
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""Fitting a DPM with an automatic estimator determined from the data."""
|
|
2
|
+
from dmx.utils.automatic import get_dpm_mixture, get_estimator
|
|
3
|
+
from dmx.bstats import *
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
if __name__ == '__main__':
|
|
8
|
+
|
|
9
|
+
rng = np.random.RandomState(2)
|
|
10
|
+
m = 10
|
|
11
|
+
n = 7
|
|
12
|
+
cc = 2.0
|
|
13
|
+
ss = 1.5
|
|
14
|
+
components = []
|
|
15
|
+
w = np.zeros(m)
|
|
16
|
+
pvec = np.ones(m) * 0.5
|
|
17
|
+
for i in range(m):
|
|
18
|
+
len_dist = IntegerCategoricalDistribution([0.2, 0.3, 0.3, 0.2], min_index=3)
|
|
19
|
+
dist1 = GaussianDistribution((i + 1) * ss, 1)
|
|
20
|
+
dist2 = IntegerCategoricalDistribution((np.eye(m)[i, :] + cc) / (m * cc + 1))
|
|
21
|
+
dist3 = CategoricalDistribution({str(j): ((1.0 + cc) if i == j else cc) / (m * cc + 1) for j in range(m)})
|
|
22
|
+
dist4 = OptionalDistribution(PoissonDistribution((i + 1) * ss), p=0.1)
|
|
23
|
+
dist = SequenceDistribution(CompositeDistribution((dist1, dist2, dist3, dist4)), len_dist)
|
|
24
|
+
components.append(dist)
|
|
25
|
+
w[i] = np.prod(1 - pvec[:i]) * pvec[i]
|
|
26
|
+
|
|
27
|
+
w[n:] = 1.0e-16
|
|
28
|
+
w /= w.sum()
|
|
29
|
+
|
|
30
|
+
dist = MixtureDistribution(components, w)
|
|
31
|
+
data = dist.sampler(seed=1).sample(300)
|
|
32
|
+
|
|
33
|
+
est = get_estimator(data, use_bstats=True)
|
|
34
|
+
model = get_dpm_mixture(data, rng=np.random.RandomState(1))
|
|
35
|
+
|
|
36
|
+
print(str(model))
|
|
37
|
+
print(model.num_components)
|
|
38
|
+
for u in model.components:
|
|
39
|
+
print(str(u))
|