Returns a sequence of histogram density values that sum to 1.0
964338
def make_random_histogram(center=0.0, stdev=default_stdev, length=default_feature_dim, num_bins=default_num_bins):
    ""

    hist, bin_edges = np.histogram(get_distr(center, stdev, length),
                                   range=edge_range, bins=num_bins, density=True)
    # to ensure they sum to 1.0
    hist = hist / sum(hist)

    if len(hist) < 2:
        raise ValueError('Invalid histogram')

    return hist, bin_edges
1254696
def _histplot_bins(column, bins=100):
    """"""
    col_min = np.min(column)
    col_max = np.max(column)
    return range(col_min, col_max + 2, max((col_max - col_min) // bins, 1))
378926
def WorkersDensity(dataTasks):
    """"""

    start_time, end_time = getTimes(dataTasks)
    graphdata = []

    for name in getWorkersName(dataTasks):
        vals = dataTasks[name]
        if hasattr(vals, 'values'):
            # Data from worker
            workerdata = []
            print("Plotting density map for {}".format(name))
            # We only have 800 pixels
            try:
                for graphtime in timeRange(start_time, end_time, DENSITY_MAP_TIME_AXIS_LENGTH):
                    for a in vals.values():
                        if not all((a['start_time'], a['end_time'])):
                            print("Invalid data:", a['start_time'], a['end_time'])
                        #print(a['start_time'], a['end_time'])
                    workerdata.append(sum([a['start_time'][0] <= float(graphtime) /
                        1000. <= a['end_time'][0] for a in vals.values()
                            if a['start_time'] and a['end_time']])
                    )
            except OverflowError:
                print("Error processing {0} or {1}".format(start_time, end_time))
            graphdata.append(workerdata)

            if args.binarydensity:
                # Normalize [...]
                maxval = max(graphdata[-1])
                if maxval > 1:
                    maxval = maxval - 1
                    graphdata[-1] = [x - maxval for x in graphdata[-1]]
    return graphdata
1227436
def step(h1: Histogram1D, ax: Axes, **kwargs):
    """"""
    show_stats = kwargs.pop("show_stats", False)
    show_values = kwargs.pop("show_values", False)
    density = kwargs.pop("density", False)
    cumulative = kwargs.pop("cumulative", False)
    value_format = kwargs.pop("value_format", None)
    text_kwargs = pop_kwargs_with_prefix("text_", kwargs)
    kwargs["label"] = kwargs.get("label", h1.name)

    data = get_data(h1, cumulative=cumulative, density=density)
    _apply_xy_lims(ax, h1, data, kwargs)
    _add_ticks(ax, h1, kwargs)
    _add_labels(ax, h1, kwargs)

    ax.step(h1.numpy_bins, np.concatenate([data[:1], data]), **kwargs)

    if show_stats:
        _add_stats_box(h1, ax, stats=show_stats)
    if show_values:
        _add_values(ax, h1, data, value_format=value_format, **text_kwargs)
900824
def getCenters(self):
        
        return np.arange(self.histogram.size) * self.binWidth + self.minValue
1192375
def _PopulateQuantilesHistogram(self, hist, nums):
    
    if not nums:
      return
    num_quantile_buckets = 10
    quantiles_to_get = [
        x * 100 / num_quantile_buckets for x in range(num_quantile_buckets + 1)
    ]
    quantiles = np.percentile(nums, quantiles_to_get)
    hist.type = self.histogram_proto.QUANTILES
    quantiles_sample_count = float(len(nums)) / num_quantile_buckets
    for low, high in zip(quantiles, quantiles[1:]):
      hist.buckets.add(
          low_value=low, high_value=high, sample_count=quantiles_sample_count)
565077
def _histplot_op(ax, data, **kwargs):
    """"""
    bins = get_bins(data)
    ax.hist(data, bins=bins, align="left", density=True, **kwargs)
    return ax
681936
def cdf(arr, pos=None):
    '''
    
    '''

    r = (arr.min(), arr.max())
    hist, bin_edges = np.histogram(arr, bins=2 * int(r[1] - r[0]), range=r)
    hist = np.asfarray(hist) / hist.sum()
    cdf = np.cumsum(hist)
    if pos is None:
        return cdf
    i = np.argmax(cdf > pos)
    return bin_edges[i]
527879
def histogram(a, bins):
    
    if any(map(lambda x: x < 0, diff(bins))):
        raise ValueError(
            'bins must increase monotonically.')

    try:
        sa = sorted(a)
    except TypeError:
        # Perhaps just a single value? Treat as a list and carry on
        sa = sorted([a])

    # import numpy as np
    # nl = np.searchsorted(sa, bins[:-1], 'left')
    # nr = np.searchsorted(sa, bins[-1], 'right')
    # nn = np.r_[nl, nr]
    #
    # # cl = list(accumulate(Counter(map(lambda x: bisect_left(bins[:-1], x), sa)))
    # # print("cl")
    # # print([cl[i] for i in range(len(bins))])
    # print("nl")
    # print(list(nl))
    # # print(Counter(map(lambda x: bisect_right([bins[-1]], x), sa)))
    # print("nr")
    # print([nr])
    # print("nn")
    # print(list(nn))
    # print("hist")
    # print(list(np.diff(nn)))
    # print(list(np.histogram(a, bins)[0]))

    nl = list(accumulate([Counter(map(lambda x: bisect_left(bins[:-1], x), sa))[i] for i in range(len(bins) - 1)]))
    # print("nl")
    # print(nl)
    nr = Counter(map(lambda x: bisect_right([bins[1]], x), sa))[1]
    # print(nl)
    # print(nr)
    n = list(nl) + [nr]

    return diff(n), bins
703224
def _sumSeries(a: float, b: float, steps: int) -> float:
        
        return a * (exp(b * steps) - 1) / (exp(b) - 1)
222671
def cumulate(self, axis):
        """"""
        axis = self.get_axis_number(axis)
        return Histdd.from_histogram(np.cumsum(self.histogram, axis=axis),
                                     bin_edges=self.bin_edges,
                                     axis_names=self.axis_names)
874540
def with_histogram(name, reservoir_type="uniform", *reservoir_args, **reservoir_kwargs):
    

    hmetric = get_or_create_histogram(name, reservoir_type, *reservoir_args, **reservoir_kwargs)

    def wrapper(f):

        @functools.wraps(f)
        def fun(*args, **kwargs):
            t1 = time.time()
            res = f(*args, **kwargs)
            t2 = time.time()

            hmetric.notify(t2-t1)
            return res

        return fun

    return wrapper
574529
def hist_from_counts(counts, normalize=False, cumulative=False, to_str=False, sep=',', min_bin=None, max_bin=None):
    
    counters = [dict((i, c)for i, c in enumerate(counts))]

    intkeys_list = [[c for c in counts_dict if (isinstance(c, int) or (isinstance(c, float) and int(c) == c))]
                    for counts_dict in counters]
    min_bin, max_bin = min_bin or 0, max_bin or len(counts) - 1

    histograms = []
    for intkeys, counts in zip(intkeys_list, counters):
        histograms += [OrderedDict()]
        if not intkeys:
            continue
        if normalize:
            N = sum(counts[c] for c in intkeys)
            for c in intkeys:
                counts[c] = float(counts[c]) / N
        if cumulative:
            for i in range(min_bin, max_bin + 1):
                histograms[-1][i] = counts.get(i, 0) + histograms[-1].get(i - 1, 0)
        else:
            for i in range(min_bin, max_bin + 1):
                histograms[-1][i] = counts.get(i, 0)
    if not histograms:
        histograms = [OrderedDict()]

    # fill in the zero counts between the integer bins of the histogram
    aligned_histograms = []

    for i in range(min_bin, max_bin + 1):
        aligned_histograms += [tuple([i] + [hist.get(i, 0) for hist in histograms])]

    if to_str:
        # FIXME: add header row
        return str_from_table(aligned_histograms, sep=sep, max_rows=365 * 2 + 1)

    return aligned_histograms
476374
def zcr(data):
    """"""
    data = np.mean(data, axis=1)

    count = len(data)
    countZ = np.sum(np.abs(np.diff(np.sign(data)))) / 2
    return (np.float64(countZ) / np.float64(count - 1.0))
596283
public static void histogram( GrayS8 input , int minValue , int histogram[] ) {
		if( BoofConcurrency.USE_CONCURRENT ) {
			ImplImageStatistics_MT.histogram(input,minValue,histogram);
		} else {
			ImplImageStatistics.histogram(input,minValue,histogram);
		}
	}
642121
def _histogram_digitize(a, w, edges, normed):
    
    weighted = w is not None
    nbin = edges.shape[0] + 1
    if weighted:
        count = zeros(nbin, dtype=w.dtype)
        if normed:
            count = zeros(nbin, dtype=float)
            w = w / w.mean()
    else:
        count = zeros(nbin, int)

    binindex = digitize(a, edges)

    # Count the number of identical indices.
    flatcount = bincount(binindex, w)

    # Place the count in the histogram array.
    count[:len(flatcount)] = flatcount

    return count
860024
def normalized(self):
        
        total = self.total()
        result = Histogram()
        for value, count in iteritems(self):
            try:
                result[value] = count / float(total)
            except UnorderableElements as e:
                result = Histogram.from_dict(dict(result), key=hash)
                result[value] = count / float(total)
        return result