Skip to content

Commit 72d5460

Browse files
utils/mol2concatinated_vector: changes for xai (#33)
* utils/mol2concatinated_vector: changes for xai - Add helper class SubpipelineExtractor to get certain parts of an existing Pipeline. - Add property to mol2concatinated_vector to extract total number of features. * utils: code review subpipeline
1 parent 5aea5f0 commit 72d5460

File tree

4 files changed

+780
-6
lines changed

4 files changed

+780
-6
lines changed

molpipeline/mol2any/mol2concatinated_vector.py

+15
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,21 @@ def element_list(self) -> list[tuple[str, MolToAnyPipelineElement]]:
7272
"""Get pipeline elements."""
7373
return self._element_list
7474

75+
@property
76+
def n_features(self) -> int:
77+
"""Calculates and returns the number of features."""
78+
feature_count = 0
79+
for _, element in self._element_list:
80+
if hasattr(element, "n_features"):
81+
feature_count += element.n_features
82+
elif hasattr(element, "n_bits"):
83+
feature_count += element.n_bits
84+
else:
85+
raise AssertionError(
86+
f"Element {element} does not have n_features or n_bits."
87+
)
88+
return feature_count
89+
7590
def get_params(self, deep: bool = True) -> dict[str, Any]:
7691
"""Return all parameters defining the object.
7792

0 commit comments

Comments
 (0)