aggregationslib 0.2.6__tar.gz → 0.2.8__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.

Potentially problematic release.


This version of aggregationslib might be problematic. Click here for more details.

Files changed (102) hide show
  1. aggregationslib-0.2.8/AGENTS.md +7 -0
  2. {aggregationslib-0.2.6/aggregationslib.egg-info → aggregationslib-0.2.8}/PKG-INFO +30 -12
  3. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/README.md +70 -14
  4. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/README.pl.md +1 -1
  5. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/README.rst +32 -19
  6. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/aggregation_classification.html +14 -14
  7. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/aggregationslib/aggregation.py +35 -13
  8. aggregationslib-0.2.8/aggregationslib/cli.py +81 -0
  9. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/aggregationslib/decimalaggregations.py +38 -18
  10. aggregationslib-0.2.8/aggregationslib/ndarray.py +200 -0
  11. {aggregationslib-0.2.6 → aggregationslib-0.2.8/aggregationslib.egg-info}/PKG-INFO +30 -12
  12. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/aggregationslib.egg-info/SOURCES.txt +21 -1
  13. aggregationslib-0.2.8/aggregationslib.egg-info/entry_points.txt +2 -0
  14. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/aggregationslib.egg-info/requires.txt +6 -0
  15. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/aggregationslib.egg-info/scm_file_list.json +20 -1
  16. aggregationslib-0.2.8/aggregationslib.egg-info/scm_version.json +8 -0
  17. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/aggregationslib.egg-info/top_level.txt +1 -0
  18. aggregationslib-0.2.8/apps/shiny/README.md +71 -0
  19. aggregationslib-0.2.8/apps/shiny/README.pl.md +71 -0
  20. aggregationslib-0.2.8/apps/shiny/app.py +709 -0
  21. aggregationslib-0.2.8/apps/shiny/column-selection.js +128 -0
  22. aggregationslib-0.2.8/apps/shiny/core.py +271 -0
  23. aggregationslib-0.2.8/apps/shiny/evaluation.py +98 -0
  24. aggregationslib-0.2.8/apps/shiny/example.csv +21 -0
  25. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/build_docs.ps1 +2 -2
  26. {aggregationslib-0.2.6/docs/assets → aggregationslib-0.2.8}/diagram-aggregation-classification.svg +18 -18
  27. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/diagram-klasyfikacja-agregacji.svg +22 -22
  28. aggregationslib-0.2.8/docs/CNAME +1 -0
  29. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/aggregation_classification.html +14 -14
  30. {aggregationslib-0.2.6 → aggregationslib-0.2.8/docs/assets}/diagram-aggregation-classification.svg +18 -18
  31. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/assets/diagram-klasyfikacja-agregacji.svg +22 -22
  32. aggregationslib-0.2.8/docs/assets/means-icon.svg +20 -0
  33. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/assets/site.css +188 -185
  34. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/en/index.html +81 -80
  35. {aggregationslib-0.2.6 → aggregationslib-0.2.8/docs}/klasyfikacja_agregacji.html +14 -14
  36. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/pl/index.html +81 -80
  37. {aggregationslib-0.2.6/docs → aggregationslib-0.2.8}/klasyfikacja_agregacji.html +14 -14
  38. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/pyproject.toml +8 -1
  39. aggregationslib-0.2.8/tests/data/README.md +54 -0
  40. aggregationslib-0.2.8/tests/data/wolfram_measure_reference.json +1983 -0
  41. aggregationslib-0.2.8/tests/test_exponential_cardinality.py +53 -0
  42. aggregationslib-0.2.8/tests/test_ndarray.py +243 -0
  43. aggregationslib-0.2.8/tests/test_shiny_app.py +151 -0
  44. aggregationslib-0.2.8/tests/test_shiny_evaluation.py +63 -0
  45. aggregationslib-0.2.8/tests/test_wolfram_measures.py +111 -0
  46. aggregationslib-0.2.6/aggregationslib.egg-info/scm_version.json +0 -8
  47. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/.gitignore +0 -0
  48. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/LICENSE +0 -0
  49. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/aggregationslib/__init__.py +0 -0
  50. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/aggregationslib/aggregations.py +0 -0
  51. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/aggregationslib/conjuctive/__init__.py +0 -0
  52. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/aggregationslib/conjuctive/purepython.py +0 -0
  53. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/aggregationslib/disjunctive/__init__.py +0 -0
  54. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/aggregationslib/example.py +0 -0
  55. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/aggregationslib/feature_selection/__init__.py +0 -0
  56. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/aggregationslib/feature_selection/binary_fuzzy_entropy.py +0 -0
  57. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/aggregationslib/feature_selection/fuzzy_com_entropy.py +0 -0
  58. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/aggregationslib/models/__init__.py +0 -0
  59. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/aggregationslib/models/ensemble/__init__.py +0 -0
  60. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/aggregationslib/models/ensemble/aggregation_regressor.py +0 -0
  61. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/aggregationslib/models/single/__init__.py +0 -0
  62. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/aggregationslib/purepython.py +0 -0
  63. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/aggregationslib.egg-info/dependency_links.txt +0 -0
  64. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/assets/icons/icon.ico +0 -0
  65. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/assets/icons/icon.png +0 -0
  66. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/assets/icons/icon.svg +0 -0
  67. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/commands.md +0 -0
  68. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/diagram-implikacja-agregacja.svg +0 -0
  69. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/diagram-odwzorowanie.svg +0 -0
  70. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/.nojekyll +0 -0
  71. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/aggregation-classes.md +0 -0
  72. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/aggregation-plots.md +0 -0
  73. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/assets/aggregation-surfaces-all.png +0 -0
  74. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/assets/aggregation-surfaces.png +0 -0
  75. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/assets/aggregations/A_amn_p=0.5.png +0 -0
  76. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/assets/aggregations/A_amx_p=0.5.png +0 -0
  77. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/assets/aggregations/A_ar.png +0 -0
  78. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/assets/aggregations/A_ex2_p=2,q=2.png +0 -0
  79. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/assets/aggregations/A_ex3_p=2,q=1.5.png +0 -0
  80. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/assets/aggregations/A_ex_r=1.png +0 -0
  81. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/assets/aggregations/A_gm.png +0 -0
  82. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/assets/aggregations/A_hm.png +0 -0
  83. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/assets/aggregations/A_lm_r=2.png +0 -0
  84. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/assets/aggregations/A_lo.png +0 -0
  85. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/assets/aggregations/A_md.png +0 -0
  86. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/assets/aggregations/A_mn.png +0 -0
  87. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/assets/aggregations/A_mx.png +0 -0
  88. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/assets/aggregations/A_ol.png +0 -0
  89. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/assets/aggregations/A_oln_p=1.png +0 -0
  90. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/assets/aggregations/A_pr.png +0 -0
  91. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/assets/aggregations/A_pw_r=2.png +0 -0
  92. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/assets/aggregations/A_qd.png +0 -0
  93. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/fuzzy-integrals.md +0 -0
  94. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/docs/index.html +0 -0
  95. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/generate_aggregation_plots.py +0 -0
  96. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/setup.cfg +0 -0
  97. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/tests/__init__.py +0 -0
  98. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/tests/data/wolfram_integral_reference.json +0 -0
  99. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/tests/test_aggregations.py +0 -0
  100. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/tests/test_decimal_exponential_mean.py +0 -0
  101. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/tests/test_decimal_fuzzy_integrals.py +0 -0
  102. {aggregationslib-0.2.6 → aggregationslib-0.2.8}/tests/test_fuzzy_integrals.py +0 -0
