Python implementation of the Multilayer Personalized Page Rank algorithm
Project description
MuLP
This repository/package includes a python script that implements the MultilayerCreditScoring (MCS) algorithim presented in Bravo and Óskarsdóttir (2020) and Óskarsdóttir and Bravo (2021, ArXiV , Publisher)
Installation
pip install MuLP
Input instructions
There are three primary input files:
- Individual layer files (.ncol)
- Common Nodes file (csv)
- Personal Node file (csv)
Each layer in the multilayer network requires its own .ncol file with the appropriate ncol file format.
Example ncol layer file (.ncol):
CommonNodeA SpecificNodeA
CommonNodeB SpecificNodeA
CommonNodeC SpecificNodeB
CommonNodeD SpecificNodeC
The inter-layer connections are only allowed between common nodes as to follow the structure layed out by Óskarsdóttir & Bravo (2021):
Example input file(.csv):
CommonNode1
CommonNode2
CommonNode3
To construct the personal matrix one must specify the influence (or personal) nodes in the following format:
Example input file(.csv):
InfluentialNode1
InfluentialNode2
InfluentialNode3
Usage
Multilayer Network Initialization
To create a Multilayer Network the following arguments are available:
layer_files (list)
: list of layer files
common_nodes_file (str)
: csv file to common nodes
personal_file (str)
: file to create personal matrix
biderectional (bool, optional)
: wheter edges are biderectional or not. Defaults to False.
sparse (bool, optional)
: use sparse or desnse matrix. Defaults to True.
from MultiLayerRanker import MultiLayerRanker
ranker = MultiLayerRanker(layer_files=['products.ncol','districts.ncol'],
common_nodes_file= './common.csv',
personal_file= './personal.csv' ,
biderectional=True,
sparse = True)
Ranking
The rank
method of the MultiLayerRanker
class runs the
MultiLayer Personalized Page Rank Algorithm. One can choose to run different experiments with varyin alphas by specifying it in the method call:
alpha (int,optional)
: page rank exploration parameter, defaults to .85
eigs = ranker.pageRank(alpha = .85)
This method returns the leading eigenvector corresponding to each node's rank.
Output Formatting
The formattedRanks
method allows you to get the rankings with appropriate node labels in a dictionary format: x
eigs (ndarray)
: corresponding eigenvector to format
ranker.formattedRanks(eigs)
The adjDF
method allows you to view format a personal or adjacency matrix with corresponding labels as a dataframe:
matrix (ndarray)
: an adj matrix or personal matrix to transform
f (str,optional)
: Optional if you wish to write the df to an output csv
#for persoanl matrix
personalDF = ranker.toDf(ranker.personal)
#for adj matrix
adjDf = ranker.toDf(ranker.matrix)
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 Distribution
Built Distribution
File details
Details for the file MuLP-0.0.7.tar.gz
.
File metadata
- Download URL: MuLP-0.0.7.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | edb93ed490a9a2b3cc26b3ae18f38c2453aec204639ff03a84f9432ca0e54953 |
|
MD5 | ba075a076e277853c62ad67ae2387846 |
|
BLAKE2b-256 | 13d65a20a704456720b29d7d8158ef9b3be2222ecf0a17faa76e2a2979fa7f0a |
File details
Details for the file MuLP-0.0.7-py3-none-any.whl
.
File metadata
- Download URL: MuLP-0.0.7-py3-none-any.whl
- Upload date:
- Size: 17.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65866d000e660b1e23957863ae77d10dbddad67754ea03a66bf41de17bb479af |
|
MD5 | c34f86af5821cb635f19ae4dc36cc7bf |
|
BLAKE2b-256 | 58707fe12d8991a0386d5337fb3c7c0b5c5f4a6c7cca9e788667c085c077a558 |