当前位置: 首页>>代码示例>>Python>>正文


Python stats.gmean方法代码示例

本文整理汇总了Python中scipy.stats.gmean方法的典型用法代码示例。如果您正苦于以下问题:Python stats.gmean方法的具体用法?Python stats.gmean怎么用?Python stats.gmean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.stats的用法示例。


在下文中一共展示了stats.gmean方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: geometric_mean_var

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gmean [as 别名]
def geometric_mean_var(z):
    for row in np.eye(z.shape[1]):
        if not np.any(np.all(row == z, axis=1)):
            z = np.row_stack([z, row])
    n_points, n_dim = z.shape

    D = vectorized_cdist(z, z)
    np.fill_diagonal(D, np.inf)

    k = n_dim - 1
    I = D.argsort(axis=1)[:, :k]

    first = np.column_stack([np.arange(n_points) for _ in range(k)])

    val = gmean(D[first, I], axis=1)

    return val.var() 
开发者ID:msu-coinlab,项目名称:pymoo,代码行数:19,代码来源:performance.py

示例2: test_1D

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gmean [as 别名]
def test_1D(self):
        a = (1,2,3,4)
        actual = mstats.gmean(a)
        desired = np.power(1*2*3*4,1./4.)
        assert_almost_equal(actual, desired, decimal=14)

        desired1 = mstats.gmean(a,axis=-1)
        assert_almost_equal(actual, desired1, decimal=14)
        assert_(not isinstance(desired1, ma.MaskedArray))

        a = ma.array((1,2,3,4),mask=(0,0,0,1))
        actual = mstats.gmean(a)
        desired = np.power(1*2*3,1./3.)
        assert_almost_equal(actual, desired,decimal=14)

        desired1 = mstats.gmean(a,axis=-1)
        assert_almost_equal(actual, desired1, decimal=14) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:19,代码来源:test_mstats_basic.py

示例3: rl_reward

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gmean [as 别名]
def rl_reward(env):

    delay = np.asarray(env.env_D)
    mask = delay == np.inf
    delay[mask] = len(delay)*np.max(delay[~mask])

    if env.PRAEMIUM == 'AVG':
        reward = -np.mean(matrix_to_rl(delay))
    elif env.PRAEMIUM == 'MAX':
        reward = -np.max(matrix_to_rl(delay))
    elif env.PRAEMIUM == 'AXM':
        reward = -(np.mean(matrix_to_rl(delay)) + np.max(matrix_to_rl(delay)))/2
    elif env.PRAEMIUM == 'GEO':
        reward = -stats.gmean(matrix_to_rl(delay))
    elif env.PRAEMIUM == 'LOST':
        reward = -env.env_L
    return reward


# WRAPPER ITSELF 
开发者ID:knowledgedefinednetworking,项目名称:a-deep-rl-approach-for-sdn-routing-optimization,代码行数:22,代码来源:Environment.py

示例4: main

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gmean [as 别名]
def main() -> None:
    throughputs_hase = []
    throughputs_original = []
    for i in range(args.n):
        with open(f"{args.name}_{i}.out") as file:
            benchmarks, throughput = parse(file)
            throughputs_original.append(throughput)
        with open(f"{args.name}_hase_{i}.out") as file:
            benchmarks, throughput = parse(file)
            throughputs_hase.append(throughput)

    throughputs_hase = np.array(throughputs_hase)
    throughputs_original = np.array(throughputs_original)

    ratios = aggregate(throughputs_hase) / aggregate(throughputs_original)

    for i in range(len(benchmarks)):
        print(f"{benchmarks[i]}\t{ratios[i]:.4f}")

    print("GeoMean\t" + str(gmean(ratios))) 
开发者ID:hase-project,项目名称:hase,代码行数:22,代码来源:aggregate.py

