conceptflow 0.4.0__tar.gz → 0.6.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 (154) hide show
  1. {conceptflow-0.4.0/src/conceptflow.egg-info → conceptflow-0.6.0}/PKG-INFO +11 -6
  2. {conceptflow-0.4.0 → conceptflow-0.6.0}/README.md +9 -4
  3. {conceptflow-0.4.0 → conceptflow-0.6.0}/pyproject.toml +4 -1
  4. conceptflow-0.6.0/src/conceptflow/_version.py +1 -0
  5. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/core/__init__.py +10 -0
  6. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/core/context.py +6 -1
  7. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/core/incomplete_context.py +6 -1
  8. conceptflow-0.6.0/src/conceptflow/core/scale_measures.py +143 -0
  9. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/datasets/_loaders.py +8 -4
  10. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/decomposition/bipartite.py +78 -22
  11. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/decomposition/ordinal_factorization.py +41 -10
  12. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/exploration/builder.py +15 -0
  13. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/io/cxt.py +3 -1
  14. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/io/formats.py +11 -5
  15. conceptflow-0.6.0/src/conceptflow/metrics/__init__.py +71 -0
  16. conceptflow-0.6.0/src/conceptflow/metrics/drawing_quality.py +898 -0
  17. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/metrics/measures.py +80 -2
  18. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/quality.py +3 -1
  19. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/visualization/__init__.py +2 -0
  20. conceptflow-0.6.0/src/conceptflow/visualization/_checks.py +44 -0
  21. conceptflow-0.6.0/src/conceptflow/visualization/_clearance.py +123 -0
  22. conceptflow-0.6.0/src/conceptflow/visualization/_text.py +52 -0
  23. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/visualization/d3_backend.py +96 -18
  24. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/visualization/dimflux_layout.py +19 -11
  25. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/visualization/graph_data.py +24 -0
  26. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/visualization/graphviz.py +5 -1
  27. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/visualization/html_figure.py +21 -4
  28. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/visualization/layered_layout.py +18 -5
  29. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/visualization/nested.py +120 -32
  30. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/visualization/static.py +18 -5
  31. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/visualization/tikz.py +29 -3
  32. {conceptflow-0.4.0 → conceptflow-0.6.0/src/conceptflow.egg-info}/PKG-INFO +11 -6
  33. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow.egg-info/SOURCES.txt +12 -2
  34. conceptflow-0.6.0/tests/test_browser.py +304 -0
  35. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_context_handling.py +12 -1
  36. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_cxt_io.py +24 -0
  37. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_d3_backend.py +41 -0
  38. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_datasets.py +11 -0
  39. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_docs_examples.py +12 -8
  40. conceptflow-0.6.0/tests/test_drawing_quality.py +336 -0
  41. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_html_figure.py +21 -3
  42. conceptflow-0.6.0/tests/test_layout_and_graphviz.py +193 -0
  43. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_measures.py +38 -0
  44. conceptflow-0.6.0/tests/test_oracles.py +464 -0
  45. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_ord2factor.py +41 -0
  46. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_patch_0_3_1.py +1 -1
  47. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_public_api.py +16 -0
  48. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_review_fixes.py +1 -1
  49. conceptflow-0.6.0/tests/test_scale_measures.py +100 -0
  50. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_static_figures.py +4 -2
  51. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_tikz.py +1 -1
  52. conceptflow-0.6.0/tests/test_visualization_options.py +158 -0
  53. conceptflow-0.6.0/tests/test_workflows.py +130 -0
  54. conceptflow-0.4.0/src/conceptflow/_version.py +0 -1
  55. conceptflow-0.4.0/src/conceptflow/metrics/__init__.py +0 -29
  56. conceptflow-0.4.0/src/conceptflow/model_selection/__init__.py +0 -11
  57. conceptflow-0.4.0/tests/test_layout_and_graphviz.py +0 -85
  58. {conceptflow-0.4.0 → conceptflow-0.6.0}/LICENSE +0 -0
  59. {conceptflow-0.4.0 → conceptflow-0.6.0}/setup.cfg +0 -0
  60. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/__init__.py +0 -0
  61. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/_deprecation.py +0 -0
  62. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/algorithms/__init__.py +0 -0
  63. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/algorithms/_bitset.py +0 -0
  64. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/algorithms/_membership.py +0 -0
  65. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/algorithms/_registry.py +0 -0
  66. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/algorithms/derivation.py +0 -0
  67. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/algorithms/enumeration.py +0 -0
  68. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/algorithms/generators.py +0 -0
  69. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/algorithms/hasse.py +0 -0
  70. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/algorithms/implications.py +0 -0
  71. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/algorithms/order.py +0 -0
  72. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/algorithms/reduction.py +0 -0
  73. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/cluster/__init__.py +0 -0
  74. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/cluster/concept_lattice.py +0 -0
  75. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/core/concept.py +0 -0
  76. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/core/lattice.py +0 -0
  77. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/core/many_valued_context.py +0 -0
  78. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/core/operations.py +0 -0
  79. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/datasets/__init__.py +0 -0
  80. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/datasets/data/fca_repository/README.md +0 -0
  81. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/datasets/data/fca_repository/animals_en.cxt +0 -0
  82. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/datasets/data/fca_repository/binary_relations_en.cxt +0 -0
  83. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/datasets/data/fca_repository/bodiesofwater_de.cxt +0 -0
  84. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/datasets/data/fca_repository/bodiesofwater_en.cxt +0 -0
  85. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/datasets/data/fca_repository/driveconcepts_de.cxt +0 -0
  86. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/datasets/data/fca_repository/driveconcepts_en.cxt +0 -0
  87. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/datasets/data/fca_repository/famous_animals_en.cxt +0 -0
  88. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/datasets/data/fca_repository/forum_romanum_en.cxt +0 -0
  89. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/datasets/data/fca_repository/livingbeings_de.cxt +0 -0
  90. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/datasets/data/fca_repository/livingbeings_en.cxt +0 -0
  91. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/datasets/data/fca_repository/missmarple_de.cxt +0 -0
  92. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/datasets/data/fca_repository/missmarple_en.cxt +0 -0
  93. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/datasets/data/fca_repository/music_en.cxt +0 -0
  94. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/datasets/data/fca_repository/newzealand_en.cxt +0 -0
  95. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/datasets/data/fca_repository/officesupplies_de.cxt +0 -0
  96. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/datasets/data/fca_repository/officesupplies_en.cxt +0 -0
  97. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/datasets/data/fca_repository/planets_en.cxt +0 -0
  98. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/datasets/data/fca_repository/seasoningplanner_de.cxt +0 -0
  99. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/datasets/data/fca_repository/tealady.cxt +0 -0
  100. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/datasets/data/fca_repository/triangles_en.cxt +0 -0
  101. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/datasets/data/fca_repository.json +0 -0
  102. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/decomposition/__init__.py +0 -0
  103. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/decomposition/boolean_factorization.py +0 -0
  104. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/exploration/__init__.py +0 -0
  105. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/exploration/combinations.py +0 -0
  106. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/exploration/view.py +0 -0
  107. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/feature_extraction/__init__.py +0 -0
  108. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/feature_extraction/concept_encoder.py +0 -0
  109. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/io/__init__.py +0 -0
  110. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/metrics/rules.py +0 -0
  111. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/preprocessing/__init__.py +0 -0
  112. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/preprocessing/conceptual_scaler.py +0 -0
  113. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/preprocessing/scales.py +0 -0
  114. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/rules/__init__.py +0 -0
  115. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/rules/implication_basis.py +0 -0
  116. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/rules/outlier_detector.py +0 -0
  117. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/validation/__init__.py +0 -0
  118. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/validation/input.py +0 -0
  119. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow/visualization/lattice_plot.py +0 -0
  120. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow.egg-info/dependency_links.txt +0 -0
  121. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow.egg-info/requires.txt +0 -0
  122. {conceptflow-0.4.0 → conceptflow-0.6.0}/src/conceptflow.egg-info/top_level.txt +0 -0
  123. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_algorithm_registry.py +0 -0
  124. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_audit_regressions.py +0 -0
  125. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_boolean_factorization.py +0 -0
  126. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_check_estimator.py +0 -0
  127. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_cluster_estimator.py +0 -0
  128. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_concept.py +0 -0
  129. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_concept_encoder.py +0 -0
  130. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_conceptual_scaler.py +0 -0
  131. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_context_operations.py +0 -0
  132. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_derivation.py +0 -0
  133. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_dimflux_layout.py +0 -0
  134. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_enumeration.py +0 -0
  135. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_exploration.py +0 -0
  136. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_formal_context.py +0 -0
  137. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_generators.py +0 -0
  138. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_graph_data.py +0 -0
  139. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_hasse.py +0 -0
  140. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_implication_basis_estimator.py +0 -0
  141. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_implications.py +0 -0
  142. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_incomplete_context.py +0 -0
  143. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_lattice.py +0 -0
  144. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_lattice_navigation.py +0 -0
  145. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_many_valued_context.py +0 -0
  146. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_metrics.py +0 -0
  147. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_nested_combinations.py +0 -0
  148. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_nested_visualization.py +0 -0
  149. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_ordinal_factorization.py +0 -0
  150. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_quality.py +0 -0
  151. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_reduction.py +0 -0
  152. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_scales.py +0 -0
  153. {conceptflow-0.4.0 → conceptflow-0.6.0}/tests/test_sklearn_compatibility.py +0 -0
  154. {conceptflow-0.4.0 → conceptflow-0.6.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.4.0
3
+ Version: 0.6.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
@@ -37,7 +37,7 @@ Project-URL: Documentation, https://conceptflow.readthedocs.io
37
37
  Project-URL: Repository, https://github.com/anuragxorma/conceptflow
38
38
  Project-URL: Issues, https://github.com/anuragxorma/conceptflow/issues
39
39
  Keywords: formal-concept-analysis,fca,scikit-learn,concept-lattice,conceptual-scaling
40
- Classifier: Development Status :: 3 - Alpha
40
+ Classifier: Development Status :: 4 - Beta
41
41
  Classifier: Intended Audience :: Science/Research
42
42
  Classifier: License :: OSI Approved :: BSD License
43
43
  Classifier: Programming Language :: Python :: 3
@@ -72,7 +72,7 @@ Dynamic: license-file
72
72
  ![Python](https://img.shields.io/badge/python-3.12%2B-blue)
73
73
  ![License](https://img.shields.io/badge/license-BSD--3--Clause-green)
74
74
  [![Documentation](https://readthedocs.org/projects/conceptflow/badge/?version=latest)](https://conceptflow.readthedocs.io)
75
- ![Status](https://img.shields.io/badge/status-experimental-orange)
75
+ ![Status](https://img.shields.io/badge/status-beta-yellow)
76
76
 
77
77
  ConceptFlow is a Python library for **Formal Concept Analysis (FCA)** that
78
78
  fits into the scientific Python stack. Its machine-learning parts are proper
@@ -107,7 +107,8 @@ for implication in compute_canonical_basis(ctx):
107
107
  # ('a', 'c') -> ('b',)
108
108
  # ('b', 'c') -> ('a',)
109
109
 
110
- cf.plot_lattice(lattice, backend="tikz", layout="layered").write("lattice.pdf")
110
+ fig = cf.plot_lattice(lattice, backend="matplotlib", layout="layered")
111
+ fig.savefig("lattice.png") # backend="tikz" gives LaTeX code instead
111
112
  ```
112
113
 
113
114
  ## Features
@@ -122,14 +123,18 @@ cf.plot_lattice(lattice, backend="tikz", layout="layered").write("lattice.pdf")
122
123
  LinCbO, proper-premise basis, near-implications with exceptions (Luxenburger
123
124
  basis), minimal generators.
124
125
  - **Measures:** stability (exact and bounds), Δ-measure, entropy, information
125
- gain, linearity and distributivity indices.
126
+ gain; lattice width, height, incomparable pairs, linearity and
127
+ distributivity indices.
128
+ - **Scale-measures:** coarser views of a context from attribute projections
129
+ and conjunctions, their verification, and refinement pairs.
126
130
  - **Conceptual scaling** of many-valued data with seven scale types and
127
131
  explicit missing-value handling.
128
132
  - **scikit-learn:** scaling, concept and implication features, and an
129
133
  outlier detector that explains its decisions with implications.
130
134
  - **Visualization:** interactive HTML, DimFlux and layered layouts,
131
135
  matplotlib, Graphviz and TikZ/LaTeX export; Toscana-style nested line
132
- diagrams.
136
+ diagrams; 14 drawing quality metrics (crossings, layering, slopes,
137
+ clearance).
133
138
  - **Data quality:** rule violations, redundant objects and attributes,
134
139
  explanations of objects and rules.
135
140
  - **Factorization:** Boolean matrix factorization (GreConD, ASSO) as
@@ -3,7 +3,7 @@
3
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
  [![Documentation](https://readthedocs.org/projects/conceptflow/badge/?version=latest)](https://conceptflow.readthedocs.io)
6
- ![Status](https://img.shields.io/badge/status-experimental-orange)
6
+ ![Status](https://img.shields.io/badge/status-beta-yellow)
7
7
 
8
8
  ConceptFlow is a Python library for **Formal Concept Analysis (FCA)** that
9
9
  fits into the scientific Python stack. Its machine-learning parts are proper
@@ -38,7 +38,8 @@ for implication in compute_canonical_basis(ctx):
38
38
  # ('a', 'c') -> ('b',)
39
39
  # ('b', 'c') -> ('a',)
40
40
 
41
- cf.plot_lattice(lattice, backend="tikz", layout="layered").write("lattice.pdf")
41
+ fig = cf.plot_lattice(lattice, backend="matplotlib", layout="layered")
42
+ fig.savefig("lattice.png") # backend="tikz" gives LaTeX code instead
42
43
  ```
43
44
 
44
45
  ## Features
@@ -53,14 +54,18 @@ cf.plot_lattice(lattice, backend="tikz", layout="layered").write("lattice.pdf")
53
54
  LinCbO, proper-premise basis, near-implications with exceptions (Luxenburger
54
55
  basis), minimal generators.
55
56
  - **Measures:** stability (exact and bounds), Δ-measure, entropy, information
56
- gain, linearity and distributivity indices.
57
+ gain; lattice width, height, incomparable pairs, linearity and
58
+ distributivity indices.
59
+ - **Scale-measures:** coarser views of a context from attribute projections
60
+ and conjunctions, their verification, and refinement pairs.
57
61
  - **Conceptual scaling** of many-valued data with seven scale types and
58
62
  explicit missing-value handling.
59
63
  - **scikit-learn:** scaling, concept and implication features, and an
60
64
  outlier detector that explains its decisions with implications.
61
65
  - **Visualization:** interactive HTML, DimFlux and layered layouts,
62
66
  matplotlib, Graphviz and TikZ/LaTeX export; Toscana-style nested line
63
- diagrams.
67
+ diagrams; 14 drawing quality metrics (crossings, layering, slopes,
68
+ clearance).
64
69
  - **Data quality:** rule violations, redundant objects and attributes,
65
70
  explanations of objects and rules.
66
71
  - **Factorization:** Boolean matrix factorization (GreConD, ASSO) as
@@ -20,7 +20,7 @@ keywords = [
20
20
  "conceptual-scaling",
21
21
  ]
22
22
  classifiers = [
23
- "Development Status :: 3 - Alpha",
23
+ "Development Status :: 4 - Beta",
24
24
  "Intended Audience :: Science/Research",
25
25
  "License :: OSI Approved :: BSD License",
26
26
  "Programming Language :: Python :: 3",
@@ -78,6 +78,9 @@ version = { attr = "conceptflow._version.__version__" }
78
78
  [tool.pytest.ini_options]
79
79
  testpaths = ["tests"]
80
80
  pythonpath = ["src"]
81
+ # scikit-mine (dim-flux -> fcapy -> scikit-mine) still imports numpy.core.
82
+ filterwarnings = ["ignore:numpy.core:DeprecationWarning:skmine"]
83
+ markers = ["browser: interactive pages in headless Firefox (needs Playwright)"]
81
84
 
82
85
  [tool.ruff]
83
86
  line-length = 100
@@ -0,0 +1 @@
1
+ __version__ = "0.6.0"
@@ -11,6 +11,12 @@ from conceptflow.core.operations import (
11
11
  dual,
12
12
  subposition,
13
13
  )
14
+ from conceptflow.core.scale_measures import (
15
+ is_scale_measure,
16
+ refines,
17
+ scale_measure,
18
+ scale_measure_problems,
19
+ )
14
20
 
15
21
  __all__ = [
16
22
  "Concept",
@@ -24,4 +30,8 @@ __all__ = [
24
30
  "direct_product",
25
31
  "complement",
26
32
  "dual",
33
+ "scale_measure",
34
+ "is_scale_measure",
35
+ "scale_measure_problems",
36
+ "refines",
27
37
  ]
@@ -268,8 +268,13 @@ class FormalContext:
268
268
  for item in items:
269
269
  if _is_index(item):
270
270
  if not 0 <= item < size:
271
+ hint = (
272
+ f" Integers are positions; for the {kind} named '{item}', "
273
+ f"pass the string '{item}'."
274
+ if str(item) in index_of else ""
275
+ )
271
276
  raise IndexError(
272
- f"{kind} index {item} is out of range for {size} {kind}s."
277
+ f"{kind} index {item} is out of range for {size} {kind}s.{hint}"
273
278
  )
274
279
  resolved.append(int(item))
275
280
  else:
@@ -280,8 +280,13 @@ class IncompleteContext:
280
280
  for item in items:
281
281
  if _is_index(item):
282
282
  if not 0 <= item < len(names):
283
+ hint = (
284
+ f" Integers are positions; for the {kind} named '{item}', "
285
+ f"pass the string '{item}'."
286
+ if str(item) in index_of else ""
287
+ )
283
288
  raise IndexError(
284
- f"{kind} index {item} is out of range for {len(names)} {kind}s."
289
+ f"{kind} index {item} is out of range for {len(names)} {kind}s.{hint}"
285
290
  )
286
291
  resolved.append(int(item))
287
292
  else:
@@ -0,0 +1,143 @@
1
+ """
2
+ Scale-measures: coarser views of a formal context on the same objects.
3
+
4
+ Following Hanika & Hirth, "On the lattice of conceptual measurements" (2022).
5
+ A scale-measure of a context K keeps K's objects and makes fewer
6
+ distinctions between them: every extent of the scale is an extent of K, so
7
+ its concept lattice is a coarser view of K's.
8
+
9
+ - ``scale_measure(context, attributes)`` builds one whose attributes are
10
+ original attributes (attribute projection, Cor. 22) or conjunctions of
11
+ them (Cor. 17); both are scale-measures unconditionally. Disjunctions and
12
+ negations are not offered: they give a scale-measure only when the
13
+ resulting extent happens to be an extent of K (Prop. 16).
14
+ - ``is_scale_measure(original, scale)`` checks the property for a context on
15
+ the same objects, attribute by attribute (Prop. 20), and
16
+ ``scale_measure_problems`` says which attributes fail.
17
+ - ``refines(coarse, fine)`` tells whether every extent of ``coarse`` is an
18
+ extent of ``fine``. Such a *refinement pair* has every concept of the
19
+ coarser view among the concepts of the finer one, so the two lattices (and
20
+ their drawings) can be compared concept by concept.
21
+
22
+ These scales are not the conceptual scales of ``conceptflow.preprocessing``,
23
+ which turn many-valued data into a formal context.
24
+ """
25
+
26
+ from __future__ import annotations
27
+
28
+ import numbers
29
+ from collections.abc import Iterable
30
+
31
+ import numpy as np
32
+
33
+ from conceptflow.core.context import FormalContext
34
+ from conceptflow.core.lattice import ConceptLattice
35
+
36
+ # Joins the names of the parts of a conjunction in the scale's attribute name.
37
+ CONJUNCTION = " ∧ "
38
+
39
+
40
+ def scale_measure(
41
+ context: FormalContext,
42
+ attributes: Iterable[str | int | Iterable[str | int]] | None,
43
+ ) -> FormalContext:
44
+ """
45
+ The scale-measure of ``context`` with the given attributes.
46
+
47
+ Each entry of ``attributes`` is one attribute of ``context`` (a name or
48
+ a position), kept as it is, or a tuple of them, which becomes their
49
+ conjunction: an object has it iff it has every part. The conjunction of
50
+ ``"a"`` and ``"b"`` is named ``"a ∧ b"``. ``None`` returns ``context``.
51
+
52
+ The objects stay those of ``context``, in the same order. The attributes
53
+ are put in one canonical order: by the positions of their parts in
54
+ ``context``, compared as sorted tuples. Two scales of one context then
55
+ list their common attributes in the same relative order, which matters
56
+ for layouts that depend on column order.
57
+
58
+ Raises
59
+ ------
60
+ KeyError
61
+ For a name that is not an attribute of ``context``.
62
+ ValueError
63
+ For an empty conjunction, or two entries that give the same name.
64
+ """
65
+ if attributes is None:
66
+ return context
67
+
68
+ entries = []
69
+ for entry in attributes:
70
+ parts = (entry,) if isinstance(entry, (str, numbers.Integral)) else tuple(entry)
71
+ if not parts:
72
+ raise ValueError("A conjunction needs at least one attribute.")
73
+ indices = context._resolve_attribute_indices(parts)
74
+ entries.append((tuple(sorted(indices)), indices))
75
+ entries.sort(key=lambda item: item[0]) # stable: equal keys keep their order
76
+
77
+ names = [CONJUNCTION.join(context.attributes[i] for i in indices) for _, indices in entries]
78
+ if len(set(names)) != len(names):
79
+ raise ValueError(f"Two attributes of the scale would have the same name: {names}.")
80
+ incidence = np.ones((context.n_objects, len(entries)), dtype=bool)
81
+ for column, (_, indices) in enumerate(entries):
82
+ for index in indices:
83
+ incidence[:, column] &= context.incidence[:, index]
84
+ return FormalContext(objects=context.objects, attributes=tuple(names), incidence=incidence)
85
+
86
+
87
+ def scale_measure_problems(original: FormalContext, scale: FormalContext) -> list[str]:
88
+ """
89
+ Why ``scale`` is not a scale-measure of ``original`` (empty if it is).
90
+
91
+ The scale must have the same objects, in the same order (the map between
92
+ them is the identity). It is then a scale-measure iff the extent of each
93
+ of its attributes is an extent of ``original``, i.e. equals its own
94
+ closure there (Hanika & Hirth, Prop. 20). That is one closure per
95
+ attribute; the scale's lattice is not enumerated.
96
+ """
97
+ if tuple(scale.objects) != tuple(original.objects):
98
+ return ["object sets differ, so the identity is not a map between them"]
99
+ problems = []
100
+ for index, name in enumerate(scale.attributes):
101
+ extent = scale.attribute_derivation([index])
102
+ closed = original.attribute_derivation(original.object_derivation(extent))
103
+ if closed != extent:
104
+ problems.append(
105
+ f"attribute {name!r}: its extent has {len(extent)} objects but closes to "
106
+ f"{len(closed)} in the original context, so it is not an extent there"
107
+ )
108
+ return problems
109
+
110
+
111
+ def is_scale_measure(original: FormalContext, scale: FormalContext) -> bool:
112
+ """Whether ``scale`` is a scale-measure of ``original`` (see ``scale_measure_problems``)."""
113
+ return not scale_measure_problems(original, scale)
114
+
115
+
116
+ def _extents_by_name(view: FormalContext | ConceptLattice) -> tuple[tuple, set[frozenset]]:
117
+ if isinstance(view, ConceptLattice):
118
+ if view.is_iceberg:
119
+ raise ValueError("refines() needs full lattices, not iceberg lattices.")
120
+ lattice = view
121
+ else:
122
+ lattice = ConceptLattice.from_context(view)
123
+ objects = lattice.context.objects
124
+ return objects, {frozenset(objects[i] for i in concept.extent) for concept in lattice.concepts}
125
+
126
+
127
+ def refines(
128
+ coarse: FormalContext | ConceptLattice,
129
+ fine: FormalContext | ConceptLattice,
130
+ ) -> bool:
131
+ """
132
+ Whether every extent of ``coarse`` is an extent of ``fine``.
133
+
134
+ Then every concept of the coarser view is a concept of the finer one,
135
+ matched by its extent, and the two form a *refinement pair*. Both must
136
+ have the same objects (matched by name); contexts or full concept
137
+ lattices can be given, a lattice saving its recomputation.
138
+ """
139
+ coarse_objects, coarse_extents = _extents_by_name(coarse)
140
+ fine_objects, fine_extents = _extents_by_name(fine)
141
+ if set(coarse_objects) != set(fine_objects):
142
+ raise ValueError("refines() compares views of the same objects; these differ.")
143
+ return coarse_extents <= fine_extents
@@ -289,8 +289,8 @@ def make_random_context(
289
289
  with probability ``density``.
290
290
 
291
291
  Objects are named ``g0, g1, ...`` and attributes ``m0, m1, ...``.
292
- ``random_state`` is an int, a NumPy Generator/RandomState or None, as in
293
- scikit-learn.
292
+ ``random_state`` is an int, None, a NumPy ``RandomState`` (as in
293
+ scikit-learn) or a NumPy ``Generator`` (``np.random.default_rng``).
294
294
  """
295
295
  for name, value in (("n_objects", n_objects), ("n_attributes", n_attributes)):
296
296
  if isinstance(value, bool) or not isinstance(value, numbers.Integral) or value < 0:
@@ -298,5 +298,9 @@ def make_random_context(
298
298
  if isinstance(density, bool) or not isinstance(density, numbers.Real) or not 0 <= density <= 1:
299
299
  raise ValueError("density must be a number in [0, 1].")
300
300
 
301
- rng = check_random_state(random_state)
302
- return FormalContext.from_array(rng.random_sample((n_objects, n_attributes)) < density)
301
+ shape = (n_objects, n_attributes)
302
+ if isinstance(random_state, np.random.Generator):
303
+ values = random_state.random(shape)
304
+ else:
305
+ values = check_random_state(random_state).random_sample(shape)
306
+ return FormalContext.from_array(values < density)
@@ -8,15 +8,17 @@ Bipartite Subgraphs" (arXiv:2211.10446, 2022), used by Ord2Factor:
8
8
  - ``minimum_bipartite_deletion``: a smallest such set (the paper's SAT
9
9
  formulation, Definition 1, solved with MiniSat 2.2; exponential in the
10
10
  worst case, as the problem is NP-hard);
11
- - ``greedy_bipartite_deletion``: a locally minimal set (Algorithm 1);
12
- - ``annealing_bipartite_deletion``: a locally minimal set improved by
11
+ - ``greedy_bipartite_deletion``: an inclusion-minimal set (Algorithm 1);
12
+ - ``annealing_bipartite_deletion``: an inclusion-minimal set improved by
13
13
  simulated annealing (Algorithm 2).
14
14
 
15
- "Locally minimal" is the guarantee of the paper's ``greedy-fill``: every
16
- deleted vertex has a neighbour on both sides of the bipartition that was
17
- built, so it cannot be added to that bipartition. (The paper calls the
18
- result inclusion-minimal; occasionally a deleted vertex could be kept with a
19
- *different* 2-colouring, which the algorithm does not search for.)
15
+ The paper states that both return an inclusion-minimal set (no deleted
16
+ vertex can be kept), but its ``greedy-fill`` only ensures that every
17
+ deleted vertex has a neighbour on both sides of the bipartition it built;
18
+ with a *different* 2-colouring a deleted vertex can sometimes be kept (in
19
+ about a fifth of small random cases). Both functions therefore end with a
20
+ pass that keeps every deleted vertex whose return leaves the graph
21
+ bipartite, which makes the paper's guarantee hold.
20
22
 
21
23
  Graphs are dicts mapping each vertex to the set of its neighbours, as
22
24
  returned by ``incompatibility_graph``. Each function returns the set D of
@@ -26,6 +28,8 @@ vertices to delete.
26
28
  from __future__ import annotations
27
29
 
28
30
  import math
31
+ import threading
32
+ import time
29
33
  from collections.abc import Hashable
30
34
 
31
35
  from sklearn.utils import check_random_state
@@ -59,7 +63,25 @@ def is_bipartite(graph: Graph, deleted=frozenset()) -> bool:
59
63
  # ---------------------------------------------------------------------------
60
64
 
61
65
 
62
- def _deletable_with_at_most(graph: Graph, vertices: list, k: int):
66
+ def _solve(solver, deadline: float | None) -> bool:
67
+ """Run the solver, interrupting it at ``deadline`` (time.monotonic())."""
68
+ if deadline is None:
69
+ return solver.solve()
70
+ remaining = deadline - time.monotonic()
71
+ if remaining <= 0:
72
+ raise TimeoutError
73
+ timer = threading.Timer(remaining, solver.interrupt)
74
+ timer.start()
75
+ try:
76
+ result = solver.solve_limited(expect_interrupt=True)
77
+ finally:
78
+ timer.cancel()
79
+ if result is None: # interrupted
80
+ raise TimeoutError
81
+ return result
82
+
83
+
84
+ def _deletable_with_at_most(graph: Graph, vertices: list, k: int, deadline=None):
63
85
  """D with |D| <= k making the graph bipartite, or None (MiniSat 2.2)."""
64
86
  from pysat.card import CardEnc, EncType
65
87
  from pysat.solvers import Minisat22
@@ -87,13 +109,13 @@ def _deletable_with_at_most(graph: Graph, vertices: list, k: int):
87
109
  encoding=EncType.seqcounter,
88
110
  )
89
111
  with Minisat22(bootstrap_with=clauses + at_most.clauses) as solver:
90
- if not solver.solve():
112
+ if not _solve(solver, deadline):
91
113
  return None
92
114
  true = {literal for literal in solver.get_model() if literal > 0}
93
115
  return {vertex for vertex in vertices if var(index[vertex], 3) in true}
94
116
 
95
117
 
96
- def minimum_bipartite_deletion(graph: Graph) -> set:
118
+ def minimum_bipartite_deletion(graph: Graph, max_time: float | None = None) -> set:
97
119
  """
98
120
  A smallest set of vertices whose deletion makes the graph bipartite.
99
121
 
@@ -102,21 +124,36 @@ def minimum_bipartite_deletion(graph: Graph) -> set:
102
124
  at most ``k`` vertices are in D. The smallest ``k`` is found as in the
103
125
  paper: ``k`` is doubled until the instance is satisfiable, then the gap
104
126
  is closed by binary search.
127
+
128
+ The problem is NP-hard and the time grows quickly with the graph (a few
129
+ hundred edges take seconds, a few thousand can take hours). With
130
+ ``max_time`` (seconds), ``TimeoutError`` is raised once that much time
131
+ has passed; the heuristics below are fast alternatives.
105
132
  """
133
+ deadline = None if max_time is None else time.monotonic() + max_time
134
+ try:
135
+ return _minimum_deletion(graph, deadline)
136
+ except TimeoutError:
137
+ raise TimeoutError(
138
+ f"No smallest deletion set found within max_time={max_time} seconds."
139
+ ) from None
140
+
141
+
142
+ def _minimum_deletion(graph: Graph, deadline) -> set:
106
143
  vertices = sorted(graph, key=repr)
107
144
  if is_bipartite(graph):
108
145
  return set()
109
146
 
110
147
  # k = 0 is unsatisfiable (the graph is not bipartite).
111
148
  low, k = 0, 1
112
- best = _deletable_with_at_most(graph, vertices, k)
149
+ best = _deletable_with_at_most(graph, vertices, k, deadline)
113
150
  while best is None:
114
151
  low, k = k, 2 * k
115
- best = _deletable_with_at_most(graph, vertices, k)
152
+ best = _deletable_with_at_most(graph, vertices, k, deadline)
116
153
  high = k
117
154
  while high - low > 1:
118
155
  middle = (low + high) // 2
119
- found = _deletable_with_at_most(graph, vertices, middle)
156
+ found = _deletable_with_at_most(graph, vertices, middle, deadline)
120
157
  if found is None:
121
158
  low = middle
122
159
  else:
@@ -149,15 +186,28 @@ def _greedy_fill(graph: Graph, a: set, b: set, d: set, rng) -> tuple[set, set, s
149
186
  return a, b, d
150
187
 
151
188
 
189
+ def _keep_what_fits(graph: Graph, d: set) -> set:
190
+ """
191
+ Make ``d`` inclusion-minimal: put back every vertex whose return leaves
192
+ the graph bipartite (in a fixed order, so results are reproducible).
193
+ """
194
+ d = set(d)
195
+ for vertex in sorted(d, key=repr):
196
+ if is_bipartite(graph, d - {vertex}):
197
+ d.discard(vertex)
198
+ return d
199
+
200
+
152
201
  def greedy_bipartite_deletion(graph: Graph, random_state=None) -> set:
153
202
  """
154
- A locally minimal set of vertices whose deletion makes the graph
155
- bipartite (the paper's Algorithm 1: ``greedy-fill`` starting with every
156
- vertex in D). Polynomial time.
203
+ An inclusion-minimal set of vertices whose deletion makes the graph
204
+ bipartite: the paper's Algorithm 1 (``greedy-fill`` starting with every
205
+ vertex in D), then the final pass described in the module docstring.
206
+ Polynomial time.
157
207
  """
158
208
  rng = check_random_state(random_state)
159
209
  _, _, d = _greedy_fill(graph, set(), set(), set(graph), rng)
160
- return d
210
+ return _keep_what_fits(graph, d)
161
211
 
162
212
 
163
213
  def annealing_bipartite_deletion(
@@ -169,11 +219,17 @@ def annealing_bipartite_deletion(
169
219
  """
170
220
  Simulated annealing (the paper's Algorithm 2), starting from the greedy
171
221
  solution. A neighbouring solution moves a random vertex ``u`` of D into
172
- A or B (at random), moves its neighbours there into D, and refills with
173
- ``greedy-fill``. A smaller D is always accepted, a larger one with
222
+ A or B (at random), moves all its neighbours in A and B into D, and
223
+ refills with ``greedy-fill``. A smaller D is always accepted, a larger one with
174
224
  probability ``exp(-(growth) / t)``, where the temperature falls linearly
175
- from ``temperature`` to 0 over ``n_iterations`` steps. As in the paper,
176
- the final D is returned; it is locally minimal.
225
+ from ``temperature`` to 0 over ``n_iterations`` steps (the paper's
226
+ linear cooling). As in the paper, the final D is returned, after the
227
+ final pass that makes it inclusion-minimal.
228
+
229
+ The defaults (``temperature=1``, 1000 iterations) are smaller than the
230
+ paper's recommendation (50, quadratic cooling, 10000 iterations): on
231
+ ordinal-factorization graphs they give the same results about ten times
232
+ faster.
177
233
  """
178
234
  rng = check_random_state(random_state)
179
235
  a, b, d = _greedy_fill(graph, set(), set(), set(graph), rng)
@@ -199,4 +255,4 @@ def annealing_bipartite_deletion(
199
255
  current_temperature > 0 and math.exp(change / current_temperature) > rng.random_sample()
200
256
  ):
201
257
  a, b, d = new_a, new_b, new_d
202
- return d
258
+ return _keep_what_fits(graph, d)
@@ -20,12 +20,15 @@ Implemented
20
20
 
21
21
  from __future__ import annotations
22
22
 
23
+ import numbers
24
+ import time
23
25
  from collections import deque
24
26
  from collections.abc import Iterable
25
27
  from dataclasses import dataclass
26
28
 
27
29
  import numpy as np
28
30
  from sklearn.base import BaseEstimator
31
+ from sklearn.utils import check_scalar
29
32
 
30
33
  from conceptflow.core import ConceptLattice, FormalContext
31
34
  from conceptflow.validation import check_binary_context_input
@@ -407,12 +410,15 @@ class Ord2Factor(BaseEstimator):
407
410
  Parameters
408
411
  ----------
409
412
  method:
410
- ``"exact"`` (default): a smallest set of crosses to drop, from the
411
- papers' SAT formulation solved with MiniSat 2.2 (exponential in the
412
- worst case; meant for small contexts). ``"greedy"``: an
413
- locally minimal set (Algorithm 1 of the 2022 paper), in polynomial
414
- time. ``"annealing"``: the
415
- greedy result improved by simulated annealing.
413
+ ``"annealing"`` (default): the greedy result improved by simulated
414
+ annealing; seconds even for contexts with hundreds of crosses, and
415
+ on small contexts as good as ``"exact"`` in our tests.
416
+ ``"exact"``: in each round a smallest set of crosses to drop, from
417
+ the papers' SAT formulation solved with MiniSat 2.2. Exponential:
418
+ about 20 s for a 15 x 15 context of density 0.4, hours a little
419
+ beyond; limited by ``max_time``. ``"greedy"``: an inclusion-minimal
420
+ set (Algorithm 1 of the 2022 paper, plus a final pass that keeps
421
+ every cross it can), in polynomial time, but often far worse.
416
422
 
417
423
  n_iterations, temperature:
418
424
  Steps and starting temperature of ``method="annealing"``.
@@ -423,6 +429,10 @@ class Ord2Factor(BaseEstimator):
423
429
  lattice_algorithm:
424
430
  Concept enumeration algorithm for the complement lattice.
425
431
 
432
+ max_time:
433
+ Time limit in seconds for ``method="exact"`` (default 60); ``fit``
434
+ raises ``TimeoutError`` once it is exceeded. ``None``: no limit.
435
+
426
436
  Attributes
427
437
  ----------
428
438
  factors_:
@@ -445,19 +455,21 @@ class Ord2Factor(BaseEstimator):
445
455
 
446
456
  def __init__(
447
457
  self,
448
- method: str = "exact",
458
+ method: str = "annealing",
449
459
  n_iterations: int = 1000,
450
460
  temperature: float = 1.0,
451
461
  random_state=None,
452
462
  lattice_algorithm: str = "nextclosure",
463
+ max_time: float | None = 60.0,
453
464
  ):
454
465
  self.method = method
455
466
  self.n_iterations = n_iterations
456
467
  self.temperature = temperature
457
468
  self.random_state = random_state
458
469
  self.lattice_algorithm = lattice_algorithm
470
+ self.max_time = max_time
459
471
 
460
- def _deletion(self, graph, rng):
472
+ def _deletion(self, graph, rng, deadline):
461
473
  from conceptflow.decomposition.bipartite import (
462
474
  annealing_bipartite_deletion,
463
475
  greedy_bipartite_deletion,
@@ -465,7 +477,10 @@ class Ord2Factor(BaseEstimator):
465
477
  )
466
478
 
467
479
  if self.method == "exact":
468
- return minimum_bipartite_deletion(graph)
480
+ remaining = None if deadline is None else deadline - time.monotonic()
481
+ if remaining is not None and remaining <= 0:
482
+ raise TimeoutError
483
+ return minimum_bipartite_deletion(graph, max_time=remaining)
469
484
  if self.method == "greedy":
470
485
  return greedy_bipartite_deletion(graph, random_state=rng)
471
486
  return annealing_bipartite_deletion(
@@ -486,19 +501,35 @@ class Ord2Factor(BaseEstimator):
486
501
  or self.n_iterations < 0
487
502
  ):
488
503
  raise ValueError("n_iterations must be a non-negative integer.")
504
+ if self.max_time is not None:
505
+ check_scalar(
506
+ self.max_time, "max_time", numbers.Real, min_val=0, include_boundaries="neither"
507
+ )
489
508
 
490
509
  context = check_binary_context_input(X)
491
510
  rng = check_random_state(self.random_state)
492
511
  incidence = np.array(context.incidence, dtype=bool)
493
512
  removed: set[IncidencePair] = set()
494
513
  rounds = 0
514
+ deadline = (
515
+ None if self.max_time is None or self.method != "exact"
516
+ else time.monotonic() + self.max_time
517
+ )
495
518
 
496
519
  while True:
497
520
  current = FormalContext(context.objects, context.attributes, incidence)
498
521
  graph = incompatibility_graph(current)
499
522
  if is_bipartite(graph):
500
523
  break
501
- dropped = self._deletion(graph, rng)
524
+ try:
525
+ dropped = self._deletion(graph, rng, deadline)
526
+ except TimeoutError:
527
+ raise TimeoutError(
528
+ f'method="exact" did not finish within max_time={self.max_time} '
529
+ "seconds: it is exponential in the size of the context. Use "
530
+ 'method="annealing" (the default) for larger contexts, or raise '
531
+ "max_time (None: no limit)."
532
+ ) from None
502
533
  for g, m in dropped:
503
534
  incidence[g, m] = False
504
535
  removed |= dropped