conceptflow 0.2.0__tar.gz → 0.3.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 (118) hide show
  1. conceptflow-0.3.0/PKG-INFO +162 -0
  2. conceptflow-0.3.0/README.md +96 -0
  3. {conceptflow-0.2.0 → conceptflow-0.3.0}/pyproject.toml +4 -0
  4. conceptflow-0.3.0/src/conceptflow/_version.py +1 -0
  5. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/algorithms/__init__.py +10 -0
  6. conceptflow-0.3.0/src/conceptflow/algorithms/enumeration.py +368 -0
  7. conceptflow-0.3.0/src/conceptflow/algorithms/generators.py +77 -0
  8. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/algorithms/hasse.py +14 -1
  9. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/algorithms/implications.py +53 -0
  10. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/algorithms/reduction.py +83 -1
  11. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/cluster/concept_lattice.py +87 -4
  12. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/core/__init__.py +14 -0
  13. conceptflow-0.3.0/src/conceptflow/core/context.py +410 -0
  14. conceptflow-0.3.0/src/conceptflow/core/lattice.py +311 -0
  15. conceptflow-0.3.0/src/conceptflow/core/operations.py +160 -0
  16. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/exploration/__init__.py +6 -1
  17. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/exploration/combinations.py +54 -1
  18. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/feature_extraction/concept_encoder.py +3 -0
  19. conceptflow-0.3.0/src/conceptflow/io/__init__.py +20 -0
  20. conceptflow-0.3.0/src/conceptflow/io/formats.py +165 -0
  21. conceptflow-0.3.0/src/conceptflow/metrics/__init__.py +29 -0
  22. conceptflow-0.3.0/src/conceptflow/metrics/measures.py +347 -0
  23. conceptflow-0.3.0/src/conceptflow/quality.py +377 -0
  24. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/rules/__init__.py +2 -0
  25. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/rules/implication_basis.py +3 -0
  26. conceptflow-0.3.0/src/conceptflow/rules/outlier_detector.py +231 -0
  27. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/validation/input.py +34 -0
  28. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/visualization/__init__.py +16 -0
  29. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/visualization/d3_backend.py +7 -4
  30. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/visualization/dimflux_layout.py +2 -1
  31. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/visualization/graph_data.py +19 -1
  32. conceptflow-0.3.0/src/conceptflow/visualization/graphviz.py +176 -0
  33. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/visualization/lattice_plot.py +30 -8
  34. conceptflow-0.3.0/src/conceptflow/visualization/layered_layout.py +199 -0
  35. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/visualization/nested.py +32 -4
  36. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/visualization/static.py +107 -105
  37. conceptflow-0.3.0/src/conceptflow/visualization/tikz.py +294 -0
  38. conceptflow-0.3.0/src/conceptflow.egg-info/PKG-INFO +162 -0
  39. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow.egg-info/SOURCES.txt +19 -0
  40. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow.egg-info/requires.txt +4 -0
  41. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_check_estimator.py +21 -2
  42. conceptflow-0.3.0/tests/test_context_handling.py +105 -0
  43. conceptflow-0.3.0/tests/test_context_operations.py +109 -0
  44. conceptflow-0.3.0/tests/test_docs_examples.py +78 -0
  45. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_enumeration.py +5 -1
  46. conceptflow-0.3.0/tests/test_generators.py +69 -0
  47. conceptflow-0.3.0/tests/test_lattice_navigation.py +180 -0
  48. conceptflow-0.3.0/tests/test_layout_and_graphviz.py +85 -0
  49. conceptflow-0.3.0/tests/test_measures.py +167 -0
  50. conceptflow-0.3.0/tests/test_quality.py +193 -0
  51. conceptflow-0.3.0/tests/test_review_fixes.py +213 -0
  52. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_static_figures.py +5 -4
  53. conceptflow-0.3.0/tests/test_tikz.py +73 -0
  54. conceptflow-0.2.0/PKG-INFO +0 -834
  55. conceptflow-0.2.0/README.md +0 -771
  56. conceptflow-0.2.0/src/conceptflow/_version.py +0 -1
  57. conceptflow-0.2.0/src/conceptflow/algorithms/enumeration.py +0 -218
  58. conceptflow-0.2.0/src/conceptflow/core/context.py +0 -283
  59. conceptflow-0.2.0/src/conceptflow/core/lattice.py +0 -144
  60. conceptflow-0.2.0/src/conceptflow/io/__init__.py +0 -6
  61. conceptflow-0.2.0/src/conceptflow/metrics/__init__.py +0 -13
  62. conceptflow-0.2.0/src/conceptflow.egg-info/PKG-INFO +0 -834
  63. {conceptflow-0.2.0 → conceptflow-0.3.0}/LICENSE +0 -0
  64. {conceptflow-0.2.0 → conceptflow-0.3.0}/setup.cfg +0 -0
  65. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/__init__.py +0 -0
  66. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/algorithms/_bitset.py +0 -0
  67. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/algorithms/_membership.py +0 -0
  68. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/algorithms/_registry.py +0 -0
  69. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/algorithms/derivation.py +0 -0
  70. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/algorithms/order.py +0 -0
  71. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/cluster/__init__.py +0 -0
  72. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/core/concept.py +0 -0
  73. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/core/incomplete_context.py +0 -0
  74. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/core/many_valued_context.py +0 -0
  75. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/decomposition/__init__.py +0 -0
  76. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/decomposition/ordinal_factorization.py +0 -0
  77. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/exploration/builder.py +0 -0
  78. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/exploration/view.py +0 -0
  79. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/feature_extraction/__init__.py +0 -0
  80. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/io/cxt.py +0 -0
  81. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/metrics/rules.py +0 -0
  82. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/model_selection/__init__.py +0 -0
  83. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/preprocessing/__init__.py +0 -0
  84. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/preprocessing/conceptual_scaler.py +0 -0
  85. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/preprocessing/scales.py +0 -0
  86. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/validation/__init__.py +0 -0
  87. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow/visualization/html_figure.py +0 -0
  88. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow.egg-info/dependency_links.txt +0 -0
  89. {conceptflow-0.2.0 → conceptflow-0.3.0}/src/conceptflow.egg-info/top_level.txt +0 -0
  90. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_algorithm_registry.py +0 -0
  91. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_audit_regressions.py +0 -0
  92. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_cluster_estimator.py +0 -0
  93. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_concept.py +0 -0
  94. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_concept_encoder.py +0 -0
  95. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_conceptual_scaler.py +0 -0
  96. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_cxt_io.py +0 -0
  97. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_d3_backend.py +0 -0
  98. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_derivation.py +0 -0
  99. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_dimflux_layout.py +0 -0
  100. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_exploration.py +0 -0
  101. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_formal_context.py +0 -0
  102. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_graph_data.py +0 -0
  103. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_hasse.py +0 -0
  104. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_html_figure.py +0 -0
  105. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_implication_basis_estimator.py +0 -0
  106. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_implications.py +0 -0
  107. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_incomplete_context.py +0 -0
  108. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_lattice.py +0 -0
  109. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_many_valued_context.py +0 -0
  110. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_metrics.py +0 -0
  111. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_nested_combinations.py +0 -0
  112. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_nested_visualization.py +0 -0
  113. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_ordinal_factorization.py +0 -0
  114. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_public_api.py +0 -0
  115. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_reduction.py +0 -0
  116. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_scales.py +0 -0
  117. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_sklearn_compatibility.py +0 -0
  118. {conceptflow-0.2.0 → conceptflow-0.3.0}/tests/test_validation_input.py +0 -0
