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
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
Hashes for cxrandomwalk-0.5.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f420b96a919299fca08e40f80eecc6590f9753979c8c780e9903deaad76ef741 |
|
MD5 | 4200848b25a4b19237c6d0262d888cd3 |
|
BLAKE2b-256 | 738440f76aa2264a070426a7ea6c7274c7f78eee2b4d343ea180920834dc8732 |
Hashes for cxrandomwalk-0.5.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d59041745f8f0badb8c5c8a6f377d90ba011c6f73fe468406556a1e5f7156687 |
|
MD5 | c2d33649e7bac3399b58b25ac03b150c |
|
BLAKE2b-256 | cd557949866faf39863c513c3fdb5ba3c49ef461554afdd2c57594c2a5e6b8ea |
Hashes for cxrandomwalk-0.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9963f7298f3d5875e7e9ebc10386cc6678f1206ace7492eadb476762295190b |
|
MD5 | 495c2b41c9747d9883922c590447b4a0 |
|
BLAKE2b-256 | d1814959053fc56816a8be3ec037fca2fbe25c3f266d6f67289a000c0e45f551 |
Hashes for cxrandomwalk-0.5.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c63b0812c29336dd0bc58af714021fd8eaabda83ba715422c15852270121e57b |
|
MD5 | 10417a9204d0e380421b69b680981e3c |
|
BLAKE2b-256 | 54a95773906516a3d2e24d21996849162418293101cc9d007adcfcd60755d57f |
Hashes for cxrandomwalk-0.5.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6d2c2aba84b46392a6461075d29858f4dcf8abcbcf9481d0e6eb366bceba13f |
|
MD5 | 5d316a490919156645e573a164b74e63 |
|
BLAKE2b-256 | cbdbef021c97e3943858d974123b426caf75437ad438acb1a8a73634d2de9169 |
Hashes for cxrandomwalk-0.5.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72333e427efdb1986eb0d7ba55c86cecd24925c8e6cc6229f50dae2fab260d33 |
|
MD5 | ad2ef9d466715208e061407789656c33 |
|
BLAKE2b-256 | a08725fce1c8361d8596adf55bfe7d7a42b17409323c9c2148340b92b7798a2c |
Hashes for cxrandomwalk-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e13cc48c8e2078ca4e1d7c455009d0cafb0ff58876df0106df3284ba45fd67c4 |
|
MD5 | a254661d7eae0e0605d8b10440e5ac3b |
|
BLAKE2b-256 | b239dd1fb092bc9038aa99057a07fe43f46f40160ccfd77f53fecd42ce04bc96 |
Hashes for cxrandomwalk-0.5.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bd7f55907534ff600812ee2472b3bf1c1f8d9013edc8f10902cb5589dcee4f1 |
|
MD5 | d008ec1c820db496e10b0cfb58a1b64a |
|
BLAKE2b-256 | 5b0784054e49c61f08c79b38ee7f562406fecf622dd1f93e4ee3eb0a2d4405ab |
Hashes for cxrandomwalk-0.5.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de037ba076cf3d2be9f0b48aea2c051ffc2eee303ce3bfcbede41a773de60a6a |
|
MD5 | 0b9ec57d4d2b6bc96a0db603a57e1573 |
|
BLAKE2b-256 | 938d1b6c261e08127280c0817becc80cf79f8b2e69e8e153803fb53182179195 |
Hashes for cxrandomwalk-0.5.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d9a4e099fd9814d69569851caa62980495cfd968dcb9c1c85b8dbf557c3e863 |
|
MD5 | 78bf9604a222a39d0fb0ccc93ba5df9f |
|
BLAKE2b-256 | 6798b9c05654c0dde959d1f51fe3fb72f3bd640d45b4bbe9d4116fb3e0a5efd6 |
Hashes for cxrandomwalk-0.5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33369c1a97d31d3377ae25e8f8fb69cabdee09a4f4f524b0a298f8350905c86a |
|
MD5 | 1b5b4893d9cfa4c14479c34dd0dff062 |
|
BLAKE2b-256 | 6924d01c1e30e392784649610e6c49d9722319384ac616ee63d8bc44ec45e951 |
Hashes for cxrandomwalk-0.5.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 918161a66d389620a565fac82c845e719d7cc41e2b08a305fea9567e6134a8ba |
|
MD5 | d9a1f5b84204187fc620be380358d343 |
|
BLAKE2b-256 | c652c8af2958feee57c71ccfe8ceeb915919a8f36c10d6d92672ce3a865d2ab8 |
Hashes for cxrandomwalk-0.5.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1ee89011200aa83a1a926dd7a5c2ca42ac147d29b6bec6dc19ba52c88042dcc |
|
MD5 | e90c36b524bdecce6ba4c280c86714d5 |
|
BLAKE2b-256 | 1c9ce57f347bcfbfcf3f368c47006a18c3e3488f2af7fccd4047676cc0cbfbd1 |
Hashes for cxrandomwalk-0.5.0-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80292c42b813f3e5902383a9bcfc38e2970701ead55c209fc63b48f8db2d4bcb |
|
MD5 | b57ecf214cdb05d69b075d48877325c6 |
|
BLAKE2b-256 | f39a719c0f64eb5f7ea07c8bf1be49151c6f4b267a23d4d4c638c67349a4bca4 |
Hashes for cxrandomwalk-0.5.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c368327f21da5ac29e5ab62e21b5342d133ca0375eb65ebe35b309a76efcb53 |
|
MD5 | 1a4ecbcd7f3c2af07a705182cebcc235 |
|
BLAKE2b-256 | 705c71e96a4fd41c935ba62a724520b51e93caa4776b60ed4eda9e419dada36a |
Hashes for cxrandomwalk-0.5.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66c8d29554329546febc1fd776cbed2e6183c76aebd8d2f7e4b1077e9d43bfda |
|
MD5 | df579aa89581804a51af5bd715c17aa2 |
|
BLAKE2b-256 | 69411a85bbcd35b3ea4436bcb5415996de3890a68f3a168ad8a1e38a6d62d45f |