Esempio n. 1
0
def create_data_nx(paths, metrics, last_time=-1):
    gt.openmp_set_num_threads(gt.openmp_get_num_threads())
    graph_paths = sorted(paths.glob("*.gt.xz"), key=lambda x: int(x.stem.split(".")[0]))
    print("Adding metrics to the graphs")
    for i in tqdm(range(len(graph_paths))):
        time = int(graph_paths[i].stem.split(".")[0])
        if time > last_time:
            add_metrics(graph_paths[i], metrics)
Esempio n. 2
0
def get_contribution(changes, **options):
    graph_tool.openmp_set_num_threads(os.cpu_count())

    contribution = None

    graph = graph_tool.Graph(directed=False)

    graph.vp.label = graph.new_vertex_property('object')
    graph.vp.bipartite = graph.new_vertex_property('bool')
    graph.ep.weight = graph.new_edge_property('int')

    nodes, edges = dict(), dict()
    for change in changes:
        developer = nodes.get(change.commit.author, None)
        if developer is None:
            developer = graph.add_vertex()
            nodes[change.commit.author] = developer

            graph.vp.bipartite[developer] = False
            graph.vp.label[developer] = change.commit.author

        for _path in change.changes:
            path = nodes.get(_path, None)
            if path is None:
                path = graph.add_vertex()
                nodes[_path] = path

                graph.vp.bipartite[path] = True
                graph.vp.label[path] = _path

            edge = edges.get((developer, path), None)
            if edge is None:
                edge = graph.add_edge(developer, path)
                edges[(developer, path)] = edge
                graph.ep.weight[edge] = 1
            else:
                graph.ep.weight[edge] += 1
    nodes.clear()
    edges.clear()

    logger.debug('# Nodes: %s', graph.num_vertices())
    logger.debug('# Edges: %s', graph.num_edges())
    _prune_graph(graph, options)
    logger.debug('# Nodes: %s', graph.num_vertices())
    logger.debug('# Edges: %s', graph.num_edges())

    centrality = _get_vertex_centrality(graph)

    # Filter developer vertices from the graph
    graph.set_vertex_filter(graph.vp.bipartite)

    contribution = [
        Contribution(path=graph.vp.label[v], contribution=centrality[v])
        for v in graph.vertices()
    ]
    graph.clear_filters()

    return contribution
Esempio n. 3
0
def get_collaboration(changes, **options):
    graph_tool.openmp_set_num_threads(os.cpu_count())
    whitelister = _get_whitelister(**options)

    collaboration = None

    files = dict()
    for change in changes:
        for path in change.changes:
            if whitelister.is_valid(path):
                if path not in files:
                    files[path] = set()
                files[path].add(change.commit.author)

    graph = graph_tool.Graph(directed=False)

    graph.vp.label = graph.new_vertex_property('object')
    graph.ep.files = graph.new_edge_property('object')

    nodes, edges = dict(), dict()
    for (file, developers) in files.items():
        for (src, dst) in itertools.combinations(developers, 2):
            snode = nodes.get(src, None)
            if snode is None:
                snode = graph.add_vertex()
                nodes[src] = snode

            dnode = nodes.get(dst, None)
            if dnode is None:
                dnode = graph.add_vertex()
                nodes[dst] = dnode

            edge = edges.get((snode, dnode), edges.get((dnode, snode), None))
            if edge is None:
                edge = graph.add_edge(snode, dnode)
                edges[(snode, dnode)] = edge
                graph.ep.files[edge] = {file}
            else:
                graph.ep.files[edge].add(file)

    logger.debug('# Nodes: %s', graph.num_vertices())
    logger.debug('# Edges: %s', graph.num_edges())

    centrality = _get_edge_centrality(graph)
    collaboration = _aggregate_centrality(_transform(graph, centrality))

    return collaboration
Esempio n. 4
0
def build_graph_analyse(dataset, options):
    """"""

    # before starting off: limit the number of threads a graph_tool job may acquire
    if not args['openmp_disabled']:
        graph_tool.openmp_set_num_threads(options['threads_openmp'])

    # init stats
    stats = dict(
        (attr, dataset[attr]) for attr in ['path_edgelist', 'path_graph_gt'])

    graph_analyze(dataset, stats, options)

    if args['print_stats']:
        if args['from_file']:
            print(', '.join([key for key in stats.keys()]))
            print(', '.join([str(stats[key]) for key in stats.keys()]))
        else:
            print(stats)
import os
import numpy as np
import pandas as pd

from graph_tool import load_graph
from glob import glob
from tqdm import tqdm
from joblib import Parallel, delayed
from itertools import product

from eval_helpers import eval_map
from experiment import one_run
from helpers import makedir_if_not_there, is_processed
from graph_tool import openmp_set_num_threads

openmp_set_num_threads(1)

parallel = True
max_n_jobs = -1
n_sample = 1000

# , 'pagerank', 'min-steiner-tree'
methods = ['our']

root_sampler = 'pagerank'

infection_proba = 0.1

# a batch of settings to iterate through
settings = [{'graphs': ['digg'], 'obs_fractions': np.linspace(0.1, 0.9, 9)}]
Esempio n. 6
0
import numpy as np
import graph_tool as gt

gt.openmp_set_num_threads(1)
from graph_tool.search import BFSVisitor, bfs_search
import pdb
from skelerator.tree import Tree


class Neuron(Tree):
    def __init__(self, skeleton, min_radius, max_radius, verbose=False):
        """
        A neuron is a graph on 3d voxel grid (its skeleton/centerline)
        together with associated radii for each vertex indicaing
        the radius of a sphere at that point. Together they
        represent a volumetric description of a neuron. The radius of 
        two neighbouring voxels is constrained to be maximally
        different by 1. This leads to smooth changes of morhphology.
        """
        assert (min_radius > 0)
        assert (max_radius >= min_radius)
        self.skeleton = skeleton
        if self.skeleton.get_graph() is None:
            raise ValueError(
                "For neuron creation a skeleton graph is required.")

        self.g = self.skeleton.get_graph()
        self.source = self.skeleton.get_root_nodes()[0]
        self.points = skeleton.get_points()
        self.min_radius = min_radius
        self.max_radius = max_radius