conceptflow 0.1.1__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.
- conceptflow-0.3.0/PKG-INFO +162 -0
- conceptflow-0.3.0/README.md +96 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/pyproject.toml +17 -12
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/__init__.py +2 -0
- conceptflow-0.3.0/src/conceptflow/_version.py +1 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/algorithms/__init__.py +20 -1
- conceptflow-0.3.0/src/conceptflow/algorithms/_bitset.py +93 -0
- conceptflow-0.3.0/src/conceptflow/algorithms/_membership.py +59 -0
- conceptflow-0.3.0/src/conceptflow/algorithms/enumeration.py +368 -0
- conceptflow-0.3.0/src/conceptflow/algorithms/generators.py +77 -0
- conceptflow-0.3.0/src/conceptflow/algorithms/hasse.py +184 -0
- conceptflow-0.3.0/src/conceptflow/algorithms/implications.py +613 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/algorithms/reduction.py +83 -1
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/cluster/concept_lattice.py +93 -12
- conceptflow-0.3.0/src/conceptflow/core/__init__.py +27 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/core/concept.py +12 -4
- conceptflow-0.3.0/src/conceptflow/core/context.py +410 -0
- conceptflow-0.3.0/src/conceptflow/core/incomplete_context.py +392 -0
- conceptflow-0.3.0/src/conceptflow/core/lattice.py +311 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/core/many_valued_context.py +9 -3
- conceptflow-0.3.0/src/conceptflow/core/operations.py +160 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/exploration/__init__.py +9 -1
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/exploration/builder.py +44 -13
- conceptflow-0.3.0/src/conceptflow/exploration/combinations.py +203 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/feature_extraction/concept_encoder.py +21 -21
- conceptflow-0.3.0/src/conceptflow/io/__init__.py +20 -0
- conceptflow-0.3.0/src/conceptflow/io/formats.py +165 -0
- conceptflow-0.3.0/src/conceptflow/metrics/__init__.py +29 -0
- conceptflow-0.3.0/src/conceptflow/metrics/measures.py +347 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/metrics/rules.py +23 -1
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/preprocessing/conceptual_scaler.py +134 -19
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/preprocessing/scales.py +28 -0
- conceptflow-0.3.0/src/conceptflow/quality.py +377 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/rules/__init__.py +2 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/rules/implication_basis.py +10 -9
- conceptflow-0.3.0/src/conceptflow/rules/outlier_detector.py +231 -0
- conceptflow-0.3.0/src/conceptflow/validation/input.py +119 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/visualization/__init__.py +29 -5
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/visualization/d3_backend.py +7 -4
- conceptflow-0.3.0/src/conceptflow/visualization/dimflux_layout.py +166 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/visualization/graph_data.py +19 -1
- conceptflow-0.3.0/src/conceptflow/visualization/graphviz.py +176 -0
- conceptflow-0.3.0/src/conceptflow/visualization/lattice_plot.py +138 -0
- conceptflow-0.3.0/src/conceptflow/visualization/layered_layout.py +199 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/visualization/nested.py +100 -72
- conceptflow-0.3.0/src/conceptflow/visualization/static.py +411 -0
- conceptflow-0.3.0/src/conceptflow/visualization/tikz.py +294 -0
- conceptflow-0.3.0/src/conceptflow.egg-info/PKG-INFO +162 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow.egg-info/SOURCES.txt +29 -13
- conceptflow-0.3.0/src/conceptflow.egg-info/requires.txt +16 -0
- conceptflow-0.3.0/tests/test_audit_regressions.py +278 -0
- conceptflow-0.3.0/tests/test_check_estimator.py +113 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/tests/test_conceptual_scaler.py +96 -1
- conceptflow-0.3.0/tests/test_context_handling.py +105 -0
- conceptflow-0.3.0/tests/test_context_operations.py +109 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/tests/test_dimflux_layout.py +64 -4
- conceptflow-0.3.0/tests/test_docs_examples.py +78 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/tests/test_enumeration.py +25 -1
- conceptflow-0.3.0/tests/test_generators.py +69 -0
- conceptflow-0.3.0/tests/test_hasse.py +66 -0
- conceptflow-0.3.0/tests/test_implications.py +302 -0
- conceptflow-0.3.0/tests/test_incomplete_context.py +118 -0
- conceptflow-0.3.0/tests/test_lattice_navigation.py +180 -0
- conceptflow-0.3.0/tests/test_layout_and_graphviz.py +85 -0
- conceptflow-0.3.0/tests/test_measures.py +167 -0
- conceptflow-0.3.0/tests/test_nested_combinations.py +99 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/tests/test_public_api.py +25 -1
- conceptflow-0.3.0/tests/test_quality.py +193 -0
- conceptflow-0.3.0/tests/test_review_fixes.py +213 -0
- conceptflow-0.3.0/tests/test_static_figures.py +134 -0
- conceptflow-0.3.0/tests/test_tikz.py +73 -0
- conceptflow-0.1.1/PKG-INFO +0 -748
- conceptflow-0.1.1/README.md +0 -684
- conceptflow-0.1.1/src/conceptflow/_version.py +0 -1
- conceptflow-0.1.1/src/conceptflow/algorithms/enumeration.py +0 -208
- conceptflow-0.1.1/src/conceptflow/algorithms/hasse.py +0 -83
- conceptflow-0.1.1/src/conceptflow/algorithms/implications.py +0 -150
- conceptflow-0.1.1/src/conceptflow/core/__init__.py +0 -11
- conceptflow-0.1.1/src/conceptflow/core/context.py +0 -241
- conceptflow-0.1.1/src/conceptflow/core/lattice.py +0 -129
- conceptflow-0.1.1/src/conceptflow/io/__init__.py +0 -6
- conceptflow-0.1.1/src/conceptflow/metrics/__init__.py +0 -11
- conceptflow-0.1.1/src/conceptflow/validation/input.py +0 -68
- conceptflow-0.1.1/src/conceptflow/visualization/dimflux/LICENSE +0 -395
- conceptflow-0.1.1/src/conceptflow/visualization/dimflux/README.md +0 -77
- conceptflow-0.1.1/src/conceptflow/visualization/dimflux/libs/brunt-fork.jar +0 -4
- conceptflow-0.1.1/src/conceptflow/visualization/dimflux/src/__init__.py +0 -0
- conceptflow-0.1.1/src/conceptflow/visualization/dimflux/src/dim_flux/additive_realizer.py +0 -213
- conceptflow-0.1.1/src/conceptflow/visualization/dimflux/src/dim_flux/dim_draw.py +0 -172
- conceptflow-0.1.1/src/conceptflow/visualization/dimflux/src/dim_flux/lgs.py +0 -149
- conceptflow-0.1.1/src/conceptflow/visualization/dimflux/src/dim_flux/projection.py +0 -137
- conceptflow-0.1.1/src/conceptflow/visualization/dimflux/src/dim_flux/realizer.py +0 -97
- conceptflow-0.1.1/src/conceptflow/visualization/dimflux/src/fca/context.py +0 -130
- conceptflow-0.1.1/src/conceptflow/visualization/dimflux/src/fca/lattice.py +0 -125
- conceptflow-0.1.1/src/conceptflow/visualization/dimflux/src/fdp/forces.py +0 -519
- conceptflow-0.1.1/src/conceptflow/visualization/dimflux/src/utils/variables.py +0 -184
- conceptflow-0.1.1/src/conceptflow/visualization/dimflux_layout.py +0 -176
- conceptflow-0.1.1/src/conceptflow/visualization/lattice_plot.py +0 -92
- conceptflow-0.1.1/src/conceptflow.egg-info/PKG-INFO +0 -748
- conceptflow-0.1.1/src/conceptflow.egg-info/requires.txt +0 -12
- conceptflow-0.1.1/tests/test_check_estimator.py +0 -90
- conceptflow-0.1.1/tests/test_implications.py +0 -117
- {conceptflow-0.1.1 → conceptflow-0.3.0}/LICENSE +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/setup.cfg +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/algorithms/_registry.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/algorithms/derivation.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/algorithms/order.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/cluster/__init__.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/decomposition/__init__.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/decomposition/ordinal_factorization.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/exploration/view.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/feature_extraction/__init__.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/io/cxt.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/model_selection/__init__.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/preprocessing/__init__.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/validation/__init__.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow/visualization/html_figure.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow.egg-info/dependency_links.txt +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/src/conceptflow.egg-info/top_level.txt +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/tests/test_algorithm_registry.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/tests/test_cluster_estimator.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/tests/test_concept.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/tests/test_concept_encoder.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/tests/test_cxt_io.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/tests/test_d3_backend.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/tests/test_derivation.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/tests/test_exploration.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/tests/test_formal_context.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/tests/test_graph_data.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/tests/test_html_figure.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/tests/test_implication_basis_estimator.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/tests/test_lattice.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/tests/test_many_valued_context.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/tests/test_metrics.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/tests/test_nested_visualization.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/tests/test_ordinal_factorization.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/tests/test_reduction.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/tests/test_scales.py +0 -0
- {conceptflow-0.1.1 → conceptflow-0.3.0}/tests/test_sklearn_compatibility.py +0 -0
- {conceptflow-0.1.1 → 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
|
+

|
|
70
|
+

|
|
71
|
+

|
|
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
|
+

|
|
4
|
+

|
|
5
|
+

|
|
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.
|
|
@@ -4,10 +4,10 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "conceptflow"
|
|
7
|
-
|
|
7
|
+
dynamic = ["version"]
|
|
8
8
|
description = "A scikit-learn compatible Formal Concept Analysis framework."
|
|
9
9
|
readme = "README.md"
|
|
10
|
-
requires-python = ">=3.
|
|
10
|
+
requires-python = ">=3.12"
|
|
11
11
|
license = { file = "LICENSE" }
|
|
12
12
|
authors = [
|
|
13
13
|
{ name = "Anurag Sharma", email = "sharma@cs.uni-kassel.de" }
|
|
@@ -24,9 +24,8 @@ classifiers = [
|
|
|
24
24
|
"Intended Audience :: Science/Research",
|
|
25
25
|
"License :: OSI Approved :: BSD License",
|
|
26
26
|
"Programming Language :: Python :: 3",
|
|
27
|
-
"Programming Language :: Python :: 3.10",
|
|
28
|
-
"Programming Language :: Python :: 3.11",
|
|
29
27
|
"Programming Language :: Python :: 3.12",
|
|
28
|
+
"Programming Language :: Python :: 3.13",
|
|
30
29
|
"Operating System :: OS Independent",
|
|
31
30
|
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
32
31
|
"Topic :: Scientific/Engineering :: Information Analysis",
|
|
@@ -35,14 +34,21 @@ dependencies = [
|
|
|
35
34
|
"numpy",
|
|
36
35
|
"pandas",
|
|
37
36
|
"scipy",
|
|
38
|
-
"scikit-learn>=1.
|
|
37
|
+
"scikit-learn>=1.5",
|
|
39
38
|
"networkx",
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
# dimflux_layout uses DimFlux's pipeline classes directly, not only its
|
|
40
|
+
# public plot(), so stay within the tested minor version.
|
|
41
|
+
"dim-flux>=1.0.11,<1.1",
|
|
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 = [
|
|
50
|
+
# The check_estimator tests use the scikit-learn >= 1.6 API.
|
|
51
|
+
"scikit-learn>=1.6",
|
|
46
52
|
"pytest",
|
|
47
53
|
"pytest-cov",
|
|
48
54
|
"ruff",
|
|
@@ -56,20 +62,19 @@ Issues = "https://github.com/anuragxorma/conceptflow/issues"
|
|
|
56
62
|
[tool.setuptools.packages.find]
|
|
57
63
|
where = ["src"]
|
|
58
64
|
|
|
59
|
-
[tool.setuptools.package-data]
|
|
60
|
-
"conceptflow.visualization.dimflux" = ["LICENSE", "README.md"]
|
|
61
|
-
"conceptflow.visualization.dimflux.libs" = ["*.jar"]
|
|
62
|
-
|
|
63
65
|
[tool.setuptools]
|
|
64
66
|
include-package-data = true
|
|
65
67
|
|
|
68
|
+
[tool.setuptools.dynamic]
|
|
69
|
+
version = { attr = "conceptflow._version.__version__" }
|
|
70
|
+
|
|
66
71
|
[tool.pytest.ini_options]
|
|
67
72
|
testpaths = ["tests"]
|
|
68
73
|
pythonpath = ["src"]
|
|
69
74
|
|
|
70
75
|
[tool.ruff]
|
|
71
76
|
line-length = 100
|
|
72
|
-
target-version = "
|
|
77
|
+
target-version = "py312"
|
|
73
78
|
|
|
74
79
|
[tool.ruff.lint]
|
|
75
80
|
select = ["E", "F", "W", "I"]
|
|
@@ -9,6 +9,7 @@ from conceptflow.core import (
|
|
|
9
9
|
Concept,
|
|
10
10
|
ConceptLattice,
|
|
11
11
|
FormalContext,
|
|
12
|
+
IncompleteContext,
|
|
12
13
|
ManyValuedContext,
|
|
13
14
|
)
|
|
14
15
|
from conceptflow.visualization import (
|
|
@@ -28,6 +29,7 @@ __all__ = [
|
|
|
28
29
|
"__version__",
|
|
29
30
|
"Concept",
|
|
30
31
|
"FormalContext",
|
|
32
|
+
"IncompleteContext",
|
|
31
33
|
"ManyValuedContext",
|
|
32
34
|
"ConceptLattice",
|
|
33
35
|
"GraphData",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.3.0"
|
|
@@ -16,13 +16,24 @@ from conceptflow.algorithms._registry import (
|
|
|
16
16
|
)
|
|
17
17
|
|
|
18
18
|
from conceptflow.algorithms.hasse import compute_hasse_edges, is_cover
|
|
19
|
-
from conceptflow.algorithms.implications import
|
|
19
|
+
from conceptflow.algorithms.implications import (
|
|
20
|
+
AssociationRule,
|
|
21
|
+
Implication,
|
|
22
|
+
compute_canonical_basis,
|
|
23
|
+
compute_canonical_basis_bruteforce,
|
|
24
|
+
compute_luxenburger_basis,
|
|
25
|
+
compute_proper_premise_basis,
|
|
26
|
+
)
|
|
27
|
+
from conceptflow.algorithms.generators import compute_minimal_generators
|
|
20
28
|
from conceptflow.algorithms.order import strict_subconcept_of, subconcept_of
|
|
21
29
|
|
|
22
30
|
from conceptflow.algorithms.reduction import (
|
|
23
31
|
ClarificationResult,
|
|
32
|
+
ReductionResult,
|
|
24
33
|
clarified_context,
|
|
25
34
|
clarify_context,
|
|
35
|
+
reduce_context,
|
|
36
|
+
reduced_context,
|
|
26
37
|
)
|
|
27
38
|
|
|
28
39
|
__all__ = [
|
|
@@ -39,9 +50,17 @@ __all__ = [
|
|
|
39
50
|
"compute_hasse_edges",
|
|
40
51
|
"Implication",
|
|
41
52
|
"compute_canonical_basis",
|
|
53
|
+
"compute_canonical_basis_bruteforce",
|
|
54
|
+
"AssociationRule",
|
|
55
|
+
"compute_luxenburger_basis",
|
|
56
|
+
"compute_proper_premise_basis",
|
|
57
|
+
"compute_minimal_generators",
|
|
42
58
|
"SUPPORTED_ENUMERATION_ALGORITHMS",
|
|
43
59
|
"normalize_enumeration_algorithm",
|
|
44
60
|
"ClarificationResult",
|
|
45
61
|
"clarified_context",
|
|
46
62
|
"clarify_context",
|
|
63
|
+
"ReductionResult",
|
|
64
|
+
"reduce_context",
|
|
65
|
+
"reduced_context",
|
|
47
66
|
]
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Integer-bitset view of a formal context.
|
|
3
|
+
|
|
4
|
+
Attribute and object sets are encoded as Python ints (bit ``j`` set iff
|
|
5
|
+
index ``j`` is in the set). Intersections, unions and subset tests then
|
|
6
|
+
become single machine-level operations on arbitrary-precision ints, which
|
|
7
|
+
is far faster than ``frozenset`` arithmetic in the inner loops of
|
|
8
|
+
NextClosure-style algorithms.
|
|
9
|
+
|
|
10
|
+
This module is internal: public functions keep returning ``frozenset[int]``
|
|
11
|
+
and convert at the boundary with ``to_indices`` / ``from_indices``.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import operator
|
|
17
|
+
from collections.abc import Iterable
|
|
18
|
+
|
|
19
|
+
import numpy as np
|
|
20
|
+
|
|
21
|
+
from conceptflow.core.context import FormalContext
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def from_indices(indices: Iterable[int]) -> int:
|
|
25
|
+
"""Encode an iterable of indices as a bitset."""
|
|
26
|
+
mask = 0
|
|
27
|
+
for index in indices:
|
|
28
|
+
# operator.index: a numpy integer here would turn the mask into a
|
|
29
|
+
# fixed-width numpy integer and silently overflow past 63 bits.
|
|
30
|
+
mask |= 1 << operator.index(index)
|
|
31
|
+
return mask
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def to_indices(mask: int) -> frozenset[int]:
|
|
35
|
+
"""Decode a bitset into a frozenset of indices."""
|
|
36
|
+
indices = []
|
|
37
|
+
while mask:
|
|
38
|
+
low = mask & -mask
|
|
39
|
+
indices.append(low.bit_length() - 1)
|
|
40
|
+
mask ^= low
|
|
41
|
+
return frozenset(indices)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def iter_bits(mask: int):
|
|
45
|
+
"""Yield the indices of the set bits of ``mask``, lowest first."""
|
|
46
|
+
while mask:
|
|
47
|
+
low = mask & -mask
|
|
48
|
+
yield low.bit_length() - 1
|
|
49
|
+
mask ^= low
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class BitsetContext:
|
|
53
|
+
"""
|
|
54
|
+
Row- and column-bitset encoding of a formal context.
|
|
55
|
+
|
|
56
|
+
Attributes
|
|
57
|
+
----------
|
|
58
|
+
rows:
|
|
59
|
+
``rows[g]`` is the attribute set ``g'`` of object ``g``.
|
|
60
|
+
|
|
61
|
+
columns:
|
|
62
|
+
``columns[m]`` is the object set ``m'`` of attribute ``m``.
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
def __init__(self, context: FormalContext) -> None:
|
|
66
|
+
incidence = np.asarray(context.incidence, dtype=bool)
|
|
67
|
+
|
|
68
|
+
self.n_objects = context.n_objects
|
|
69
|
+
self.n_attributes = context.n_attributes
|
|
70
|
+
self.all_objects = (1 << self.n_objects) - 1
|
|
71
|
+
self.all_attributes = (1 << self.n_attributes) - 1
|
|
72
|
+
self.rows = [from_indices(np.flatnonzero(row).tolist()) for row in incidence]
|
|
73
|
+
self.columns = [
|
|
74
|
+
from_indices(np.flatnonzero(column).tolist()) for column in incidence.T
|
|
75
|
+
]
|
|
76
|
+
|
|
77
|
+
def extent(self, attributes: int) -> int:
|
|
78
|
+
"""B' for an attribute bitset B."""
|
|
79
|
+
objects = self.all_objects
|
|
80
|
+
for m in iter_bits(attributes):
|
|
81
|
+
objects &= self.columns[m]
|
|
82
|
+
return objects
|
|
83
|
+
|
|
84
|
+
def intent(self, objects: int) -> int:
|
|
85
|
+
"""A' for an object bitset A."""
|
|
86
|
+
attributes = self.all_attributes
|
|
87
|
+
for g in iter_bits(objects):
|
|
88
|
+
attributes &= self.rows[g]
|
|
89
|
+
return attributes
|
|
90
|
+
|
|
91
|
+
def closure(self, attributes: int) -> int:
|
|
92
|
+
"""B'' for an attribute bitset B."""
|
|
93
|
+
return self.intent(self.extent(attributes))
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Vectorised "does this object have every attribute of this set?" tests.
|
|
3
|
+
|
|
4
|
+
Used by the transformers that turn objects into one boolean feature per
|
|
5
|
+
concept intent or implication premise.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from collections.abc import Sequence
|
|
11
|
+
|
|
12
|
+
import numpy as np
|
|
13
|
+
from scipy import sparse
|
|
14
|
+
|
|
15
|
+
# Upper bound on cells per chunk of the (objects x sets) result, which keeps
|
|
16
|
+
# each chunk's intermediates around 16 MB however many objects there are.
|
|
17
|
+
_CHUNK_CELLS = 1 << 22
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def contains_sets(
|
|
21
|
+
incidence: np.ndarray,
|
|
22
|
+
attribute_sets: Sequence[frozenset[int]],
|
|
23
|
+
) -> np.ndarray:
|
|
24
|
+
"""
|
|
25
|
+
Return ``result[g, k] = attribute_sets[k] ⊆ row g of incidence``.
|
|
26
|
+
|
|
27
|
+
An object contains a set iff none of the set's attributes is missing
|
|
28
|
+
from its row, so one product of "missing attributes" (objects x
|
|
29
|
+
attributes) and the sets (attributes x sets) counts the misses for every
|
|
30
|
+
pair at once. The sets are stored sparsely, so memory grows with their
|
|
31
|
+
total size rather than with sets x attributes, and objects are processed
|
|
32
|
+
in chunks.
|
|
33
|
+
"""
|
|
34
|
+
incidence = np.asarray(incidence, dtype=bool)
|
|
35
|
+
n_objects, n_attributes = incidence.shape
|
|
36
|
+
n_sets = len(attribute_sets)
|
|
37
|
+
|
|
38
|
+
lengths = [len(attributes) for attributes in attribute_sets]
|
|
39
|
+
indptr = np.concatenate([[0], np.cumsum(lengths, dtype=np.int64)])
|
|
40
|
+
indices = np.fromiter(
|
|
41
|
+
(m for attributes in attribute_sets for m in attributes),
|
|
42
|
+
dtype=np.int64,
|
|
43
|
+
count=int(indptr[-1]),
|
|
44
|
+
)
|
|
45
|
+
sets = sparse.csr_matrix(
|
|
46
|
+
(np.ones(len(indices), dtype=np.float32), indices, indptr),
|
|
47
|
+
shape=(n_sets, n_attributes),
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
result = np.empty((n_objects, n_sets), dtype=bool)
|
|
51
|
+
chunk = max(1, _CHUNK_CELLS // max(1, n_sets, n_attributes))
|
|
52
|
+
|
|
53
|
+
for start in range(0, n_objects, chunk):
|
|
54
|
+
stop = start + chunk
|
|
55
|
+
missing = (~incidence[start:stop]).astype(np.float32)
|
|
56
|
+
# (sets x attributes) @ (attributes x chunk) -> misses per (set, object).
|
|
57
|
+
result[start:stop] = (sets @ missing.T).T == 0
|
|
58
|
+
|
|
59
|
+
return result
|