conceptflow 0.1.1__tar.gz → 0.2.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 (110) hide show
  1. {conceptflow-0.1.1/src/conceptflow.egg-info → conceptflow-0.2.0}/PKG-INFO +134 -48
  2. {conceptflow-0.1.1 → conceptflow-0.2.0}/README.md +128 -41
  3. {conceptflow-0.1.1 → conceptflow-0.2.0}/pyproject.toml +13 -12
  4. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/__init__.py +2 -0
  5. conceptflow-0.2.0/src/conceptflow/_version.py +1 -0
  6. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/algorithms/__init__.py +10 -1
  7. conceptflow-0.2.0/src/conceptflow/algorithms/_bitset.py +93 -0
  8. conceptflow-0.2.0/src/conceptflow/algorithms/_membership.py +59 -0
  9. conceptflow-0.2.0/src/conceptflow/algorithms/enumeration.py +218 -0
  10. conceptflow-0.2.0/src/conceptflow/algorithms/hasse.py +171 -0
  11. conceptflow-0.2.0/src/conceptflow/algorithms/implications.py +560 -0
  12. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/cluster/concept_lattice.py +7 -9
  13. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/core/__init__.py +3 -1
  14. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/core/concept.py +12 -4
  15. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/core/context.py +52 -10
  16. conceptflow-0.2.0/src/conceptflow/core/incomplete_context.py +392 -0
  17. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/core/lattice.py +25 -10
  18. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/core/many_valued_context.py +9 -3
  19. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/exploration/__init__.py +4 -1
  20. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/exploration/builder.py +44 -13
  21. conceptflow-0.2.0/src/conceptflow/exploration/combinations.py +150 -0
  22. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/feature_extraction/concept_encoder.py +18 -21
  23. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/metrics/__init__.py +3 -1
  24. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/metrics/rules.py +23 -1
  25. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/preprocessing/conceptual_scaler.py +134 -19
  26. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/preprocessing/scales.py +28 -0
  27. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/rules/implication_basis.py +7 -9
  28. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/validation/input.py +19 -2
  29. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/visualization/__init__.py +13 -5
  30. conceptflow-0.2.0/src/conceptflow/visualization/dimflux_layout.py +165 -0
  31. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/visualization/lattice_plot.py +34 -10
  32. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/visualization/nested.py +71 -71
  33. conceptflow-0.2.0/src/conceptflow/visualization/static.py +409 -0
  34. {conceptflow-0.1.1 → conceptflow-0.2.0/src/conceptflow.egg-info}/PKG-INFO +134 -48
  35. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow.egg-info/SOURCES.txt +10 -13
  36. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow.egg-info/requires.txt +3 -3
  37. conceptflow-0.2.0/tests/test_audit_regressions.py +278 -0
  38. conceptflow-0.2.0/tests/test_check_estimator.py +94 -0
  39. {conceptflow-0.1.1 → conceptflow-0.2.0}/tests/test_conceptual_scaler.py +96 -1
  40. {conceptflow-0.1.1 → conceptflow-0.2.0}/tests/test_dimflux_layout.py +64 -4
  41. {conceptflow-0.1.1 → conceptflow-0.2.0}/tests/test_enumeration.py +21 -1
  42. conceptflow-0.2.0/tests/test_hasse.py +66 -0
  43. conceptflow-0.2.0/tests/test_implications.py +302 -0
  44. conceptflow-0.2.0/tests/test_incomplete_context.py +118 -0
  45. conceptflow-0.2.0/tests/test_nested_combinations.py +99 -0
  46. {conceptflow-0.1.1 → conceptflow-0.2.0}/tests/test_public_api.py +25 -1
  47. conceptflow-0.2.0/tests/test_static_figures.py +133 -0
  48. conceptflow-0.1.1/src/conceptflow/_version.py +0 -1
  49. conceptflow-0.1.1/src/conceptflow/algorithms/enumeration.py +0 -208
  50. conceptflow-0.1.1/src/conceptflow/algorithms/hasse.py +0 -83
  51. conceptflow-0.1.1/src/conceptflow/algorithms/implications.py +0 -150
  52. conceptflow-0.1.1/src/conceptflow/visualization/dimflux/LICENSE +0 -395
  53. conceptflow-0.1.1/src/conceptflow/visualization/dimflux/README.md +0 -77
  54. conceptflow-0.1.1/src/conceptflow/visualization/dimflux/libs/brunt-fork.jar +0 -4
  55. conceptflow-0.1.1/src/conceptflow/visualization/dimflux/src/__init__.py +0 -0
  56. conceptflow-0.1.1/src/conceptflow/visualization/dimflux/src/dim_flux/additive_realizer.py +0 -213
  57. conceptflow-0.1.1/src/conceptflow/visualization/dimflux/src/dim_flux/dim_draw.py +0 -172
  58. conceptflow-0.1.1/src/conceptflow/visualization/dimflux/src/dim_flux/lgs.py +0 -149
  59. conceptflow-0.1.1/src/conceptflow/visualization/dimflux/src/dim_flux/projection.py +0 -137
  60. conceptflow-0.1.1/src/conceptflow/visualization/dimflux/src/dim_flux/realizer.py +0 -97
  61. conceptflow-0.1.1/src/conceptflow/visualization/dimflux/src/fca/context.py +0 -130
  62. conceptflow-0.1.1/src/conceptflow/visualization/dimflux/src/fca/lattice.py +0 -125
  63. conceptflow-0.1.1/src/conceptflow/visualization/dimflux/src/fdp/forces.py +0 -519
  64. conceptflow-0.1.1/src/conceptflow/visualization/dimflux/src/utils/variables.py +0 -184
  65. conceptflow-0.1.1/src/conceptflow/visualization/dimflux_layout.py +0 -176
  66. conceptflow-0.1.1/tests/test_check_estimator.py +0 -90
  67. conceptflow-0.1.1/tests/test_implications.py +0 -117
  68. {conceptflow-0.1.1 → conceptflow-0.2.0}/LICENSE +0 -0
  69. {conceptflow-0.1.1 → conceptflow-0.2.0}/setup.cfg +0 -0
  70. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/algorithms/_registry.py +0 -0
  71. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/algorithms/derivation.py +0 -0
  72. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/algorithms/order.py +0 -0
  73. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/algorithms/reduction.py +0 -0
  74. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/cluster/__init__.py +0 -0
  75. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/decomposition/__init__.py +0 -0
  76. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/decomposition/ordinal_factorization.py +0 -0
  77. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/exploration/view.py +0 -0
  78. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/feature_extraction/__init__.py +0 -0
  79. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/io/__init__.py +0 -0
  80. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/io/cxt.py +0 -0
  81. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/model_selection/__init__.py +0 -0
  82. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/preprocessing/__init__.py +0 -0
  83. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/rules/__init__.py +0 -0
  84. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/validation/__init__.py +0 -0
  85. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/visualization/d3_backend.py +0 -0
  86. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/visualization/graph_data.py +0 -0
  87. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow/visualization/html_figure.py +0 -0
  88. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow.egg-info/dependency_links.txt +0 -0
  89. {conceptflow-0.1.1 → conceptflow-0.2.0}/src/conceptflow.egg-info/top_level.txt +0 -0
  90. {conceptflow-0.1.1 → conceptflow-0.2.0}/tests/test_algorithm_registry.py +0 -0
  91. {conceptflow-0.1.1 → conceptflow-0.2.0}/tests/test_cluster_estimator.py +0 -0
  92. {conceptflow-0.1.1 → conceptflow-0.2.0}/tests/test_concept.py +0 -0
  93. {conceptflow-0.1.1 → conceptflow-0.2.0}/tests/test_concept_encoder.py +0 -0
  94. {conceptflow-0.1.1 → conceptflow-0.2.0}/tests/test_cxt_io.py +0 -0
  95. {conceptflow-0.1.1 → conceptflow-0.2.0}/tests/test_d3_backend.py +0 -0
  96. {conceptflow-0.1.1 → conceptflow-0.2.0}/tests/test_derivation.py +0 -0
  97. {conceptflow-0.1.1 → conceptflow-0.2.0}/tests/test_exploration.py +0 -0
  98. {conceptflow-0.1.1 → conceptflow-0.2.0}/tests/test_formal_context.py +0 -0
  99. {conceptflow-0.1.1 → conceptflow-0.2.0}/tests/test_graph_data.py +0 -0
  100. {conceptflow-0.1.1 → conceptflow-0.2.0}/tests/test_html_figure.py +0 -0
  101. {conceptflow-0.1.1 → conceptflow-0.2.0}/tests/test_implication_basis_estimator.py +0 -0
  102. {conceptflow-0.1.1 → conceptflow-0.2.0}/tests/test_lattice.py +0 -0
  103. {conceptflow-0.1.1 → conceptflow-0.2.0}/tests/test_many_valued_context.py +0 -0
  104. {conceptflow-0.1.1 → conceptflow-0.2.0}/tests/test_metrics.py +0 -0
  105. {conceptflow-0.1.1 → conceptflow-0.2.0}/tests/test_nested_visualization.py +0 -0
  106. {conceptflow-0.1.1 → conceptflow-0.2.0}/tests/test_ordinal_factorization.py +0 -0
  107. {conceptflow-0.1.1 → conceptflow-0.2.0}/tests/test_reduction.py +0 -0
  108. {conceptflow-0.1.1 → conceptflow-0.2.0}/tests/test_scales.py +0 -0
  109. {conceptflow-0.1.1 → conceptflow-0.2.0}/tests/test_sklearn_compatibility.py +0 -0
  110. {conceptflow-0.1.1 → conceptflow-0.2.0}/tests/test_validation_input.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: conceptflow
