Пример #1
0
def plot_rc(g, controls, ax, **kwargs):

    rc = richclub.rich_club_coefficient(g, **kwargs)

    rich_club_coefficient = vectorize(richclub.rich_club_coefficient)

    rc_controls = []
    for c in controls:
        rc_controls.append(richclub.rich_club_coefficient(c, **kwargs))
    rc_controls = array(rc_controls)
    control_mean = mean(rc_controls, axis=0)

    if 'rank' in kwargs:
        x = kwargs['rank']
    else:
        if 'mode' in kwargs:
            mode = kwargs['mode']
        else:
            mode = 'percentile'
        if mode == 'percentile':
            x = arange(10.0, 100.0, 10.0)
        else:
            x = unique(g.degree())

    from scipy.stats import scoreatpercentile
    upper95 = array(
        [scoreatpercentile(rc_controls[:, i], 95) for i in range(len(x))])
    lower95 = array(
        [scoreatpercentile(rc_controls[:, i], 5) for i in range(len(x))])

    ax.plot(x, rc, color='r')
    ax.plot(x, control_mean, color='b')
    ax.fill_between(x,
                    lower95,
                    upper95,
                    where=(lower95 > 0) & (upper95 > 0),
                    alpha=.1,
                    color='b')
    ax.set_yscale('log')
    #ax.set_xscale('log')

    rc_norm = rc / control_mean
    ax2 = ax.twinx()
    ax2.plot(x, rc_norm, linewidth=4, color='k')
    ax2.plot(ax.get_xlim(), (1, 1), linestyle='--', color='k')
    ax2.set_ylim(bottom=0)
    if ax2.get_ylim()[1] < 2:
        ax2.set_ylim(top=2)
    ax2.set_ylabel(r"$\phi_{norm}$, normalized rich club coefficient")
    ax2.fill_between(x,
                     1,
                     rc_norm,
                     where=(rc > upper95) | (rc < lower95),
                     alpha=.05,
                     color='g')

    return ax, rc, lower95, upper95
Пример #2
0
    def test_rich_club_coefficient(self):
        print """Testing rich_club_coefficient"""

        self.assertTrue(True)
        ns = [
            60,
        ]
        ms = [60, 10, 600]
        directeds = [True, False]
        highests = [True, False]
        scoress = [None, 'r']

        test_cases = [(n, m, directed, highest, score) for n in ns for m in ms
                      for directed in directeds for highest in highests
                      for score in scoress]

        rc_properties = [
            'intensity_P_wm', 'intensity_L_wm', 'intensity_P_local',
            'intensity_L_local', 'intensity_L_global', 'intensity_P_global'
        ]

        for n, m, directed, highest, score in test_cases:
            g = Graph.Erdos_Renyi(n=n, m=m, directed=directed)
            #            print "%i nodes, %i links, directed: %i, highest: %i, "\
            #                "score: %s"\

            for p in rc_properties:
                print p
                rc = richclub.rich_club_coefficient(g, club_property=p)
            self.assertTrue(True)
