def metric_entropy(x, y, name=None, type_map=None, direction=None): if (sum(x) == 0): return 1 #x = np.array(x[:]) #y = np.array(y[:]) #x = np.ndarray.flatten(x) #y = np.ndarray.flatten(y) if (direction == 0): x_type = type_map.loc[name]["A type"] y_type = type_map.loc[name]["B type"] else: x_type = type_map.loc[name]["B type"] y_type = type_map.loc[name]["A type"] if (x_type == "Numerical"): x = cluster(x) if (y_type == "Numerical"): y = cluster(y) data = np.zeros((2, len(x))) #print name, x_type,y_type,len(x),type(x), "data.shape" data[0] = x data[1] = y it = InformationTheoryTool(data) entropy = float(it.single_entropy(0, 2)) / log(float(count_unique(x)), 2) H = float(entropy) return H
def metric_entropy(x, y, name=None, type_map=None, direction=None): if sum(x) == 0: return 1 # x = np.array(x[:]) # y = np.array(y[:]) # x = np.ndarray.flatten(x) # y = np.ndarray.flatten(y) if direction == 0: x_type = type_map.loc[name]["A type"] y_type = type_map.loc[name]["B type"] else: x_type = type_map.loc[name]["B type"] y_type = type_map.loc[name]["A type"] if x_type == "Numerical": x = cluster(x) if y_type == "Numerical": y = cluster(y) data = np.zeros((2, len(x))) # print name, x_type,y_type,len(x),type(x), "data.shape" data[0] = x data[1] = y it = InformationTheoryTool(data) entropy = float(it.single_entropy(0, 2)) / log(float(count_unique(x)), 2) H = float(entropy) return H
def mutual_information(x, y, name=None, type_map=None, direction=None): if (sum(y) == 0): return 0 #x = np.array(x[:]) #y = np.array(y[:]) #x = np.ndarray.flatten(x) #y = np.ndarray.flatten(y) if (direction == 0): x_type = type_map.loc[name]["A type"] y_type = type_map.loc[name]["B type"] else: x_type = type_map.loc[name]["B type"] y_type = type_map.loc[name]["A type"] if (x_type == "Numerical"): x = cluster(x) if (y_type == "Numerical"): y = cluster(y) data = np.zeros((2, len(x))) #print name, x_type,y_type,len(x),type(x), "data.shape" data[0] = x data[1] = y it = InformationTheoryTool(data) mutual_info = it.mutual_information(0, 1, 2) #print len(y) #g = float(mi)/(2.0*len(y)) #print x,y # entropy = it.single_entropy(0,2) # if(entropy == 0): # return 1000 C = float(mutual_info) return C
def mutual_information(x, y, name=None, type_map=None, direction=None): if sum(y) == 0: return 0 # x = np.array(x[:]) # y = np.array(y[:]) # x = np.ndarray.flatten(x) # y = np.ndarray.flatten(y) if direction == 0: x_type = type_map.loc[name]["A type"] y_type = type_map.loc[name]["B type"] else: x_type = type_map.loc[name]["B type"] y_type = type_map.loc[name]["A type"] if x_type == "Numerical": x = cluster(x) if y_type == "Numerical": y = cluster(y) data = np.zeros((2, len(x))) # print name, x_type,y_type,len(x),type(x), "data.shape" data[0] = x data[1] = y it = InformationTheoryTool(data) mutual_info = it.mutual_information(0, 1, 2) # print len(y) # g = float(mi)/(2.0*len(y)) # print x,y # entropy = it.single_entropy(0,2) # if(entropy == 0): # return 1000 C = float(mutual_info) return C