3
- Version: 0.1.1
3
+ Version: 0.2.0
4
4
  Summary: A scikit-learn compatible Formal Concept Analysis framework.
5
5
  Author-email: Anurag Sharma <sharma@cs.uni-kassel.de>
6
6
  License: BSD 3-Clause License
@@ -40,23 +40,22 @@ Classifier: Development Status :: 3 - Alpha
40
40
  Classifier: Intended Audience :: Science/Research
41
41
  Classifier: License :: OSI Approved :: BSD License
42
42
  Classifier: Programming Language :: Python :: 3
43
- Classifier: Programming Language :: Python :: 3.10
44
- Classifier: Programming Language :: Python :: 3.11
45
43
  Classifier: Programming Language :: Python :: 3.12
44
+ Classifier: Programming Language :: Python :: 3.13
46
45
  Classifier: Operating System :: OS Independent
47
46
  Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
48
47
  Classifier: Topic :: Scientific/Engineering :: Information Analysis
49
- Requires-Python: >=3.10
48
+ Requires-Python: >=3.12
50
49
  Description-Content-Type: text/markdown
51
50
  License-File: LICENSE
52
51
  Requires-Dist: numpy
53
52
  Requires-Dist: pandas
54
53
  Requires-Dist: scipy
55
- Requires-Dist: scikit-learn>=1.2
54
+ Requires-Dist: scikit-learn>=1.5
56
55
  Requires-Dist: networkx
