def test_sampling_bias2(self):
    from spikecount.shannon import entropy2, bootstrap
    from numpy import pi, e, log2
    from numpy import array, polyfit

    print 
    print "Sampling bias 2d"
    x = generate_gaussian(sigma = 5, N=100000)
    y = generate_gaussian(sigma = 5, N=100000)
    
    print entropy2(x,y), entropy2(x,y)-log2(x.std())-log2(y.std()), log2(2*pi*e)
    
    scompare = bootstrap(entropy2, x, y, debug=False)['predict']
    print scompare, scompare - log2(x.std()) - log2(y.std()), log2(2*pi*e)
  def test_entropy2(self):
    from spikecount.shannon import entropy2
    from numpy import pi, e, log2

    print
    print "Test 2d entropy."
    x = generate_gaussian(sigma = 2)
    y = generate_gaussian(sigma = 2)
    print entropy2(x,y), entropy2(x,y)-log2(x.std())-log2(y.std()), log2(2*pi*e)

    x = generate_gaussian(sigma = 10)
    y = generate_gaussian(sigma = 10)
    print entropy2(x,y), entropy2(x,y)-log2(x.std())-log2(y.std()), log2(2*pi*e)

    x = generate_gaussian(sigma = 20)
    y = generate_gaussian(sigma = 20)
    print entropy2(x,y), entropy2(x,y)-log2(x.std())-log2(y.std()), log2(2*pi*e)
 def test_mix_samples(self):
   from spikecount.shannon import mix_samples, entropy2, entropy1, log2, bootstrap
   from numpy import hstack
   print "\nTest mixing samples."
   c = 0.3
   x1, y1 = generate_correlated_gaussian(sigma=5, N=100000, c = c)
   x2, y2 = generate_correlated_gaussian(sigma=10, N=100000, c = c)
   print "Well mixed samples"
   z1 = mix_samples([x1,x2])
   z2 = mix_samples([y1,y2])
   print entropy1(z1) + entropy1(z2) - entropy2(z1, z2), -log2(1-c**2)/2
   print "Datasets pasted side by side"
   z1 = hstack((x1, x2))
   z2 = hstack((y1, y2))
   print entropy1(z1) + entropy1(z2) - entropy2(z1, z2), -log2(1-c**2)/2    
   
   print "Now testing shifting and mixing samples"
   x1, y1 = generate_correlated_gaussian(sigma=4, N=100000, c = c)
   x2, y2 = generate_correlated_gaussian(sigma=4, N=100000, c = c)
   z1 = mix_samples((x1,x2+1000))
   z2 = mix_samples((y1,y2+1000))
   print bootstrap(entropy1, z1)['predict'] + bootstrap(entropy1, z2)['predict'] - bootstrap(entropy2, z1, z2)['predict'], -log2(1-c**2)/2    
   print bootstrap(entropy1, x2)['predict'] + bootstrap(entropy1, y2)['predict'] - bootstrap(entropy2, x2, y2)['predict'], -log2(1-c**2)/2