コード例 #1
0
plt.ion()

NTRIALS = 500

# PLOT PARAMETERS
FIGSIZE = (11, 4)
FACECOLOR = 'k'
BRAINCOLOR = 'm'
MODELCOLOR = 'orange'
ERCOLOR = 'r'
FONTSIZE = 16
NBINS = 15

# load brain graph
Gbrain, Abrain, Dbrain, labels = brain_graph(p_th=.05)

# create model graph
G, A, D = biophysical_model(N=bc.num_brain_nodes,
                            N_edges=bc.num_brain_edges_directed,
                            L=.75,
                            gamma=1.)

# create random graph
Grandom, Arandom, Drandom = ER_distance(bc.num_brain_nodes,
                                        p=bc.p_brain_edge_directed)

# calculate random swap cost distribution for brain and model
brain_cost = swapped_cost_distr(Abrain, Dbrain, n_trials=NTRIALS)
model_cost = swapped_cost_distr(A, D, n_trials=NTRIALS)
random_cost = swapped_cost_distr(Arandom, Drandom, n_trials=NTRIALS)
コード例 #2
0
ファイル: reciprocity_versus_L.py プロジェクト: wronk/dbw
    for j,L in enumerate(Ls):
        for n in range(N):
            G, A, labels = biophysical_model(N=num_brain_nodes,
                                         N_edges=num_brain_edges_directed,
                                         L=L,
                                         gamma=1.)
            recip = reciprocity(A)
            modelReciprocity[j,n] = recip
            print "Reciprocity: " + str(np.mean(modelReciprocity[:,n])) + "(" + str(np.std(modelReciprocity[:,n])) + ")"




meanReciprocity = np.mean(modelReciprocity,axis=1)

G,A,labels = brain_graph()
brainReciprocity = reciprocity(A)

configReciprocity = np.zeros([20,1])
nodes = G.nodes()
inDeg = G.in_degree(); inDeg = [inDeg[node] for node in nodes]
outDeg = G.out_degree(); outDeg = [outDeg[node] for node in nodes]
for j in range(20):
    G_config = nx.directed_configuration_model(inDeg,outDeg)
    A_config = nx.adjacency_matrix(G_config)
    A_configInt = np.zeros(A_config.shape,dtype=int)
    
    A_configInt[A_config < 0.5] = 0
    A_configInt[A_config > 0.5] = 1
    
    configReciprocity[j] = reciprocity(A_configInt)
コード例 #3
0
ファイル: reciprocity_analysis.py プロジェクト: wronk/dbw
from numpy import concatenate as cc

from extract.brain_graph import binary_directed as brain_graph
from random_graph.binary_directed import biophysical_reverse_outdegree_reciprocal as model_graph
from metrics.binary_directed import reciprocity
from network_plot.change_settings import set_all_text_fontsizes as set_fontsize

from brain_constants import *

# PARAMETERS
NER = 100 # number of ER-directed graphs to generate
NMODEL = 100

# load brain graph, adjacency matrix, and labels
Gbrain, Abrain, labels = brain_graph()
reciprocity_brain = reciprocity(G)

# calculate reciprocity for several ER-directed graphs
reciprocity_ER = np.zeros((NER,), dtype=float)
for ctr in range(NER):
    GER = nx.erdos_renyi_graph(num_brain_nodes, p_brain_edge_directed, 
                               directed=True)
    reciprocity_ER[ctr] = reciprocity(GER)

# calculate reciprocity for several model graphs
reciprocity_model = np.zeros((NMODEL,), dtype=float)
for ctr in range(NMODEL):
    print ctr
    Gmodel = model_graph(N=num_brain_nodes, 
                         N_edges=num_brain_edges_directed, 
コード例 #4
0
ファイル: brain_cost_random_swaps.py プロジェクト: wronk/dbw
"""
Created on Fri Jan 23 13:11:36 2015

@author: rkp

Plot the in- vs. outdegree distribution for the Allen Brain mouse connectome.
"""

import numpy as np
import matplotlib.pyplot as plt
import networkx as nx

from extract.brain_graph import binary_directed as brain_graph
from graph_tools.auxiliary import swap_node_positions as swap

plt.ion()

# PLOT PARAMETERS
FACECOLOR = 'black'
MARKERCOLOR='m'
FONTSIZE = 24
NBINS = 15

# load brain graph, adjacency matrix, and labels
G, A, D, labels = brain_graph(p_th=.01)

brain_avg_shortest_path = nx.average_shortest_path_length(G, weight='distance')

# randomly swap two nodes
Gswapped, Dswapped = swap(G, D)
swapped_avg_shortest_path = nx.average_shortest_path_length(Gswapped, weight='distance')
コード例 #5
0
from numpy import concatenate as cc

from extract.brain_graph import binary_directed as brain_graph
from random_graph.binary_directed import biophysical_reverse_outdegree as biophysical_model
from network_plot.change_settings import set_all_text_fontsizes as set_fontsize

import aux_random_graphs

from brain_constants import *


if __name__ == "__main__":

    # load brain graph, adjacency matrix, and labels
    G_brain, A_brain, labels_brain = brain_graph()
    G_model, A_model, labels_model = biophysical_model(N=num_brain_nodes,
                                 N_edges=num_brain_edges_directed,
                                 L=.76,
                                 gamma=1.)
    Gs = [G_brain,G_model]
    As = [A_brain,A_model]
    allLabels = [labels_brain,labels_model]


    fig,axs = plt.subplots(1,ncols=2,facecolor='white')
    
    for g,G in enumerate(Gs):
        A = As[g]
        labels = allLabels[g]
        
コード例 #6
0
                                 rowspan=cf.top_margin_rowspan,
                                 colspan=cf.top_margin_colspan,
                                 sharex=left_main_ax)

