Skip to content

Commit

Permalink
Add hierarchical statistics support
Browse files Browse the repository at this point in the history
This change adds hierarchical federated statistics support.

The existing `StatisticsController` outputs global statistics in a flat
hierarchy. There are usecases where global statistics are required to be
generated as per the given hierarchy configuration where NVFlare clients
can be specified to belong to a particular hierarchy.

The new class `HierarchicalStatisticsController` is added to support
hierarchical statistics. It is derived from `StatisticsController` and
takes additional argument `hierarchy_config` for hierarchy specification
file providing details about all the clients and their hierarchy.

Example hierarchy config file contents:

    {
        "Manufacturers": [
            {
                "Name": "Manufacturer-1",
                "Orgs": [
                     {
                         "Name": "Org-1",
                         "Sites": ["Site-1"]
                     },
                     {
                         "Name": "Org-2",
                         "Sites": ["Site-2"]
                     }
                ],
            },
            {
                "Name": "Manufacturer-2",
                "Orgs": [
                    {
                        "Name": "Org-3",
                        "Sites": ["Site-3", "Site-4"]
                    }
                ]
            },
        ]
    }

The above hierarchy config specifies three level hierarchy for four NVFlare
clients named 'Site-1', 'Site-2', 'Site-3' and 'Site-4'. And the
generate global statistics output will in hierarchical format like below. At
each hierarchical level, global statistics are caulculated whereas local
statistics are reported at the last hierarchical level.

{
    "Global": {
        <Global stats>
    },
    "Manufacturers": [
        {
            "Name": "Manufacturer-1",
            "Global": {
                <Manufacturer level stats>
            },
            "Orgs": [
                {
                    "Name": "Org-1",
                    "Global": {
                        <Org level stats>
                    },
                    "Sites": [
                        {
                            "Name": "Site-1",
                            "Local": {
                                <Local stats>
                            },
                        },
                        {
                            "Name": "Site-2",
                            "Local": {
                                <Local stats>
                            },
                        }
                    ],
                },
            ]
        },
    ],
}

The number of hierarchical levels and the hierarchical level names are
automatically calculated from the given hierarchy config. Any number of
hierarchical levels are supported.

This change also adds unit test to test hierarchical global statistics
upto four hierarchical levels.
  • Loading branch information
apatole committed Jun 6, 2024
1 parent 35972e9 commit c022a6b
Show file tree
Hide file tree
Showing 4 changed files with 1,868 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nvflare/app_common/app_constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ class StatisticsConstants(AppConstants):
STATS_2nd_STATISTICS = "fed_stats_2nd_statistics"

GLOBAL = "Global"
LOCAL = "Local"
NAME = "Name"

ordered_statistics = {
STATS_1st_STATISTICS: [STATS_COUNT, STATS_FAILURE_COUNT, STATS_SUM, STATS_MEAN, STATS_MIN, STATS_MAX],
Expand Down
Loading

0 comments on commit c022a6b

Please sign in to comment.