Library to perform random walks on 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
File details
Details for the file cxrandomwalk-0.5.8-cp312-cp312-win_amd64.whl
.
File metadata
- Download URL: cxrandomwalk-0.5.8-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 27.9 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84ee200a350b48c7695ca2985af4b50fd24840b2c4a97ae82075f4194963c85b |
|
MD5 | 994eb2267d91508bda1554f7c51e3c7d |
|
BLAKE2b-256 | 0dc7549e049a45beaaa42ae57a76518a795f72d7128bd6b3194742c8da167da0 |
File details
Details for the file cxrandomwalk-0.5.8-cp312-cp312-macosx_11_0_arm64.whl
.
File metadata
- Download URL: cxrandomwalk-0.5.8-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 66.5 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a8060603b74475b6bba1b165d49ce915c3a3fb2fadacc2b1dcad0eb8fbe88c4 |
|
MD5 | 85f8117f55858d6e6ce58908939d0deb |
|
BLAKE2b-256 | afd0ff2826c314a64698cf03c155e92940d1d68452274bdc7d44518b1aef5b32 |
File details
Details for the file cxrandomwalk-0.5.8-cp312-cp312-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: cxrandomwalk-0.5.8-cp312-cp312-macosx_10_9_x86_64.whl
- Upload date:
- Size: 73.4 kB
- Tags: CPython 3.12, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2dc94219f7a9c71cae69a8e4e98841ce46482ca425fa74cbe5a27bc41dfb115c |
|
MD5 | 7af6497418d5214c00d9ac7a353790fc |
|
BLAKE2b-256 | 3eb19aee930986f1c79e6737b708309261d286a3d05be9ddb375f571408e3b2a |
File details
Details for the file cxrandomwalk-0.5.8-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: cxrandomwalk-0.5.8-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 27.9 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea57d279de49163e1d9b16eee7d5ca9cf4292e276ab9692d3971886977f81b2c |
|
MD5 | 74299f6a2002e4f18a3e552facfccbfa |
|
BLAKE2b-256 | 8ab203a1e52dc0da0552c3becf5c551e1b8ef2c92c0788523094f63151afeda1 |
File details
Details for the file cxrandomwalk-0.5.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: cxrandomwalk-0.5.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 428.5 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50dfbc6684b209839405683e5da3ab1034cc44acb57051908e8c49325efc76a2 |
|
MD5 | 0e91735552e5f89a1569309780231cfb |
|
BLAKE2b-256 | 7da0f8cc929f3e1c4e4c22da779dfee015704c3bdf9047b236e78fedb8847e53 |
File details
Details for the file cxrandomwalk-0.5.8-cp311-cp311-macosx_11_0_arm64.whl
.
File metadata
- Download URL: cxrandomwalk-0.5.8-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 66.5 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e7274cb6252b344a02eeadaedfdf6c422163c9c98e43614e6ab0ac2bd659413 |
|
MD5 | f4ffaa7ec1f991700bfd1675095de904 |
|
BLAKE2b-256 | d4ed72377a007769a17492dd7865080376ee4e1aaa4ed5e2900a0828fc017cf0 |
File details
Details for the file cxrandomwalk-0.5.8-cp311-cp311-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: cxrandomwalk-0.5.8-cp311-cp311-macosx_10_9_x86_64.whl
- Upload date:
- Size: 73.3 kB
- Tags: CPython 3.11, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3654ea594f44c91eb7b7489d1a0286b7e44050b402af3f4ea644b18756d76479 |
|
MD5 | 77c736d93322a3ee02fba5631f07c61b |
|
BLAKE2b-256 | 1735e439353a020495075f8c00afc5bdcfef2709dbe885b64e3b7eaf65ed44e8 |
File details
Details for the file cxrandomwalk-0.5.8-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: cxrandomwalk-0.5.8-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 27.9 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a32a3b25f4dbd339d06f5026597e351a4007b0a758a40de3f40da43cad56901c |
|
MD5 | 3c926ec38d36cfde25f9d8868c28ebf5 |
|
BLAKE2b-256 | baecccb284eb5bf77c469217967c10d780e68b7d897b09adb8f9434f59af45a0 |
File details
Details for the file cxrandomwalk-0.5.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: cxrandomwalk-0.5.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 428.0 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50db4a2f52661386b8b0f6824a3b91619acfbb524293e98d8f68fcfa5d6db32a |
|
MD5 | 2699750c4705cbf9548e9e37e00c4f7e |
|
BLAKE2b-256 | 9dfe0e6b0ccf3a9a46951333ceb1d0cab27baa0920b955af0281208fd77e2a40 |
File details
Details for the file cxrandomwalk-0.5.8-cp310-cp310-macosx_11_0_arm64.whl
.
File metadata
- Download URL: cxrandomwalk-0.5.8-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 66.5 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a70e40067181d9a386b671ac99b556f13fc361bab9cce9d0bffdb09f00202d6 |
|
MD5 | bd72fe7df99ca77ecfba7a385069f93d |
|
BLAKE2b-256 | 96d5b971851a87d71431e8696d753a74fdde7d648b36b71cfdf1456980e99243 |
File details
Details for the file cxrandomwalk-0.5.8-cp310-cp310-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: cxrandomwalk-0.5.8-cp310-cp310-macosx_10_9_x86_64.whl
- Upload date:
- Size: 73.3 kB
- Tags: CPython 3.10, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcc64880d5ccf23365390e3b6b8a5c94fe5f99dc8a192b958a75e2c0930c870d |
|
MD5 | 882d2822e99173e4ccb038a6fabba63f |
|
BLAKE2b-256 | f9226dad6a8c799e94409a8019c183d0ba74e3bfaab751f778e1fde64caef7d7 |
File details
Details for the file cxrandomwalk-0.5.8-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: cxrandomwalk-0.5.8-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 27.9 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04154b96a69c4e4297c1eb59dbf871f7dd2d60aeb322959e29156bc1b966dc6c |
|
MD5 | 97f2cfde513b7299d66cb37f6c6ff768 |
|
BLAKE2b-256 | 9620e18491c0e189d08c2c6f2d50504f7f80f372e0d374f9a23e09988ce5fee7 |
File details
Details for the file cxrandomwalk-0.5.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: cxrandomwalk-0.5.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 428.0 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7dfb4722c344d9e4b3e99b3a10dde76fb060733437a4ea97eb1763e25ebb513f |
|
MD5 | 7e8127f4d798468cd636821cab695a11 |
|
BLAKE2b-256 | 97ba1c52294bee5e7e801ab5bb821c83d29c3f854b596de5f34980cb07c5c874 |
File details
Details for the file cxrandomwalk-0.5.8-cp39-cp39-macosx_11_0_arm64.whl
.
File metadata
- Download URL: cxrandomwalk-0.5.8-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 66.5 kB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca6efbf09cfa51d0b35283f04ddbda0d79cc67e9681312e8cfa10d901e9cb64d |
|
MD5 | df50cfd58ae045cd0daa8d5b7de7879d |
|
BLAKE2b-256 | b80357354256bea3e31461782a0b377d13b065850640e7c0f47a74e9016dfe35 |
File details
Details for the file cxrandomwalk-0.5.8-cp39-cp39-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: cxrandomwalk-0.5.8-cp39-cp39-macosx_10_9_x86_64.whl
- Upload date:
- Size: 73.3 kB
- Tags: CPython 3.9, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc7c2e30d2d76af90ec060a7a4c704b88eff51190765178084d57b96e98111f4 |
|
MD5 | 155a08fd5a1f5b678973eaca0baa8968 |
|
BLAKE2b-256 | e41ccdb209ec9ac52082c52707c44beec0dc25abb32781385e440855f8aea893 |