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


Python numpy.quantile方法代码示例

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


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

示例1: pollution_confounded_propensity

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import quantile [as 别名]
def pollution_confounded_propensity(intervention, untreated_runs, treatment_bias):
    """Probability of treating each unit.

    To generate confounding, we are more likely to treat worlds with high pollution.
    """

    def persistent_pollution(run):
        return run[intervention.time].persistent_pollution

    pollution = [persistent_pollution(run) for run in untreated_runs]
    upper_quantile = np.quantile(pollution, 0.9)

    def treatment_prob(idx):
        if pollution[idx] > upper_quantile:
            return treatment_bias
        return 1.0 - treatment_bias

    return np.array([treatment_prob(idx) for idx in range(len(untreated_runs))])


# pylint: disable-msg=invalid-name
#: An observational experiment with confounding. Polluted states are more likely to be treated. 
开发者ID:zykls,项目名称:whynot,代码行数:24,代码来源:experiments.py

示例2: find_best_eps

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import quantile [as 别名]
def find_best_eps(data, q=0.05):
    """
    Find best maximal distance (eps) between dots for DBSCAN clustering.

    Parameters
    -------
    data: pd.DataFrame
        Dataframe with features for clustering indexed as in ``retention_config.index_col``
    q: float, optional
        Quantile of nearest neighbor positive distance between dots. The value of it will be an eps. Default: ``0.05``

    Returns
    -------
    Optimal eps

    Return type
    -------
    Float
    """
    nn = NearestNeighbors()
    nn.fit(data)
    dist = nn.kneighbors()[0]
    dist = dist.flatten()
    dist = dist[dist > 0]
    return np.quantile(dist, q) 
开发者ID:retentioneering,项目名称:retentioneering-tools,代码行数:27,代码来源:clustering.py

示例3: setSymColormap

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import quantile [as 别名]
def setSymColormap(self):
        cmap = {'ticks':
                [[0., (0, 0, 0, 255)],
                 [1e-3, (106, 0, 31, 255)],
                 [.5, (255, 255, 255, 255)],
                 [1., (8, 54, 104, 255)]],
                'mode': 'rgb'}
        cmap = {'ticks':
                [[0., (0, 0, 0)],
                 [1e-3, (172, 56, 56)],
                 [.5, (255, 255, 255)],
                 [1., (51, 53, 120)]],
                'mode': 'rgb'}

        relevant_data = num.abs(self._plot.data[num.isfinite(self._plot.data)])
        if num.any(relevant_data):
            lvl_max = num.quantile(relevant_data, .999)
        else:
            lvl_max = 1.

        self.gradient.restoreState(cmap)
        self.setLevels(-lvl_max, lvl_max) 
开发者ID:pyrocko,项目名称:kite,代码行数:24,代码来源:base.py

示例4: trimean

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import quantile [as 别名]
def trimean(self, data):
        """
        I'm exposing this as a public method because
        the trimean is not implemented in enough packages.
        
        Formula:
        (25th percentile + 2*50th percentile + 75th percentile)/4
        
        Parameters
        ----------
        data : array-like
          an iterable, either a list or a numpy array

        Returns
        -------
        the trimean: float
        """
        q1 = np.quantile(data, 0.25)
        q3 = np.quantile(data, 0.75)
        median = np.median(data)
        return (q1 + 2*median + q3)/4 
开发者ID:EricSchles,项目名称:drifter_ml,代码行数:23,代码来源:regression_tests.py

示例5: prepare_confusion_mat

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import quantile [as 别名]
def prepare_confusion_mat(self, labels, scores, add_to_end=True, ):
        sorted_labels, sorted_scores = sort_score_and_label(labels, scores)

        score_threshold, cuts = None, None

        if self.cut_method == 'step':
            score_threshold, cuts = ThresholdCutter.cut_by_step(sorted_scores, steps=0.01)
            if add_to_end:
                score_threshold.append(min(score_threshold) - 0.001)
                cuts.append(1)

        elif self.cut_method == 'quantile':
            score_threshold = ThresholdCutter.cut_by_quantile(sorted_scores, remove_duplicate=self.remove_duplicate)
            score_threshold = list(np.flip(score_threshold))

        confusion_mat = ConfusionMatrix.compute(sorted_labels, sorted_scores, score_threshold,
                                                ret=['tp', 'fp', 'fn', 'tn'])

        return confusion_mat, score_threshold, cuts 
