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 networkedges
- list of edgesdirected
- directed or notweights
- 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 walkwalksPerNode
- number of sentences to be generatedverbose
- enable verbose modefilename
- save sentences to filename instead of returning the sequencescallback
- callback function that runsupdateInterval
- 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
Built Distributions
Hashes for cxrandomwalk-0.1.3-pp37-pypy37_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6562a2eba9cbc61a2e39672597a696fb4eef6a0ae8f3ce4b145a99bc61018c1c |
|
MD5 | 89b73064e15fdb3ec5f1cb1e38b50e76 |
|
BLAKE2b-256 | e78d492e8ad52ef396a4999e31a598dcb8830721b586ad1ddc05c4097b1ef27f |
Hashes for cxrandomwalk-0.1.3-pp36-pypy36_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 604cb3532664d01b805a3bc92bb437962e11a566db9848584f2c8d90d43567a1 |
|
MD5 | 895e8d7ad707e00879f599bcd515f438 |
|
BLAKE2b-256 | 59b73fcd2bd7428db2867a47ab973b5d9b316dac5a06a7c55b3ccee67a93cbc5 |
Hashes for cxrandomwalk-0.1.3-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fd362339c6840ea7450296fdbc7f215ac280f1927c611de4ef1f75ccb7c6f1b |
|
MD5 | f6e5329be793b5a1be7a00a351331218 |
|
BLAKE2b-256 | 4329bc3103ee8ff36de4b424d0878661d5681d369e43a9b8529dd6e048a0cf4f |
Hashes for cxrandomwalk-0.1.3-cp39-cp39-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22e6a6a0c0518adb5e1c08436c222e91cc7b190d7fb788ba1de8a44ec72bc61e |
|
MD5 | b946cc589ef2dacfd07e8b9940c0897a |
|
BLAKE2b-256 | 4860c92821c2c01f97475a816d552f183c2b7ee3762dc6a1946b85f7106c2303 |
Hashes for cxrandomwalk-0.1.3-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05098e16e08c22a9a1764c9dc0464ab409820b318aee990c2e72fa2a47b0b553 |
|
MD5 | 3deef9747459a2bd12163102098e01cf |
|
BLAKE2b-256 | 051eabf9e04de0366162c712db46054352c5dc571d4510d8021eaea2070c5ca8 |
Hashes for cxrandomwalk-0.1.3-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdb70636115730ac0ee83c4db3b3a0210004305e15d6a2b150968a752f7b3ea2 |
|
MD5 | 44173c899e6c5530ae5504f85c083758 |
|
BLAKE2b-256 | 587a8588b7342213c48ccb1f6b25ce15f101433da2bc352f594c299e22cd1a2c |
Hashes for cxrandomwalk-0.1.3-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 899acf7c7740fd7880af621cc1b55a828938790d244f25447edebfc4959cf377 |
|
MD5 | 59b0ba115bf32426e033dbb85b2643ff |
|
BLAKE2b-256 | f7417ad0be5be67c843f731e72e4b826d9caf6c361003d567570398f43ab08cc |
Hashes for cxrandomwalk-0.1.3-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38bf19d2e5c76813e788b1176cd2114d90ca8fcb93fe9866c78ed29627cdf075 |
|
MD5 | af40e5562506b20ff3f7eb2d898327d8 |
|
BLAKE2b-256 | fe62169d9d0c73a6ebbd9d1096b4b070470c14ae6da1e027fc082f64993d4de2 |
Hashes for cxrandomwalk-0.1.3-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9bd410a94f9c81c762cd789f86d8fad6d4c5bdc7d3687c867f9807b147e2440e |
|
MD5 | 4df4096d04dd7708f8fe4142b4ed4733 |
|
BLAKE2b-256 | 7d94694b98d982e55446d9512e179ab2e0d992b46fe5c2330c122e0d748bc222 |
Hashes for cxrandomwalk-0.1.3-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c5338f7b46f921dbb9b5e64c4fc2cc60581d0aa2b6e5c6ba6aaf0b1e0175d2f |
|
MD5 | 283505ad32fe4bc8ca5729b0107b1663 |
|
BLAKE2b-256 | dc1e21773bedfa94c42b157930f7c8ba8e1b68fa67a2c9732b494137fc9afe52 |
Hashes for cxrandomwalk-0.1.3-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 528adb4738b65da7b974eb3281e91bf9fc093f468711944aae1ad162c7ace288 |
|
MD5 | 4a8606ae47f0bea66ce9e0b907c2ea90 |
|
BLAKE2b-256 | f02f26869745973474418d3b141f0c1c3586f42f2999a419d0b41b4d0f740ca7 |
Hashes for cxrandomwalk-0.1.3-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 697c607cc913403699848f7db7e933b593c5a6c032e86e199683ce941431ff8d |
|
MD5 | 7efa625ed107bc4b6ffd0190bfdc067c |
|
BLAKE2b-256 | 0f3bd2e0f8be4bf75920190502004030a4c721cd0988e68ca9207b22ee04b93b |
Hashes for cxrandomwalk-0.1.3-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1a7a0901f90901202d608e1094f9bd68394bd1e27258575a5d509e05ec6f19e |
|
MD5 | ede165f69d16bb4b84267fae51d7ee54 |
|
BLAKE2b-256 | 6786b5fc85fdf0319884f0808c7e75c7f3f8cce337b137a141c13dc9d25e7e8c |
Hashes for cxrandomwalk-0.1.3-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9f41ca4796f64b32318ef42f011cc001c46ce15181c902a6e14e7dc33ef382c |
|
MD5 | fa3426e45eac13c7073be77c9e1aeaf7 |
|
BLAKE2b-256 | 9bcd5b15d56ce7389bd161dcfb89743f03f1f8f1d17a24b688d3d5e938698357 |