Beispiel #1
0
 def ctau(self, i=None, j=None):
     """Kendall's tau: 4*\int C(x,y) dC(x,y)-1
     """
     if i is not None and j is not None:
         var, c_var = self.prepare_var([i, j])
         dij = self.eliminate(c_var)
         if i == j:
             c, e = 1, 0
         else:
             #c, e = integrate_iter(lambda x, y: x * y * dij.cpdf(x, y), 0.0, 1.0, 0.0, 1.0)
             c, e = integrate_iter(lambda x, y: dij.ccdf(x, y) * dij.cpdf(x, y), 0.0, 1.0, 0.0, 1.0)
             c = 4 * c - 1
         return c
     else:
         c = zeros((self.d, self.d))
         for i in range(self.d):
             for j in range(self.d):
                 c[i, j] = self.ctau(i, j)                                          
         return c
Beispiel #2
0
 def rho_s(self, i=None, j=None):
     """Spearmans rho: 12*\int x*y dC(x,y)-3 = 12 \int C(d,y)dxdy - 3
     """
     if i is not None and j is not None:
         var, c_var = self.prepare_var([i, j])
         dij = self.eliminate(c_var)
         if i == j:
             c, e = 1, 0
         else:
             #c, e = integrate_iter(lambda x, y: x * y * dij.cpdf(x, y), 0.0, 1.0, 0.0, 1.0)
             c, e = integrate_iter(lambda x, y: dij.ccdf(x, y), 0.0, 1.0, 0.0, 1.0)
             c = 12 * c - 3
         return c
     else:
         c = zeros((self.d, self.d))
         for i in range(self.d):
             for j in range(self.d):
                 c[i, j] = self.rho_s(i, j)                                          
         return c
Beispiel #3
0
 def rho_s(self, i=None, j=None):
     """Spearmans rho: 12*\int x*y dC(x,y)-3 = 12 \int C(d,y)dxdy - 3
     """
     if i is not None and j is not None:
         var, c_var = self.prepare_var([i, j])
         dij = self.eliminate(c_var)
         if i == j:
             c, e = 1, 0
         else:
             #c, e = integrate_iter(lambda x, y: x * y * dij.cpdf(x, y), 0.0, 1.0, 0.0, 1.0)
             c, e = integrate_iter(lambda x, y: dij.ccdf(x, y), 0.0, 1.0,
                                   0.0, 1.0)
             c = 12 * c - 3
         return c
     else:
         c = zeros((self.d, self.d))
         for i in range(self.d):
             for j in range(self.d):
                 c[i, j] = self.rho_s(i, j)
         return c
Beispiel #4
0
 def ctau(self, i=None, j=None):
     """Kendall's tau: 4*\int C(x,y) dC(x,y)-1
     """
     if i is not None and j is not None:
         var, c_var = self.prepare_var([i, j])
         dij = self.eliminate(c_var)
         if i == j:
             c, e = 1, 0
         else:
             #c, e = integrate_iter(lambda x, y: x * y * dij.cpdf(x, y), 0.0, 1.0, 0.0, 1.0)
             c, e = integrate_iter(
                 lambda x, y: dij.ccdf(x, y) * dij.cpdf(x, y), 0.0, 1.0,
                 0.0, 1.0)
             c = 4 * c - 1
         return c
     else:
         c = zeros((self.d, self.d))
         for i in range(self.d):
             for j in range(self.d):
                 c[i, j] = self.ctau(i, j)
         return c
Beispiel #5
0
 def tau(self, i=None, j=None):
     """Kendall's tau: 4*\int C(x,y) dC(x,y)-1
     """
     if i is not None and j is not None:
         var, c_var = self.prepare_var([i, j])
         dij = self.eliminate(c_var)
         f, g = dij.marginals[0], self.marginals[1]
         f0, f1 = f.get_piecewise_pdf().range()
         g0, g1 = g.get_piecewise_pdf().range()
         if i == j:
             c, e = 1, 0
         else:
             c, e = integrate_iter(lambda x, y: dij.cdf(x, y) * dij.pdf(x, y), f0, f1, g0, g1)
             c = 4 * c - 1
         return c
     else:
         c = zeros((self.d, self.d))
         for i in range(self.d):
             for j in range(self.d):
                 c[i, j] = self.ctau(i, j)                                          
         return c