开发者ID:FederatedAI,项目名称:FATE,代码行数:21,代码来源:classification_metric.py

示例6: __init__

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import quantile [as 别名]
def __init__(self, recording, scale=1.0, median=0.0, q1=0.01, q2=0.99, seed=0):
        if not isinstance(recording, RecordingExtractor):
            raise ValueError("'recording' must be a RecordingExtractor")
        self._recording = recording

        random_data = self._get_random_data_for_scaling(seed=seed).ravel()
        loc_q1, pre_median, loc_q2 = np.quantile(random_data, q=[q1, 0.5, q2])
        pre_scale = abs(loc_q2 - loc_q1)

        self._scalar = scale / pre_scale
        self._offset = median - pre_median * self._scalar
        RecordingExtractor.__init__(self)
        self.copy_channel_properties(recording=self._recording)
        self.is_filtered = self._recording.is_filtered

        self._kwargs = {'recording': recording.make_serialized_dict(), 'scale': scale, 'median': median,
                        'q1': q1, 'q2': q2, 'seed': seed} 
开发者ID:SpikeInterface,项目名称:spiketoolkit,代码行数:19,代码来源:normalize_by_quantile.py

示例7: quantile_sorted

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import quantile [as 别名]
def quantile_sorted(sorted_arr, quantile):
    # For small arrays (less than about 4000 items) np.quantile is significantly
    # slower than sorting the array and picking the quantile out by index. Computing
    # quantiles this way significantly improves performance for computing
    # trip time stats across all stops.

    max_index = len(sorted_arr) - 1
    quantile_index = max_index * quantile
    quantile_index_int = int(quantile_index)
    quantile_index_fractional = quantile_index - quantile_index_int

    quantile_lower = sorted_arr[quantile_index_int]
    if quantile_index_fractional > 0:
        quantile_upper = sorted_arr[quantile_index_int + 1]
        return quantile_lower + (quantile_upper - quantile_lower) * quantile_index_fractional
    else:
        return quantile_lower 
开发者ID:trynmaps,项目名称:metrics-mvp,代码行数:19,代码来源:util.py

示例8: get_tolerance

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import quantile [as 别名]
def get_tolerance(self,g):
        """
        Parameters
        ----------
        g: integer
           generation number of the ABC-SMC/MNN algorithm
        """
        # choose the tolerance given the generation number and how q and tol are defined
        if g == 0:
            if not hasattr(self.tol, "__len__"):
                return self.tol
            else:
                return self.tol[0]
        else:
            if self.q is not None:
                return np.quantile(self.dist,self.q)
            else:
                return self.tol[g] 
开发者ID:publichealthengland,项目名称:pygom,代码行数:20,代码来源:approximate_bayesian_computation.py

示例9: test_wrap_ufunc_output

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import quantile [as 别名]
def test_wrap_ufunc_output(quantile, arg):
    ary = np.random.randn(4, 100)
    n_output = len(quantile)
    if arg:
        res = wrap_xarray_ufunc(
            np.quantile, ary, ufunc_kwargs={"n_output": n_output}, func_args=(quantile,)
        )
    else:
        if n_output == 1:
            res = wrap_xarray_ufunc(np.quantile, ary, func_kwargs={"q": quantile})
        else:
            res = wrap_xarray_ufunc(
                np.quantile, ary, ufunc_kwargs={"n_output": n_output}, func_kwargs={"q": quantile}
            )
    if n_output == 1:
        assert not isinstance(res, tuple)
    else:
        assert isinstance(res, tuple)
        assert len(res) == n_output 