示例5: main

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gmean [as 别名]
def main() -> None:
    throughputs_hase = []
    throughputs_original = []
    for i in range(args.n):
        with open(f"{args.outdir}/{args.name}_{i}.out") as file:
            benchmarks, throughput = parse(file)
            throughputs_original.append(throughput)
        with open(f"{args.outdir}/{args.name}_hase_{i}.out") as file:
            benchmarks, throughput = parse(file)
            throughputs_hase.append(throughput)

    throughputs_hase = np.array(throughputs_hase)
    throughputs_original = np.array(throughputs_original)

    ratios = aggregate(throughputs_hase) / aggregate(throughputs_original)

    for i in range(len(benchmarks)):
        print(f"{benchmarks[i]}\t{ratios[i]:.4f}")

    print("GeoMean\t" + str(gmean(ratios))) 
开发者ID:hase-project,项目名称:hase,代码行数:22,代码来源:aggregate.py

示例6: main

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gmean [as 别名]
def main() -> None:
    throughputs_hase = []
    throughputs_original = []
    for i in range(args.n):
        with open(f"{args.name}_{i}.out") as file:
            benchmarks, throughput = parse(file)
            throughputs_original.append(throughput)
        with open(f"{args.name}_hase_{i}.out") as file:
            benchmarks, throughput = parse(file)
            throughputs_hase.append(throughput)

    throughputs_hase = np.array(throughputs_hase)
    throughputs_original = np.array(throughputs_original)

    ratios = aggregate(throughputs_hase) / aggregate(throughputs_original)

    for i in range(len(benchmarks)):
        print(f"{benchmarks[i]}\t{ratios[i]:.4f}")

    # print("GeoMean\t" + str(gmean(ratios))) 
开发者ID:hase-project,项目名称:hase,代码行数:22,代码来源:aggregate.py

示例7: _aggregate_test_prediction

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gmean [as 别名]
def _aggregate_test_prediction(out_of_fold_test_predictions):
    agg_methods = {'mean': np.mean,
                   'gmean': gmean}
    prediction_column = [col for col in out_of_fold_test_predictions.columns if '_prediction' in col][0]
    if params.aggregation_method == 'rank_mean':
        rank_column = prediction_column.replace('_prediction', '_rank')
        test_predictions_with_ranks = []
        for fold_id, fold_df in out_of_fold_test_predictions.groupby('fold_id'):
            fold_df[rank_column] = calculate_rank(fold_df[prediction_column])
            test_predictions_with_ranks.append(fold_df)
        test_predictions_with_ranks = pd.concat(test_predictions_with_ranks, axis=0)

        test_prediction_aggregated = test_predictions_with_ranks.groupby(cfg.ID_COLUMNS)[rank_column].apply(
            np.mean).reset_index()
    else:
        test_prediction_aggregated = out_of_fold_test_predictions.groupby(cfg.ID_COLUMNS)[prediction_column].apply(
            agg_methods[params.aggregation_method]).reset_index()

    test_prediction_aggregated.columns = [cfg.ID_COLUMNS + cfg.TARGET_COLUMNS]
    return test_prediction_aggregated 
开发者ID:minerva-ml,项目名称:open-solution-home-credit,代码行数:22,代码来源:pipeline_manager.py

示例8: get_statistical_property_scores_per_input_per_impl

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gmean [as 别名]
def get_statistical_property_scores_per_input_per_impl(self, func: StatisticalPropertyFunc, input_num: int,
                                                           reduce: ReduceFunc = stats.gmean) -> t.Dict[str, t.List[float]]:
        """
        Assumptions:
            - Most programs have the same number of input (known as max input number)
            - The input number n takes roughly the same amount of time for every program category
        """
        cats = self._get_categories_for_number_of_inputs(self.get_max_input_num())
        scores_per_impl = InsertionTimeOrderedDict()
        for cat in cats:
            scores = cat.get_statistical_property_scores_per_input_per_impl(func, cat.get_input_strs()[input_num])
            for impl in scores:
                if impl not in scores_per_impl:
                    scores_per_impl[impl] = []
                scores_per_impl[impl].append(reduce(scores[impl]))
        return scores_per_impl 
开发者ID:parttimenerd,项目名称:temci,代码行数:18,代码来源:game.py