Beispiel #6
0
 def cov(self, i=None, j=None):
     if i is not None and j is not None:
         var, c_var = self.prepare_var([i, j])
         dij = self.eliminate(c_var)
         f, g = dij.marginals[0], self.marginals[1]
         fmean = f.mean()
         gmean = g.mean()
         f0, f1 = f.get_piecewise_pdf().range()
         g0, g1 = g.get_piecewise_pdf().range()
         print(fmean, gmean, var, c_var, f0, f1, g0, g1)
         if i == j:
             c, e = c, e = integrate_fejer2(lambda x: (x - fmean) ** 2 * f.pdf(x), f0, f1)                  
         else:
             c, e = integrate_iter(lambda x, y: (x - fmean) * (y - gmean) * dij.pdf(x, y), f0, f1, g0, g1)
         return c
     else:
         c = zeros((self.d, self.d))
         for i in range(self.d):
             for j in range(self.d):
                 c[i, j] = self.cov(i, j)                                          
         return c
Beispiel #7
0
 def cov(self, i=None, j=None):
     if i is not None and j is not None:
         var, c_var = self.prepare_var([i, j])
         dij = self.eliminate(c_var)
         f, g  = dij.Vars[0], self.Vars[1]
         fmean = 0 #f.mean()
         gmean = 0 #g.mean()
         f0, f1 = f.range()
         g0, g1 = g.range()
         if i == j:
             c, e =  1, 0#integrate_fejer2(lambda x: (x - fmean) ** 2 * f.pdf(x), f0, f1)
         else:
             c, e = integrate_iter(lambda x, y: (x - fmean) * (y - gmean) * dij.pdf(x, y), f0, f1, g0, g1)
         return c
     else:
         c = zeros((self.d, self.d))
         for i in range(self.d):
             for j in range(self.d):
                 #print c[i,j]
                 #print self.cov(i,j)
                 c[i, j] = self.cov(i,j)
         return c
Beispiel #8
0
 def tau(self, i=None, j=None):
     """Kendall's tau: 4*\int C(x,y) dC(x,y)-1
     """
     if i is not None and j is not None:
         var, c_var = self.prepare_var([i, j])
         dij = self.eliminate(c_var)
         f, g = dij.marginals[0], self.marginals[1]
         f0, f1 = f.get_piecewise_pdf().range()
         g0, g1 = g.get_piecewise_pdf().range()
         if i == j:
             c, e = 1, 0
         else:
             c, e = integrate_iter(
                 lambda x, y: dij.cdf(x, y) * dij.pdf(x, y), f0, f1, g0, g1)
             c = 4 * c - 1
         return c
     else:
         c = zeros((self.d, self.d))
         for i in range(self.d):
             for j in range(self.d):
                 c[i, j] = self.ctau(i, j)
         return c
Beispiel #9
0
 def cov(self, i=None, j=None):
     if i is not None and j is not None:
         var, c_var = self.prepare_var([i, j])
         dij = self.eliminate(c_var)
         f, g = dij.marginals[0], self.marginals[1]
         fmean = f.mean()
         gmean = g.mean()
         f0, f1 = f.get_piecewise_pdf().range()
         g0, g1 = g.get_piecewise_pdf().range()
         print fmean, gmean, var, c_var, f0, f1, g0, g1
         if i == j:
             c, e = c, e = integrate_fejer2(
                 lambda x: (x - fmean)**2 * f.pdf(x), f0, f1)
         else:
             c, e = integrate_iter(
                 lambda x, y: (x - fmean) * (y - gmean) * dij.pdf(x, y), f0,
                 f1, g0, g1)
         return c
     else:
         c = zeros((self.d, self.d))
         for i in range(self.d):
             for j in range(self.d):
                 c[i, j] = self.cov(i, j)
         return c