Code Monkey home page Code Monkey logo

sample's Introduction

Efficient Sampling of Directed Graphs

This repo contains an efficient implementation of the idea proposed in Constructing and Sampling Directed Graphs with Linearly Rescaled Degree Matrices.

The algorithm constructed a small graph from the original graph using Joint Degree Matrix and Degree Correlation Matrix (see paper for more details).

Dependencies

python
networkx
numpy
scipy

Usage of Main Algorithm

The main algorithm is implemented in src/sample.py

sample(G, k, file_name)

Inputs: G: The original graph (nx.DiGraph); k: input_sample_ratio (float, within (0,1)); file_name: the name of the original graph (defined by user, a folder for storing output files will be created at results/[file_name])

Returns: time_list: time used in each step (python list); number of duplicate edges: int

Outputs: edgelist: stored as results/[file_name]/sampled_[k]_edge_list.txt (using nx.write_edgelist); degree_sequence: stored as results/[file_name]/sampled_[k]_degree_sequence.txt formatted as {ind},{outd}, each row correponds to one node in the sampled graph

An Easy Example

import networkx as nx
from src import sample

er = nx.fast_gnp_random_graph(1000, 1e-3,directed=True) # create an Erdős-Rényi graph
time_list, duplicate = sample.sample(er, 0.1, 'erdos_renyi_graph') # sample the graph
er_sampled = nx.read_edgelist("results/erdos_renyi_graph/sampled_0.1_edge_list.txt", create_using=nx.DiGraph(), data=False)  # reads back the sampled graph

Advanced Usage

This repo also contains the following content for advanced usage.

  • data: folder where 10 synthetic datasets (5 Erdős-Rényi graphs, 5 scale-free graphs) and 8 real-world datasets (from The KONECT Project) are stored.
  • results: folder where sampling results are stored. For the 10 datasets in data folder, the sampled graph (k=0.75) and a range of related files are given
  • src: folder where the main algorithm (sample.py) and many helper files are stored.
  • experiment.sh: shellcode to automatically run all kinds of experiments with arguments (-re: --run-experiments, -gd: --run-experiments, -god: --run-experiments, -pd: --run-experiments, -gfd: --run-experiments, -fpl: --run-experiments). sample_ratio needs to be specified at the top of the shellcode

sample's People

Contributors

raccoononion avatar

Stargazers

Borys Jastrzębski avatar  avatar

Watchers

Meng Jiang avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.