@@ -0,0 +1,7 @@
1
+ # Słowniczek projektu
2
+
3
+ Stosuj poniższe formy w polskiej dokumentacji, na stronie projektu i w interfejsie.
4
+
5
+ | Stosuj | Zamiast |
6
+ | --- | --- |
7
+ | Funkcje agregacji dla Python | Funkcje agregacji dla Pythona |
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aggregationslib
3
- Version: 0.2.6
3
+ Version: 0.2.8
4
4
  Summary: Python implementation of Arithmetic, quasi arithmetic and other aggregating functions
5
5
  Author: wgalka
6
6
  Project-URL: Homepage, https://github.com/wgalka/Means
@@ -12,12 +12,17 @@ Requires-Python: >=3.14
12
12
  Description-Content-Type: text/x-rst
13
13
  License-File: LICENSE
14
14
  Requires-Dist: numpy>=2.2.2
15
+ Requires-Dist: packaging
15
16
  Requires-Dist: pynverse
16
17
  Requires-Dist: scikit-learn
17
18
  Requires-Dist: pandas
18
19
  Requires-Dist: scipy
19
20
  Provides-Extra: test
20
21
  Requires-Dist: pytest>=8.3.4; extra == "test"
22
+ Provides-Extra: app
23
+ Requires-Dist: shiny<2,>=1.9; extra == "app"
24
+ Requires-Dist: pygments<3,>=2.19; extra == "app"
25
+ Requires-Dist: matplotlib<4,>=3.9; extra == "app"
21
26
  Dynamic: license-file
22
27
 
23
28
  Means
@@ -30,12 +35,22 @@ Documentation:
30
35
  - English: https://wgalka.github.io/Means/en/
31
36
  - Polski: https://wgalka.github.io/Means/pl/
32
37
 
33
- Aggregations functions are:
38
+ **Table of contents**
34
39
 
35
- - Conjuctive - the final aggregated value will always be influenced by
36
- the smallest value among the inputs.
37
- - Disjnuctive - the aggregated value will always be influenced by the
38
- largest value among the inputs.
40
+ - `Example 1 <#example-1>`__
41
+ - `Example 2 <#example2>`__
42
+ - `Aggregation functions <#aggregation-functions>`__
43
+ - `References <#references>`__
44
+
45
+ Aggregation functions can be classified in several ways. A familiar distinction
46
+ is between three types of behaviour:
47
+
48
+ - Conjunctive — an AND-like combination of the inputs.
49
+ - Averaging — a result between the smallest and largest input values.
50
+ - Disjunctive — an OR-like combination of the inputs.
51
+
52
+ These are not the only possibilities: aggregation functions can also exhibit
53
+ mixed behaviour. The diagram below presents a broader classification.
39
54
 
40
55
  .. image:: https://raw.githubusercontent.com/wgalka/Means/main/docs/assets/diagram-aggregation-classification.svg
41
56
  :alt: Classification of aggregation functions
@@ -106,7 +121,7 @@ intervals. ``[0,1]`` means only the unit interval. These are
106
121
  mathematical properties; most callable objects do not validate input
107
122
  bounds at runtime. Some tags depend on parameters or the fuzzy measure.
108
123
 
109
- :math:`\mathbf{A_{ch}^{(\mu)}}` **- Choquet integral [1]**
124
+ :math:`\mathbf{A_{ch}^{(\mu)}}` **- Discrete Choquet integral [1]**
110
125
 
111
126
  Tags: ``averaging`` ``aggregation interval: [0,1]``
112
127
  ``symmetric if μ is symmetric``
