docstr: ...Test Poisson random numbers simulation
          
docstr_tok: ["...","Test","Poisson","random","numbers","simulation"]
code: def test_poisson_random(self):
      """...Test Poisson random numbers simulation"""
      rate = 5
      seeded_sample = [3.0, 6.0, 2.0, 4.0, 3.0]
  
      self._test_dist_with_seed(
          seeded_sample, test_poisson, rate, discrete=True
      )
  
      # Statistical tests
      # We take a smaller sample as chi2 test is expensive
      sample_size = self.stat_size
      sample = test_poisson(rate, sample_size)
  
      # To test statistical consistency of poisson we do like if it was a
      # discrete law with a probability of sum_{k>K}(P(k)) for the last event
      K = 20  # Expected larger than `rate`
      probs_ = [stats.poisson.pmf(i, rate) for i in range(K)]
      obs_ = [sum(sample == i) for i in range(K)]
  
      # We add the last event
      obs_.append(sum(sample >= K))
      probs_.append(1 - sum(probs_))
  
      f_exp = sample_size * np.array(probs_, dtype=float)
      f_obs = np.array(obs_, dtype=float)
      self.assertEqual(
          f_exp.shape,
          f_obs.shape,
          "expected frequency vector and "
          "observed frequency vector "
          "do not have tha same shape! ",
      )
      self.assertTrue(
          np.allclose(
              np.sum(f_exp), np.sum(f_obs), rtol=1e-8, atol=1e-18
          ),
          "sum  of expected frequencies and "
          "sum of observed frequencies "
          "must agree with relative tolerance 1e-8."
          "This is required by scipy.stats.chisquare . "
          f"sample_size = {sample_size}; "
          f"np.sum(f_exp) = {np.sum(f_exp)}; "
          f"np.sum(f_obs) = {np.sum(f_obs)}. ",
      )
  
      # We test the null hypothesis that the sample is drawn
      # from a Poisson distribution.
      # We use a chi-square test.
      # The p-value should indicate that the null hypothesis cannot be rejected.
  
      p_threshold = 0.05
      chi_stat, p = stats.chisquare(f_exp=f_exp, f_obs=f_obs)
      self.assertGreater(
          p,
          p_threshold,
          "Poisson random number generation: "
          "p-value of Chi-square test is smaller than threshold. "
          f"p-value: {p}; "
          f"p_threshold: {p_threshold}; "
          f"Chi square test statistics: {chi_stat}.",
      )
  
imports: import unittest
  import multiprocessing
  from multiprocessing.pool import Pool
  import itertools
  import numpy
  import threading
  from scipy import stats
  from tick.random import test_uniform, test_gaussian, test_poisson, test_exponential, test_uniform_int, test_discrete, test_uniform_threaded
label_desc: Use image node_id 10 for calling the Test obj's underlying member method code with example usage: obj.test_poisson_random() without return types