Skip to content

Commit

Permalink
utils/mol2concatinated_vector: changes for xai (#33)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
JochenSiegWork authored Jul 5, 2024
1 parent 5aea5f0 commit 72d5460
Show file tree
Hide file tree
Showing 4 changed files with 780 additions and 6 deletions.
15 changes: 15 additions & 0 deletions molpipeline/mol2any/mol2concatinated_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ def element_list(self) -> list[tuple[str, MolToAnyPipelineElement]]:
"""Get pipeline elements."""
return self._element_list

@property
def n_features(self) -> int:
"""Calculates and returns the number of features."""
feature_count = 0
for _, element in self._element_list:
if hasattr(element, "n_features"):
feature_count += element.n_features
elif hasattr(element, "n_bits"):
feature_count += element.n_bits
else:
raise AssertionError(
f"Element {element} does not have n_features or n_bits."
)
return feature_count

def get_params(self, deep: bool = True) -> dict[str, Any]:
"""Return all parameters defining the object.
Expand Down
Loading

0 comments on commit 72d5460

Please sign in to comment.