code: def test_kde_1d_weighted():
      # some basic tests comparing to normal distribution
      np.random.seed(8765678)
      n_basesample = 500
      xn = np.random.randn(n_basesample)
      wn = np.random.rand(n_basesample)
      xnmean = np.average(xn, weights=wn)
      xnstd = np.sqrt(np.average((xn - xnmean) ** 2, weights=wn))
  
      # get kde for original sample
      gkde = stats.gaussian_kde(xn, weights=wn)
  
      # evaluate the density function for the kde for some points
      xs = np.linspace(-7, 7, 501)
      kdepdf = gkde.evaluate(xs)
      normpdf = stats.norm.pdf(xs, loc=xnmean, scale=xnstd)
      intervall = xs[1] - xs[0]
  
      assert_(np.sum((kdepdf - normpdf) ** 2) * intervall < 0.01)
      prob1 = gkde.integrate_box_1d(xnmean, np.inf)
      prob2 = gkde.integrate_box_1d(-np.inf, xnmean)
      assert_almost_equal(prob1, 0.5, decimal=1)
      assert_almost_equal(prob2, 0.5, decimal=1)
      assert_almost_equal(
          gkde.integrate_box(xnmean, np.inf), prob1, decimal=13
      )
      assert_almost_equal(
          gkde.integrate_box(-np.inf, xnmean), prob2, decimal=13
      )
  
      assert_almost_equal(
          gkde.integrate_kde(gkde),
          (kdepdf**2).sum() * intervall,
          decimal=2,
      )
      assert_almost_equal(
          gkde.integrate_gaussian(xnmean, xnstd**2),
          (kdepdf * normpdf).sum() * intervall,
          decimal=2,
      )
  
imports: from scipy import stats
  import numpy
  from numpy.testing import assert_almost_equal, assert_, assert_array_almost_equal, assert_array_almost_equal_nulp, assert_allclose
  import pytest
  from pytest import raises
label_desc: Use image node_id 2 for calling a global function with example usage: test_kde_1d_weighted() without return types