In [202]:
import numpy as np

In [206]:
def  kin_energy(random_vec):
    """return    kinetic  energy  of   random vector represented   of   (1,) dimmensional  array"""
    freq=np.unique(random_vec,return_counts=True)
    prob=freq[1]/random_vec.shape[0]
    energy=np.sum(prob**2)
    return  energy
              
import numpy as np
a=np.array([1,3,2,2])
print(kin_energy(a))
#case with     total energy
a=np.array([1,1,1,1,1,1])
print(kin_energy(a))
#case  with    converging    to  zero
a=np.array([1,2,3,4,5,6,7,8,9,10])
print(kin_energy(a))


0.375
1.0
0.1

In [207]:
def  ic(vector1,vector2):
    """return  information  coefficient   IC  for  2  random  variables 
    -defined as   dot product of   probabilities  corresponding to  each class
    
    """
    a=vector1
    b=vector2
    # get the probs  in order  to    do     dot product with  them 
    prob1=np.unique(a,return_counts=True)[1]/a.shape[0]
    prob2=np.unique(b,return_counts=True)[1]/b.shape[0]
    p1=list(prob1)
    p2=list(prob2)
    diff=len(p1)-len(p2)
    if diff>0:
        for elem in range(diff):
            p2.append(0)
    if diff<0:
        for  elem in range((diff*-1)):
            p1.append(0)
    ic=np.dot(np.array(p1),np.array(p2))
    return ic

In [208]:
a=np.array([1,1,1,1,1,1,1])
b=np.array([1,1,1,1,1,1,1])

In [201]:
ic(a,b)


Out[201]:
1.0

In [221]:
def  o(vector1,vector2):
    """return onicescu   information   correlation   based on kinetic energy """
    i_c=ic(vector1,vector2)
    o=i_c/np.sqrt(kin_energy(vector1)*kin_energy(vector2))
    return o

In [222]:
o(a,b)


Out[222]:
0.98639392383214375

In [230]:
a=np.array([1,2,3,4,5,6,7])
b=a**2
o(a,b)


Out[230]:
1.0

In [225]:
ic(a,b)


Out[225]:
1.0

In [220]:
ic(a,b)/np.sqrt(kin_energy(a))


Out[220]:
0.98639392383214375

In [216]:
kin_energy(b)


Out[216]:
1.0

In [ ]: