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.6-pp37-pypy37_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb817164816f75c34b8ed27cd6b6b6d2d1536b502e057a0c8a8b99205d894059 |
|
MD5 | db803fb5017342a026074d841a1aa84b |
|
BLAKE2b-256 | cd3c9ff3a6843e64491d9a66146fe01dbf0409e39cb3646f7dfa50ff1ae6688a |
Hashes for cxrandomwalk-0.1.6-pp36-pypy36_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d77b898b4f2896f28ce4c91c3d5ebcda4c15a976c9f3bbf7fbe7c10bd621cacc |
|
MD5 | 4e53055a6bf7b184035ab22e16102a6e |
|
BLAKE2b-256 | 806fb6f8fdb99e7a94e4138abcd6a523df15cfc0b3b280b6a87b89987f905d93 |
Hashes for cxrandomwalk-0.1.6-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a98b7e5593bfeda760ff27e0404e9f1013fd453e6cf9121c0d8c66b792989892 |
|
MD5 | 48360dafa550ed447dfbd1f3766cbf7b |
|
BLAKE2b-256 | c77e793606030ae5eb081d67c15144a1d409e709a8514700ade39de4ecd2bb23 |
Hashes for cxrandomwalk-0.1.6-cp39-cp39-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b49fa3565947bbab0110cdacd6d5eb4258f1d087b0eca390dd8b0a416bf93352 |
|
MD5 | 0d02dae02771a2d4420eace861da8b5a |
|
BLAKE2b-256 | 9525a560647e37ddac22c5bd0d423b645bcf558620e4e6b6b837f3b708bebd76 |
Hashes for cxrandomwalk-0.1.6-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3d20382cb18809089d409cf1c803e1c32057550a917220aded7a12f9f14bf00 |
|
MD5 | c0f91311f45d9a7da1f7571b1b6d4f47 |
|
BLAKE2b-256 | 543e892ca26a93e08ee2b8bbc63097474ff2ce5596bd9e51bf3de87dcb12fde9 |
Hashes for cxrandomwalk-0.1.6-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3edc7c4765e849ff1f90637cb10dcd3159556447c2943264355598a8a91bf9f2 |
|
MD5 | 37601250c5479d4f4167d2539fe02f30 |
|
BLAKE2b-256 | 2f35e6648be3a358ef976ba6cbba49434997f4806e8214e35f08cb055841586a |
Hashes for cxrandomwalk-0.1.6-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74aa37b6eb163b7b9c0df7fd7f4aa74d7e259e8aed3564764d3e9a21f831e8cf |
|
MD5 | 997d47dcc90970d0fac91af92505f6a3 |
|
BLAKE2b-256 | bff837d5189e707c663d5498461491106784719c5bdd0f1a3f8063884cdfbdf2 |
Hashes for cxrandomwalk-0.1.6-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f53a73d33a0029346ba6fac0e2ec6c6e92a68616a4645143a432a0010267e5d |
|
MD5 | 96cb3188ef24aa3aa63fa69b3a5ee8d9 |
|
BLAKE2b-256 | 70c4572deb5a114d77308e05705e4127518bd2ceef63292670710467e35296db |
Hashes for cxrandomwalk-0.1.6-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0b4747fe4b331bf5abf75ccac02c8d6f1f048bf782a11b90ea09f62714d4dba |
|
MD5 | 2d5528ff108ccfdb05330f459cffc8d4 |
|
BLAKE2b-256 | 49156432f0fe00c962ecaf40431c7e57238f7e0038d4a345fb9efea8007bbbe7 |
Hashes for cxrandomwalk-0.1.6-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fe1fdfddd6090496f41991addbe82dcd34d400af58eab6e0fe8a8975f56347f |
|
MD5 | d0275db1f58e28dd5023d5b20d42a8b2 |
|
BLAKE2b-256 | 542c3f219b56882d12d2e1866d170aa5d6bbb5f2c050239ac99e128766ed11c2 |
Hashes for cxrandomwalk-0.1.6-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f74aad19d7ff43430584d7b2cab08ce2a8074453fe3935e12b2591e7f25e110c |
|
MD5 | 7476cf96bfa8ce11c7b7ba3dd4a2cfa4 |
|
BLAKE2b-256 | a190e8b38e2da492de66a03cd01d164a6ebdae55446d4b02fffc87f8ed35b087 |
Hashes for cxrandomwalk-0.1.6-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4789b7cda7e383f576b9abe2363dcff4370762a71ebdc051bdce681ab42586cc |
|
MD5 | 9b283ea589e163206e986628efa6fe31 |
|
BLAKE2b-256 | 4b53c3ca5675b72094120eee3333464047ad25e4d9a4c4c0424384b16738d8ef |
Hashes for cxrandomwalk-0.1.6-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0aca59dfac84e7fa269320b0d132117f75f4aa36453c5aec107e75aa80472776 |
|
MD5 | a2999e60a3c07a1d1dc7684bb5f9373c |
|
BLAKE2b-256 | f89a4568e920d354c13ce5e6300d3895718e5844e1109a1cab69bff458451c9c |
Hashes for cxrandomwalk-0.1.6-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88c2b51faac46006bcd99884a2f4bccfd79d1e44cca7dbc62d540909d22bcedb |
|
MD5 | fb5a863ddf60b3522f96447ea933d31f |
|
BLAKE2b-256 | 1065c501f966945e4b6afe683761890e711ce7e90f0844bb2e7ab0071627b83a |