Copulas icon indicating copy to clipboard operation
Copulas copied to clipboard

Why are there a LOT of repeated calculations in Tree.get_tau_matrix()? possibly bug?

Open faniuy opened this issue 3 years ago • 0 comments

Below is the code from copulas/multivariate/tree.py The inner loop(j loop) repeatedly calculates kendalltau for the same data, and the columns of tau matrix are all the same.

def get_tau_matrix(self):
        num_edges = len(self.edges)
        tau = np.empty([num_edges, num_edges])
        for i in range(num_edges):
            edge = self.edges[i]
            for j in edge.neighbors:  
                if self.level == 1:
                    left_u = self.u_matrix[:, edge.L]
                    right_u = self.u_matrix[:, edge.R]
                else:
                    left_parent, right_parent = edge.parents
                    left_u, right_u = Edge.get_conditional_uni(left_parent, right_parent)

                # left_u and right_u are the same for different j's.
                tau[i, j], pvalue = scipy.stats.kendalltau(left_u, right_u) 

        return tau

faniuy avatar Mar 01 '22 08:03 faniuy