class_docstr: Approximate number of unique values counter.
  
  This is basically an implementation of the HyperLogLog algorithm. Adapted from
  [`hypy`](https://github.com/clarkduvall/hypy). The code is a bit too terse but it will do for
  now.
  
  Parameters
  ----------
  error_rate
      Desired error rate. Memory usage is inversely proportional to this value.
  seed
      Set the seed to produce identical results.
  
  Attributes
  ----------
  n_bits : int
  n_buckets : int
  buckets : list
  
  Examples
  --------
  
  >>> import string
  >>> from river import stats
  
  >>> alphabet = string.ascii_lowercase
  >>> n_unique = stats.NUnique(error_rate=0.2, seed=42)
  
  >>> n_unique.update('a')
  >>> n_unique.get()
  1
  
  >>> n_unique.update('b')
  >>> n_unique.get()
  2
  
  >>> for letter in alphabet:
  ...     n_unique.update(letter)
  >>> n_unique.get()
  31
  
  Lowering the `error_rate` parameter will increase the precision.
  
  >>> n_unique = stats.NUnique(error_rate=0.01, seed=42)
  >>> for letter in alphabet:
  ...     n_unique.update(letter)
  >>> n_unique.get()
  26
  
  References
  ----------
  [^1]: [My favorite algorithm (and data structure): HyperLogLog](https://odino.org/my-favorite-data-structure-hyperloglog/)
  [^2]: [Flajolet, P., Fusy, É., Gandouet, O. and Meunier, F., 2007, June. Hyperloglog: the analysis of a near-optimal cardinality estimation algorithm.](http://algo.inria.fr/flajolet/Publications/FlFuGaMe07.pdf)
class_docstr_tok: ["Approximate","number","of","unique","values","counter",".","This","is","basically","an","implementation","of","the","HyperLogLog","algorithm",".","Adapted","from","[","`","hypy","`","]","(","https",":","\/\/github.com\/clarkduvall\/hypy",")",".","The","code","is","a","bit","too","terse","but","it","will","do","for","now",".","Parameters","--","--","--","--","--","error_rate","Desired","error","rate",".","Memory","usage","is","inversely","proportional","to","this","value",".","seed","Set","the","seed","to","produce","identical","results",".","Attributes","--","--","--","--","--","n_bits",":","int","n_buckets",":","int","buckets",":","list","Examples","--","--","--","--",">",">",">","import","string",">",">",">","from","river","import","stats",">",">",">","alphabet","=","string.ascii_lowercase",">",">",">","n_unique","=","stats.NUnique","(","error_rate=0.2",",","seed=42",")",">",">",">","n_unique.update","(","'","a","'",")",">",">",">","n_unique.get","(",")","1",">",">",">","n_unique.update","(","'","b","'",")",">",">",">","n_unique.get","(",")","2",">",">",">","for","letter","in","alphabet",":","...","n_unique.update","(","letter",")",">",">",">","n_unique.get","(",")","31","Lowering","the","`","error_rate","`","parameter","will","increase","the","precision",".",">",">",">","n_unique","=","stats.NUnique","(","error_rate=0.01",",","seed=42",")",">",">",">","for","letter","in","alphabet",":","...","n_unique.update","(","letter",")",">",">",">","n_unique.get","(",")","26","References","--","--","--","--","--","[","^1","]",":","[","My","favorite","algorithm","(","and","data","structure",")",":","HyperLogLog","]","(","https",":","\/\/odino.org\/my-favorite-data-structure-hyperloglog\/",")","[","^2","]",":","[","Flajolet",",","P.",",","Fusy",",","\u00c9.",",","Gandouet",",","O.","and","Meunier",",","F.",",","2007",",","June",".","Hyperloglog",":","the","analysis","of","a","near-optimal","cardinality","estimation","algorithm",".","]","(","http",":","\/\/algo.inria.fr\/flajolet\/Publications\/FlFuGaMe07.pdf",")"]
code: def __init__(self, error_rate=0.01, seed: int | None = None):
      self.error_rate = error_rate
      self.seed = seed
  
      self.n_bits = int(
          math.ceil(math.log((1.04 / error_rate) ** 2, 2))
      )
      self.n_buckets = 1 << self.n_bits
      self.buckets = [0] * self.n_buckets
      self._salt = np.random.RandomState(seed).bytes(
          hashlib.blake2s.SALT_SIZE
      )
  
file_path: river/river/stats/n_unique.py
imports: from __future__ import annotations
  import hashlib
  import math
  import numpy
  from river import stats
label_desc: Use image node_id 1 to create a new NUnique object from inherited base classes: stats.base with example: obj = NUnique(error_rate, seed)