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())))
Metadata
Release files for cxrandomwalk 0.5.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cxrandomwalk-0.5.9.tar.gz | 74.5 kB | Details |
Built distributions (wheels)
Total release size: 2.0 MB
Release files / cxrandomwalk-0.5.9.tar.gz
| Download URL | cxrandomwalk-0.5.9.tar.gz |
|---|---|
| Size | 74.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a26fec870f7ef63be3f2929424c838fa23eb4afd5862ae472f074ab4fd5d3131
|
|
BLAKE2b-256 checksum How to use checksums |
67b1ea6d3f6e2f4eed3f9eda3b9170bca395c0b69943c541a8b228b550ac38ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / cxrandomwalk-0.5.9-cp312-cp312-win_amd64.whl
| Download URL | cxrandomwalk-0.5.9-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 27.9 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
5fe104ad7dac5381b057ae25e807fdc16dd8dea909281059e522bdd8046afe49
|
|
BLAKE2b-256 checksum How to use checksums |
7eacffc8f2163d72c745c0188f0368e0f745d34b5ba4346f1501b8ffbf838b5f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / cxrandomwalk-0.5.9-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | cxrandomwalk-0.5.9-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 66.5 kB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
2c332054b215f6a09c0af9d36fc2ce6d2980a11f53dc6e97b940e4e9ec1feea8
|
|
BLAKE2b-256 checksum How to use checksums |
793fe4f40328ad4416dd53e763279828da7b66744293e66d733da5888867d43b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / cxrandomwalk-0.5.9-cp312-cp312-macosx_10_9_x86_64.whl
| Download URL | cxrandomwalk-0.5.9-cp312-cp312-macosx_10_9_x86_64.whl |
|---|---|
| Size | 73.4 kB |
| Tags | CPython 3.12 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
74631a6c52b33dce41a92e33a1d7619f333222c4f23a1380eabff07780e8b0a9
|
|
BLAKE2b-256 checksum How to use checksums |
a418c8a01ec1c419dd2ed2572135d54ab005fa2b942d24164bde5aa07a88d925
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / cxrandomwalk-0.5.9-cp311-cp311-win_amd64.whl
| Download URL | cxrandomwalk-0.5.9-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 27.9 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
29265fff630d01d00bc4e4c9844c41f526cf9d887a2aaed5d30b2a6349145c4a
|
|
BLAKE2b-256 checksum How to use checksums |
76ed7de708b72fcd18aaad9e032b922d3130a26dbaa9f3d34346936a4daa97a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / cxrandomwalk-0.5.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | cxrandomwalk-0.5.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 428.5 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
0424968874d24d860c65ebac96961dcc5182d528057f6a0e85060875e44a2f84
|
|
BLAKE2b-256 checksum How to use checksums |
ba63f85945619348017bdb77843752815c20ef3240f77d4ffed85fce80f70dd9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / cxrandomwalk-0.5.9-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | cxrandomwalk-0.5.9-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 66.5 kB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
f11f9db54c57dc7e7127bdeb296d4f06a7c33f132ccf338a849f677d6a4235d7
|
|
BLAKE2b-256 checksum How to use checksums |
9a1e45309a76936a5a2b87da4a5ba3f02ccb4147642c44d760a0b4c3c3d6fe69
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / cxrandomwalk-0.5.9-cp311-cp311-macosx_10_9_x86_64.whl
| Download URL | cxrandomwalk-0.5.9-cp311-cp311-macosx_10_9_x86_64.whl |
|---|---|
| Size | 73.3 kB |
| Tags | CPython 3.11 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
cd387a4b4459824f30c2eb23e11b7aff52c32047f77c0825ddb68a890b7991e1
|
|
BLAKE2b-256 checksum How to use checksums |
705b0c7f21fedd61e456477796049690ebab400bacf77d985dac9618b2bb18dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / cxrandomwalk-0.5.9-cp310-cp310-win_amd64.whl
| Download URL | cxrandomwalk-0.5.9-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 27.9 kB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
83dda9a7b137f4d06f9d70a57f5565085e1cf0145e45c56ec7062e1530b88511
|
|
BLAKE2b-256 checksum How to use checksums |
7609fe6202fdc192e2a96a900461ea8bef70be3d07aae318a0ba911e6941afd6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / cxrandomwalk-0.5.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | cxrandomwalk-0.5.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 428.0 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
1e22666f883141dbf1ee76af1d62e4528fff1d85af7d842c4e7235c58567ed75
|
|
BLAKE2b-256 checksum How to use checksums |
1c77a8f39fe9dc5349d0166f0d6eb1fbf1ebd000792ef672ba8ba54354ae1f60
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / cxrandomwalk-0.5.9-cp310-cp310-macosx_11_0_arm64.whl
| Download URL | cxrandomwalk-0.5.9-cp310-cp310-macosx_11_0_arm64.whl |
|---|---|
| Size | 66.5 kB |
| Tags | CPython 3.10 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
fe17a0bf3c2fe41fe5b694a0a93096fa04b9bb917695c7f831b04536acfeef19
|
|
BLAKE2b-256 checksum How to use checksums |
4411bab4834206bd21810bf4a5292a20606c11aa6535375edd584d0cd1b4df2a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / cxrandomwalk-0.5.9-cp310-cp310-macosx_10_9_x86_64.whl
| Download URL | cxrandomwalk-0.5.9-cp310-cp310-macosx_10_9_x86_64.whl |
|---|---|
| Size | 73.3 kB |
| Tags | CPython 3.10 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
dce23bff44492c8dbfd2b99d5f74ef09d5932b8e53c5de5241fed9c1d813f26b
|
|
BLAKE2b-256 checksum How to use checksums |
cf60839deaedc26dc5179240fdad54ebdc227c484251067067225c5baa0ca3f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / cxrandomwalk-0.5.9-cp39-cp39-win_amd64.whl
| Download URL | cxrandomwalk-0.5.9-cp39-cp39-win_amd64.whl |
|---|---|
| Size | 27.9 kB |
| Tags | CPython 3.9 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
b8070125c9e9f2833cf3cd67441f0603be0abef6fd69384beb9c783c9d267704
|
|
BLAKE2b-256 checksum How to use checksums |
4869a82d87856691a05b6ff0785699575707b915d71711d655b18d4a24b96704
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / cxrandomwalk-0.5.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | cxrandomwalk-0.5.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 428.0 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
96dfc017f44a173aacefb185a53d3209bd5a9cd3cde0ae4d01946567798a9fa3
|
|
BLAKE2b-256 checksum How to use checksums |
15c7a36739b8819f3a4298e090dfef2f5ee7ea07ae8dafa16c2a2a9de8a08d90
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / cxrandomwalk-0.5.9-cp39-cp39-macosx_11_0_arm64.whl
| Download URL | cxrandomwalk-0.5.9-cp39-cp39-macosx_11_0_arm64.whl |
|---|---|
| Size | 66.5 kB |
| Tags | CPython 3.9 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
aa0f0c7e7c3c697f2abb109d910925caadf9ead69cf996cf05748d151dea66ab
|
|
BLAKE2b-256 checksum How to use checksums |
bc35f31f49ca4df92e45e6b1806f1c913e35e4996dc4ab8dd96ba82dfd0c7649
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / cxrandomwalk-0.5.9-cp39-cp39-macosx_10_9_x86_64.whl
| Download URL | cxrandomwalk-0.5.9-cp39-cp39-macosx_10_9_x86_64.whl |
|---|---|
| Size | 73.3 kB |
| Tags | CPython 3.9 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
74c3d74932f72349ae1cdcebaa74dbac1bb433538de2e2e1b7dcc5733951eaff
|
|
BLAKE2b-256 checksum How to use checksums |
9d468760699d4b35b5d3d3c2123b2cbdd793752cbdc31a3d7198b0993ad22ba8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|