@@ -0,0 +1,162 @@
1
+ Metadata-Version: 2.4
2
+ Name: conceptflow
3
+ Version: 0.3.0
4
+ Summary: A scikit-learn compatible Formal Concept Analysis framework.
5
+ Author-email: Anurag Sharma <sharma@cs.uni-kassel.de>
6
+ License: BSD 3-Clause License
7
+
8
+ Copyright (c) 2025, Anurag Sharma
9
+
10
+ Redistribution and use in source and binary forms, with or without
11
+ modification, are permitted provided that the following conditions are met:
12
+
13
+ 1. Redistributions of source code must retain the above copyright notice, this
14
+ list of conditions and the following disclaimer.
15
+
16
+ 2. Redistributions in binary form must reproduce the above copyright notice,
17
+ this list of conditions and the following disclaimer in the documentation
18
+ and/or other materials provided with the distribution.
19
+
20
+ 3. Neither the name of the copyright holder nor the names of its
21
+ contributors may be used to endorse or promote products derived from
22
+ this software without specific prior written permission.
23
+
24
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+
35
+ Project-URL: Homepage, https://github.com/anuragxorma/conceptflow
36
+ Project-URL: Repository, https://github.com/anuragxorma/conceptflow
37
+ Project-URL: Issues, https://github.com/anuragxorma/conceptflow/issues
38
+ Keywords: formal-concept-analysis,fca,scikit-learn,concept-lattice,conceptual-scaling
39
+ Classifier: Development Status :: 3 - Alpha
40
+ Classifier: Intended Audience :: Science/Research
41
+ Classifier: License :: OSI Approved :: BSD License
42
+ Classifier: Programming Language :: Python :: 3
43
+ Classifier: Programming Language :: Python :: 3.12
44
+ Classifier: Programming Language :: Python :: 3.13
45
+ Classifier: Operating System :: OS Independent
46
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
47
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
48
+ Requires-Python: >=3.12
49
+ Description-Content-Type: text/markdown
50
+ License-File: LICENSE
51
+ Requires-Dist: numpy
52
+ Requires-Dist: pandas
53
+ Requires-Dist: scipy
54
+ Requires-Dist: scikit-learn>=1.5
55
+ Requires-Dist: networkx
56
+ Requires-Dist: dim-flux<1.1,>=1.0.11
57
+ Provides-Extra: docs
58
+ Requires-Dist: mkdocs-material>=9.5; extra == "docs"
59
+ Requires-Dist: mkdocstrings[python]>=0.26; extra == "docs"
60
+ Provides-Extra: dev
61
+ Requires-Dist: scikit-learn>=1.6; extra == "dev"
62
+ Requires-Dist: pytest; extra == "dev"
63
+ Requires-Dist: pytest-cov; extra == "dev"
64
+ Requires-Dist: ruff; extra == "dev"
65
+ Dynamic: license-file
66
+
67
+ # ConceptFlow
68
+
69
+ ![Python](https://img.shields.io/badge/python-3.12%2B-blue)
70
+ ![License](https://img.shields.io/badge/license-BSD--3--Clause-green)
71
+ ![Status](https://img.shields.io/badge/status-experimental-orange)
72
+
73
+ ConceptFlow is a Python library for **Formal Concept Analysis (FCA)** that
74
+ fits into the scientific Python stack. Its machine-learning parts are proper
75
+ [scikit-learn](https://scikit-learn.org) estimators that pass scikit-learn's
76
+ estimator checks.
77
+
78
+ ```bash
79
+ pip install conceptflow
80
+ ```
81
+
82
+ Requires Python 3.12 or newer.
83
+
84
+ ## Example
85
+
86
+ ```python
87
+ import conceptflow as cf
88
+ from conceptflow.algorithms import compute_canonical_basis
89
+
90
+ # Each object has either all three attributes or exactly one.
91
+ ctx = cf.FormalContext.from_array(
92
+ [[1, 1, 1], [1, 0, 0], [0, 1, 0], [0, 0, 1]],
93
+ objects=["g1", "g2", "g3", "g4"],
94
+ attributes=["a", "b", "c"],
95
+ )
96
+
97
+ lattice = cf.ConceptLattice.from_context(ctx)
98
+ print(lattice.n_concepts) # 5
99
+
100
+ for implication in compute_canonical_basis(ctx):
101
+ print(implication.premise_names(ctx), "->", implication.conclusion_names(ctx))
102
+ # ('a', 'b') -> ('c',)
103
+ # ('a', 'c') -> ('b',)
104
+ # ('b', 'c') -> ('a',)
105
+
106
+ cf.plot_lattice(lattice, backend="tikz", layout="layered").write("lattice.pdf")
107
+ ```
108
+
109
+ ## Features
110
+
111
+ - **Formal contexts:** building and editing, clarification and reduction,
112
+ apposition, subposition, direct sum and product; `.cxt`, JSON (FCART/fcapy)
113
+ and CSV files; incomplete (yes/no/unknown) contexts.
114
+ - **Concept lattices:** NextClosure and Close-by-One on bitsets, iceberg
115
+ lattices, navigation (join, meet, up-sets, object and attribute concepts),
116
+ explicit opt-in limits for very large lattices.
117
+ - **Implications and rules:** canonical (Duquenne-Guigues) basis,
118
+ proper-premise basis, near-implications with exceptions (Luxenburger basis),
119
+ minimal generators.
120
+ - **Measures:** stability (exact and bounds), Δ-measure, entropy, information
121
+ gain, linearity and distributivity indices.
122
+ - **Conceptual scaling** of many-valued data with seven scale types and
123
+ explicit missing-value handling.
124
+ - **scikit-learn:** scaling, concept and implication features, and an
125
+ outlier detector that explains its decisions with implications.
126
+ - **Visualization:** interactive HTML, DimFlux and layered layouts,
127
+ matplotlib, Graphviz and TikZ/LaTeX export; Toscana-style nested line
128
+ diagrams.
129
+ - **Data quality:** rule violations, redundant objects and attributes,
130
+ explanations of objects and rules.
131
+
132
+ ## Documentation
133
+
134
+ The documentation lives in [`docs/`](https://github.com/anuragxorma/conceptflow/blob/main/docs/index.md):
135
+
136
+ - [Getting started](https://github.com/anuragxorma/conceptflow/blob/main/docs/getting-started.md)
137
+ - User guide: [contexts](https://github.com/anuragxorma/conceptflow/blob/main/docs/guide/contexts.md),
138
+ [lattices](https://github.com/anuragxorma/conceptflow/blob/main/docs/guide/lattices.md),
139
+ [implications](https://github.com/anuragxorma/conceptflow/blob/main/docs/guide/rules.md),
140
+ [measures](https://github.com/anuragxorma/conceptflow/blob/main/docs/guide/measures.md),
141
+ [scaling](https://github.com/anuragxorma/conceptflow/blob/main/docs/guide/scaling.md),
142
+ [scikit-learn](https://github.com/anuragxorma/conceptflow/blob/main/docs/guide/sklearn.md),
143
+ [visualization](https://github.com/anuragxorma/conceptflow/blob/main/docs/guide/visualization.md),
144
+ [nested diagrams](https://github.com/anuragxorma/conceptflow/blob/main/docs/guide/nested.md),
145
+ [data quality](https://github.com/anuragxorma/conceptflow/blob/main/docs/guide/quality.md)
146
+ - [Changelog](https://github.com/anuragxorma/conceptflow/blob/main/CHANGELOG.md)
147
+
148
+ To build the documentation site locally (with the API reference):
149
+
150
+ ```bash
151
+ pip install -e ".[docs]"
152
+ mkdocs serve
153
+ ```
154
+
155
+ Runnable examples, including a full case study, are in
156
+ [`examples/`](https://github.com/anuragxorma/conceptflow/tree/main/examples).
157
+
158
+ ## License
159
+
160
+ BSD 3-Clause; see [LICENSE](https://github.com/anuragxorma/conceptflow/blob/main/LICENSE).
161
+ Lattice layouts use [DimFlux](https://arxiv.org/abs/2603.16366) (the
162
+ `dim-flux` package, CC BY 4.0), installed automatically.
@@ -0,0 +1,96 @@
1
+ # ConceptFlow
2
+
3
+ ![Python](https://img.shields.io/badge/python-3.12%2B-blue)
4
+ ![License](https://img.shields.io/badge/license-BSD--3--Clause-green)
5
+ ![Status](https://img.shields.io/badge/status-experimental-orange)
6
+
7
+ ConceptFlow is a Python library for **Formal Concept Analysis (FCA)** that
8
+ fits into the scientific Python stack. Its machine-learning parts are proper
9
+ [scikit-learn](https://scikit-learn.org) estimators that pass scikit-learn's
10
+ estimator checks.
11
+
12
+ ```bash
13
+ pip install conceptflow
14
+ ```
15
+
16
+ Requires Python 3.12 or newer.
17
+
18
+ ## Example
19
+
20
+ ```python
21
+ import conceptflow as cf
22
+ from conceptflow.algorithms import compute_canonical_basis
23
+
24
+ # Each object has either all three attributes or exactly one.
25
+ ctx = cf.FormalContext.from_array(
26
+ [[1, 1, 1], [1, 0, 0], [0, 1, 0], [0, 0, 1]],
27
+ objects=["g1", "g2", "g3", "g4"],
28
+ attributes=["a", "b", "c"],
29
+ )
30
+
31
+ lattice = cf.ConceptLattice.from_context(ctx)
32
+ print(lattice.n_concepts) # 5
33
+
34
+ for implication in compute_canonical_basis(ctx):
35
+ print(implication.premise_names(ctx), "->", implication.conclusion_names(ctx))
36
+ # ('a', 'b') -> ('c',)
37
+ # ('a', 'c') -> ('b',)
38
+ # ('b', 'c') -> ('a',)
39
+
40
+ cf.plot_lattice(lattice, backend="tikz", layout="layered").write("lattice.pdf")
41
+ ```
42
+
43
+ ## Features
44
+
45
+ - **Formal contexts:** building and editing, clarification and reduction,
46
+ apposition, subposition, direct sum and product; `.cxt`, JSON (FCART/fcapy)
47
+ and CSV files; incomplete (yes/no/unknown) contexts.
48
+ - **Concept lattices:** NextClosure and Close-by-One on bitsets, iceberg
49
+ lattices, navigation (join, meet, up-sets, object and attribute concepts),
50
+ explicit opt-in limits for very large lattices.
51
+ - **Implications and rules:** canonical (Duquenne-Guigues) basis,
52
+ proper-premise basis, near-implications with exceptions (Luxenburger basis),
53
+ minimal generators.
54
+ - **Measures:** stability (exact and bounds), Δ-measure, entropy, information
55
+ gain, linearity and distributivity indices.
56
+ - **Conceptual scaling** of many-valued data with seven scale types and
57
+ explicit missing-value handling.
58
+ - **scikit-learn:** scaling, concept and implication features, and an
59
+ outlier detector that explains its decisions with implications.
60
+ - **Visualization:** interactive HTML, DimFlux and layered layouts,
61
+ matplotlib, Graphviz and TikZ/LaTeX export; Toscana-style nested line
62
+ diagrams.
63
+ - **Data quality:** rule violations, redundant objects and attributes,
64
+ explanations of objects and rules.
65
+
66
+ ## Documentation
67
+
68
+ The documentation lives in [`docs/`](https://github.com/anuragxorma/conceptflow/blob/main/docs/index.md):
69
+
70
+ - [Getting started](https://github.com/anuragxorma/conceptflow/blob/main/docs/getting-started.md)
71
+ - User guide: [contexts](https://github.com/anuragxorma/conceptflow/blob/main/docs/guide/contexts.md),
72
+ [lattices](https://github.com/anuragxorma/conceptflow/blob/main/docs/guide/lattices.md),
73
+ [implications](https://github.com/anuragxorma/conceptflow/blob/main/docs/guide/rules.md),
74
+ [measures](https://github.com/anuragxorma/conceptflow/blob/main/docs/guide/measures.md),
75
+ [scaling](https://github.com/anuragxorma/conceptflow/blob/main/docs/guide/scaling.md),
76
+ [scikit-learn](https://github.com/anuragxorma/conceptflow/blob/main/docs/guide/sklearn.md),
77
+ [visualization](https://github.com/anuragxorma/conceptflow/blob/main/docs/guide/visualization.md),
78
+ [nested diagrams](https://github.com/anuragxorma/conceptflow/blob/main/docs/guide/nested.md),
79
+ [data quality](https://github.com/anuragxorma/conceptflow/blob/main/docs/guide/quality.md)
80
+ - [Changelog](https://github.com/anuragxorma/conceptflow/blob/main/CHANGELOG.md)
81
+
82
+ To build the documentation site locally (with the API reference):
83
+
84
+ ```bash
85
+ pip install -e ".[docs]"
86
+ mkdocs serve
87
+ ```
88
+
89
+ Runnable examples, including a full case study, are in
90
+ [`examples/`](https://github.com/anuragxorma/conceptflow/tree/main/examples).
91
+
92
+ ## License
93
+
94
+ BSD 3-Clause; see [LICENSE](https://github.com/anuragxorma/conceptflow/blob/main/LICENSE).
95
+ Lattice layouts use [DimFlux](https://arxiv.org/abs/2603.16366) (the
96
+ `dim-flux` package, CC BY 4.0), installed automatically.
@@ -42,6 +42,10 @@ dependencies = [
42
42
  ]
43
43
 
44
44
  [project.optional-dependencies]
45
+ docs = [
46
+ "mkdocs-material>=9.5",
47
+ "mkdocstrings[python]>=0.26",
48
+ ]
45
49
  dev = [
46
50
  # The check_estimator tests use the scikit-learn >= 1.6 API.
47
51
  "scikit-learn>=1.6",
@@ -0,0 +1 @@
1
+ __version__ = "0.3.0"
@@ -22,13 +22,18 @@ from conceptflow.algorithms.implications import (
22
22
  compute_canonical_basis,
23
23
  compute_canonical_basis_bruteforce,
24
24
  compute_luxenburger_basis,
25
+ compute_proper_premise_basis,
25
26
  )
27
+ from conceptflow.algorithms.generators import compute_minimal_generators
26
28
  from conceptflow.algorithms.order import strict_subconcept_of, subconcept_of
27
29
 
28
30
  from conceptflow.algorithms.reduction import (
29
31
  ClarificationResult,
32
+ ReductionResult,
30
33
  clarified_context,
31
34
  clarify_context,
35
+ reduce_context,
36
+ reduced_context,
32
37
  )
33
38
 
34
39
  __all__ = [
@@ -48,9 +53,14 @@ __all__ = [
48
53
  "compute_canonical_basis_bruteforce",
49
54
  "AssociationRule",
50
55
  "compute_luxenburger_basis",
56
+ "compute_proper_premise_basis",
57
+ "compute_minimal_generators",
51
58
  "SUPPORTED_ENUMERATION_ALGORITHMS",
52
59
  "normalize_enumeration_algorithm",
53
60
  "ClarificationResult",
54
61
  "clarified_context",
55
62
  "clarify_context",
63
+ "ReductionResult",
64
+ "reduce_context",
65
+ "reduced_context",
56
66
  ]
@@ -0,0 +1,368 @@
1
+ """
2
+ Concept enumeration algorithms for ConceptFlow.
3
+
4
+ This module contains algorithms for enumerating formal concepts from a
5
+ formal context.
6
+
7
+ Implemented methods:
8
+
9
+ - brute-force enumeration
10
+ - NextClosure enumeration
11
+ - CloseByOne-style recursive enumeration
12
+
13
+ The brute-force algorithm is kept as a correctness baseline. NextClosure is
14
+ the first FCA-native enumeration algorithm used by ConceptFlow.
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ import numbers
20
+ import os
21
+ import warnings
22
+ from collections.abc import Iterable
23
+ from itertools import chain, combinations
24
+
25
+ from conceptflow.algorithms._bitset import BitsetContext, to_indices
26
+ from conceptflow.algorithms._registry import normalize_enumeration_algorithm
27
+ from conceptflow.algorithms.derivation import (
28
+ attribute_closure,
29
+ attribute_derivation,
30
+ )
31
+ from conceptflow.core.concept import Concept
32
+ from conceptflow.core.context import FormalContext
33
+
34
+
35
+ def powerset(items: Iterable[int]) -> Iterable[tuple[int, ...]]:
36
+ """
37
+ Yield all subsets of the given iterable.
38
+ """
39
+ items = list(items)
40
+ return chain.from_iterable(
41
+ combinations(items, r) for r in range(len(items) + 1)
42
+ )
43
+
44
+
45
+ def enumerate_concepts_bruteforce(context: FormalContext) -> list[Concept]:
46
+ """
47
+ Enumerate all formal concepts using brute force.
48
+
49
+ This tries every subset of attributes, closes it, and constructs the
50
+ corresponding concept.
51
+ """
52
+ concepts: set[Concept] = set()
53
+
54
+ attribute_indices = range(context.n_attributes)
55
+
56
+ for subset in powerset(attribute_indices):
57
+ intent = attribute_closure(context, subset)
58
+ extent = attribute_derivation(context, intent)
59
+ concepts.add(Concept(extent=extent, intent=intent))
60
+
61
+ return sorted(
62
+ concepts,
63
+ key=lambda c: (
64
+ len(c.extent),
65
+ sorted(c.extent),
66
+ sorted(c.intent),
67
+ ),
68
+ )
69
+
70
+
71
+ # Warnings are attributed to the first stack frame outside ConceptFlow (and
72
+ # scikit-learn, so warnings raised inside a Pipeline point at user code).
73
+ _PACKAGE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + os.sep
74
+
75
+
76
+ def _internal_prefixes() -> tuple[str, ...]:
77
+ prefixes = [_PACKAGE_DIR]
78
+ try:
79
+ import sklearn
80
+
81
+ prefixes.append(os.path.dirname(os.path.abspath(sklearn.__file__)) + os.sep)
82
+ except ImportError: # pragma: no cover - sklearn is a dependency
83
+ pass
84
+ return tuple(prefixes)
85
+
86
+
87
+ _INTERNAL_PREFIXES = _internal_prefixes()
88
+
89
+ # Enumerations warn once when they pass this many concepts (see _SizeGuard).
90
+ LARGE_LATTICE_WARNING_SIZE = 50_000
91
+
92
+
93
+ class LargeLatticeWarning(UserWarning):
94
+ """Emitted while enumerating a lattice that is becoming very large."""
95
+
96
+
97
+ class ConceptLimitExceeded(ValueError):
98
+ """Raised when an enumeration exceeds an explicit ``max_concepts`` limit."""
99
+
100
+
101
+ class _SizeGuard:
102
+ """
103
+ Watches the number of concepts produced by an enumeration.
104
+
105
+ Nothing changes by default: past ``LARGE_LATTICE_WARNING_SIZE`` concepts a
106
+ single warning names the opt-in options, and the enumeration continues.
107
+ Only an explicit ``max_concepts`` stops it.
108
+ """
109
+
110
+ def __init__(self, max_concepts: int | None = None) -> None:
111
+ if max_concepts is not None and (
112
+ isinstance(max_concepts, bool)
113
+ or not isinstance(max_concepts, numbers.Integral)
114
+ or max_concepts < 1
115
+ ):
116
+ raise ValueError("max_concepts must be None or a positive integer.")
117
+ self.max_concepts = None if max_concepts is None else int(max_concepts)
118
+ self.count = 0
119
+ self.warned = False
120
+
121
+ def tick(self) -> None:
122
+ self.count += 1
123
+
124
+ if self.max_concepts is not None and self.count > self.max_concepts:
125
+ raise ConceptLimitExceeded(
126
+ f"The lattice has more than max_concepts={self.max_concepts} "
127
+ "concepts. Use min_support=... to compute only frequent "
128
+ "concepts, or raise max_concepts."
129
+ )
130
+
131
+ # With an explicit max_concepts the user has already decided.
132
+ if (
133
+ not self.warned
134
+ and self.max_concepts is None
135
+ and self.count > LARGE_LATTICE_WARNING_SIZE
136
+ ):
137
+ self.warned = True
138
+ warnings.warn(
139
+ f"The concept lattice has more than {LARGE_LATTICE_WARNING_SIZE:,} "
140
+ "concepts and is still growing. Computation continues. To limit "
141
+ "it, use min_support=... (only concepts with at least that many "
142
+ "objects) or max_concepts=... (stop with an error past a limit).",
143
+ LargeLatticeWarning,
144
+ skip_file_prefixes=_INTERNAL_PREFIXES,
145
+ )
146
+
147
+
148
+ def _intent_of(extent: int, columns: list[int]) -> int:
149
+ """A' for an object bitset A: attributes whose column contains A."""
150
+ intent = 0
151
+ for m, column in enumerate(columns):
152
+ if extent & column == extent:
153
+ intent |= 1 << m
154
+ return intent
155
+
156
+
157
+ def _to_concept(extent: int, intent: int) -> Concept:
158
+ return Concept(extent=to_indices(extent), intent=to_indices(intent))
159
+
160
+
161
+ def enumerate_concepts_nextclosure(
162
+ context: FormalContext,
163
+ *,
164
+ _guard: _SizeGuard | None = None,
165
+ ) -> list[Concept]:
166
+ """
167
+ Enumerate all formal concepts using the NextClosure algorithm.
168
+
169
+ Concepts are returned in lectic order of their intents (attribute 0 is
170
+ the most significant). Sets are integer bitsets internally, so a closure
171
+ costs one AND per attribute instead of NumPy calls.
172
+ """
173
+ bits = BitsetContext(context)
174
+ columns = bits.columns
175
+ n_attributes = bits.n_attributes
176
+ guard = _guard or _SizeGuard()
177
+
178
+ def close(attributes: int) -> tuple[int, int]:
179
+ extent = bits.extent(attributes)
180
+ return extent, _intent_of(extent, columns)
181
+
182
+ concepts: list[Concept] = []
183
+ current: tuple[int, int] | None = close(0)
184
+
185
+ while current is not None:
186
+ extent, intent = current
187
+ guard.tick()
188
+ concepts.append(_to_concept(extent, intent))
189
+
190
+ current = None
191
+ prefix = intent
192
+
193
+ for i in range(n_attributes - 1, -1, -1):
194
+ bit = 1 << i
195
+
196
+ if prefix & bit:
197
+ prefix &= ~bit
198
+ continue
199
+
200
+ candidate_extent, candidate_intent = close(prefix | bit)
201
+
202
+ # Canonical iff the closure adds no attribute below i.
203
+ if (candidate_intent & ~prefix) & (bit - 1) == 0:
204
+ current = (candidate_extent, candidate_intent)
205
+ break
206
+
207
+ return concepts
208
+
209
+
210
+ def _closebyone_bitsets(
211
+ bits: BitsetContext,
212
+ min_extent_size: int = 0,
213
+ guard: _SizeGuard | None = None,
214
+ ) -> list[tuple[int, int]]:
215
+ """
216
+ Close-by-One on integer bitsets; returns ``(extent, intent)`` pairs.
217
+
218
+ Concepts with fewer than ``min_extent_size`` objects are pruned with
219
+ their whole subtree: extending a concept only shrinks its extent, and a
220
+ concept's canonical generation path runs through larger extents only,
221
+ so no concept above the threshold is lost.
222
+ """
223
+ columns = bits.columns
224
+ n_attributes = bits.n_attributes
225
+
226
+ if bits.n_objects < min_extent_size:
227
+ # Not even the top concept is frequent; it is still returned, so an
228
+ # iceberg lattice always has its top.
229
+ if guard is not None:
230
+ guard.tick()
231
+ return [(bits.all_objects, _intent_of(bits.all_objects, columns))]
232
+
233
+ found: list[tuple[int, int]] = []
234
+ stack = [(bits.all_objects, _intent_of(bits.all_objects, columns), 0)]
235
+
236
+ while stack:
237
+ extent, intent, start = stack.pop()
238
+ if guard is not None:
239
+ guard.tick()
240
+ found.append((extent, intent))
241
+
242
+ for j in range(start, n_attributes):
243
+ if intent >> j & 1:
244
+ continue
245
+
246
+ new_extent = extent & columns[j]
247
+
248
+ if new_extent.bit_count() < min_extent_size:
249
+ continue
250
+
251
+ if any(
252
+ not intent >> m & 1 and new_extent & columns[m] == new_extent
253
+ for m in range(j)
254
+ ):
255
+ continue
256
+
257
+ new_intent = intent | (1 << j)
258
+ for m in range(j + 1, n_attributes):
259
+ if not new_intent >> m & 1 and new_extent & columns[m] == new_extent:
260
+ new_intent |= 1 << m
261
+
262
+ stack.append((new_extent, new_intent, j + 1))
263
+
264
+ return found
265
+
266
+
267
+ def enumerate_concepts_closebyone(
268
+ context: FormalContext,
269
+ *,
270
+ _guard: _SizeGuard | None = None,
271
+ ) -> list[Concept]:
272
+ """
273
+ Enumerate formal concepts using Close-by-One.
274
+
275
+ Starting from the top concept, each concept (A, B) is extended by every
276
+ attribute j > (the attribute that generated it) not in B: the new extent
277
+ is A ∩ j'. The extension is canonical, and therefore new, iff no
278
+ attribute below j that is missing from B holds for the whole new extent;
279
+ that test runs before the rest of the new intent is computed, so most
280
+ duplicates are rejected early. Sets are integer bitsets throughout.
281
+ """
282
+ found = _closebyone_bitsets(BitsetContext(context), guard=_guard or _SizeGuard())
283
+
284
+ concepts = [_to_concept(extent, intent) for extent, intent in found]
285
+
286
+ return sorted(concepts, key=_size_order)
287
+
288
+
289
+ def _size_order(concept: Concept):
290
+ """Order used by bruteforce and Close-by-One: by extent size, then content."""
291
+ return (len(concept.extent), sorted(concept.extent), sorted(concept.intent))
292
+
293
+
294
+ def _lectic_order(n_attributes: int):
295
+ """NextClosure's order: intents compared as bit strings, attribute 0 first."""
296
+ def key(concept: Concept) -> int:
297
+ return sum(1 << (n_attributes - 1 - m) for m in concept.intent)
298
+
299
+ return key
300
+
301
+ def _resolve_min_support(min_support: int | float | None, n_objects: int) -> int:
302
+ """Turn an absolute (int) or relative (float) support into an object count."""
303
+ if min_support is None:
304
+ return 0
305
+
306
+ from conceptflow.algorithms.implications import _resolve_min_support as resolve
307
+
308
+ return resolve(min_support, n_objects)
309
+
310
+
311
+ def enumerate_concepts(
312
+ context: FormalContext,
313
+ method: str = "nextclosure",
314
+ min_support: int | float | None = None,
315
+ max_concepts: int | None = None,
316
+ ) -> list[Concept]:
317
+ """
318
+ Enumerate concepts using the selected method.
319
+
320
+ Parameters
321
+ ----------
322
+ context:
323
+ The formal context.
324
+
325
+ method:
326
+ "nextclosure" (lectic order), "closebyone" or "bruteforce" (both
327
+ ordered by extent size).
328
+
329
+ min_support:
330
+ Only enumerate concepts whose extent has at least this many objects
331
+ (an int) or this fraction of all objects (a float): the "iceberg"
332
+ of the lattice. These concepts form an up-set, so the top concept is
333
+ always included.
334
+
335
+ max_concepts:
336
+ Stop with :class:`ConceptLimitExceeded` once more than this many
337
+ concepts were found. By default there is no limit; enumerations past
338
+ 50,000 concepts emit a :class:`LargeLatticeWarning` and continue.
339
+ """
340
+ method = normalize_enumeration_algorithm(method)
341
+ guard = _SizeGuard(max_concepts)
342
+ threshold = _resolve_min_support(min_support, context.n_objects)
343
+
344
+ if threshold > 0:
345
+ # Pruned Close-by-One computes exactly the frequent concepts; they are
346
+ # then put in the order the requested method would have produced.
347
+ found = _closebyone_bitsets(BitsetContext(context), threshold, guard)
348
+ concepts = [_to_concept(extent, intent) for extent, intent in found]
349
+ if method == "nextclosure":
350
+ return sorted(concepts, key=_lectic_order(context.n_attributes))
351
+ return sorted(concepts, key=_size_order)
352
+
353
+ if method == "bruteforce":
354
+ # Bruteforce has no incremental output; count once it is done.
355
+ concepts = enumerate_concepts_bruteforce(context)
356
+ for _ in concepts:
357
+ guard.tick()
358
+ return concepts
359
+
360
+ if method == "nextclosure":
361
+ return enumerate_concepts_nextclosure(context, _guard=guard)
362
+
363
+ if method == "closebyone":
364
+ return enumerate_concepts_closebyone(context, _guard=guard)
365
+
366
+ raise RuntimeError(
367
+ f'Algorithm "{method}" was normalized but has no implementation.'
368
+ )