right_margin_ax = plt.subplot2grid(cf.subplot_divisions,
                                   cf.right_margin_location,
                                   rowspan=cf.right_margin_rowspan,
                                   colspan=cf.right_margin_colspan,
                                   sharey=left_main_ax)

# To make log axes we need to create another axes on top of our existing ones
top_dummy_ax = top_margin_ax.twinx()
right_dummy_ax = right_margin_ax.twiny()

# Extract information for the Allen mouse connectome
G, _, _ = brain_graph()

# Get in- & out-degree
indeg = np.array([G.in_degree()[node] for node in G])
outdeg = np.array([G.out_degree()[node] for node in G])
deg = indeg + outdeg

# Calculate proportion in degree
percent_indeg = indeg / deg.astype(float)
a1 = 1.0

# Left main plot (in vs out degree)
left_main_ax.scatter(indeg,
                     outdeg,
                     c=config.COLORS['brain'],
                     s=cf.MARKERSIZE,
コード例 #7
0
ファイル: fig3.py プロジェクト: neofunkatron/neofunkatron
                                 rowspan=cf.top_margin_rowspan,
                                 colspan=cf.top_margin_colspan,
                                 sharex=left_main_ax)

right_margin_ax = plt.subplot2grid(cf.subplot_divisions,
                                   cf.right_margin_location,
                                   rowspan=cf.right_margin_rowspan,
                                   colspan=cf.right_margin_colspan,
                                   sharey=left_main_ax)

# To make log axes we need to create another axes on top of our existing ones
top_dummy_ax = top_margin_ax.twinx()
right_dummy_ax = right_margin_ax.twiny()

# Extract information for the Allen mouse connectome
G, _, _ = brain_graph()

# Get in- & out-degree
indeg = np.array([G.in_degree()[node] for node in G])
outdeg = np.array([G.out_degree()[node] for node in G])
deg = indeg + outdeg

# Calculate proportion in degree
percent_indeg = indeg / deg.astype(float)
a1 = 1.0

# Left main plot (in vs out degree)
left_main_ax.scatter(indeg, outdeg, c=config.COLORS['brain'], s=cf.MARKERSIZE,
                     lw=0, alpha=ALPHA)

left_main_ax.set_xlabel('In-degree')
コード例 #8
0
Plot proportion in-degree of mouse connectome
"""

import numpy as np
import matplotlib.pyplot as plt
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))

from extract.brain_graph import binary_directed as brain_graph
from config import COLORS

fontsize = 12

# Load connectome graph
G = brain_graph()[0]


# Calculate proportion in-degree
outdeg = G.out_degree()
indeg = G.in_degree()
nodes = G.nodes()
sumdeg = [float(outdeg[node] + indeg[node]) for node in nodes]
prop_indeg = [indeg[node] / sumdeg[node] for node in nodes]

# Plot in-degree
fig, ax = plt.subplots(1, facecolor='w', figsize=(3.5, 2.75))
fig.subplots_adjust(bottom=0.2, left=0.2)
bins = np.linspace(0, 1, 11)
ax.hist(prop_indeg, bins, facecolor=COLORS['brain'])
コード例 #9
0
from __future__ import division
import numpy as np
import networkx as nx
import os

from extract.brain_graph import binary_directed as brain_graph
from network_compute import reciprocity

G, A, labels = brain_graph()

edges = G.edges()
edges = {edge: 1 for edge in edges}

recip_counter = 0
for edge in edges:
    complementary_edge = (edge[1], edge[0])
    if edges.has_key(complementary_edge):
        recip_counter += 1

recip_counter /= 2  # double-counted above

recip_from_loop = recip_counter / len(edges)

recip_from_function = reciprocity(A)

print("Reciprocity from loop: %.3f" % (recip_from_loop))
print("Reciprocity from function: %.3f" % (recip_from_function))