code: #!/usr/bin/env python3
  
  """ Demo for exponentiated Jensen-Tsallis kernel-1 estimators.
  
  Analytical vs estimated value is illustrated for spherical normal random
  variables.
  
  """
  
  from numpy import eye
  from numpy.random import rand, multivariate_normal, randn
  from scipy import arange, zeros, ones
  import matplotlib.pyplot as plt
  
  from ite.cost.x_factory import co_factory
  from ite.cost.x_analytical_values import analytical_value_k_ejt1
  
  
  def main():
      # parameters:
      dim = 1  # dimension of the distribution
      num_of_samples_v = arange(1000, 50*1000+1, 2000)
      u = 0.8  # >0, parameter of the Jensen-Tsallis kernel
      cost_name = 'MKExpJT1_HT'  # dim >= 1
  
      # initialization:
      alpha = 2
      # fixed; parameter of the Jensen-Tsallis kernel; for alpha = 2 we have
      # explicit formula for the Tsallis entropy, and hence for the
      # Jensen-Tsallis kernel(-1).
  
      distr = 'normal'  # fixed
      num_of_samples_max = num_of_samples_v[-1]
      length = len(num_of_samples_v)
      co = co_factory(cost_name, mult=True, alpha=alpha, u=u)  # cost object
      k_hat_v = zeros(length)  # vector of estimated kernel values
  
      # distr, dim -> samples (y1,y2), distribution parameters (par1,par2), 
      # analytical value (k):
      if distr == 'normal':
          # generate samples (y1,y2); y1~N(m1,s1^2xI), y2~N(m2,s2^2xI):
          m1, s1 = randn(dim), rand(1)
          m2, s2 = randn(dim), rand(1)
          y1 = multivariate_normal(m1, s1**2 * eye(dim), num_of_samples_max)
          y2 = multivariate_normal(m2, s2**2 * eye(dim), num_of_samples_max)
          
          par1 = {"mean": m1, "std": s1}
          par2 = {"mean": m2, "std": s2}
      else:
          raise Exception('Distribution=?')        
          
      k = analytical_value_k_ejt1(distr, distr, u, par1, par2)
      
      # estimation:
      for (tk, num_of_samples) in enumerate(num_of_samples_v):
          k_hat_v[tk] = co.estimation(y1[0:num_of_samples],
                                      y2[0:num_of_samples])  # broadcast
          print("tk={0}/{1}".format(tk+1, length))
          
      # plot:    
      plt.plot(num_of_samples_v, k_hat_v, num_of_samples_v, ones(length)*k)
      plt.xlabel('Number of samples')
      plt.ylabel('Exponentiated Jensen-Tsallis kernel-1')
      plt.legend(('estimation', 'analytical value'), loc='best')
      plt.title("Estimator: " + cost_name)
      plt.show()
  
  
  if __name__ == "__main__":
      main()
   #!/usr/bin/env python3
  
  """ Demo for Renyi mutual information estimators.
  
  Analytical vs estimated value is illustrated for normal random variables.
  
  """
  
  from numpy.random import rand, multivariate_normal
  from numpy import arange, zeros, dot, ones
  import matplotlib.pyplot as plt
  
  from ite.cost.x_factory import co_factory
  from ite.cost.x_analytical_values import analytical_value_i_renyi
  
  
  def main():
      # parameters:
      alpha = 0.7  # parameter of Renyi mutual information, \ne 1
      dim = 2  # >=2; dimension of the distribution
      num_of_samples_v = arange(100, 10*1000+1, 500)
  
      cost_name = 'MIRenyi_DR'
      # cost_name = 'MIRenyi_HR'
      
      # initialization:
      distr = 'normal'  # distribution; fixed    
      ds = ones(dim, dtype='int')  # dimensions of the 'subspaces'
      num_of_samples_max = num_of_samples_v[-1]
      length = len(num_of_samples_v)
      co = co_factory(cost_name, mult=True, alpha=alpha)  # cost object
      # vector of estimated mutual information values:
      i_hat_v = zeros(length)
  
      # distr, dim -> samples (y), distribution parameters (par), analytical 
      # value (i):
      if distr == 'normal':
          # mean (m), covariance matrix (c):
          m = rand(dim) 
          l = rand(dim, dim)
          c = dot(l, l.T)
          
          # generate samples (y~N(m,c)): 
          y = multivariate_normal(m, c, num_of_samples_max)
             
          par = {"cov": c} 
      else:
          raise Exception('Distribution=?')
      
      i = analytical_value_i_renyi(distr, alpha, par)
          
      # estimation:
      for (tk, num_of_samples) in enumerate(num_of_samples_v):
          i_hat_v[tk] = co.estimation(y[0:num_of_samples], ds)  # broadcast
          print("tk={0}/{1}".format(tk+1, length))
          
      # plot:    
      plt.plot(num_of_samples_v, i_hat_v, num_of_samples_v, ones(length)*i)
      plt.xlabel('Number of samples')
      plt.ylabel('Renyi mutual information')
      plt.legend(('estimation', 'analytical value'), loc='best')
      plt.title("Estimator: " + cost_name)
      plt.show()
  
  
  if __name__ == "__main__":
      main()
  
apis: numpy.eye matplotlib.pyplot.legend scipy.zeros numpy.random.randn scipy.ones matplotlib.pyplot.title matplotlib.pyplot.show matplotlib.pyplot.ylabel numpy.random.rand scipy.arange matplotlib.pyplot.xlabel
apis: numpy.ones matplotlib.pyplot.legend numpy.zeros numpy.arange matplotlib.pyplot.title numpy.random.multivariate_normal matplotlib.pyplot.show matplotlib.pyplot.ylabel numpy.random.rand numpy.dot matplotlib.pyplot.xlabel