1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
# SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: LicenseRef-NvidiaProprietary
#
# NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
# property and proprietary rights in and to this material, related
# documentation and any modifications thereto. Any use, reproduction,
# disclosure or distribution of this material and related documentation
# without an express license agreement from NVIDIA CORPORATION or
# its affiliates is strictly prohibited.
import numpy as np
from nsys_recipe.lib import exceptions
def filter_none(dfs):
"""Remove Nones from the dataframe list.
If the list only contains Nones or empty dataframes, raise an exception.
"""
dfs = [df for df in dfs if df is not None and len(df) != 0]
if not dfs:
raise exceptions.NoDataError
return dfs
def stddev(group_df, series_dict, n_col_name="Instances"):
"""Calculate the standard deviation out of aggregated values.
Parameters
----------
group_df : dataframe
Subset of data sharing a common grouping key. It contains values before
the overall aggregation.
series_dict : dict
Dictionary of series containing the overall aggregated values.
n_col_name : str
Name of the column representing population size.
"""
instance = series_dict[n_col_name].loc[group_df.name]
if instance <= 1:
return group_df["StdDev"].iloc[0]
var_sum = np.dot(group_df[n_col_name] - 1, group_df["StdDev"] ** 2)
deviation = group_df["Avg"] - series_dict["Avg"].loc[group_df.name]
dev_sum = np.dot(group_df[n_col_name], deviation**2)
variance = (var_sum + dev_sum) / (instance - 1)
return (variance**0.5).round(1)
|