示例9: _compute_neighborhood_graph_weight

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gmean [as 别名]
def _compute_neighborhood_graph_weight(self, root, graph):
        # list all nodes at increasing distances
        # at each distance
        # compute the arithmetic mean weight on nodes
        # compute the geometric mean weight on edges
        # compute the product of the two
        # make a list of the neighborhood_graph_weight at every distance
        neighborhood_graph_weight_list = []
        w = graph.nodes[root][self.key_weight]
        node_weight_list = np.array([w], dtype=np.float64)
        node_average = node_weight_list[0]
        edge_weight_list = np.array([1], dtype=np.float64)
        edge_average = edge_weight_list[0]
        # for all distances
        root_dist_dict = graph.nodes[root]['remote_neighbours']
        for dist in root_dist_dict.keys():
            # extract array of weights at given dist
            weight_array_at_d = np.array([graph.nodes[v][self.key_weight]
                                          for v in root_dist_dict[dist]],
                                         dtype=np.float64)
            if dist % 2 == 0:  # nodes
                node_weight_list = np.concatenate(
                    (node_weight_list, weight_array_at_d))
                node_average = np.mean(node_weight_list)
            else:  # edges
                edge_weight_list = np.concatenate(
                    (edge_weight_list, weight_array_at_d))
                edge_average = stats.gmean(edge_weight_list)
            weight = node_average * edge_average
            neighborhood_graph_weight_list.append(weight)
        graph.nodes[root]['neigh_graph_weight'] = \
            neighborhood_graph_weight_list 
开发者ID:fabriziocosta,项目名称:EDeN,代码行数:34,代码来源:graph.py

示例10: agg_method

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gmean [as 别名]
def agg_method(self):
        methods = {'mean': np.mean,
                   'max': np.max,
                   'min': np.min,
                   'gmean': gmean
                   }
        return partial(methods[self.method], axis=-1) 
开发者ID:minerva-ml,项目名称:steppy-toolkit,代码行数:9,代码来源:segmentation.py

示例11: gmean

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gmean [as 别名]
def gmean(self):
        """Returns the gmean of the models predictions.

        Returns
        -------
        `PipeApply`
        """
        return self.apply(lambda x: gmean(x, axis=0)) 
开发者ID:rushter,项目名称:heamy,代码行数:10,代码来源:pipeline.py

示例12: test_1D_list

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gmean [as 别名]
def test_1D_list(self):
        a = (1,2,3,4)
        actual = stats.gmean(a)
        desired = power(1*2*3*4,1./4.)
        assert_almost_equal(actual, desired,decimal=14)

        desired1 = stats.gmean(a,axis=-1)
        assert_almost_equal(actual, desired1, decimal=14) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:test_stats.py

示例13: test_1D_array

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gmean [as 别名]
def test_1D_array(self):
        a = array((1,2,3,4), float32)
        actual = stats.gmean(a)
        desired = power(1*2*3*4,1./4.)
        assert_almost_equal(actual, desired, decimal=7)

        desired1 = stats.gmean(a,axis=-1)
        assert_almost_equal(actual, desired1, decimal=7) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:test_stats.py

示例14: test_2D_array_default

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gmean [as 别名]
def test_2D_array_default(self):
        a = array(((1,2,3,4),
                   (1,2,3,4),
                   (1,2,3,4)))
        actual = stats.gmean(a)
        desired = array((1,2,3,4))
        assert_array_almost_equal(actual, desired, decimal=14)

        desired1 = stats.gmean(a,axis=0)
        assert_array_almost_equal(actual, desired1, decimal=14) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:12,代码来源:test_stats.py

示例15: test_2D_array_dim1

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gmean [as 别名]
def test_2D_array_dim1(self):
        a = array(((1,2,3,4),
                   (1,2,3,4),
                   (1,2,3,4)))
        actual = stats.gmean(a, axis=1)
        v = power(1*2*3*4,1./4.)
        desired = array((v,v,v))
        assert_array_almost_equal(actual, desired, decimal=14) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:test_stats.py


注:本文中的scipy.stats.gmean方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。