@@ -142,8 +157,10 @@ Each constructor returns a monotone fuzzy measure with
142
157
  :math:`\mu(A)=\sum_{j=1}^{|A|}w_j`. The normalized weights are applied
143
158
  by descending value rank, so the first belongs to the largest value;
144
159
  with the Choquet integral this capacity gives the OWA aggregation.
145
- - **Exponential cardinality**: :math:`\mu(A)=(|A|/n)^q` is not
146
- implemented yet; choosing ``q`` is future work.
160
+ - **Exponential cardinality** (``exponential_cardinality_measure(n, q=1)``):
161
+ :math:`\mu(A)=(|A|/n)^q`, where ``q`` must be finite and :math:`q>0`.
162
+ For :math:`q=1`, this is the uniform/cardinality measure, and the discrete
163
+ Choquet integral equals the arithmetic mean.
147
164
 
148
165
  The constructors are in ``aggregationslib.aggregation``; Decimal
149
166
  equivalents are available in ``aggregationslib.decimalaggregations``.
@@ -157,7 +174,7 @@ two-argument function ``O(x, mu)`` as ``quasi_overlap`` to
157
174
  ``choquet_integral`` or ``A_ch``. The default remains the classical
158
175
  product-based Choquet integral.
159
176
 
160
- :math:`\mathbf{A_{sg}^{(\mu)}}` **- Sugeno integral [1]**
177
+ :math:`\mathbf{A_{sg}^{(\mu)}}` **- Discrete Sugeno integral [1]**
161
178
 
162
179
  Tags: ``averaging`` ``aggregation interval: [0,1]``
163
180
  ``symmetric if μ is symmetric``
@@ -196,8 +213,9 @@ available in ``aggregationslib.aggregation`` and
196
213
  by descending value rank, so the first belongs to the largest value.
197
214
  In the Sugeno integral this capacity is used in the max–min formula;
198
215
  the result is not the OWA aggregation.
199
- - **Exponential cardinality**: :math:`\mu(A)=(|A|/n)^q` is not
200
- implemented yet; choosing ``q`` is future work.
216
+ - **Exponential cardinality** (``exponential_cardinality_measure(n, q=1)``):
217
+ :math:`\mu(A)=(|A|/n)^q`, where ``q`` must be finite and :math:`q>0`.
218
+ For :math:`q=1`, this is the uniform/cardinality measure.
201
219
 
202
220
  :math:`\mathbf{A_{ar}}` **- Arithmetic mean**
203
221
 
@@ -6,14 +6,20 @@ Documentation:
6
6
  - English: https://wgalka.github.io/Means/en/
7
7
  - Polski: https://wgalka.github.io/Means/pl/
8
8
 
