conceptflow 0.6.0__tar.gz → 0.6.2__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.6.0/src/conceptflow.egg-info → conceptflow-0.6.2}/PKG-INFO +2 -31
- {conceptflow-0.6.0 → conceptflow-0.6.2}/pyproject.toml +3 -3
- conceptflow-0.6.2/src/conceptflow/_version.py +1 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/core/context.py +29 -4
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/core/incomplete_context.py +30 -9
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/core/many_valued_context.py +4 -4
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/core/scale_measures.py +10 -1
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/decomposition/boolean_factorization.py +16 -1
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/exploration/builder.py +68 -4
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/exploration/view.py +2 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/metrics/drawing_quality.py +58 -25
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/preprocessing/conceptual_scaler.py +9 -9
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/validation/input.py +35 -0
- conceptflow-0.6.2/src/conceptflow/visualization/_checks.py +168 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/visualization/_clearance.py +15 -4
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/visualization/d3_backend.py +106 -26
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/visualization/dimflux_layout.py +25 -1
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/visualization/graphviz.py +4 -1
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/visualization/html_figure.py +7 -2
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/visualization/lattice_plot.py +12 -5
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/visualization/nested.py +224 -94
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/visualization/tikz.py +9 -1
- {conceptflow-0.6.0 → conceptflow-0.6.2/src/conceptflow.egg-info}/PKG-INFO +2 -31
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow.egg-info/SOURCES.txt +1 -0
- conceptflow-0.6.2/tests/test_browser.py +554 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_d3_backend.py +17 -6
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_dimflux_layout.py +65 -1
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_drawing_quality.py +112 -3
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_exploration.py +58 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_formal_context.py +29 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_html_figure.py +7 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_incomplete_context.py +30 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_layout_and_graphviz.py +57 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_nested_combinations.py +15 -0
- conceptflow-0.6.2/tests/test_nested_levels.py +165 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_scale_measures.py +11 -0
- conceptflow-0.6.2/tests/test_sklearn_compatibility.py +175 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_tikz.py +29 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_visualization_options.py +64 -7
- conceptflow-0.6.0/src/conceptflow/_version.py +0 -1
- conceptflow-0.6.0/src/conceptflow/visualization/_checks.py +0 -44
- conceptflow-0.6.0/tests/test_browser.py +0 -304
- conceptflow-0.6.0/tests/test_sklearn_compatibility.py +0 -81
- {conceptflow-0.6.0 → conceptflow-0.6.2}/LICENSE +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/README.md +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/setup.cfg +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/__init__.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/_deprecation.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/algorithms/__init__.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/algorithms/_bitset.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/algorithms/_membership.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/algorithms/_registry.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/algorithms/derivation.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/algorithms/enumeration.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/algorithms/generators.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/algorithms/hasse.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/algorithms/implications.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/algorithms/order.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/algorithms/reduction.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/cluster/__init__.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/cluster/concept_lattice.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/core/__init__.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/core/concept.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/core/lattice.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/core/operations.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/datasets/__init__.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/datasets/_loaders.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/README.md +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/animals_en.cxt +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/binary_relations_en.cxt +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/bodiesofwater_de.cxt +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/bodiesofwater_en.cxt +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/driveconcepts_de.cxt +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/driveconcepts_en.cxt +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/famous_animals_en.cxt +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/forum_romanum_en.cxt +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/livingbeings_de.cxt +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/livingbeings_en.cxt +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/missmarple_de.cxt +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/missmarple_en.cxt +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/music_en.cxt +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/newzealand_en.cxt +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/officesupplies_de.cxt +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/officesupplies_en.cxt +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/planets_en.cxt +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/seasoningplanner_de.cxt +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/tealady.cxt +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/triangles_en.cxt +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository.json +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/decomposition/__init__.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/decomposition/bipartite.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/decomposition/ordinal_factorization.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/exploration/__init__.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/exploration/combinations.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/feature_extraction/__init__.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/feature_extraction/concept_encoder.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/io/__init__.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/io/cxt.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/io/formats.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/metrics/__init__.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/metrics/measures.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/metrics/rules.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/preprocessing/__init__.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/preprocessing/scales.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/quality.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/rules/__init__.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/rules/implication_basis.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/rules/outlier_detector.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/validation/__init__.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/visualization/__init__.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/visualization/_text.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/visualization/graph_data.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/visualization/layered_layout.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/visualization/static.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow.egg-info/dependency_links.txt +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow.egg-info/requires.txt +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow.egg-info/top_level.txt +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_algorithm_registry.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_audit_regressions.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_boolean_factorization.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_check_estimator.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_cluster_estimator.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_concept.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_concept_encoder.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_conceptual_scaler.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_context_handling.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_context_operations.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_cxt_io.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_datasets.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_derivation.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_docs_examples.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_enumeration.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_generators.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_graph_data.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_hasse.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_implication_basis_estimator.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_implications.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_lattice.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_lattice_navigation.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_many_valued_context.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_measures.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_metrics.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_nested_visualization.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_oracles.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_ord2factor.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_ordinal_factorization.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_patch_0_3_1.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_public_api.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_quality.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_reduction.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_review_fixes.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_scales.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_static_figures.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_validation_input.py +0 -0
- {conceptflow-0.6.0 → conceptflow-0.6.2}/tests/test_workflows.py +0 -0
|
@@ -1,37 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: conceptflow
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.2
|
|
4
4
|
Summary: A scikit-learn compatible Formal Concept Analysis framework.
|
|
5
5
|
Author-email: Anurag Sharma <sharma@cs.uni-kassel.de>
|
|
6
|
-
License: BSD
|
|
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
|
-
|
|
6
|
+
License-Expression: BSD-3-Clause
|
|
35
7
|
Project-URL: Homepage, https://github.com/anuragxorma/conceptflow
|
|
36
8
|
Project-URL: Documentation, https://conceptflow.readthedocs.io
|
|
37
9
|
Project-URL: Repository, https://github.com/anuragxorma/conceptflow
|
|
@@ -39,7 +11,6 @@ Project-URL: Issues, https://github.com/anuragxorma/conceptflow/issues
|
|
|
39
11
|
Keywords: formal-concept-analysis,fca,scikit-learn,concept-lattice,conceptual-scaling
|
|
40
12
|
Classifier: Development Status :: 4 - Beta
|
|
41
13
|
Classifier: Intended Audience :: Science/Research
|
|
42
|
-
Classifier: License :: OSI Approved :: BSD License
|
|
43
14
|
Classifier: Programming Language :: Python :: 3
|
|
44
15
|
Classifier: Programming Language :: Python :: 3.12
|
|
45
16
|
Classifier: Programming Language :: Python :: 3.13
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
[build-system]
|
|
2
|
-
requires = ["setuptools>=
|
|
2
|
+
requires = ["setuptools>=77", "wheel"]
|
|
3
3
|
build-backend = "setuptools.build_meta"
|
|
4
4
|
|
|
5
5
|
[project]
|
|
@@ -8,7 +8,8 @@ dynamic = ["version"]
|
|
|
8
8
|
description = "A scikit-learn compatible Formal Concept Analysis framework."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.12"
|
|
11
|
-
license =
|
|
11
|
+
license = "BSD-3-Clause"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
12
13
|
authors = [
|
|
13
14
|
{ name = "Anurag Sharma", email = "sharma@cs.uni-kassel.de" }
|
|
14
15
|
]
|
|
@@ -22,7 +23,6 @@ keywords = [
|
|
|
22
23
|
classifiers = [
|
|
23
24
|
"Development Status :: 4 - Beta",
|
|
24
25
|
"Intended Audience :: Science/Research",
|
|
25
|
-
"License :: OSI Approved :: BSD License",
|
|
26
26
|
"Programming Language :: Python :: 3",
|
|
27
27
|
"Programming Language :: Python :: 3.12",
|
|
28
28
|
"Programming Language :: Python :: 3.13",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.6.2"
|
|
@@ -67,6 +67,27 @@ def _cell_is_cross(value) -> bool:
|
|
|
67
67
|
raise ValueError(f"Cannot read {value!r} as a cross or non-cross.") from None
|
|
68
68
|
|
|
69
69
|
|
|
70
|
+
def _check_unique_names(names: tuple[str, ...], kind: str) -> None:
|
|
71
|
+
"""
|
|
72
|
+
Raise if ``names`` (already strings) has duplicates, naming them. ``kind``
|
|
73
|
+
is "object" or "attribute"; DataFrames give their index or columns.
|
|
74
|
+
"""
|
|
75
|
+
if len(set(names)) == len(names):
|
|
76
|
+
return
|
|
77
|
+
seen: set[str] = set()
|
|
78
|
+
duplicates = sorted({name for name in names if name in seen or seen.add(name)})
|
|
79
|
+
source = (
|
|
80
|
+
"its index: df.reset_index(drop=True) numbers the rows instead"
|
|
81
|
+
if kind == "object"
|
|
82
|
+
else "its columns"
|
|
83
|
+
)
|
|
84
|
+
raise ValueError(
|
|
85
|
+
f"{kind.capitalize()} names must be unique, but {duplicates[:5]} occur more "
|
|
86
|
+
f"than once (names are compared as strings, so 1 and '1' are the same). "
|
|
87
|
+
f"For a DataFrame, the {kind} names are {source}."
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
|
|
70
91
|
def _cross_table(data) -> np.ndarray:
|
|
71
92
|
"""
|
|
72
93
|
Convert incidence data to a boolean cross table, cell by cell:
|
|
@@ -144,11 +165,9 @@ class FormalContext:
|
|
|
144
165
|
object.__setattr__(self, "objects", tuple(map(str, self.objects)))
|
|
145
166
|
object.__setattr__(self, "attributes", tuple(map(str, self.attributes)))
|
|
146
167
|
|
|
147
|
-
|
|
148
|
-
raise ValueError("Object names must be unique.")
|
|
168
|
+
_check_unique_names(self.objects, "object")
|
|
149
169
|
|
|
150
|
-
|
|
151
|
-
raise ValueError("Attribute names must be unique.")
|
|
170
|
+
_check_unique_names(self.attributes, "attribute")
|
|
152
171
|
|
|
153
172
|
incidence = _cross_table(self.incidence)
|
|
154
173
|
|
|
@@ -167,6 +186,12 @@ class FormalContext:
|
|
|
167
186
|
incidence.flags.writeable = False
|
|
168
187
|
object.__setattr__(self, "incidence", incidence)
|
|
169
188
|
|
|
189
|
+
def __setstate__(self, state: dict) -> None:
|
|
190
|
+
# pickle and copy.deepcopy restore the attributes without __post_init__,
|
|
191
|
+
# and an unpickled array is writeable again.
|
|
192
|
+
self.__dict__.update(state)
|
|
193
|
+
self.incidence.flags.writeable = False
|
|
194
|
+
|
|
170
195
|
def __eq__(self, other: object) -> bool:
|
|
171
196
|
if not isinstance(other, FormalContext):
|
|
172
197
|
return NotImplemented
|
|
@@ -25,7 +25,12 @@ from typing import Any, Iterable
|
|
|
25
25
|
import numpy as np
|
|
26
26
|
import pandas as pd
|
|
27
27
|
|
|
28
|
-
from conceptflow.core.context import
|
|
28
|
+
from conceptflow.core.context import (
|
|
29
|
+
FormalContext,
|
|
30
|
+
_check_unique_names,
|
|
31
|
+
_cross_table,
|
|
32
|
+
_is_index,
|
|
33
|
+
)
|
|
29
34
|
|
|
30
35
|
UNKNOWN_MARKERS = frozenset({"?"})
|
|
31
36
|
|
|
@@ -116,24 +121,30 @@ class IncompleteContext:
|
|
|
116
121
|
object.__setattr__(self, "objects", tuple(map(str, self.objects)))
|
|
117
122
|
object.__setattr__(self, "attributes", tuple(map(str, self.attributes)))
|
|
118
123
|
|
|
119
|
-
|
|
120
|
-
raise ValueError("Object names must be unique.")
|
|
124
|
+
_check_unique_names(self.objects, "object")
|
|
121
125
|
|
|
122
|
-
|
|
123
|
-
raise ValueError("Attribute names must be unique.")
|
|
126
|
+
_check_unique_names(self.attributes, "attribute")
|
|
124
127
|
|
|
125
|
-
# Copies, read-only: the context cannot change after creation.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
+
# Copies, read-only: the context cannot change after creation. Cells
|
|
129
|
+
# are read as in FormalContext, so "0" and NaN are not crosses.
|
|
130
|
+
certain = _cross_table(self.certain)
|
|
131
|
+
unknown = _cross_table(self.unknown)
|
|
128
132
|
expected_shape = (len(self.objects), len(self.attributes))
|
|
129
133
|
|
|
130
134
|
for name, matrix in (("certain", certain), ("unknown", unknown)):
|
|
135
|
+
if matrix.size == 0 and 0 in expected_shape:
|
|
136
|
+
continue
|
|
131
137
|
if matrix.shape != expected_shape:
|
|
132
138
|
raise ValueError(
|
|
133
139
|
f"{name} matrix has shape {matrix.shape}, but expected "
|
|
134
140
|
f"{expected_shape}."
|
|
135
141
|
)
|
|
136
142
|
|
|
143
|
+
if certain.size == 0:
|
|
144
|
+
certain = np.zeros(expected_shape, dtype=bool)
|
|
145
|
+
if unknown.size == 0:
|
|
146
|
+
unknown = np.zeros(expected_shape, dtype=bool)
|
|
147
|
+
|
|
137
148
|
if (certain & unknown).any():
|
|
138
149
|
raise ValueError("An entry cannot be both certain and unknown.")
|
|
139
150
|
|
|
@@ -143,6 +154,14 @@ class IncompleteContext:
|
|
|
143
154
|
object.__setattr__(self, "certain", certain)
|
|
144
155
|
object.__setattr__(self, "unknown", unknown)
|
|
145
156
|
|
|
157
|
+
def __setstate__(self, state: dict) -> None:
|
|
158
|
+
# pickle and copy.deepcopy restore the attributes without __post_init__,
|
|
159
|
+
# and unpickled arrays are writeable again.
|
|
160
|
+
self.__dict__.update(state)
|
|
161
|
+
for name in ("certain", "unknown", "possible"):
|
|
162
|
+
if name in self.__dict__:
|
|
163
|
+
self.__dict__[name].flags.writeable = False
|
|
164
|
+
|
|
146
165
|
def __eq__(self, other: object) -> bool:
|
|
147
166
|
if not isinstance(other, IncompleteContext):
|
|
148
167
|
return NotImplemented
|
|
@@ -181,7 +200,9 @@ class IncompleteContext:
|
|
|
181
200
|
@cached_property
|
|
182
201
|
def possible(self) -> np.ndarray:
|
|
183
202
|
"""True where the object has, or might have, the attribute."""
|
|
184
|
-
|
|
203
|
+
possible = self.certain | self.unknown
|
|
204
|
+
possible.flags.writeable = False # cached, so it must not change
|
|
205
|
+
return possible
|
|
185
206
|
|
|
186
207
|
@property
|
|
187
208
|
def is_complete(self) -> bool:
|
|
@@ -40,6 +40,8 @@ from typing import Any
|
|
|
40
40
|
import numpy as np
|
|
41
41
|
import pandas as pd
|
|
42
42
|
|
|
43
|
+
from conceptflow.core.context import _check_unique_names
|
|
44
|
+
|
|
43
45
|
|
|
44
46
|
@dataclass(frozen=True)
|
|
45
47
|
class ManyValuedContext:
|
|
@@ -79,11 +81,9 @@ class ManyValuedContext:
|
|
|
79
81
|
objects = tuple(map(str, self.objects))
|
|
80
82
|
attributes = tuple(map(str, self.attributes))
|
|
81
83
|
|
|
82
|
-
|
|
83
|
-
raise ValueError("Object names must be unique.")
|
|
84
|
+
_check_unique_names(objects, "object")
|
|
84
85
|
|
|
85
|
-
|
|
86
|
-
raise ValueError("Attribute names must be unique.")
|
|
86
|
+
_check_unique_names(attributes, "attribute")
|
|
87
87
|
|
|
88
88
|
if isinstance(self.data, pd.DataFrame):
|
|
89
89
|
data = self.data.copy()
|
|
@@ -27,6 +27,7 @@ from __future__ import annotations
|
|
|
27
27
|
|
|
28
28
|
import numbers
|
|
29
29
|
from collections.abc import Iterable
|
|
30
|
+
from collections.abc import Set as AbstractSet
|
|
30
31
|
|
|
31
32
|
import numpy as np
|
|
32
33
|
|
|
@@ -47,7 +48,9 @@ def scale_measure(
|
|
|
47
48
|
Each entry of ``attributes`` is one attribute of ``context`` (a name or
|
|
48
49
|
a position), kept as it is, or a tuple of them, which becomes their
|
|
49
50
|
conjunction: an object has it iff it has every part. The conjunction of
|
|
50
|
-
``"a"`` and ``"b"`` is named ``"a ∧ b"
|
|
51
|
+
``"a"`` and ``"b"`` is named ``"a ∧ b"``: parts are named in the order
|
|
52
|
+
given, or, for a set, in the order of ``context``'s attributes.
|
|
53
|
+
``None`` returns ``context``.
|
|
51
54
|
|
|
52
55
|
The objects stay those of ``context``, in the same order. The attributes
|
|
53
56
|
are put in one canonical order: by the positions of their parts in
|
|
@@ -71,6 +74,8 @@ def scale_measure(
|
|
|
71
74
|
if not parts:
|
|
72
75
|
raise ValueError("A conjunction needs at least one attribute.")
|
|
73
76
|
indices = context._resolve_attribute_indices(parts)
|
|
77
|
+
if isinstance(entry, AbstractSet):
|
|
78
|
+
indices = tuple(sorted(indices)) # a set has no order of its own
|
|
74
79
|
entries.append((tuple(sorted(indices)), indices))
|
|
75
80
|
entries.sort(key=lambda item: item[0]) # stable: equal keys keep their order
|
|
76
81
|
|
|
@@ -93,6 +98,10 @@ def scale_measure_problems(original: FormalContext, scale: FormalContext) -> lis
|
|
|
93
98
|
of its attributes is an extent of ``original``, i.e. equals its own
|
|
94
99
|
closure there (Hanika & Hirth, Prop. 20). That is one closure per
|
|
95
100
|
attribute; the scale's lattice is not enumerated.
|
|
101
|
+
|
|
102
|
+
A scale with the same objects in another order is reported as having
|
|
103
|
+
different objects; ``scale.subcontext(objects=original.objects)`` puts
|
|
104
|
+
them in the original's order. ``refines`` matches objects by name.
|
|
96
105
|
"""
|
|
97
106
|
if tuple(scale.objects) != tuple(original.objects):
|
|
98
107
|
return ["object sets differ, so the identity is not a map between them"]
|
{conceptflow-0.6.0 → conceptflow-0.6.2}/src/conceptflow/decomposition/boolean_factorization.py
RENAMED
|
@@ -35,7 +35,11 @@ from sklearn.utils.validation import check_is_fitted
|
|
|
35
35
|
from conceptflow.algorithms._membership import contains_sets
|
|
36
36
|
from conceptflow.core import Concept
|
|
37
37
|
from conceptflow.validation import check_binary_context_input
|
|
38
|
-
from conceptflow.validation.input import
|
|
38
|
+
from conceptflow.validation.input import (
|
|
39
|
+
check_feature_names,
|
|
40
|
+
check_input_features,
|
|
41
|
+
remember_feature_names,
|
|
42
|
+
)
|
|
39
43
|
|
|
40
44
|
|
|
41
45
|
def _counting_dtype(n_cells: int):
|
|
@@ -96,6 +100,17 @@ class _BooleanFactorization(ClassNamePrefixFeaturesOutMixin, TransformerMixin, B
|
|
|
96
100
|
dtype = _counting_dtype(usage.size)
|
|
97
101
|
return (usage.astype(dtype) @ self.components_.astype(dtype)) > 0
|
|
98
102
|
|
|
103
|
+
def get_feature_names_out(self, input_features=None):
|
|
104
|
+
"""
|
|
105
|
+
Output feature names: the class name and the factor number, e.g.
|
|
106
|
+
``grecond0``. ``input_features`` must be the names seen during fit, if
|
|
107
|
+
the input had names; otherwise any names of the right length are
|
|
108
|
+
accepted, such as those a previous Pipeline step passes on.
|
|
109
|
+
"""
|
|
110
|
+
check_is_fitted(self, "_n_features_out")
|
|
111
|
+
check_input_features(self, input_features)
|
|
112
|
+
return super().get_feature_names_out()
|
|
113
|
+
|
|
99
114
|
def transform(self, X):
|
|
100
115
|
"""
|
|
101
116
|
Factor memberships S: one boolean column per factor.
|
|
@@ -4,8 +4,11 @@ Builder API for nested conceptual exploration.
|
|
|
4
4
|
|
|
5
5
|
from __future__ import annotations
|
|
6
6
|
|
|
7
|
+
import numbers
|
|
7
8
|
from collections.abc import Callable
|
|
8
9
|
|
|
10
|
+
from sklearn.utils import check_scalar
|
|
11
|
+
|
|
9
12
|
from conceptflow.core import Concept, ConceptLattice, ManyValuedContext
|
|
10
13
|
from conceptflow.exploration.view import ExplorationView
|
|
11
14
|
from conceptflow.preprocessing import ConceptualScaler, Scale
|
|
@@ -77,16 +80,24 @@ class ExplorationBuilder:
|
|
|
77
80
|
)
|
|
78
81
|
|
|
79
82
|
def _scale(self, mvc: ManyValuedContext, scales: list[Scale]):
|
|
80
|
-
"""
|
|
83
|
+
"""
|
|
84
|
+
Scale ``mvc`` into a formal context with this builder's policy.
|
|
85
|
+
|
|
86
|
+
The scales are fit on all of the builder's data, so a view of some
|
|
87
|
+
objects has the same attributes as the view of all objects, including
|
|
88
|
+
values its objects lack: the "≠ v" of a contranominal scale holds for
|
|
89
|
+
all of them, and dropping it would change their intents.
|
|
90
|
+
"""
|
|
81
91
|
self._check_scales(scales)
|
|
82
92
|
scaler = ConceptualScaler(
|
|
83
93
|
scales=scales,
|
|
84
94
|
output="context",
|
|
85
|
-
missing=
|
|
86
|
-
)
|
|
95
|
+
missing="false", # the vocabulary; missing values are checked below
|
|
96
|
+
).fit(self.mvc)
|
|
97
|
+
scaler.set_params(missing=self.missing)
|
|
87
98
|
|
|
88
99
|
try:
|
|
89
|
-
return scaler.
|
|
100
|
+
return scaler.transform(mvc)
|
|
90
101
|
except ValueError as exc:
|
|
91
102
|
if "Input contains NaN" not in str(exc):
|
|
92
103
|
raise
|
|
@@ -104,6 +115,19 @@ class ExplorationBuilder:
|
|
|
104
115
|
"""
|
|
105
116
|
return len(concept.extent) > 0
|
|
106
117
|
|
|
118
|
+
@staticmethod
|
|
119
|
+
def _is_concept_of(view: ExplorationView, concept: Concept) -> bool:
|
|
120
|
+
"""Whether ``concept`` is a concept of ``view``'s context."""
|
|
121
|
+
context = view.context
|
|
122
|
+
if not all(0 <= g < context.n_objects for g in concept.extent) or not all(
|
|
123
|
+
0 <= m < context.n_attributes for m in concept.intent
|
|
124
|
+
):
|
|
125
|
+
return False
|
|
126
|
+
return (
|
|
127
|
+
context.object_derivation(concept.extent) == concept.intent
|
|
128
|
+
and context.attribute_derivation(concept.intent) == concept.extent
|
|
129
|
+
)
|
|
130
|
+
|
|
107
131
|
def _object_names_from_parent_extent(
|
|
108
132
|
self,
|
|
109
133
|
parent: ExplorationView,
|
|
@@ -126,7 +150,19 @@ class ExplorationBuilder:
|
|
|
126
150
|
) -> ExplorationView:
|
|
127
151
|
"""
|
|
128
152
|
Expand one parent concept into a child exploration view.
|
|
153
|
+
|
|
154
|
+
The child view scales the objects of ``concept`` with ``scales``,
|
|
155
|
+
fit on all of the builder's data: it has the same attributes as a view
|
|
156
|
+
of all objects with these scales.
|
|
157
|
+
``concept`` must be a concept of ``parent.lattice``. Expanding a
|
|
158
|
+
concept that already has a child view replaces that view.
|
|
129
159
|
"""
|
|
160
|
+
if not self._is_concept_of(parent, concept):
|
|
161
|
+
raise ValueError(
|
|
162
|
+
f"The concept is not a concept of the parent view {parent.name!r}. "
|
|
163
|
+
"Pass a concept from parent.lattice.concepts; concepts of other "
|
|
164
|
+
"views refer to other objects."
|
|
165
|
+
)
|
|
130
166
|
if not self._is_expandable(concept):
|
|
131
167
|
raise ValueError(
|
|
132
168
|
"Cannot expand a concept with an empty extent. "
|
|
@@ -196,8 +232,18 @@ class ExplorationBuilder:
|
|
|
196
232
|
"""
|
|
197
233
|
Expand all selected expandable concepts of a parent view.
|
|
198
234
|
|
|
235
|
+
Concepts that already have a child view get a new one (see
|
|
236
|
+
``expand``).
|
|
237
|
+
|
|
199
238
|
Parameters
|
|
200
239
|
----------
|
|
240
|
+
name_template:
|
|
241
|
+
Name of each child view. May use ``{label}``, ``{intent}``,
|
|
242
|
+
``{extent_size}`` and ``{depth}``.
|
|
243
|
+
|
|
244
|
+
min_extent_size, max_extent_size:
|
|
245
|
+
Expand only concepts with at least / at most this many objects.
|
|
246
|
+
|
|
201
247
|
include_top:
|
|
202
248
|
If False, skip the top concept (the one with every object in its
|
|
203
249
|
extent).
|
|
@@ -208,12 +254,30 @@ class ExplorationBuilder:
|
|
|
208
254
|
raises ValueError for it) regardless of this flag. Kept for
|
|
209
255
|
backward-compatible signatures; do not rely on it to include or
|
|
210
256
|
exclude anything.
|
|
257
|
+
|
|
258
|
+
predicate:
|
|
259
|
+
If given, expand only concepts for which ``predicate(concept)``
|
|
260
|
+
is true.
|
|
211
261
|
"""
|
|
212
262
|
self._check_scales(scales)
|
|
213
263
|
if not isinstance(name_template, str):
|
|
214
264
|
raise TypeError(
|
|
215
265
|
f"name_template must be a string, got {name_template!r}."
|
|
216
266
|
)
|
|
267
|
+
try:
|
|
268
|
+
name_template.format(label="", intent="", extent_size=0, depth=0)
|
|
269
|
+
except (KeyError, IndexError, ValueError) as exc:
|
|
270
|
+
raise ValueError(
|
|
271
|
+
f"name_template {name_template!r} is not valid: it may use {{label}}, "
|
|
272
|
+
"{intent}, {extent_size} and {depth}."
|
|
273
|
+
) from exc
|
|
274
|
+
check_scalar(min_extent_size, "min_extent_size", numbers.Integral, min_val=0)
|
|
275
|
+
if max_extent_size is not None:
|
|
276
|
+
check_scalar(max_extent_size, "max_extent_size", numbers.Integral, min_val=0)
|
|
277
|
+
if predicate is not None and not callable(predicate):
|
|
278
|
+
raise TypeError(
|
|
279
|
+
f"predicate must be a callable taking a Concept, got {predicate!r}."
|
|
280
|
+
)
|
|
217
281
|
children: list[ExplorationView] = []
|
|
218
282
|
|
|
219
283
|
parent_object_count = parent.context.n_objects
|
|
@@ -26,6 +26,8 @@ class ExplorationView:
|
|
|
26
26
|
def add_child(self, concept_id: str, child: "ExplorationView") -> None:
|
|
27
27
|
"""
|
|
28
28
|
Attach a child exploration view to a concept in this view.
|
|
29
|
+
|
|
30
|
+
A child view already attached to the concept is replaced.
|
|
29
31
|
"""
|
|
30
32
|
self.children[concept_id] = child
|
|
31
33
|
|
|
@@ -189,6 +189,12 @@ def _check_drawing(drawing) -> _Drawing:
|
|
|
189
189
|
else:
|
|
190
190
|
xy = np.array([(node.x, node.y) for node in drawing.nodes], dtype=float)
|
|
191
191
|
edges = [(edge.source, edge.target) for edge in drawing.edges]
|
|
192
|
+
elif isinstance(drawing, nx.MultiDiGraph):
|
|
193
|
+
raise TypeError(
|
|
194
|
+
"A drawing must be a networkx.DiGraph, not a MultiDiGraph: a line diagram "
|
|
195
|
+
"has at most one edge between two nodes. networkx.DiGraph(graph) merges "
|
|
196
|
+
"parallel edges."
|
|
197
|
+
)
|
|
192
198
|
elif isinstance(drawing, nx.DiGraph):
|
|
193
199
|
nodes = list(drawing.nodes)
|
|
194
200
|
try:
|
|
@@ -505,11 +511,24 @@ def edge_crossing_score(drawing) -> float:
|
|
|
505
511
|
"""
|
|
506
512
|
``1 - crossings / possible crossings``.
|
|
507
513
|
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
of edges
|
|
514
|
+
Following Purchase's crossing score with a bound tightened for order
|
|
515
|
+
diagrams, ``1 - |X| / X_max`` with
|
|
516
|
+
``X_max = C(|E|, 2) - X_deg - X_comp``:
|
|
517
|
+
|
|
518
|
+
- ``|X|`` is the number of pairs of edges that cross (also touching or
|
|
519
|
+
overlapping) without sharing an endpoint;
|
|
520
|
+
- ``X_deg`` is the number of pairs of edges that share an endpoint;
|
|
521
|
+
- ``X_comp`` is the number of the other pairs whose four endpoints are
|
|
522
|
+
pairwise comparable. For cover edges these are the pairs with one edge
|
|
523
|
+
entirely below the other, which cannot cross in an upward drawing.
|
|
524
|
+
|
|
525
|
+
Pairs of edges with only some endpoints comparable can cross and are
|
|
526
|
+
counted. An edge of (almost) zero length, between two nodes drawn at one
|
|
527
|
+
point, crosses nothing; ``node_node_conflict_score`` measures such
|
|
528
|
+
overlaps. 1.0 if no pair of edges could cross (a chain, for example). A
|
|
529
|
+
drawing that is not upward can also have crossings between pairs counted
|
|
530
|
+
in ``X_comp``; they count as crossings too, and the score is then clipped
|
|
531
|
+
at 0.
|
|
513
532
|
"""
|
|
514
533
|
drawing = _check_drawing(drawing)
|
|
515
534
|
edges = drawing.edges
|
|
@@ -526,28 +545,28 @@ def edge_crossing_score(drawing) -> float:
|
|
|
526
545
|
chunk = max(1, _CHUNK_CELLS // len(edges))
|
|
527
546
|
for first in range(0, len(edges), chunk):
|
|
528
547
|
block = slice(first, first + chunk)
|
|
529
|
-
|
|
530
|
-
|
|
548
|
+
shared = (
|
|
549
|
+
(lower[block, None] == lower[None, :])
|
|
550
|
+
| (lower[block, None] == upper[None, :])
|
|
551
|
+
| (upper[block, None] == lower[None, :])
|
|
552
|
+
| (upper[block, None] == upper[None, :])
|
|
553
|
+
)
|
|
554
|
+
# The endpoints of one edge are comparable (u < v), so all four are
|
|
555
|
+
# pairwise comparable iff every endpoint of one edge is comparable
|
|
556
|
+
# with every endpoint of the other.
|
|
557
|
+
all_comparable = (
|
|
531
558
|
comparable[np.ix_(lower[block], lower)]
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
559
|
+
& comparable[np.ix_(lower[block], upper)]
|
|
560
|
+
& comparable[np.ix_(upper[block], lower)]
|
|
561
|
+
& comparable[np.ix_(upper[block], upper)]
|
|
535
562
|
)
|
|
536
563
|
# Count each unordered pair once: row k of the block is edge first + k.
|
|
537
|
-
possible += int(np.triu(~
|
|
564
|
+
possible += int(np.triu(~(shared | all_comparable), k=first + 1).sum())
|
|
538
565
|
if possible == 0:
|
|
539
566
|
return 1.0
|
|
540
567
|
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
i, j, _ = drawing.crossings
|
|
544
|
-
free = ~(
|
|
545
|
-
comparable[lower[i], lower[j]]
|
|
546
|
-
| comparable[lower[i], upper[j]]
|
|
547
|
-
| comparable[upper[i], lower[j]]
|
|
548
|
-
| comparable[upper[i], upper[j]]
|
|
549
|
-
)
|
|
550
|
-
return float(1.0 - int(free.sum()) / possible)
|
|
568
|
+
crossings = len(drawing.crossings[0])
|
|
569
|
+
return float(max(0.0, 1.0 - crossings / possible))
|
|
551
570
|
|
|
552
571
|
|
|
553
572
|
def _crossing_angles(drawing: _Drawing) -> np.ndarray:
|
|
@@ -814,6 +833,14 @@ def _ratio_balance(left: float, right: float) -> float:
|
|
|
814
833
|
return float(1.0 - abs(left - right) / total)
|
|
815
834
|
|
|
816
835
|
|
|
836
|
+
def _maximal_and_minimal(drawing: _Drawing) -> tuple[list[int], list[int]]:
|
|
837
|
+
"""The nodes without upper covers, and those without lower covers."""
|
|
838
|
+
graph = drawing.graph
|
|
839
|
+
tops = [x for x in graph.nodes if graph.out_degree(x) == 0]
|
|
840
|
+
bottoms = [x for x in graph.nodes if graph.in_degree(x) == 0]
|
|
841
|
+
return tops, bottoms
|
|
842
|
+
|
|
843
|
+
|
|
817
844
|
def vertical_axis_balance_score(drawing) -> float:
|
|
818
845
|
"""
|
|
819
846
|
Left-right balance around the vertical line through the top element.
|
|
@@ -826,9 +853,7 @@ def vertical_axis_balance_score(drawing) -> float:
|
|
|
826
853
|
Needs a unique top and bottom element, so not iceberg lattices.
|
|
827
854
|
"""
|
|
828
855
|
drawing = _check_drawing(drawing)
|
|
829
|
-
|
|
830
|
-
tops = [x for x in graph.nodes if graph.out_degree(x) == 0]
|
|
831
|
-
bottoms = [x for x in graph.nodes if graph.in_degree(x) == 0]
|
|
856
|
+
tops, bottoms = _maximal_and_minimal(drawing)
|
|
832
857
|
if len(tops) != 1 or len(bottoms) != 1:
|
|
833
858
|
raise ValueError(
|
|
834
859
|
"vertical_axis_balance_score needs a unique top and bottom element, "
|
|
@@ -889,9 +914,17 @@ def drawing_quality_scores(drawing, *, worst_case: bool = False) -> dict[str, fl
|
|
|
889
914
|
metrics that average over nodes, vertices or crossings: the worst single
|
|
890
915
|
term, on the same scale. The structures the metrics share are computed
|
|
891
916
|
only once.
|
|
917
|
+
|
|
918
|
+
``"vertical_axis_balance"`` is NaN for a drawing without a unique top and
|
|
919
|
+
bottom element (an iceberg lattice), where it is not defined.
|
|
892
920
|
"""
|
|
893
921
|
drawing = _check_drawing(drawing)
|
|
894
|
-
|
|
922
|
+
tops, bottoms = _maximal_and_minimal(drawing)
|
|
923
|
+
has_axis = len(tops) == 1 and len(bottoms) == 1
|
|
924
|
+
scores = {
|
|
925
|
+
name: float("nan") if name == "vertical_axis_balance" and not has_axis else metric(drawing)
|
|
926
|
+
for name, metric in _SCORES.items()
|
|
927
|
+
}
|
|
895
928
|
if worst_case:
|
|
896
929
|
for name in _WORST_CASE_SCORES:
|
|
897
930
|
scores[f"{name}_min"] = _SCORES[name](drawing, aggregate="min")
|
|
@@ -18,6 +18,7 @@ from sklearn.utils.validation import check_is_fitted
|
|
|
18
18
|
from conceptflow.core import FormalContext, IncompleteContext, ManyValuedContext
|
|
19
19
|
from conceptflow.core.incomplete_context import is_missing
|
|
20
20
|
from conceptflow.preprocessing.scales import Scale, UnknownValueError
|
|
21
|
+
from conceptflow.validation.input import check_input_features, has_string_feature_names
|
|
21
22
|
|
|
22
23
|
|
|
23
24
|
class ConceptualScaler(TransformerMixin, BaseEstimator):
|
|
@@ -120,6 +121,13 @@ class ConceptualScaler(TransformerMixin, BaseEstimator):
|
|
|
120
121
|
|
|
121
122
|
self.input_context_ = mvc
|
|
122
123
|
self.scales_ = scales
|
|
124
|
+
# input_features is checked by name only after a fit on a
|
|
125
|
+
# ManyValuedContext or a DataFrame with string column names (as in
|
|
126
|
+
# scikit-learn).
|
|
127
|
+
self._fit_feature_names = mvc.attributes
|
|
128
|
+
self._input_features_by_name = isinstance(
|
|
129
|
+
X, ManyValuedContext
|
|
130
|
+
) or has_string_feature_names(X)
|
|
123
131
|
self.feature_names_in_ = mvc.attributes
|
|
124
132
|
self.n_features_in_ = mvc.n_attributes
|
|
125
133
|
self.object_names_in_ = mvc.objects
|
|
@@ -406,13 +414,5 @@ class ConceptualScaler(TransformerMixin, BaseEstimator):
|
|
|
406
414
|
Return output feature names for the scaled binary attributes.
|
|
407
415
|
"""
|
|
408
416
|
check_is_fitted(self, "scaled_attributes_")
|
|
409
|
-
|
|
410
|
-
if input_features is not None:
|
|
411
|
-
input_features = tuple(map(str, input_features))
|
|
412
|
-
|
|
413
|
-
if input_features != tuple(self.feature_names_in_):
|
|
414
|
-
raise ValueError(
|
|
415
|
-
"input_features does not match feature_names_in_."
|
|
416
|
-
)
|
|
417
|
-
|
|
417
|
+
check_input_features(self, input_features)
|
|
418
418
|
return pd.Index(self.scaled_attributes_, dtype="object").to_numpy()
|
|
@@ -119,9 +119,44 @@ def input_feature_names(X) -> tuple[str, ...] | None:
|
|
|
119
119
|
return None
|
|
120
120
|
|
|
121
121
|
|
|
122
|
+
def has_string_feature_names(X) -> bool:
|
|
123
|
+
"""
|
|
124
|
+
Whether scikit-learn would see feature names in ``X``: a DataFrame has
|
|
125
|
+
them only if all its column names are strings (integer column names are
|
|
126
|
+
taken as positions, e.g. by a ColumnTransformer). A FormalContext always
|
|
127
|
+
has them.
|
|
128
|
+
"""
|
|
129
|
+
if isinstance(X, pd.DataFrame):
|
|
130
|
+
return all(isinstance(column, str) for column in X.columns)
|
|
131
|
+
return isinstance(X, FormalContext)
|
|
132
|
+
|
|
133
|
+
|
|
122
134
|
def remember_feature_names(estimator, X) -> None:
|
|
123
135
|
"""At fit time: remember the column names of named input."""
|
|
124
136
|
estimator._fit_feature_names = input_feature_names(X)
|
|
137
|
+
estimator._input_features_by_name = has_string_feature_names(X)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def check_input_features(estimator, input_features) -> None:
|
|
141
|
+
"""
|
|
142
|
+
``get_feature_names_out(input_features)``, as in scikit-learn: after a fit
|
|
143
|
+
on input with string column names, ``input_features`` must be those
|
|
144
|
+
names; otherwise (an array, or integer column names) any names of the
|
|
145
|
+
right length are accepted, such as those a previous Pipeline step or a
|
|
146
|
+
ColumnTransformer passes on.
|
|
147
|
+
"""
|
|
148
|
+
if input_features is None:
|
|
149
|
+
return
|
|
150
|
+
input_features = tuple(map(str, input_features))
|
|
151
|
+
fitted = getattr(estimator, "_fit_feature_names", None)
|
|
152
|
+
if fitted is not None and getattr(estimator, "_input_features_by_name", True):
|
|
153
|
+
if input_features != tuple(fitted):
|
|
154
|
+
raise ValueError("input_features is not equal to feature_names_in_.")
|
|
155
|
+
elif len(input_features) != estimator.n_features_in_:
|
|
156
|
+
raise ValueError(
|
|
157
|
+
f"input_features should have length equal to number of features "
|
|
158
|
+
f"({estimator.n_features_in_}), got {len(input_features)}."
|
|
159
|
+
)
|
|
125
160
|
|
|
126
161
|
|
|
127
162
|
def check_feature_names(estimator, X) -> None:
|