Skip to main content

Experimental library to visualize complex networks

Project description

CXRandomWalk

Fast library written in C for python to generate sentences based on random walks from networks. Can be used to generate input data for word2vec and other embedding techniques.

Install

Requires python headers and a C11 compatible compiler, such as gcc or clang.

To install it, simply run:

pip install cxrandomwalk

or clone this repository and install it from master by running:

pip install git+git://github.com/filipinascimento/cxrandomwalk.git

Usage

The walking algorithm uses regular random walks and biased random walks according to node2vec ([https://snap.stanford.edu/node2vec/]).

Step 1: Import the libraries

import numpy as np
import cxrandomwalk as rw

Step 2: Convert network to a edgelist and a list of weights (optional)

vertexCount = 10;
edges = np.random.randint(0,vertexCount-1,(vertexCount*2, 2))
weights = np.random.random(size=vertexCount*2);

Step 3: Load the network data in an agent object

agent = rw.Agent(vertexCount,edges,False,weights)

To generate the sequences use:

sequences = agent.generateWalks(p=2,q=3,verbose=True)

The output is a list of lists with the walks.

API Documentation

cxrandomwalk.Agent(vertexCount,edges,directed=False,weights=None)
  • vertexCount - number of vertices in the network
  • edges - list of edges
  • directed - directed or not
  • weights - list containing the weights of the edges (use the same order as edges) returns a rw.Agent instance
cxrandomwalk.Agent.generateWalks(p=1.0,q=1.0,windowSize=80,walksPerNode=10,verbose=False,filename=None,callback=None,updateInterval=1000)
  • p - for p in node2vec walks (1.0 for unbiased)
  • q - for q in node2vec walks (1.0 for unbiased)
  • windowSize - length of each walk
  • walksPerNode - number of sentences to be generated
  • verbose - enable verbose mode
  • filename - save sentences to filename instead of returning the sequences
  • callback - callback function that runs
  • updateInterval - set the interval between iterations so that python interruptions work

returns a list of lists containing the sequences. If filename is provided, instead of returning a list, the method creates the file and fill with the walks, with words separated by spaces and sentences separated by new lines. It can be used directly on gensim.

TODO

  • Include other kinds of walks
  • Better documentation and CLI help

Example with tqdm callback

import numpy as np
import cxrandomwalk as rw
from tqdm.auto import tqdm 

vertexCount = 10000;
edges = np.random.randint(0,vertexCount-1,(vertexCount*2, 2))
weights = np.random.random(size=vertexCount*2);

agent = rw.Agent(vertexCount,edges,False,weights)

def make_pbar():
  pbar = None
  def inner(current,total):
    nonlocal pbar
    if(pbar is None):
      pbar= tqdm(total=total);
    pbar.update(current - pbar.n)
  return inner

print(len(agent.generateWalks(q=1.0,p=1.0,verbose=False,updateInterval=1000,callback=make_pbar())))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cxrandomwalk-0.1.3.tar.gz (26.5 kB view hashes)

Uploaded Source

Built Distributions

cxrandomwalk-0.1.3-pp37-pypy37_pp73-manylinux2010_x86_64.whl (135.0 kB view hashes)

Uploaded PyPy manylinux: glibc 2.12+ x86-64

cxrandomwalk-0.1.3-pp36-pypy36_pp73-manylinux2010_x86_64.whl (135.0 kB view hashes)

Uploaded PyPy manylinux: glibc 2.12+ x86-64

cxrandomwalk-0.1.3-cp39-cp39-manylinux2010_x86_64.whl (323.5 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

cxrandomwalk-0.1.3-cp39-cp39-manylinux2010_i686.whl (286.0 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ i686

cxrandomwalk-0.1.3-cp39-cp39-macosx_10_14_x86_64.whl (59.3 kB view hashes)

Uploaded CPython 3.9 macOS 10.14+ x86-64

cxrandomwalk-0.1.3-cp38-cp38-manylinux2010_x86_64.whl (324.0 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

cxrandomwalk-0.1.3-cp38-cp38-manylinux2010_i686.whl (286.3 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ i686

cxrandomwalk-0.1.3-cp38-cp38-macosx_10_14_x86_64.whl (59.2 kB view hashes)

Uploaded CPython 3.8 macOS 10.14+ x86-64

cxrandomwalk-0.1.3-cp37-cp37m-manylinux2010_x86_64.whl (323.8 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

cxrandomwalk-0.1.3-cp37-cp37m-manylinux2010_i686.whl (286.0 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ i686

cxrandomwalk-0.1.3-cp37-cp37m-macosx_10_14_x86_64.whl (59.2 kB view hashes)

Uploaded CPython 3.7m macOS 10.14+ x86-64

cxrandomwalk-0.1.3-cp36-cp36m-manylinux2010_x86_64.whl (322.9 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

cxrandomwalk-0.1.3-cp36-cp36m-manylinux2010_i686.whl (285.2 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ i686

cxrandomwalk-0.1.3-cp36-cp36m-macosx_10_14_x86_64.whl (59.2 kB view hashes)

Uploaded CPython 3.6m macOS 10.14+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page