Пример #3
0
def plot_rc(g, controls, ax, **kwargs):
    
    rc = richclub.rich_club_coefficient(g, **kwargs)
    
    rich_club_coefficient = vectorize(richclub.rich_club_coefficient)
    
    rc_controls = []
    for c in controls:
        rc_controls.append(richclub.rich_club_coefficient(c, **kwargs))
    rc_controls = array(rc_controls)
    control_mean = mean(rc_controls, axis=0)
    
    if 'rank' in kwargs:
        x = kwargs['rank']
    else:
        if 'mode' in kwargs:
            mode = kwargs['mode']
        else:
            mode = 'percentile'
        if mode=='percentile':
            x = arange(10.0,100.0, 10.0)
        else:
            x = unique(g.degree())
            
    from scipy.stats import scoreatpercentile
    upper95 = array([scoreatpercentile(rc_controls[:,i], 95) for i in range(len(x))])
    lower95 = array([scoreatpercentile(rc_controls[:,i], 5) for i in range(len(x))])
    
    ax.plot(x, rc, color='r')
    ax.plot(x, control_mean, color='b')
    ax.fill_between(x, lower95, upper95, where=(lower95>0)&(upper95>0), alpha=.1, color='b')
    ax.set_yscale('log')
    #ax.set_xscale('log')
    
    rc_norm = rc/control_mean
    ax2 = ax.twinx()
    ax2.plot(x, rc_norm, linewidth=4, color='k')
    ax2.plot(ax.get_xlim(), (1,1), linestyle='--', color='k')
    ax2.set_ylim(bottom=0)
    if ax2.get_ylim()[1]<2:
        ax2.set_ylim(top=2)
    ax2.set_ylabel(r"$\phi_{norm}$, normalized rich club coefficient")
    ax2.fill_between(x, 1,rc_norm, where=(rc>upper95) | (rc<lower95), alpha=.05, color='g')
    
    return ax, rc, lower95, upper95
Пример #4
0
    def test_rich_club_coefficient(self):
        print """Testing rich_club_coefficient"""

        self.assertTrue(True)
        ns = [60]
        ms = [60, 10, 600]
        directeds = [True, False]
        highests = [True, False]
        scoress = [None, "r"]

        test_cases = [
            (n, m, directed, highest, score)
            for n in ns
            for m in ms
            for directed in directeds
            for highest in highests
            for score in scoress
        ]

        rc_properties = [
            "intensity_P_wm",
            "intensity_L_wm",
            "intensity_P_local",
            "intensity_L_local",
            "intensity_L_global",
            "intensity_P_global",
        ]

        for n, m, directed, highest, score in test_cases:
            g = Graph.Erdos_Renyi(n=n, m=m, directed=directed)
            #            print "%i nodes, %i links, directed: %i, highest: %i, "\
            #                "score: %s"\

            for p in rc_properties:
                print p
                rc = richclub.rich_club_coefficient(g, club_property=p)
            self.assertTrue(True)
Пример #5
0
 def calculate_rc_codelength_in(g):
     return richclub.rich_club_coefficient(
         g, richness='in_strength',
         club_property='codelength')
Пример #6
0
 def calculate_rc_q_infomap_in(g):
     return richclub.rich_club_coefficient(
         g, richness='in_strength',
         club_property='q_infomap')
Пример #7
0
 def calculate_rc_n_infomap_out(g):
     return richclub.rich_club_coefficient(
         g, richness='out_strength',
         club_property='n_infomap')
Пример #8
0
 def calculate_rc_clustering_out(g):
     return richclub.rich_club_coefficient(
         g, richness='out_strength',
         club_property='clustering')
Пример #9
0
 def calculate_rc_iNpwmg_in(g):
     return richclub.rich_club_coefficient(
         g, richness='in_strength',
         club_property='intensity_topNpweightmax_global')
Пример #10
0
 def calculate_rc_iNpg_out(g):
     return richclub.rich_club_coefficient(
         g, richness='out_strength',
         club_property='intensity_topNp_global')
Пример #11
0
 def calculate_rc_itg_in(g):
     return richclub.rich_club_coefficient(
         g, richness='in_strength',
         club_property='intensity_total_global')
Пример #12
0
 def calculate_rc_iNpwml_out(g):
     return richclub.rich_club_coefficient(
         g, richness='out_strength',
         club_property='intensity_topNpweightmax_local')
Пример #13
0
 def calculate_rc_iNpl_in(g):
     return richclub.rich_club_coefficient(
         g, richness='in_strength',
         club_property='intensity_topNp_local')
Пример #14
0
 def calculate_rc_itl_out(g):
     return richclub.rich_club_coefficient(
         g, richness='out_strength',
         club_property='intensity_total_local')