开发者ID:arviz-devs,项目名称:arviz,代码行数:21,代码来源:test_stats_utils.py

示例10: visit_quantile

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import quantile [as 别名]
def visit_quantile(transform: alt.QuantileTransform, df: pd.DataFrame) -> pd.DataFrame:
    transform = transform.to_dict()
    quantile = transform["quantile"]
    groupby = transform.get("groupby")
    pname, vname = transform.get("as", ["prob", "value"])
    probs = transform.get("probs")
    if probs is None:
        step = transform.get("step", 0.01)
        probs = np.arange(0.5 * step, 1.0, step)

    def qq(s: pd.Series) -> pd.DataFrame:
        return pd.DataFrame({pname: probs, vname: np.quantile(s, probs)})

    if groupby:
        return (
            df.groupby(groupby)[quantile]
            .apply(qq)
            .reset_index(groupby)
            .reset_index(drop=True)
        )

    else:
        return qq(df[quantile]).reset_index(drop=True) 
开发者ID:altair-viz,项目名称:altair-transform,代码行数:25,代码来源:quantile.py

示例11: report

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import quantile [as 别名]
def report(self):
        est = self
        print(est.name, "max", np.max(est.errs), "99th",
              np.quantile(est.errs, 0.99), "95th", np.quantile(est.errs, 0.95),
              "median", np.quantile(est.errs, 0.5), "time_ms",
              np.mean(est.query_dur_ms)) 
开发者ID:naru-project,项目名称:naru,代码行数:8,代码来源:estimators.py

示例12: ReportEsts

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import quantile [as 别名]
def ReportEsts(estimators):
    v = -1
    for est in estimators:
        print(est.name, 'max', np.max(est.errs), '99th',
              np.quantile(est.errs, 0.99), '95th', np.quantile(est.errs, 0.95),
              'median', np.quantile(est.errs, 0.5))
        v = max(v, np.max(est.errs))
    return v 
开发者ID:naru-project,项目名称:naru,代码行数:10,代码来源:eval_model.py

示例13: mediation_propensity_scores

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import quantile [as 别名]
def mediation_propensity_scores(intervention, untreated_runs):
    """Probability of treating each unit.

    Units with the largest populations are more likely to be treated.
    """
    populations = [run[intervention.time].population for run in untreated_runs]
    upper_quantile = np.quantile(populations, 0.9)
    propensities = 0.05 * np.ones(len(untreated_runs))
    propensities[populations > upper_quantile] = 0.9
    return propensities 
开发者ID:zykls,项目名称:whynot,代码行数:12,代码来源:experiments.py

示例14: bootstrap_sample_ate_ci

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import quantile [as 别名]
def bootstrap_sample_ate_ci(self, num_bootstrap_samples=2000, alpha=0.05):
        """Bootstrap a (1-alpha)% confidence interval for the sample ate."""
        means = []
        for _ in range(num_bootstrap_samples):
            sample = np.random.choice(
                self.true_effects, size=len(self.true_effects), replace=True
            )
            means.append(np.mean(sample))
        lower_tail, upper_tail = alpha / 2.0, 1.0 - alpha / 2.0
        return (np.quantile(means, lower_tail), np.quantile(means, upper_tail)) 
开发者ID:zykls,项目名称:whynot,代码行数:12,代码来源:framework.py

示例15: _nanquantile_1d

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import quantile [as 别名]
def _nanquantile_1d(arr1d, q, overwrite_input=False, interpolation='linear'):
    """
    Private function for rank 1 arrays. Compute quantile ignoring NaNs.
    See nanpercentile for parameter usage
    """
    arr1d, overwrite_input = _remove_nan_1d(arr1d,
        overwrite_input=overwrite_input)
    if arr1d.size == 0:
        return np.full(q.shape, np.nan)[()]  # convert to scalar

    return function_base._quantile_unchecked(
        arr1d, q, overwrite_input=overwrite_input, interpolation=interpolation) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:14,代码来源:nanfunctions.py


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