9
- Aggregations functions are:
10
- - Conjuctive - the final aggregated value will always be influenced by the smallest value among the inputs.
11
- - Disjnuctive - the aggregated value will always be influenced by the largest value among the inputs.
12
-
13
- [![Classification of aggregation functions](https://raw.githubusercontent.com/wgalka/Means/main/docs/assets/diagram-aggregation-classification.svg)](https://wgalka.github.io/Means/aggregation_classification.html)
14
-
15
- *Diagram elaborated on the basis of: A. Pradera, G. Beliakov, H. Bustince, B. De Baets, "A review of the relationships between implication, negation and aggregation functions from the point of view of material implication", Information Sciences 329 (2016) 357–380, [DOI: 10.1016/j.ins.2015.09.033](https://doi.org/10.1016/j.ins.2015.09.033).*
16
-
9
+ Aggregation functions can be classified in several ways. A familiar distinction
10
+ is between three types of behaviour:
11
+
12
+ - Conjunctive — an AND-like combination of the inputs.
13
+ - Averaging — a result between the smallest and largest input values.
14
+ - Disjunctive — an OR-like combination of the inputs.
15
+
16
+ These are not the only possibilities: aggregation functions can also exhibit
17
+ mixed behaviour. The diagram below presents a broader classification.
18
+
19
+ [![Classification of aggregation functions](https://raw.githubusercontent.com/wgalka/Means/main/docs/assets/diagram-aggregation-classification.svg)](https://wgalka.github.io/Means/aggregation_classification.html)
20
+
21
+ *Diagram elaborated on the basis of: A. Pradera, G. Beliakov, H. Bustince, B. De Baets, "A review of the relationships between implication, negation and aggregation functions from the point of view of material implication", Information Sciences 329 (2016) 357–380, [DOI: 10.1016/j.ins.2015.09.033](https://doi.org/10.1016/j.ins.2015.09.033).*
22
+
17
23
  An interactive version of this diagram is available at: https://wgalka.github.io/Means/aggregation_classification.html
18
24
 
19
25
  #### Example 1:
@@ -51,6 +57,47 @@ print(func3.__repr__()) # function parameters are printed in order: func1, func2
51
57
 
52
58
 
53
59
 
60
+ ## Multidimensional arrays
61
+
62
+ `aggregationslib.ndarray` provides the same `A_...` objects as
63
+ `aggregationslib.aggregations`, with additional constructor options `axis`
64
+ and `keepdims`. It applies the existing vector implementation separately
65
+ to each vector along the selected axis.
66
+
67
+ ```python
68
+ import numpy as np
69
+ from aggregationslib.ndarray import A_ar, A_ch
70
+ from aggregationslib import weighted_measure
71
+
72
+ X = np.array([[0.2, 0.6, 0.9], [0.9, 0.2, 0.6]])
73
+ A_ar(axis=1)(X) # shape (2,): one value per row
74
+ A_ar(axis=0)(X) # shape (3,): one value per column
75
+ A_ar(axis=1, keepdims=True)(X) # shape (2, 1)
76
+ A_ar()(X) # scalar: aggregate all elements
77
+
78
+ mu = weighted_measure([0.5, 0.3, 0.2])
79
+ A_ch(measure=mu, axis=-1)(X) # array([0.46, 0.63])
80
+ ```
81
+
82
+ `axis=None` (the default) flattens the input in C order. An integer axis,
83
+ including a negative index, reduces that axis; tuples of axes are not
84
+ supported. For an input of shape `(m, n)`, `axis=1` returns shape `(m,)`,
85
+ including `(1,)` when there is just one row. `keepdims=True` retains reduced
86
+ dimensions with length one. A complete reduction returns a scalar unless
87
+ `keepdims=True`.
88
+
89
+ Choquet and Sugeno use the same measure for each vector. Its size must match
90
+ the selected axis length, or the total element count for `axis=None`.
91
+ Choquet's `quasi_overlap` continues to accept scalar callbacks.
92
+ `Combine2Aggregations` accepts vector callables or objects from this module;
93
+ the combination's own `axis` and `keepdims` control the reduction.
94
+
95
+ Empty vectors are rejected. An empty batch of nonempty vectors returns an
96
+ empty floating-point array of the appropriate shape. The mathematical
97
+ domains, parameter rules and numerical behavior are inherited from the
98
+ vector implementations. This module uses iteration over vectors, not
99
+ vectorized implementations of the aggregation formulas.
100
+
54
101
  ## Aggregation functions
55
102
 
56
103
  An aggregation function on the unit interval [1] is an increasing mapping
@@ -71,7 +118,7 @@ intervals. `[0,1]` means only the unit interval. These are mathematical
71
118
  properties; most callable objects do not validate input bounds at runtime.
72
119
  Some tags depend on parameters or the fuzzy measure.
73
120
 
74
- $\mathbf{A_{ch}^{(\mu)}}$ **- Choquet integral [1]**
121
+ $\mathbf{A_{ch}^{(\mu)}}$ **- Discrete Choquet integral [1]**
75
122
 
76
123
  Tags: `averaging` `aggregation interval: [0,1]` `symmetric if μ is symmetric`
77
124
 
@@ -102,8 +149,10 @@ $\mu(\emptyset)=0$ and $\mu(N)=1$.
102
149
  $\mu(A)=\sum_{j=1}^{|A|}w_j$. The normalized weights are applied by
103
150
  descending value rank, so the first belongs to the largest value; with the
104
151
  Choquet integral this capacity gives the OWA aggregation.
105
- - **Exponential cardinality**: $\mu(A)=(|A|/n)^q$ is not implemented yet;
106
- choosing `q` is future work.
152
+ - **Exponential cardinality** (`exponential_cardinality_measure(n, q=1)`):
153
+ $\mu(A)=(|A|/n)^q$, where `q` must be finite and $q>0$.
154
+ For $q=1$, this is the uniform/cardinality measure, and the discrete
155
+ Choquet integral equals the arithmetic mean.
107
156
 
108
157
  The constructors are in `aggregationslib.aggregation`; Decimal equivalents
109
158
  are available in `aggregationslib.decimalaggregations`.
@@ -115,7 +164,7 @@ For the quasi-overlap generalization from Equation (9), pass a two-argument
115
164
  function `O(x, mu)` as `quasi_overlap` to `choquet_integral` or `A_ch`. The
116
165
  default remains the classical product-based Choquet integral.
117
166
 
118
- $\mathbf{A_{sg}^{(\mu)}}$ **- Sugeno integral [1]**
167
+ $\mathbf{A_{sg}^{(\mu)}}$ **- Discrete Sugeno integral [1]**
119
168
 
120
169
  Tags: `averaging` `aggregation interval: [0,1]` `symmetric if μ is symmetric`
121
170
 
@@ -149,8 +198,9 @@ $\mu(\emptyset)=0$ and $\mu(N)=1$. The same constructors are available in
149
198
  descending value rank, so the first belongs to the largest value. In the
150
199
  Sugeno integral this capacity is used in the max–min formula; the result is
151
200
  not the OWA aggregation.
152
- - **Exponential cardinality**: $\mu(A)=(|A|/n)^q$ is not implemented yet;
153
- choosing `q` is future work.
201
+ - **Exponential cardinality** (`exponential_cardinality_measure(n, q=1)`):
202
+ $\mu(A)=(|A|/n)^q$, where `q` must be finite and $q>0$.
203
+ For $q=1$, this is the uniform/cardinality measure.
154
204
 
155
205
  $\mathbf{A_{ar}}$ **- Arithmetic mean**
156
206
 
@@ -305,3 +355,9 @@ We can construct covex combination of aggregation functions as $A^{(p)}_{A_1,A_2
305
355
 
306
356
  1. Beliakov, G., Bustince, H., and Calvo, T.: *A Practical Guide to Averaging Functions*. Berlin: Springer, vol. 329, 2016.
307
357
  2. [Mustonen, Seppo. (2010). Logarithmic mean for several arguments. ](https://www.researchgate.net/publication/228886844_Logarithmic_mean_for_several_arguments)
358
+ # Shiny app
359
+
360
+ A local interface lets you upload a CSV table, select columns and an
361
+ aggregation, add input vectors, and download row-wise results. It also
362
+ generates the equivalent Python code using `aggregationslib.ndarray`.
363
+ See [setup and usage](apps/shiny/README.md).
@@ -1,6 +1,6 @@
1
1
  # Means
2
2
 
3
- Means to biblioteka funkcji agregacji dla języka Python.
3
+ Means to biblioteka, która udostępnia funkcje agregacji dla Python.
4
4
 
5
5
  Dokumentacja:
6
6
 
@@ -8,19 +8,29 @@ Documentation:
8
8
  - English: https://wgalka.github.io/Means/en/
9
9
  - Polski: https://wgalka.github.io/Means/pl/
10
10
 
11
- Aggregations functions are:
12
-
13
- - Conjuctive - the final aggregated value will always be influenced by
14
- the smallest value among the inputs.
15
- - Disjnuctive - the aggregated value will always be influenced by the
16
- largest value among the inputs.
17
-
18
- .. image:: https://raw.githubusercontent.com/wgalka/Means/main/docs/assets/diagram-aggregation-classification.svg
19
- :alt: Classification of aggregation functions
20
- :target: https://wgalka.github.io/Means/aggregation_classification.html
21
-
22
- *Diagram elaborated on the basis of: A. Pradera, G. Beliakov, H. Bustince, B. De Baets, "A review of the relationships between implication, negation and aggregation functions from the point of view of material implication", Information Sciences 329 (2016) 357–380,* `DOI: 10.1016/j.ins.2015.09.033 <https://doi.org/10.1016/j.ins.2015.09.033>`__.
23
-
11
+ **Table of contents**
12
+
13
+ - `Example 1 <#example-1>`__
14
+ - `Example 2 <#example2>`__
15
+ - `Aggregation functions <#aggregation-functions>`__
16
+ - `References <#references>`__
17
+
18
+ Aggregation functions can be classified in several ways. A familiar distinction
19
+ is between three types of behaviour:
20
+
21
+ - Conjunctive — an AND-like combination of the inputs.
22
+ - Averaging — a result between the smallest and largest input values.
23
+ - Disjunctive — an OR-like combination of the inputs.
24
+
25
+ These are not the only possibilities: aggregation functions can also exhibit
26
+ mixed behaviour. The diagram below presents a broader classification.
27
+
28
+ .. image:: https://raw.githubusercontent.com/wgalka/Means/main/docs/assets/diagram-aggregation-classification.svg
29
+ :alt: Classification of aggregation functions
30
+ :target: https://wgalka.github.io/Means/aggregation_classification.html
31
+
32
+ *Diagram elaborated on the basis of: A. Pradera, G. Beliakov, H. Bustince, B. De Baets, "A review of the relationships between implication, negation and aggregation functions from the point of view of material implication", Information Sciences 329 (2016) 357–380,* `DOI: 10.1016/j.ins.2015.09.033 <https://doi.org/10.1016/j.ins.2015.09.033>`__.
33
+
24
34
  An interactive version of this diagram is available at: https://wgalka.github.io/Means/aggregation_classification.html
25
35
 
26
36
  Example 1:
@@ -84,7 +94,7 @@ intervals. ``[0,1]`` means only the unit interval. These are
84
94
  mathematical properties; most callable objects do not validate input
85
95
  bounds at runtime. Some tags depend on parameters or the fuzzy measure.
86
96
 
87
- :math:`\mathbf{A_{ch}^{(\mu)}}` **- Choquet integral [1]**
97
+ :math:`\mathbf{A_{ch}^{(\mu)}}` **- Discrete Choquet integral [1]**
88
98
 
89
99
  Tags: ``averaging`` ``aggregation interval: [0,1]``
90
100
  ``symmetric if μ is symmetric``
@@ -120,8 +130,10 @@ Each constructor returns a monotone fuzzy measure with
120
130
  :math:`\mu(A)=\sum_{j=1}^{|A|}w_j`. The normalized weights are applied
121
131
  by descending value rank, so the first belongs to the largest value;
122
132
  with the Choquet integral this capacity gives the OWA aggregation.
123
- - **Exponential cardinality**: :math:`\mu(A)=(|A|/n)^q` is not
124
- implemented yet; choosing ``q`` is future work.
133
+ - **Exponential cardinality** (``exponential_cardinality_measure(n, q=1)``):
134
+ :math:`\mu(A)=(|A|/n)^q`, where ``q`` must be finite and :math:`q>0`.
135
+ For :math:`q=1`, this is the uniform/cardinality measure, and the discrete
136
+ Choquet integral equals the arithmetic mean.
125
137
 
126
138
  The constructors are in ``aggregationslib.aggregation``; Decimal
127
139
  equivalents are available in ``aggregationslib.decimalaggregations``.
@@ -135,7 +147,7 @@ two-argument function ``O(x, mu)`` as ``quasi_overlap`` to
135
147
  ``choquet_integral`` or ``A_ch``. The default remains the classical
136
148
  product-based Choquet integral.
137
149
 
138
- :math:`\mathbf{A_{sg}^{(\mu)}}` **- Sugeno integral [1]**
150
+ :math:`\mathbf{A_{sg}^{(\mu)}}` **- Discrete Sugeno integral [1]**
139
151
 
140
152
  Tags: ``averaging`` ``aggregation interval: [0,1]``
141
153
  ``symmetric if μ is symmetric``
@@ -174,8 +186,9 @@ available in ``aggregationslib.aggregation`` and
174
186
  by descending value rank, so the first belongs to the largest value.
175
187
  In the Sugeno integral this capacity is used in the max–min formula;
176
188
  the result is not the OWA aggregation.
177
- - **Exponential cardinality**: :math:`\mu(A)=(|A|/n)^q` is not
178
- implemented yet; choosing ``q`` is future work.
189
+ - **Exponential cardinality** (``exponential_cardinality_measure(n, q=1)``):
190
+ :math:`\mu(A)=(|A|/n)^q`, where ``q`` must be finite and :math:`q>0`.
191
+ For :math:`q=1`, this is the uniform/cardinality measure.
179
192
 
180
193
  :math:`\mathbf{A_{ar}}` **- Arithmetic mean**
181
194
 
@@ -185,10 +185,10 @@
185
185
  <clipPath id="clip-0Strict"><path d="M 1722 58 H 1185 V 255 H 845 V 588 H 1190 V 902 H 1722 Z"/></clipPath>
186
186
  <clipPath id="clip-0Div"><ellipse cx="615" cy="615" rx="565" ry="115" transform="rotate(21.5 615 615)"/></clipPath>
187
187
  <clipPath id="clip-1Div"><ellipse cx="1185" cy="615" rx="565" ry="115" transform="rotate(-21.5 1185 615)"/></clipPath>
188
- <clipPath id="clip-NC"><path d="M 235 370 L 766 568 L 766 768 L 235 515 Z"/></clipPath>
189
- <clipPath id="clip-SNC"><path d="M 355 505 L 766 576 L 766 738 Z"/></clipPath>
190
- <clipPath id="clip-EM"><path d="M 1565 370 L 1034 568 L 1034 768 L 1565 515 Z"/></clipPath>
191
- <clipPath id="clip-SEM"><path d="M 1445 505 L 1034 576 L 1034 738 Z"/></clipPath>
188
+ <clipPath id="clip-NC"><path d="M 245 408 L 766 570 L 766 766 L 245 535 Z"/></clipPath>
189
+ <clipPath id="clip-SNC"><path d="M 340 495 L 766 576 L 766 742 Z"/></clipPath>
190
+ <clipPath id="clip-EM"><path d="M 1555 408 L 1034 570 L 1034 766 L 1555 535 Z"/></clipPath>
191
+ <clipPath id="clip-SEM"><path d="M 1460 495 L 1034 576 L 1034 742 Z"/></clipPath>
192
192
  <clipPath id="clip-NE1"><rect x="105" y="465" width="350" height="380" rx="44"/></clipPath>
193
193
  <clipPath id="clip-NE0"><rect x="1345" y="465" width="350" height="380" rx="44"/></clipPath>
194
194
 
@@ -248,19 +248,19 @@
248
248
  fill="#ffedd5" fill-opacity="0.36" stroke="#9a3412" stroke-width="3.5"/>
249
249
 
250
250
  <path id="shape-NC" onclick="toggleProperty('NC')" class="region-shape"
251
- d="M 235 370 L 766 568 L 766 768 L 235 515 Z"
251
+ d="M 245 408 L 766 570 L 766 766 L 245 535 Z"
252
252
  fill="#dcfce7" fill-opacity="0.52" stroke="#16a34a" stroke-width="4" stroke-linejoin="round"/>
253
253
 
254
254
  <path id="shape-SNC" onclick="toggleProperty('SNC')" class="region-shape"
255
- d="M 355 505 L 766 576 L 766 738 Z"
255
+ d="M 340 495 L 766 576 L 766 742 Z"
256
256
  fill="#ecfccb" fill-opacity="0.68" stroke="#65a30d" stroke-width="4" stroke-linejoin="round"/>
257
257
 
258
258
  <path id="shape-EM" onclick="toggleProperty('EM')" class="region-shape"
259
- d="M 1565 370 L 1034 568 L 1034 768 L 1565 515 Z"
259
+ d="M 1555 408 L 1034 570 L 1034 766 L 1555 535 Z"
260
260
  fill="#ffedd5" fill-opacity="0.55" stroke="#ea580c" stroke-width="4" stroke-linejoin="round"/>
261
261
 
262
262
  <path id="shape-SEM" onclick="toggleProperty('SEM')" class="region-shape"
263
- d="M 1445 505 L 1034 576 L 1034 738 Z"
263
+ d="M 1460 495 L 1034 576 L 1034 742 Z"
264
264
  fill="#fef9c3" fill-opacity="0.72" stroke="#ca8a04" stroke-width="4" stroke-linejoin="round"/>
265
265
 
266
266
  <!-- 4. Semi-copulas & Dual semi-copulas -->
@@ -361,38 +361,38 @@
361
361
  </g>
362
362
 
363
363
  <!-- 0Div, NC, S-NC Labels -->
364
- <g id="label-0Div" onclick="toggleProperty('0Div')" class="region-shape" transform="translate(155, 375)" filter="url(#badge-shadow)">
364
+ <g id="label-0Div" onclick="toggleProperty('0Div')" class="region-shape" transform="translate(175, 428)" filter="url(#badge-shadow)">
365
365
  <rect x="-56" y="-20" width="112" height="42" rx="9" fill="#eff6ff" stroke="#2563eb" stroke-width="2"/>
366
366
  <text x="0" y="-1" text-anchor="middle" class="badge-text" fill="#1d4ed8">0Div</text>
367
367
  <text x="0" y="15" text-anchor="middle" class="badge-sub" fill="#2563eb">A(a,b) = 0</text>
368
368
  </g>
369
369
 
370
- <g id="label-NC" onclick="toggleProperty('NC')" class="region-shape" transform="translate(305, 435)" filter="url(#badge-shadow)">
370
+ <g id="label-NC" onclick="toggleProperty('NC')" class="region-shape" transform="translate(312, 475)" filter="url(#badge-shadow)">
371
371
  <rect x="-64" y="-20" width="128" height="42" rx="9" fill="#f0fdf4" stroke="#16a34a" stroke-width="2"/>
372
372
  <text x="0" y="-1" text-anchor="middle" class="badge-text" fill="#15803d">NC</text>
373
373
  <text x="0" y="15" text-anchor="middle" class="badge-sub" fill="#16a34a">A(x,N(x)) = 0</text>
374
374
  </g>
375
375
 
376
- <g id="label-SNC" onclick="toggleProperty('SNC')" class="region-shape" transform="translate(500, 575)" filter="url(#badge-shadow)">
376
+ <g id="label-SNC" onclick="toggleProperty('SNC')" class="region-shape" transform="translate(500, 565)" filter="url(#badge-shadow)">
377
377
  <rect x="-72" y="-20" width="144" height="42" rx="9" fill="#f7fee7" stroke="#65a30d" stroke-width="2"/>
378
378
  <text x="0" y="-1" text-anchor="middle" class="badge-text" fill="#4d7c0f">S-NC</text>
379
379
  <text x="0" y="15" text-anchor="middle" class="badge-sub" fill="#65a30d">y≤N(x) ⇔ A=0</text>
380
380
  </g>
381
381
 
382
382
  <!-- 1Div, EM, S-EM Labels -->
383
- <g id="label-1Div" onclick="toggleProperty('1Div')" class="region-shape" transform="translate(1645, 375)" filter="url(#badge-shadow)">
383
+ <g id="label-1Div" onclick="toggleProperty('1Div')" class="region-shape" transform="translate(1625, 428)" filter="url(#badge-shadow)">
384
384
  <rect x="-72" y="-20" width="144" height="42" rx="9" fill="#fff7ed" stroke="#9a3412" stroke-width="2"/>
385
385
  <text x="0" y="-1" text-anchor="middle" class="badge-text" fill="#9a3412" id="title-1Div">1Div</text>
386
386
  <text x="0" y="15" text-anchor="middle" class="badge-sub" fill="#9a3412" id="sub-1Div">A(a,b) = 1</text>
387
387
  </g>
388
388
 
389
- <g id="label-EM" onclick="toggleProperty('EM')" class="region-shape" transform="translate(1495, 435)" filter="url(#badge-shadow)">
389
+ <g id="label-EM" onclick="toggleProperty('EM')" class="region-shape" transform="translate(1488, 475)" filter="url(#badge-shadow)">
390
390
  <rect x="-76" y="-20" width="152" height="42" rx="9" fill="#fff7ed" stroke="#ea580c" stroke-width="2"/>
391
391
  <text x="0" y="-1" text-anchor="middle" class="badge-text" fill="#c2410c" id="title-EM">EM</text>
392
392
  <text x="0" y="15" text-anchor="middle" class="badge-sub" fill="#ea580c" id="sub-EM">A(x,N(x)) = 1</text>
393
393
  </g>
394
394
 
395
- <g id="label-SEM" onclick="toggleProperty('SEM')" class="region-shape" transform="translate(1300, 575)" filter="url(#badge-shadow)">
395
+ <g id="label-SEM" onclick="toggleProperty('SEM')" class="region-shape" transform="translate(1300, 565)" filter="url(#badge-shadow)">
396
396
  <rect x="-82" y="-20" width="164" height="42" rx="9" fill="#fefce8" stroke="#ca8a04" stroke-width="2"/>
397
397
  <text x="0" y="-1" text-anchor="middle" class="badge-text" fill="#a16207" id="title-SEM">S-EM</text>
398
398
  <text x="0" y="15" text-anchor="middle" class="badge-sub" fill="#ca8a04" id="sub-SEM">y≥N(x) ⇔ A=1</text>
@@ -339,6 +339,25 @@ def uniform_measure(n: int) -> FuzzyMeasure:
339
339
  return _capacity_from_function(n, lambda subset: len(subset) / n)
340
340
 
341
341
 
342
+ def exponential_cardinality_measure(n: int, q: object = 1) -> FuzzyMeasure:
343
+ """Return ``mu(A) = (|A| / n)**q`` for finite ``q > 0``.
344
+
345
+ For q=1 this is the uniform measure. Increasing q cannot increase
346
+ either classical integral; only Choquet reduces to arithmetic mean at q=1.
347
+ """
348
+ n = _measure_size(n)
349
+ if isinstance(q, (bool, np.bool_)):
350
+ raise TypeError("q must be a real number, not bool")
351
+ try:
352
+ q = float(q)
353
+ except (ValueError, TypeError, OverflowError) as exc:
354
+ raise ValueError("q must be finite and greater than 0") from exc
355
+ if not isfinite(q) or q <= 0:
356
+ raise ValueError("q must be finite and greater than 0")
357
+ levels = [(size / n) ** q for size in range(n + 1)]
358
+ return _capacity_from_function(n, lambda subset: levels[len(subset)])
359
+
360
+
342
361
  def relative_measure(n: int) -> FuzzyMeasure:
343
362
  """Return the relative capacity with singleton weights 1, ..., n."""
344
363
  n = _measure_size(n)
@@ -372,6 +391,15 @@ def owa_measure(weights: object) -> FuzzyMeasure:
372
391
  )
373
392
 
374
393
 
394
+ def _lambda_capacity(weights, parameter):
395
+ # Equivalent to (prod(1 + parameter*w) - 1) / parameter,
396
+ # without cancellation or division by a parameter close to zero.
397
+ value = 0.0
398
+ for weight in weights:
399
+ value = value * (1.0 + parameter * float(weight)) + float(weight)
400
+ return value
401
+
402
+
375
403
  def _sugeno_lambda(weights: np.ndarray) -> float:
376
404
  total = math.fsum(float(weight) for weight in weights)
377
405
  if total == 1.0:
@@ -384,19 +412,17 @@ def _sugeno_lambda(weights: np.ndarray) -> float:
384
412
  "singleton weights do not define a normalized k-fuzzy measure"
385
413
  )
386
414
 
387
- def log_gap(value):
388
- return math.fsum(
389
- math.log1p(value * float(weight)) for weight in weights
390
- ) - math.log1p(value)
415
+ def gap(value):
416
+ return _lambda_capacity(weights, value) - 1.0
391
417
 
392
418
  lower, upper = 0.0, 1.0
393
- while log_gap(upper) <= 0.0:
419
+ while gap(upper) <= 0.0:
394
420
  upper *= 2.0
395
421
  if not isfinite(upper):
396
422
  raise ValueError("could not find the k-fuzzy measure parameter")
397
423
  for _ in range(100):
398
424
  middle = (lower + upper) / 2.0
399
- if log_gap(middle) < 0.0:
425
+ if gap(middle) < 0.0:
400
426
  lower = middle
401
427
  else:
402
428
  upper = middle
@@ -406,13 +432,12 @@ def _sugeno_lambda(weights: np.ndarray) -> float:
406
432
  return -1.0
407
433
 
408
434
  def gap(value):
409
- product = math.prod(1.0 + value * float(weight) for weight in weights)
410
- return product - (1.0 + value)
435
+ return _lambda_capacity(weights, value) - 1.0
411
436
 
412
437
  lower, upper = -1.0, 0.0
413
438
  for _ in range(100):
414
439
  middle = (lower + upper) / 2.0
415
- if gap(middle) > 0.0:
440
+ if gap(middle) < 0.0:
416
441
  lower = middle
417
442
  else:
418
443
  upper = middle
@@ -438,10 +463,7 @@ def k_fuzzy_measure(singleton_weights: object) -> FuzzyMeasure:
438
463
  subset_weights = [float(vector[index]) for index in subset]
439
464
  if parameter == 0.0:
440
465
  return math.fsum(subset_weights)
441
- if parameter == -1.0:
442
- return 1.0 - math.prod(1.0 - weight for weight in subset_weights)
443
- product = math.prod(1.0 + parameter * weight for weight in subset_weights)
444
- return (product - 1.0) / parameter
466
+ return _lambda_capacity(subset_weights, parameter)
445
467
 
446
468
  values = {}
447
469
  for mask in range(1 << n):
@@ -0,0 +1,81 @@
1
+ """Command line entry point for the Shiny interface."""
2
+
3
+ import argparse
4
+ from importlib import invalidate_caches
5
+ from importlib.metadata import PackageNotFoundError, requires, version
6
+ from pathlib import Path
7
+ import site
8
+ import subprocess
9
+ import sys
10
+ import tomllib
11
+
12
+ from packaging.requirements import Requirement
13
+
14
+
15
+ def _missing_app_requirements():
16
+ try:
17
+ requirements = requires("aggregationslib") or []
18
+ except PackageNotFoundError:
19
+ # Support running the CLI as a module from a source checkout.
20
+ pyproject = Path(__file__).resolve().parents[1] / "pyproject.toml"
21
+ with pyproject.open("rb") as file:
22
+ extras = tomllib.load(file)["project"]["optional-dependencies"]["app"]
23
+ requirements = [f'{item}; extra == "app"' for item in extras]
24
+
25
+ missing = []
26
+ for item in requirements:
27
+ requirement = Requirement(item)
28
+ marker = requirement.marker
29
+ if not marker or not marker.evaluate({"extra": "app"}) or marker.evaluate({"extra": ""}):
30
+ continue
31
+ try:
32
+ if requirement.specifier.contains(version(requirement.name), prereleases=True):
33
+ continue
34
+ except PackageNotFoundError:
35
+ pass
36
+ requirement.marker = None
37
+ missing.append(str(requirement))
38
+ return missing
39
+
40
+
41
+ def main():
42
+ parser = argparse.ArgumentParser(prog="agglib")
43
+ commands = parser.add_subparsers(dest="command", required=True)
44
+ commands.add_parser("start", aliases=["serve"], help="Open the local Shiny app")
45
+ parser.parse_args()
46
+
47
+ missing = _missing_app_requirements()
48
+ if missing:
49
+ if not sys.stdin.isatty():
50
+ parser.exit(
51
+ 1,
52
+ 'Run agglib start in a terminal or install the app with '
53
+ 'python -m pip install "aggregationslib[app]".\n',
54
+ )
55
+ try:
56
+ answer = input("Install the graphical interface? [Y/n] ").strip().lower()
57
+ except EOFError:
58
+ return
59
+ except KeyboardInterrupt:
60
+ parser.exit(130, "\n")
61
+ if answer not in {"", "y", "yes"}:
62
+ return
63
+
64
+ try:
65
+ subprocess.run([sys.executable, "-m", "pip", "install", *missing], check=True)
66
+ except subprocess.CalledProcessError as exc:
67
+ parser.exit(exc.returncode, "Could not install the graphical interface dependencies.\n")
68
+ if site.ENABLE_USER_SITE:
69
+ user_site = site.getusersitepackages()
70
+ if user_site not in sys.path and Path(user_site).is_dir():
71
+ site.addsitedir(user_site)
72
+ invalidate_caches()
73
+
74
+ from shiny import run_app
75
+ from apps.shiny.app import app
76
+
77
+ run_app(app, host="127.0.0.1", launch_browser=True)
78
+
79
+
80
+ if __name__ == "__main__":
81
+ main()