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.
Files changed (113) hide show
  1. dmx_learn-1.0.0/LICENSE +27 -0
  2. dmx_learn-1.0.0/MANIFEST.in +10 -0
  3. dmx_learn-1.0.0/PKG-INFO +81 -0
  4. dmx_learn-1.0.0/README.md +55 -0
  5. dmx_learn-1.0.0/pyproject.toml +53 -0
  6. dmx_learn-1.0.0/setup.cfg +4 -0
  7. dmx_learn-1.0.0/src/dmx/__init__.py +3 -0
  8. dmx_learn-1.0.0/src/dmx/arithmetic.py +28 -0
  9. dmx_learn-1.0.0/src/dmx/bexamples/dpm_auto_example1.py +19 -0
  10. dmx_learn-1.0.0/src/dmx/bexamples/dpm_auto_example2.py +39 -0
  11. dmx_learn-1.0.0/src/dmx/bstats/__init__.py +491 -0
  12. dmx_learn-1.0.0/src/dmx/bstats/bernoulli.py +253 -0
  13. dmx_learn-1.0.0/src/dmx/bstats/bestimation.py +267 -0
  14. dmx_learn-1.0.0/src/dmx/bstats/beta.py +69 -0
  15. dmx_learn-1.0.0/src/dmx/bstats/catdirichlet.py +84 -0
  16. dmx_learn-1.0.0/src/dmx/bstats/categorical.py +293 -0
  17. dmx_learn-1.0.0/src/dmx/bstats/composite.py +294 -0
  18. dmx_learn-1.0.0/src/dmx/bstats/conditional.py +298 -0
  19. dmx_learn-1.0.0/src/dmx/bstats/dirac.py +134 -0
  20. dmx_learn-1.0.0/src/dmx/bstats/dirichlet.py +335 -0
  21. dmx_learn-1.0.0/src/dmx/bstats/dmvn.py +278 -0
  22. dmx_learn-1.0.0/src/dmx/bstats/dpm.py +428 -0
  23. dmx_learn-1.0.0/src/dmx/bstats/exponential.py +209 -0
  24. dmx_learn-1.0.0/src/dmx/bstats/gamma.py +172 -0
  25. dmx_learn-1.0.0/src/dmx/bstats/gaussian.py +292 -0
  26. dmx_learn-1.0.0/src/dmx/bstats/geometric.py +259 -0
  27. dmx_learn-1.0.0/src/dmx/bstats/ignored.py +122 -0
  28. dmx_learn-1.0.0/src/dmx/bstats/intrange.py +329 -0
  29. dmx_learn-1.0.0/src/dmx/bstats/mixture.py +382 -0
  30. dmx_learn-1.0.0/src/dmx/bstats/mvngamma.py +108 -0
  31. dmx_learn-1.0.0/src/dmx/bstats/normgamma.py +96 -0
  32. dmx_learn-1.0.0/src/dmx/bstats/nulldist.py +154 -0
  33. dmx_learn-1.0.0/src/dmx/bstats/optional.py +287 -0
  34. dmx_learn-1.0.0/src/dmx/bstats/pdist.py +194 -0
  35. dmx_learn-1.0.0/src/dmx/bstats/poisson.py +259 -0
  36. dmx_learn-1.0.0/src/dmx/bstats/sequence.py +340 -0
  37. dmx_learn-1.0.0/src/dmx/bstats/setdist.py +230 -0
  38. dmx_learn-1.0.0/src/dmx/bstats/symdirichlet.py +49 -0
  39. dmx_learn-1.0.0/src/dmx/mpi4py/bstats/__init__.py +285 -0
  40. dmx_learn-1.0.0/src/dmx/mpi4py/stats/__init__.py +309 -0
  41. dmx_learn-1.0.0/src/dmx/mpi4py/utils/automatic.py +69 -0
  42. dmx_learn-1.0.0/src/dmx/mpi4py/utils/bestimation.py +177 -0
  43. dmx_learn-1.0.0/src/dmx/mpi4py/utils/estimation.py +296 -0
  44. dmx_learn-1.0.0/src/dmx/mpi4py/utils/humap.py +87 -0
  45. dmx_learn-1.0.0/src/dmx/mpi4py/utils/optsutil.py +16 -0
  46. dmx_learn-1.0.0/src/dmx/stats/__init__.py +692 -0
  47. dmx_learn-1.0.0/src/dmx/stats/binomial.py +608 -0
  48. dmx_learn-1.0.0/src/dmx/stats/categorical.py +515 -0
  49. dmx_learn-1.0.0/src/dmx/stats/catmultinomial.py +731 -0
  50. dmx_learn-1.0.0/src/dmx/stats/composite.py +569 -0
  51. dmx_learn-1.0.0/src/dmx/stats/conditional.py +839 -0
  52. dmx_learn-1.0.0/src/dmx/stats/dirac_length.py +803 -0
  53. dmx_learn-1.0.0/src/dmx/stats/dirichlet.py +711 -0
  54. dmx_learn-1.0.0/src/dmx/stats/dmvn.py +606 -0
  55. dmx_learn-1.0.0/src/dmx/stats/dmvn_mixture.py +887 -0
  56. dmx_learn-1.0.0/src/dmx/stats/exponential.py +454 -0
  57. dmx_learn-1.0.0/src/dmx/stats/gamma.py +511 -0
  58. dmx_learn-1.0.0/src/dmx/stats/gaussian.py +504 -0
  59. dmx_learn-1.0.0/src/dmx/stats/geometric.py +455 -0
  60. dmx_learn-1.0.0/src/dmx/stats/gmm.py +780 -0
  61. dmx_learn-1.0.0/src/dmx/stats/heterogeneous_mixture.py +817 -0
  62. dmx_learn-1.0.0/src/dmx/stats/hidden_association.py +424 -0
  63. dmx_learn-1.0.0/src/dmx/stats/hidden_markov.py +1859 -0
  64. dmx_learn-1.0.0/src/dmx/stats/hmixture.py +785 -0
  65. dmx_learn-1.0.0/src/dmx/stats/icltree.py +407 -0
  66. dmx_learn-1.0.0/src/dmx/stats/ignored.py +300 -0
  67. dmx_learn-1.0.0/src/dmx/stats/int_edit_setdist.py +560 -0
  68. dmx_learn-1.0.0/src/dmx/stats/int_edit_stepsetdist.py +470 -0
  69. dmx_learn-1.0.0/src/dmx/stats/int_hidden_association.py +886 -0
  70. dmx_learn-1.0.0/src/dmx/stats/int_markovchain.py +707 -0
  71. dmx_learn-1.0.0/src/dmx/stats/int_plsi.py +870 -0
  72. dmx_learn-1.0.0/src/dmx/stats/int_spike.py +483 -0
  73. dmx_learn-1.0.0/src/dmx/stats/intmultinomial.py +639 -0
  74. dmx_learn-1.0.0/src/dmx/stats/intrange.py +495 -0
  75. dmx_learn-1.0.0/src/dmx/stats/intsetdist.py +404 -0
  76. dmx_learn-1.0.0/src/dmx/stats/jmixture.py +649 -0
  77. dmx_learn-1.0.0/src/dmx/stats/lda.py +822 -0
  78. dmx_learn-1.0.0/src/dmx/stats/log_gaussian.py +357 -0
  79. dmx_learn-1.0.0/src/dmx/stats/look_back_hmm.py +874 -0
  80. dmx_learn-1.0.0/src/dmx/stats/markovchain.py +826 -0
  81. dmx_learn-1.0.0/src/dmx/stats/mixture.py +696 -0
  82. dmx_learn-1.0.0/src/dmx/stats/mvn.py +404 -0
  83. dmx_learn-1.0.0/src/dmx/stats/null_dist.py +297 -0
  84. dmx_learn-1.0.0/src/dmx/stats/optional.py +518 -0
  85. dmx_learn-1.0.0/src/dmx/stats/pdist.py +435 -0
  86. dmx_learn-1.0.0/src/dmx/stats/poisson.py +336 -0
  87. dmx_learn-1.0.0/src/dmx/stats/rdd_sampler.py +99 -0
  88. dmx_learn-1.0.0/src/dmx/stats/select.py +224 -0
  89. dmx_learn-1.0.0/src/dmx/stats/sequence.py +624 -0
  90. dmx_learn-1.0.0/src/dmx/stats/setdist.py +396 -0
  91. dmx_learn-1.0.0/src/dmx/stats/sparse_markov_transform.py +606 -0
  92. dmx_learn-1.0.0/src/dmx/stats/spearman_rho.py +312 -0
  93. dmx_learn-1.0.0/src/dmx/stats/ss_mixture.py +544 -0
  94. dmx_learn-1.0.0/src/dmx/stats/tree_hmm.py +1602 -0
  95. dmx_learn-1.0.0/src/dmx/stats/vmf.py +498 -0
  96. dmx_learn-1.0.0/src/dmx/stats/weighted.py +247 -0
  97. dmx_learn-1.0.0/src/dmx/utils/__init__.py +1 -0
  98. dmx_learn-1.0.0/src/dmx/utils/automatic.py +436 -0
  99. dmx_learn-1.0.0/src/dmx/utils/builder.py +83 -0
  100. dmx_learn-1.0.0/src/dmx/utils/estimation.py +459 -0
  101. dmx_learn-1.0.0/src/dmx/utils/htsne.py +496 -0
  102. dmx_learn-1.0.0/src/dmx/utils/humap.py +69 -0
  103. dmx_learn-1.0.0/src/dmx/utils/metrics.py +173 -0
  104. dmx_learn-1.0.0/src/dmx/utils/optsutil.py +242 -0
  105. dmx_learn-1.0.0/src/dmx/utils/pvalues.py +102 -0
  106. dmx_learn-1.0.0/src/dmx/utils/special.py +148 -0
  107. dmx_learn-1.0.0/src/dmx/utils/vector.py +688 -0
  108. dmx_learn-1.0.0/src/dmx_learn.egg-info/PKG-INFO +81 -0
  109. dmx_learn-1.0.0/src/dmx_learn.egg-info/SOURCES.txt +111 -0
  110. dmx_learn-1.0.0/src/dmx_learn.egg-info/dependency_links.txt +1 -0
  111. dmx_learn-1.0.0/src/dmx_learn.egg-info/not-zip-safe +1 -0
  112. dmx_learn-1.0.0/src/dmx_learn.egg-info/requires.txt +13 -0
  113. dmx_learn-1.0.0/src/dmx_learn.egg-info/top_level.txt +1 -0
@@ -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.
@@ -0,0 +1,10 @@
1
+ # Include package data inside your dmx package (if you have any)
2
+ recursive-include src/dmx *.py *.txt *.md
3
+
4
+ # Exclude everything else
5
+ exclude README.md
6
+ exclude LICENSE
7
+ exclude requirements.txt
8
+ prune docs
9
+ prune examples
10
+ prune tests
@@ -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,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ __all__ = ['stats', 'utils','src']
2
+
3
+
@@ -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))