Skip to content

Create HierarchicalStructure #1041

Closed
alex-hse-repository opened this issue Dec 12, 2022 · 0 comments
Closed

Create HierarchicalStructure #1041

alex-hse-repository opened this issue Dec 12, 2022 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@alex-hse-repository
Copy link
Collaborator

alex-hse-repository commented Dec 12, 2022

🚀 Feature Request

Create class to handle hierarchical structure

Proposal

  1. Create class
class HierarchicalStructure(BaseMixin):

    def __init__(self, level_structure: Dict[str, List[str]], level_names: Optional[List[str]]=None):
        """Init HierarchicalStructure.

         Parameters
         ----------
         level_structure:
             Adjacency list describing the structure of the hierarchy tree (i.e. {"total":["X", "Y"], "X":["a", "b"], "Y":["c", "d"]})
         level_names:
             Names of levels in the hierarchy in the order from top to bottom (i.e. ["total", "category", "product"]), if None is passed, generate level names 
         """
        pass
  • Check that structure defines a tree
  • Check that number of levels is the same as depth of the tree
  • Create attribute _level_series with mapping {"level": [list of segments]}
  • Create adjacency matrix out of adjacency list and store it in sparce format
  1. Create method to generate summing matrix between levels:
    def get_summing_matrix(target_level: str, source_level: str) -> scipy.sparse.base.spmatrix:
        pass
  • Check that target level is upper than source
  • Return summing matrix
  • S[i,j] = 1, if there is path from i to j, else 0
  1. Add some helper functions:
    @property
    def level_names(self) -> List[str]:
        pass
    def get_level_segments(self, level_name: str) -> List[str]
        pass

Test cases

  1. Test that constructor correctly handles different types of input paramters:
  • Not a tree
  • No level names
  • Number of levels != depth
  • Tree + level names
  1. Test that constructor generates correct adjacency matrixes
  2. Test that get_summing_matrix generates correct matrix
  3. Test level_names and get_level_segments

Additional context

No response

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
Status: Done
Development

No branches or pull requests

2 participants