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.5-pp37-pypy37_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3863858471e05a51ddc1b2c5bd5d9569b4ca58bf3dbef632e110bf513ca518b3 |
|
MD5 | 95433a455221491741d66a8a0feb827c |
|
BLAKE2b-256 | ab0b30e247c432bd943c58157f35520c8a0f6138c17f87a9ac2a9acd298489e2 |
Hashes for cxrandomwalk-0.1.5-pp36-pypy36_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2575aa9bb9c0e5ea49af7740099108efc627ef3e5adca6a5b2e92085a1e0ec9 |
|
MD5 | 03c1645c100ac791ddfe9af864adcd93 |
|
BLAKE2b-256 | 70483e86746cb692191278bcfb1539f49c577c307b5a11c2060656e7639e061e |
Hashes for cxrandomwalk-0.1.5-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0d1c891c9dbcff0efc88ff436a2154a096912fad617a736b47002d313a1fe48 |
|
MD5 | c0dbf24c79bfff5d00a2208c9673789a |
|
BLAKE2b-256 | 0ff4418c404f383fb779f4e63ebab0b53afca544bfbc414a140d1fe6c3f6bc74 |
Hashes for cxrandomwalk-0.1.5-cp39-cp39-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32198ce84d88218355be5b174b33152d1aa586dbd4ec501697f2b979b3accf8b |
|
MD5 | 44118cd02edd19aa4fb6426b06905b15 |
|
BLAKE2b-256 | d11053a4c7a1e7494d706a4d33a553fdbadf99178fb9995ac64fe9e273a123b2 |
Hashes for cxrandomwalk-0.1.5-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6635d9b01382453be6c4ae73fcc1f60a5e80683098a04f844cbba785f9af49a |
|
MD5 | 296651893d818c44461df7b054c22dcc |
|
BLAKE2b-256 | 175a9d03eea2c4412b0b11b06335c7c25f09ad6c56ad061a955b5660aafd02f2 |
Hashes for cxrandomwalk-0.1.5-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4570b6554bfaa00962da7633463bfa9e8e41f453ebf39b04b863cbd03e53be60 |
|
MD5 | c40d8eee22ebbb6728a6512321eab65c |
|
BLAKE2b-256 | da4c9cc0fe9d7d3e4d5a30d07ddf449abadd02c3ef90898840443dfb363f363f |
Hashes for cxrandomwalk-0.1.5-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98f8bbb1c62218a42cad0ce439e7394782150c11211c3600d3f864ce73690cea |
|
MD5 | 6675c3650c1a776c566658ede57636bf |
|
BLAKE2b-256 | c5b7ba6321e800b7aabb4af2e27b5c68583d6726d9a2d6dbb56377ce947da541 |
Hashes for cxrandomwalk-0.1.5-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1e3b020ba45a1acf1f17c8202b9ae8fe9aa5eb08c3036643c13b7c942ddda4b |
|
MD5 | 442aba177602af19f7aceaad072119f6 |
|
BLAKE2b-256 | b060cf9f5a60df9b4a35fccf64509613219bfde884a5fff7a994865a2b038055 |
Hashes for cxrandomwalk-0.1.5-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a41908cb0cdd134363a773e9aa7087e1d3f1c5b368949f353e07e7b5139cea7 |
|
MD5 | a721afccf09be2a251082318f479b90d |
|
BLAKE2b-256 | 0350d84baef1376714278bd5ccf2281aaac74efce9d2d690964b42c90e437ac3 |
Hashes for cxrandomwalk-0.1.5-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6449df772a6528926b82e9c657c00090813f7f321d2a82edbed841f8efb8292f |
|
MD5 | 0d16ef5418559f9778638c38ed621326 |
|
BLAKE2b-256 | 98de0e21b730a150b2d747fd298af85f9a8001c0309641c9cb0fea0423f4f41d |
Hashes for cxrandomwalk-0.1.5-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 201ac7d7c8d99ff7f5053a734555c25c4e97cd0a052924f8f86f2427f6f1b464 |
|
MD5 | a81b8afa0719957a4a69380443bba580 |
|
BLAKE2b-256 | dac15610497a0786c73ee21b608d34b03b158a44440bfe30e037b69aa62a711a |
Hashes for cxrandomwalk-0.1.5-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa19d5cf948fbb92973009b606311f3b99f6256881df13ce24486b1a5f46f98a |
|
MD5 | 10a4bb9ba5c724f10ef0d0210ad58ea2 |
|
BLAKE2b-256 | 335c039d061a4ddac11e1f638c7cfe9166f9468e7171d3491d85ebb1a90c9ec5 |
Hashes for cxrandomwalk-0.1.5-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98e4675a97d6668c4e34d126f7a675d10f32f80d9c0c2b214073e51f304778ba |
|
MD5 | 1c8206f603fcc1a3182273d520264f9e |
|
BLAKE2b-256 | b1fbdd01991e6eaf1b23b7a0382f3a1df2678d284a5ef40e5294527f97ebe0e8 |
Hashes for cxrandomwalk-0.1.5-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33ce470fc6302b47d0a6f8c09cee02162f649156439f94a3a57a546862706dd4 |
|
MD5 | aa1defe74cdb73a787113fe21f11fbde |
|
BLAKE2b-256 | 4a93ed8e8704cb8688a96114ee3d238fb20c4943e8a69fc9ddfa16c369245ee3 |