Skip to main content

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 network
  • edges - list of edges
  • directed - directed or not
  • weights - 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 walk
  • walksPerNode - number of sentences to be generated
  • verbose - enable verbose mode
  • filename - save sentences to filename instead of returning the sequences
  • callback - callback function that runs
  • updateInterval - 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

cxrandomwalk-0.5.9.tar.gz (74.5 kB view details)

Uploaded Source

Built Distributions

cxrandomwalk-0.5.9-cp312-cp312-win_amd64.whl (27.9 kB view details)

Uploaded CPython 3.12 Windows x86-64

cxrandomwalk-0.5.9-cp312-cp312-macosx_11_0_arm64.whl (66.5 kB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

cxrandomwalk-0.5.9-cp312-cp312-macosx_10_9_x86_64.whl (73.4 kB view details)

Uploaded CPython 3.12 macOS 10.9+ x86-64

cxrandomwalk-0.5.9-cp311-cp311-win_amd64.whl (27.9 kB view details)

Uploaded CPython 3.11 Windows x86-64

cxrandomwalk-0.5.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (428.5 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

cxrandomwalk-0.5.9-cp311-cp311-macosx_11_0_arm64.whl (66.5 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

cxrandomwalk-0.5.9-cp311-cp311-macosx_10_9_x86_64.whl (73.3 kB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

cxrandomwalk-0.5.9-cp310-cp310-win_amd64.whl (27.9 kB view details)

Uploaded CPython 3.10 Windows x86-64

cxrandomwalk-0.5.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (428.0 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

cxrandomwalk-0.5.9-cp310-cp310-macosx_11_0_arm64.whl (66.5 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

cxrandomwalk-0.5.9-cp310-cp310-macosx_10_9_x86_64.whl (73.3 kB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

cxrandomwalk-0.5.9-cp39-cp39-win_amd64.whl (27.9 kB view details)

Uploaded CPython 3.9 Windows x86-64

cxrandomwalk-0.5.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (428.0 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

cxrandomwalk-0.5.9-cp39-cp39-macosx_11_0_arm64.whl (66.5 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

cxrandomwalk-0.5.9-cp39-cp39-macosx_10_9_x86_64.whl (73.3 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

File details

Details for the file cxrandomwalk-0.5.9.tar.gz.

File metadata

  • Download URL: cxrandomwalk-0.5.9.tar.gz
  • Upload date:
  • Size: 74.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for cxrandomwalk-0.5.9.tar.gz
Algorithm Hash digest
SHA256 a26fec870f7ef63be3f2929424c838fa23eb4afd5862ae472f074ab4fd5d3131
MD5 7e66f14f235a81d74c02f3de4b425632
BLAKE2b-256 67b1ea6d3f6e2f4eed3f9eda3b9170bca395c0b69943c541a8b228b550ac38ca

See more details on using hashes here.

File details

Details for the file cxrandomwalk-0.5.9-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for cxrandomwalk-0.5.9-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 5fe104ad7dac5381b057ae25e807fdc16dd8dea909281059e522bdd8046afe49
MD5 96e1268d9bf2d43a24b8766c729a45a4
BLAKE2b-256 7eacffc8f2163d72c745c0188f0368e0f745d34b5ba4346f1501b8ffbf838b5f

See more details on using hashes here.

File details

Details for the file cxrandomwalk-0.5.9-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cxrandomwalk-0.5.9-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2c332054b215f6a09c0af9d36fc2ce6d2980a11f53dc6e97b940e4e9ec1feea8
MD5 27bb8fa0b8a7d0abb610a4a4ebb9e0fa
BLAKE2b-256 793fe4f40328ad4416dd53e763279828da7b66744293e66d733da5888867d43b

See more details on using hashes here.

File details

Details for the file cxrandomwalk-0.5.9-cp312-cp312-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for cxrandomwalk-0.5.9-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 74631a6c52b33dce41a92e33a1d7619f333222c4f23a1380eabff07780e8b0a9
MD5 127ce51d6b6bc49558608c87bb78ebb7
BLAKE2b-256 a418c8a01ec1c419dd2ed2572135d54ab005fa2b942d24164bde5aa07a88d925

See more details on using hashes here.

File details

Details for the file cxrandomwalk-0.5.9-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for cxrandomwalk-0.5.9-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 29265fff630d01d00bc4e4c9844c41f526cf9d887a2aaed5d30b2a6349145c4a
MD5 b621b90daba25ee38cb0b6d24736a3d6
BLAKE2b-256 76ed7de708b72fcd18aaad9e032b922d3130a26dbaa9f3d34346936a4daa97a3

See more details on using hashes here.

File details

Details for the file cxrandomwalk-0.5.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cxrandomwalk-0.5.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0424968874d24d860c65ebac96961dcc5182d528057f6a0e85060875e44a2f84
MD5 efa24d221ff30b8895374c576cb20420
BLAKE2b-256 ba63f85945619348017bdb77843752815c20ef3240f77d4ffed85fce80f70dd9

See more details on using hashes here.

File details

Details for the file cxrandomwalk-0.5.9-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cxrandomwalk-0.5.9-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f11f9db54c57dc7e7127bdeb296d4f06a7c33f132ccf338a849f677d6a4235d7
MD5 db5179b6ed0a82b162f822c3041e1899
BLAKE2b-256 9a1e45309a76936a5a2b87da4a5ba3f02ccb4147642c44d760a0b4c3c3d6fe69

See more details on using hashes here.

File details

Details for the file cxrandomwalk-0.5.9-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for cxrandomwalk-0.5.9-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 cd387a4b4459824f30c2eb23e11b7aff52c32047f77c0825ddb68a890b7991e1
MD5 f80f03792ccb88e810a251c4de55df94
BLAKE2b-256 705b0c7f21fedd61e456477796049690ebab400bacf77d985dac9618b2bb18dc

See more details on using hashes here.

File details

Details for the file cxrandomwalk-0.5.9-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for cxrandomwalk-0.5.9-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 83dda9a7b137f4d06f9d70a57f5565085e1cf0145e45c56ec7062e1530b88511
MD5 b6e50a9d5c9bd45c758a4433773d6f2d
BLAKE2b-256 7609fe6202fdc192e2a96a900461ea8bef70be3d07aae318a0ba911e6941afd6

See more details on using hashes here.

File details

Details for the file cxrandomwalk-0.5.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cxrandomwalk-0.5.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1e22666f883141dbf1ee76af1d62e4528fff1d85af7d842c4e7235c58567ed75
MD5 df69794a84118707dfa2cc775729ebb1
BLAKE2b-256 1c77a8f39fe9dc5349d0166f0d6eb1fbf1ebd000792ef672ba8ba54354ae1f60

See more details on using hashes here.

File details

Details for the file cxrandomwalk-0.5.9-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cxrandomwalk-0.5.9-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fe17a0bf3c2fe41fe5b694a0a93096fa04b9bb917695c7f831b04536acfeef19
MD5 f1e3ff28756669c1c99d878ca145d42e
BLAKE2b-256 4411bab4834206bd21810bf4a5292a20606c11aa6535375edd584d0cd1b4df2a

See more details on using hashes here.

File details

Details for the file cxrandomwalk-0.5.9-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for cxrandomwalk-0.5.9-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 dce23bff44492c8dbfd2b99d5f74ef09d5932b8e53c5de5241fed9c1d813f26b
MD5 892c34bf9671a6cbbde99499666861ed
BLAKE2b-256 cf60839deaedc26dc5179240fdad54ebdc227c484251067067225c5baa0ca3f1

See more details on using hashes here.

File details

Details for the file cxrandomwalk-0.5.9-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for cxrandomwalk-0.5.9-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 b8070125c9e9f2833cf3cd67441f0603be0abef6fd69384beb9c783c9d267704
MD5 2d14b40c5307a0bce617e74fdaecc263
BLAKE2b-256 4869a82d87856691a05b6ff0785699575707b915d71711d655b18d4a24b96704

See more details on using hashes here.

File details

Details for the file cxrandomwalk-0.5.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cxrandomwalk-0.5.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 96dfc017f44a173aacefb185a53d3209bd5a9cd3cde0ae4d01946567798a9fa3
MD5 cf8d66c2fcd195f15f5aa0a1fc570d7d
BLAKE2b-256 15c7a36739b8819f3a4298e090dfef2f5ee7ea07ae8dafa16c2a2a9de8a08d90

See more details on using hashes here.

File details

Details for the file cxrandomwalk-0.5.9-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cxrandomwalk-0.5.9-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aa0f0c7e7c3c697f2abb109d910925caadf9ead69cf996cf05748d151dea66ab
MD5 7d4fd9591fbee7b961df4a8d9b5225b9
BLAKE2b-256 bc35f31f49ca4df92e45e6b1806f1c913e35e4996dc4ab8dd96ba82dfd0c7649

See more details on using hashes here.

File details

Details for the file cxrandomwalk-0.5.9-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for cxrandomwalk-0.5.9-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 74c3d74932f72349ae1cdcebaa74dbac1bb433538de2e2e1b7dcc5733951eaff
MD5 909527773b8dc2076a3a354f0493df48
BLAKE2b-256 9d468760699d4b35b5d3d3c2123b2cbdd793752cbdc31a3d7198b0993ad22ba8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page