class_docstr: Streaming histogram.
  
  Parameters
  ----------
  max_bins
      Maximal number of bins.
  
  Attributes
  ----------
  n
      Total number of seen values.
  
  Examples
  --------
  
  >>> from river import sketch
  >>> import numpy as np
  
  >>> np.random.seed(42)
  
  >>> values = np.hstack((
  ...     np.random.normal(-3, 1, 1000),
  ...     np.random.normal(3, 1, 1000),
  ... ))
  
  >>> hist = sketch.Histogram(max_bins=15)
  
  >>> for x in values:
  ...     hist.update(x)
  
  >>> for bin in hist:
  ...     print(bin)
  [-6.24127, -6.24127]: 1
  [-5.69689, -5.19881]: 8
  [-5.12390, -4.43014]: 57
  [-4.42475, -3.72574]: 158
  [-3.71984, -3.01642]: 262
  [-3.01350, -2.50668]: 206
  [-2.50329, -0.81020]: 294
  [-0.80954, 0.29677]: 19
  [0.40896, 0.82733]: 7
  [0.84661, 1.25147]: 24
  [1.26029, 2.30758]: 178
  [2.31081, 3.05701]: 284
  [3.05963, 3.69695]: 242
  [3.69822, 5.64434]: 258
  [6.13775, 6.19311]: 2
  
  References
  ----------
  [^1]: [Ben-Haim, Y. and Tom-Tov, E., 2010. A streaming parallel decision tree algorithm. Journal of Machine Learning Research, 11(Feb), pp.849-872.](http://jmlr.org/papers/volume11/ben-haim10a/ben-haim10a.pdf)
  [^2]: [Go implementation](https://github.com/VividCortex/gohistogram)
docstr: Example:
  
      >>> h1 = Histogram()
      >>> for b in [Bin(0, 2, 4), Bin(4, 5, 9)]:
      ...     h1.append(b)
  
      >>> h2 = Histogram()
      >>> for b in [Bin(1, 3, 8), Bin(3, 4, 5)]:
      ...     h2.append(b)
  
      >>> h1 + h2
      [0.00000, 1.00000]: 2.0
      [1.00000, 2.00000]: 6.0
      [2.00000, 3.00000]: 4.0
      [3.00000, 4.00000]: 5.0
      [4.00000, 5.00000]: 9.0
docstr_tok: ["Example",":",">",">",">","h1","=","Histogram","(",")",">",">",">","for","b","in","[","Bin","(","0",",","2",",","4",")",",","Bin","(","4",",","5",",","9",")","]",":","...","h1.append","(","b",")",">",">",">","h2","=","Histogram","(",")",">",">",">","for","b","in","[","Bin","(","1",",","3",",","8",")",",","Bin","(","3",",","4",",","5",")","]",":","...","h2.append","(","b",")",">",">",">","h1","+","h2","[","0.00000",",","1.00000","]",":","2.0","[","1.00000",",","2.00000","]",":","6.0","[","2.00000",",","3.00000","]",":","4.0","[","3.00000",",","4.00000","]",":","5.0","[","4.00000",",","5.00000","]",":","9.0"]
code: def __add__(self, other):
      """
  
      Example:
  
          >>> h1 = Histogram()
          >>> for b in [Bin(0, 2, 4), Bin(4, 5, 9)]:
          ...     h1.append(b)
  
          >>> h2 = Histogram()
          >>> for b in [Bin(1, 3, 8), Bin(3, 4, 5)]:
          ...     h2.append(b)
  
          >>> h1 + h2
          [0.00000, 1.00000]: 2.0
          [1.00000, 2.00000]: 6.0
          [2.00000, 3.00000]: 4.0
          [3.00000, 4.00000]: 5.0
          [4.00000, 5.00000]: 9.0
  
      """
  
      xs = iter(self)
      ys = iter(other)
      rights = heapq.merge(
          itertools.chain.from_iterable(
              (b.left, b.right) for b in self
          ),
          itertools.chain.from_iterable(
              (b.left, b.right) for b in other
          ),
      )
  
      b = Bin(next(rights), next(rights), 0)
  
      x = next(xs)
      y = next(ys)
  
      hist = Histogram(max_bins=max(self.max_bins, other.max_bins))
  
      while True:
          b.count += coverage_ratio(b, x) * x.count
          b.count += coverage_ratio(b, y) * y.count
  
          if b.count:
              hist.append(b)
  
          try:
              b = Bin(b.right, next(rights), 0)
          except StopIteration:
              break
  
          if b.left >= x.right:
              x = next(xs, x)
          if b.left >= y.right:
              y = next(ys, y)
  
      hist._shrink(k=len(hist) - hist.max_bins)
  
      return hist
  
imports: from __future__ import annotations
  import collections
  import heapq
  import itertools
  import math
  from river import base
label_desc: Use image node_id 6 for calling the Histogram obj's underlying member method code with example usage: obj.__add__(other) and returns: hist