57
- Requires-Dist: sympy
58
- Requires-Dist: z3-solver
56
+ Requires-Dist: dim-flux<1.1,>=1.0.11
59
57
  Provides-Extra: dev
58
+ Requires-Dist: scikit-learn>=1.6; extra == "dev"
60
59
  Requires-Dist: pytest; extra == "dev"
61
60
  Requires-Dist: pytest-cov; extra == "dev"
62
61
  Requires-Dist: ruff; extra == "dev"
@@ -64,7 +63,7 @@ Dynamic: license-file
64
63
 
65
64
  # ConceptFlow
66
65
 
67
- ![Python](https://img.shields.io/badge/python-3.10%2B-blue)
66
+ ![Python](https://img.shields.io/badge/python-3.12%2B-blue)
68
67
  ![License](https://img.shields.io/badge/license-BSD--3--Clause-green)
69
68
  ![Status](https://img.shields.io/badge/status-experimental-orange)
70
69
 
@@ -86,40 +85,22 @@ cd conceptflow
86
85
  pip install -e ".[dev]"
87
86
  ```
88
87
 
89
- ### Java requirement for nested diagrams
88
+ ConceptFlow requires Python 3.12 or newer. Lattice and nested-diagram layouts
89
+ use [DimFlux](https://arxiv.org/abs/2603.16366) (the `dim-flux` package, installed
90
+ automatically; licensed CC BY 4.0). matplotlib, used for static figures, is
91
+ installed with it.
90
92
 
91
- Nested-diagram layout (`plot_nested`, and anything using the DimFlux/DimDraw
92
- layout engine) shells out to a bundled Java tool, so a JRE (Java 11+) must be
93
- installed and available as `java` on `PATH`. Core FCA computation (contexts,
94
- lattices, scaling, enumeration) does not need Java — only nested-diagram
95
- rendering does.
93
+ See [CHANGELOG.md](https://github.com/anuragxorma/conceptflow/blob/main/CHANGELOG.md) for what changed between releases.
96
94
 
97
- ```bash
98
- # Debian/Ubuntu
99
- sudo apt install default-jre
100
-
101
- # macOS (Homebrew)
102
- brew install openjdk
103
-
104
- # Verify it's on PATH
105
- java -version
106
- ```
107
-
108
- If you'd rather not put a JRE on `PATH`, point ConceptFlow at a specific
109
- binary instead:
110
-
111
- ```bash
112
- export CONCEPTFLOW_JAVA_BIN=/path/to/java
113
- ```
114
-
115
- Runnable versions of every code snippet below live in [`examples/`](examples/),
116
- including a full case study in [`examples/eurovision_nested_diagram.py`](examples/eurovision_nested_diagram.py).
95
+ Runnable versions of every code snippet below live in [`examples/`](https://github.com/anuragxorma/conceptflow/tree/main/examples/),
96
+ including a full case study in [`examples/eurovision_nested_diagram.py`](https://github.com/anuragxorma/conceptflow/blob/main/examples/eurovision_nested_diagram.py).
117
97
 
118
98
  ## Current features
119
99
 
120
100
  **Core FCA structures**
121
101
  - Binary formal contexts
122
102
  - Many-valued contexts
103
+ - Incomplete (three-valued: yes / no / unknown) contexts
123
104
  - Formal concepts
124
105
  - Concept lattice construction
125
106
 
@@ -128,6 +109,7 @@ including a full case study in [`examples/eurovision_nested_diagram.py`](example
128
109
 
129
110
  **Preprocessing**
130
111
  - Conceptual scaling with seven scale types
112
+ - Explicit missing-value handling (error / closed world / unknown)
131
113
  - scikit-learn compatible preprocessing
132
114
 
133
115
  **scikit-learn estimators**
@@ -137,15 +119,18 @@ including a full case study in [`examples/eurovision_nested_diagram.py`](example
137
119
  **Visualization**
138
120
  - Nested line diagrams (subdirect decomposition)
139
121
  - Interactive nested diagram visualization
122
+ - Static SVG/PDF/PNG export of lattices and nested diagrams (matplotlib)
123
+ - Realized / unrealized nested-diagram combinations as a DataFrame
140
124
 
141
125
  **I/O**
142
126
  - Burmeister `.cxt` read/write support
143
127
 
144
128
  **Metrics**
145
- - Basic support and confidence metrics
129
+ - Basic support and confidence metrics, exception objects of a rule
146
130
 
147
131
  **Rules**
148
- - Duquenne-Guigues (stem) basis / implication computation
132
+ - Duquenne-Guigues (stem) basis / implication computation (NextClosure)
133
+ - Luxenburger basis of near-implications, with exception objects
149
134
 
150
135
  **Decomposition**
151
136
  - Ordinal two-factorization
@@ -266,6 +251,48 @@ Supported outputs:
266
251
  "sparse" -> scipy.sparse CSR matrix
267
252
  ```
268
253
 
254
+ ### Missing values
255
+
256
+ In a binary `FormalContext`, empty cells (None, NaN, `pd.NA`) mean "no
257
+ cross", as in a printed cross table. In many-valued data a missing value
258
+ (None, NaN, NaT, `pd.NA`, or the string `"?"`) is ambiguous: the attribute may
259
+ not apply to the object, or its value may be unknown. It is never silently
260
+ turned into crosses or non-crosses; `ConceptualScaler(missing=...)` makes the
261
+ choice explicit:
262
+
263
+ ```text
264
+ "error" -> raise ValueError naming the attribute and objects (default)
265
+ "false" -> the object gets none of that scale's attributes (closed world)
266
+ "unknown" -> attributes true for every value of the scale stay known-yes,
267
+ those true for none stay known-no, the rest become unknown
268
+ ```
269
+
270
+ With `missing="unknown"`, `output="context"` returns an `IncompleteContext`,
271
+ `"array"` and `"dataframe"` return floats (1.0 / 0.0, NaN for unknown), the
272
+ scikit-learn convention for missing values.
273
+ Unknown entries are independent of each other, so an implication that follows
274
+ from a scale itself (such as `size>=L -> size>=M`) may be reported as
275
+ "possible" rather than "valid".
276
+
277
+ ### Incomplete contexts
278
+
279
+ `IncompleteContext` stores yes / no / unknown entries. Questions are answered
280
+ over all *completions* (ways to fill in the unknowns):
281
+
282
+ ```python
283
+ from conceptflow import IncompleteContext
284
+
285
+ ctx = IncompleteContext.from_dataframe(df) # True/False/1/0; None, NaN or "?" = unknown
286
+
287
+ ctx.certain_context() # FormalContext with unknown -> no
288
+ ctx.possible_context() # FormalContext with unknown -> yes
289
+ ctx.implication_status(["linear"], ["polar"]) # "valid" | "possible" | "refuted"
290
+ ctx.implication_counterexamples(["linear"], ["polar"]) # (certain, possible) object indices
291
+ ```
292
+
293
+ Only booleans and 0/1 are accepted as known values; strings such as `"no"`
294
+ raise instead of being coerced to True.
295
+
269
296
  ### Scale types
270
297
 
271
298
  **`NominalScale(source_attribute)`**
@@ -468,10 +495,40 @@ fig.show() # display in Jupyter
468
495
  fig.write_html("out.html") # export to HTML
469
496
  ```
470
497
 
471
- `plot_nested` computes the subdirect product of the two factor lattices using the
472
- join-closure algorithm (no explicit combined context is built), then renders an
473
- interactive navigator with the D3.js force-directed layout. See
474
- [docs/nested_diagram_tutorial.md](docs/nested_diagram_tutorial.md) for the full
498
+ `plot_nested` determines which (outer, inner) concept pairs of the two factor
499
+ lattices are realized by the combined context, then renders an interactive
500
+ navigator with the D3.js force-directed layout.
501
+
502
+ For publication figures, use the matplotlib backend and save to any format
503
+ matplotlib supports:
504
+
505
+ ```python
506
+ from conceptflow.visualization import plot_lattice, plot_nested
507
+
508
+ fig = plot_nested(outer_view, backend="matplotlib", show_object_labels=True)
509
+ fig.savefig("nested.pdf")
510
+
511
+ fig = plot_lattice(lattice, backend="matplotlib")
512
+ fig.savefig("lattice.svg")
513
+
514
+ # Lattices too large for DimFlux: use a quick layered layout instead.
515
+ fig = plot_lattice(lattice, backend="matplotlib", layout="none", show_object_labels=False)
516
+ ```
517
+
518
+ DimFlux layouts take seconds for small lattices but can take minutes once a
519
+ lattice has a few hundred concepts (ConceptFlow warns above 150). `timeout_ms`
520
+ (default 1000) limits each optimization phase loosely, not the total run time.
521
+
522
+ The realized and unrealized combinations (filled and hollow inner nodes) are
523
+ also available as data:
524
+
525
+ ```python
526
+ from conceptflow.exploration import nested_combinations
527
+
528
+ table = nested_combinations(outer_view) # one row per (outer, inner) pair
529
+ table[~table.realized] # attribute combinations that never occur
530
+ ``` See
531
+ [docs/nested_diagram_tutorial.md](https://github.com/anuragxorma/conceptflow/blob/main/docs/nested_diagram_tutorial.md) for the full
475
532
  mathematical derivation.
476
533
 
477
534
  ## `.cxt` input/output
@@ -489,6 +546,7 @@ write_cxt(ctx, "output.cxt")
489
546
  from conceptflow.metrics import (
490
547
  attribute_set_support,
491
548
  implication_confidence,
549
+ implication_exceptions,
492
550
  )
493
551
 
494
552
  support = attribute_set_support(ctx, attributes=[0, 1])
@@ -498,6 +556,9 @@ confidence = implication_confidence(
498
556
  premise=[0],
499
557
  conclusion=[1],
500
558
  )
559
+
560
+ # Objects with the premise but not the conclusion (empty iff the rule holds).
561
+ exceptions = implication_exceptions(ctx, premise=["a"], conclusion=["b"])
501
562
  ```
502
563
 
503
564
  ## Feature extraction
@@ -610,14 +671,39 @@ for implication in estimator.get_implications():
610
671
  objects); `transform` re-derives, for any object (not just the ones it was
611
672
  fit on), which implications' premises that object's own attributes satisfy —
612
673
  one boolean feature per implication. The underlying algorithm
613
- (`conceptflow.algorithms.compute_canonical_basis`) enumerates candidate
614
- attribute sets smallest-first and checks each against the standard
615
- pseudo-intent definition; see
616
- [docs/nested_diagram_tutorial.md](docs/nested_diagram_tutorial.md) for how
674
+ (`conceptflow.algorithms.compute_canonical_basis`) is Ganter's NextClosure on
675
+ integer bitsets, which visits only intents and pseudo-intents; closures under
676
+ the implications found so far are vectorised with NumPy and abandoned as soon
677
+ as they fail the canonicity test. A 357 x 42 context with 1,376 implications
678
+ takes about 0.2 s. `compute_canonical_basis_bruteforce` checks every attribute
679
+ subset against the pseudo-intent definition and is
680
+ kept as a reference implementation. See
681
+ [docs/nested_diagram_tutorial.md](https://github.com/anuragxorma/conceptflow/blob/main/docs/nested_diagram_tutorial.md) for how
617
682
  implications relate to hollow nodes in a nested diagram, and
618
- [examples/eurovision_nested_diagram.py](examples/eurovision_nested_diagram.py)
683
+ [examples/eurovision_nested_diagram.py](https://github.com/anuragxorma/conceptflow/blob/main/examples/eurovision_nested_diagram.py)
619
684
  for a full worked example.
620
685
 
686
+ ### Near-implications (Luxenburger basis)
687
+
688
+ Rules that hold for most but not all objects come from neighbouring concepts:
689
+ for an upper neighbour `(A1, B1)` of `(A2, B2)`, the rule `B1 -> B2 \ B1` has
690
+ confidence `|A2| / |A1|`. Each rule lists its exception objects.
691
+
692
+ ```python
693
+ from conceptflow.algorithms import compute_luxenburger_basis
694
+
695
+ rules = compute_luxenburger_basis(ctx, min_confidence=0.8, min_support=3)
696
+
697
+ for rule in rules:
698
+ print(
699
+ rule.premise_names(ctx), "->", rule.conclusion_names(ctx),
700
+ f"conf={rule.confidence:.2f}", f"support={rule.support}/{rule.premise_support}",
701
+ "exceptions:", rule.exception_names(ctx),
702
+ )
703
+ ```
704
+
705
+ `min_support` is an object count (int) or a fraction of all objects (float).
706
+
621
707
  ## Design philosophy
622
708
 
623
709
  ConceptFlow separates:
@@ -733,9 +819,9 @@ This separation allows the same FCA structures to be reused across:
733
819
 
734
820
  ## Further reading
735
821
 
736
- - [docs/architecture.md](docs/architecture.md) — the full layered-architecture design.
737
- - [docs/nested_diagram_tutorial.md](docs/nested_diagram_tutorial.md) — tutorial on nested line diagrams.
738
- - [docs/nested_diagram_construction.md](docs/nested_diagram_construction.md) — mathematical construction of the join-closure algorithm.
822
+ - [docs/architecture.md](https://github.com/anuragxorma/conceptflow/blob/main/docs/architecture.md) — the full layered-architecture design.
823
+ - [docs/nested_diagram_tutorial.md](https://github.com/anuragxorma/conceptflow/blob/main/docs/nested_diagram_tutorial.md) — tutorial on nested line diagrams.
824
+ - [docs/nested_diagram_construction.md](https://github.com/anuragxorma/conceptflow/blob/main/docs/nested_diagram_construction.md) — mathematical construction of the join-closure algorithm.
739
825
  - [Eurovision case study](https://kde.cs.uni-kassel.de/blogs/esc) — worked example and interactive diagram.
740
826
 
741
827
  ## License
@@ -1,6 +1,6 @@
1
1
  # ConceptFlow
2
2
 
3
- ![Python](https://img.shields.io/badge/python-3.10%2B-blue)
3
+ ![Python](https://img.shields.io/badge/python-3.12%2B-blue)
4
4
  ![License](https://img.shields.io/badge/license-BSD--3--Clause-green)
5
5
  ![Status](https://img.shields.io/badge/status-experimental-orange)
6
6
 
@@ -22,40 +22,22 @@ cd conceptflow
22
22
  pip install -e ".[dev]"
23
23
  ```
24
24
 
25
- ### Java requirement for nested diagrams
25
+ ConceptFlow requires Python 3.12 or newer. Lattice and nested-diagram layouts
26
+ use [DimFlux](https://arxiv.org/abs/2603.16366) (the `dim-flux` package, installed
27
+ automatically; licensed CC BY 4.0). matplotlib, used for static figures, is
28
+ installed with it.
26
29
 
27
- Nested-diagram layout (`plot_nested`, and anything using the DimFlux/DimDraw
28
- layout engine) shells out to a bundled Java tool, so a JRE (Java 11+) must be
29
- installed and available as `java` on `PATH`. Core FCA computation (contexts,
30
- lattices, scaling, enumeration) does not need Java — only nested-diagram
31
- rendering does.
30
+ See [CHANGELOG.md](https://github.com/anuragxorma/conceptflow/blob/main/CHANGELOG.md) for what changed between releases.
32
31
 
33
- ```bash
34
- # Debian/Ubuntu
35
- sudo apt install default-jre
36
-
37
- # macOS (Homebrew)
38
- brew install openjdk
39
-
40
- # Verify it's on PATH
41
- java -version
42
- ```
43
-
44
- If you'd rather not put a JRE on `PATH`, point ConceptFlow at a specific
45
- binary instead:
46
-
47
- ```bash
48
- export CONCEPTFLOW_JAVA_BIN=/path/to/java
49
- ```
50
-
51
- Runnable versions of every code snippet below live in [`examples/`](examples/),
52
- including a full case study in [`examples/eurovision_nested_diagram.py`](examples/eurovision_nested_diagram.py).
32
+ Runnable versions of every code snippet below live in [`examples/`](https://github.com/anuragxorma/conceptflow/tree/main/examples/),
33
+ including a full case study in [`examples/eurovision_nested_diagram.py`](https://github.com/anuragxorma/conceptflow/blob/main/examples/eurovision_nested_diagram.py).
53
34
 
54
35
  ## Current features
55
36
 
56
37
  **Core FCA structures**
57
38
  - Binary formal contexts
58
39
  - Many-valued contexts
40
+ - Incomplete (three-valued: yes / no / unknown) contexts
59
41
  - Formal concepts
60
42
  - Concept lattice construction
61
43
 
@@ -64,6 +46,7 @@ including a full case study in [`examples/eurovision_nested_diagram.py`](example
64
46
 
65
47
  **Preprocessing**
66
48
  - Conceptual scaling with seven scale types
49
+ - Explicit missing-value handling (error / closed world / unknown)
67
50
  - scikit-learn compatible preprocessing
68
51
 
69
52
  **scikit-learn estimators**
@@ -73,15 +56,18 @@ including a full case study in [`examples/eurovision_nested_diagram.py`](example
73
56
  **Visualization**
74
57
  - Nested line diagrams (subdirect decomposition)
75
58
  - Interactive nested diagram visualization
59
+ - Static SVG/PDF/PNG export of lattices and nested diagrams (matplotlib)
60
+ - Realized / unrealized nested-diagram combinations as a DataFrame
76
61
 
77
62
  **I/O**
78
63
  - Burmeister `.cxt` read/write support
79
64
 
80
65
  **Metrics**
81
- - Basic support and confidence metrics
66
+ - Basic support and confidence metrics, exception objects of a rule
82
67
 
83
68
  **Rules**
84
- - Duquenne-Guigues (stem) basis / implication computation
69
+ - Duquenne-Guigues (stem) basis / implication computation (NextClosure)
70
+ - Luxenburger basis of near-implications, with exception objects
85
71
 
86
72
  **Decomposition**
87
73
  - Ordinal two-factorization
@@ -202,6 +188,48 @@ Supported outputs:
202
188
  "sparse" -> scipy.sparse CSR matrix
203
189
  ```
204
190
 
191
+ ### Missing values
192
+
193
+ In a binary `FormalContext`, empty cells (None, NaN, `pd.NA`) mean "no
194
+ cross", as in a printed cross table. In many-valued data a missing value
195
+ (None, NaN, NaT, `pd.NA`, or the string `"?"`) is ambiguous: the attribute may
196
+ not apply to the object, or its value may be unknown. It is never silently
197
+ turned into crosses or non-crosses; `ConceptualScaler(missing=...)` makes the
198
+ choice explicit:
199
+
200
+ ```text
201
+ "error" -> raise ValueError naming the attribute and objects (default)
202
+ "false" -> the object gets none of that scale's attributes (closed world)
203
+ "unknown" -> attributes true for every value of the scale stay known-yes,
204
+ those true for none stay known-no, the rest become unknown
205
+ ```
206
+
207
+ With `missing="unknown"`, `output="context"` returns an `IncompleteContext`,
208
+ `"array"` and `"dataframe"` return floats (1.0 / 0.0, NaN for unknown), the
209
+ scikit-learn convention for missing values.
210
+ Unknown entries are independent of each other, so an implication that follows
211
+ from a scale itself (such as `size>=L -> size>=M`) may be reported as
212
+ "possible" rather than "valid".
213
+
214
+ ### Incomplete contexts
215
+
216
+ `IncompleteContext` stores yes / no / unknown entries. Questions are answered
217
+ over all *completions* (ways to fill in the unknowns):
218
+
219
+ ```python
220
+ from conceptflow import IncompleteContext
221
+
222
+ ctx = IncompleteContext.from_dataframe(df) # True/False/1/0; None, NaN or "?" = unknown
223
+
224
+ ctx.certain_context() # FormalContext with unknown -> no
225
+ ctx.possible_context() # FormalContext with unknown -> yes
226
+ ctx.implication_status(["linear"], ["polar"]) # "valid" | "possible" | "refuted"
227
+ ctx.implication_counterexamples(["linear"], ["polar"]) # (certain, possible) object indices
228
+ ```
229
+
230
+ Only booleans and 0/1 are accepted as known values; strings such as `"no"`
231
+ raise instead of being coerced to True.
232
+
205
233
  ### Scale types
206
234
 
207
235
  **`NominalScale(source_attribute)`**
@@ -404,10 +432,40 @@ fig.show() # display in Jupyter
404
432
  fig.write_html("out.html") # export to HTML
405
433
  ```
406
434
 
407
- `plot_nested` computes the subdirect product of the two factor lattices using the
408
- join-closure algorithm (no explicit combined context is built), then renders an
409
- interactive navigator with the D3.js force-directed layout. See
410
- [docs/nested_diagram_tutorial.md](docs/nested_diagram_tutorial.md) for the full
435
+ `plot_nested` determines which (outer, inner) concept pairs of the two factor
436
+ lattices are realized by the combined context, then renders an interactive
437
+ navigator with the D3.js force-directed layout.
438
+
439
+ For publication figures, use the matplotlib backend and save to any format
440
+ matplotlib supports:
441
+
442
+ ```python
443
+ from conceptflow.visualization import plot_lattice, plot_nested
444
+
445
+ fig = plot_nested(outer_view, backend="matplotlib", show_object_labels=True)
446
+ fig.savefig("nested.pdf")
447
+
448
+ fig = plot_lattice(lattice, backend="matplotlib")
449
+ fig.savefig("lattice.svg")
450
+
451
+ # Lattices too large for DimFlux: use a quick layered layout instead.
452
+ fig = plot_lattice(lattice, backend="matplotlib", layout="none", show_object_labels=False)
453
+ ```
454
+
455
+ DimFlux layouts take seconds for small lattices but can take minutes once a
456
+ lattice has a few hundred concepts (ConceptFlow warns above 150). `timeout_ms`
457
+ (default 1000) limits each optimization phase loosely, not the total run time.
458
+
459
+ The realized and unrealized combinations (filled and hollow inner nodes) are
460
+ also available as data:
461
+
462
+ ```python
463
+ from conceptflow.exploration import nested_combinations
464
+
465
+ table = nested_combinations(outer_view) # one row per (outer, inner) pair
466
+ table[~table.realized] # attribute combinations that never occur
467
+ ``` See
468
+ [docs/nested_diagram_tutorial.md](https://github.com/anuragxorma/conceptflow/blob/main/docs/nested_diagram_tutorial.md) for the full
411
469
  mathematical derivation.
412
470
 
413
471
  ## `.cxt` input/output
@@ -425,6 +483,7 @@ write_cxt(ctx, "output.cxt")
425
483
  from conceptflow.metrics import (
426
484
  attribute_set_support,
427
485
  implication_confidence,
486
+ implication_exceptions,
428
487
  )
429
488
 
430
489
  support = attribute_set_support(ctx, attributes=[0, 1])
@@ -434,6 +493,9 @@ confidence = implication_confidence(
434
493
  premise=[0],
435
494
  conclusion=[1],
436
495
  )
496
+
497
+ # Objects with the premise but not the conclusion (empty iff the rule holds).
498
+ exceptions = implication_exceptions(ctx, premise=["a"], conclusion=["b"])
437
499
  ```
438
500
 
439
501
  ## Feature extraction
@@ -546,14 +608,39 @@ for implication in estimator.get_implications():
546
608
  objects); `transform` re-derives, for any object (not just the ones it was
547
609
  fit on), which implications' premises that object's own attributes satisfy —
548
610
  one boolean feature per implication. The underlying algorithm
549
- (`conceptflow.algorithms.compute_canonical_basis`) enumerates candidate
550
- attribute sets smallest-first and checks each against the standard
551
- pseudo-intent definition; see
552
- [docs/nested_diagram_tutorial.md](docs/nested_diagram_tutorial.md) for how
611
+ (`conceptflow.algorithms.compute_canonical_basis`) is Ganter's NextClosure on
612
+ integer bitsets, which visits only intents and pseudo-intents; closures under
613
+ the implications found so far are vectorised with NumPy and abandoned as soon
614
+ as they fail the canonicity test. A 357 x 42 context with 1,376 implications
615
+ takes about 0.2 s. `compute_canonical_basis_bruteforce` checks every attribute
616
+ subset against the pseudo-intent definition and is
617
+ kept as a reference implementation. See
618
+ [docs/nested_diagram_tutorial.md](https://github.com/anuragxorma/conceptflow/blob/main/docs/nested_diagram_tutorial.md) for how
553
619
  implications relate to hollow nodes in a nested diagram, and
554
- [examples/eurovision_nested_diagram.py](examples/eurovision_nested_diagram.py)
620
+ [examples/eurovision_nested_diagram.py](https://github.com/anuragxorma/conceptflow/blob/main/examples/eurovision_nested_diagram.py)
555
621
  for a full worked example.
556
622
 
623
+ ### Near-implications (Luxenburger basis)
624
+
625
+ Rules that hold for most but not all objects come from neighbouring concepts:
626
+ for an upper neighbour `(A1, B1)` of `(A2, B2)`, the rule `B1 -> B2 \ B1` has
627
+ confidence `|A2| / |A1|`. Each rule lists its exception objects.
628
+
629
+ ```python
630
+ from conceptflow.algorithms import compute_luxenburger_basis
631
+
632
+ rules = compute_luxenburger_basis(ctx, min_confidence=0.8, min_support=3)
633
+
634
+ for rule in rules:
635
+ print(
636
+ rule.premise_names(ctx), "->", rule.conclusion_names(ctx),
637
+ f"conf={rule.confidence:.2f}", f"support={rule.support}/{rule.premise_support}",
638
+ "exceptions:", rule.exception_names(ctx),
639
+ )
640
+ ```
641
+
642
+ `min_support` is an object count (int) or a fraction of all objects (float).
643
+
557
644
  ## Design philosophy
558
645
 
559
646
  ConceptFlow separates:
@@ -669,9 +756,9 @@ This separation allows the same FCA structures to be reused across:
669
756
 
670
757
  ## Further reading
671
758
 
672
- - [docs/architecture.md](docs/architecture.md) — the full layered-architecture design.
673
- - [docs/nested_diagram_tutorial.md](docs/nested_diagram_tutorial.md) — tutorial on nested line diagrams.
674
- - [docs/nested_diagram_construction.md](docs/nested_diagram_construction.md) — mathematical construction of the join-closure algorithm.
759
+ - [docs/architecture.md](https://github.com/anuragxorma/conceptflow/blob/main/docs/architecture.md) — the full layered-architecture design.
760
+ - [docs/nested_diagram_tutorial.md](https://github.com/anuragxorma/conceptflow/blob/main/docs/nested_diagram_tutorial.md) — tutorial on nested line diagrams.
761
+ - [docs/nested_diagram_construction.md](https://github.com/anuragxorma/conceptflow/blob/main/docs/nested_diagram_construction.md) — mathematical construction of the join-closure algorithm.
675
762
  - [Eurovision case study](https://kde.cs.uni-kassel.de/blogs/esc) — worked example and interactive diagram.
676
763
 
677
764
  ## License
@@ -4,10 +4,10 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "conceptflow"
7
- version = "0.1.1"
7
+ dynamic = ["version"]
8
8
  description = "A scikit-learn compatible Formal Concept Analysis framework."
9
9
  readme = "README.md"
10
- requires-python = ">=3.10"
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,17 @@ dependencies = [
35
34
  "numpy",
36
35
  "pandas",
37
36
  "scipy",
38
- "scikit-learn>=1.2",
37
+ "scikit-learn>=1.5",
39
38
  "networkx",
40
- "sympy",
41
- "z3-solver",
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
45
  dev = [
46
+ # The check_estimator tests use the scikit-learn >= 1.6 API.
47
+ "scikit-learn>=1.6",
46
48
  "pytest",
47
49
  "pytest-cov",
48
50
  "ruff",
@@ -56,20 +58,19 @@ Issues = "https://github.com/anuragxorma/conceptflow/issues"
56
58
  [tool.setuptools.packages.find]
57
59
  where = ["src"]
58
60
 
59
- [tool.setuptools.package-data]
60
- "conceptflow.visualization.dimflux" = ["LICENSE", "README.md"]
61
- "conceptflow.visualization.dimflux.libs" = ["*.jar"]
62
-
63
61
  [tool.setuptools]
64
62
  include-package-data = true
65
63
 
64
+ [tool.setuptools.dynamic]
65
+ version = { attr = "conceptflow._version.__version__" }
66
+
66
67
  [tool.pytest.ini_options]
67
68
  testpaths = ["tests"]
68
69
  pythonpath = ["src"]
69
70
 
70
71
  [tool.ruff]
71
72
  line-length = 100
72
- target-version = "py310"
73
+ target-version = "py312"
73
74
 
74
75
  [tool.ruff.lint]
75
76
  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.2.0"
@@ -16,7 +16,13 @@ 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 Implication, compute_canonical_basis
19
+ from conceptflow.algorithms.implications import (
20
+ AssociationRule,
21
+ Implication,
22
+ compute_canonical_basis,
23
+ compute_canonical_basis_bruteforce,
24
+ compute_luxenburger_basis,
25
+ )
20
26
  from conceptflow.algorithms.order import strict_subconcept_of, subconcept_of
21
27
 
22
28
  from conceptflow.algorithms.reduction import (
@@ -39,6 +45,9 @@ __all__ = [
39
45
  "compute_hasse_edges",
40
46
  "Implication",
41
47
  "compute_canonical_basis",
48
+ "compute_canonical_basis_bruteforce",
49
+ "AssociationRule",
50
+ "compute_luxenburger_basis",
42
51
  "SUPPORTED_ENUMERATION_ALGORITHMS",
43
52
  "normalize_enumeration_algorithm",
44
53
  "ClarificationResult",