Skip to main content

TP Similarity

TP Similarity is a Python package for computing Transition Probability (TP) similarities between nodes in a network. It offers various methods to estimate these similarities, including exact computation, estimation via random walks, shortest paths, and node2vec-based cosine similarity.

Build Status Coverage Status

Table of Contents

Overview

TP similarity is a measure designed for papers and authors, simulating a literature search procedure on citation networks. Inspired by information retrieval concepts, this approach does not rely on curated classification systems, avoids clustering complexities, and provides a continuous measure of similarity between nodes. By implementing the TP similarity measure, researchers can approximate the research interest similarity of individual scientists using publication-level information.

The package accompanies the paper:

Varga, Attila, Sadamori Kojaku, and Filipi N. Silva. "Measuring Research Interest Similarity with Transition Probabilities." arXiv preprint arXiv:2409.18240 (2024). Available on arXiv

Installation

Install the package using pip:

pip install tpsimilarity

Features

  • Exact Transition Probabilities (TP): Computes the exact transition probabilities between nodes in a graph.
  • Estimated Transition Probabilities: Estimates transition probabilities using random walks.
  • Shortest Paths Transition Probabilities: Computes transition probabilities along the shortest paths.
  • Node2Vec Similarity: Computes cosine similarity between node embeddings generated by node2vec.

Getting Started

Prerequisites

  • Python: Version 3.6 or higher
  • Dependencies:
    • numpy
    • scipy
    • gensim
    • tqdm
    • joblib
    • igraph
    • (optional) networkx

Install the dependencies using:

pip install numpy scipy networkx gensim tqdm joblib igraph

Importing the Package

from tpsimilarity import similarity

Example Usage

1. Compute Exact Transition Probabilities (TP)

import networkx as nx
import igraph as ig
from tpsimilarity import similarity

# Create or load your graph
G = nx.karate_club_graph()

# Convert NetworkX graph to iGraph
G = ig.Graph.from_networkx(G)

# Define sources and targets
sources = [0, 1, 2]  # Source nodes
targets = [3, 4, 5]  # Target nodes

# Compute exact TP similarities
tp_sim = similarity.TP(
    graph=G,
    sources=sources,
    targets=targets,
    window_length=5
)

# tp_sim contains the similarity matrix or list based on return_type

2. Compute Estimated Transition Probabilities

# Estimate TP similarities using random walks
estimated_tp = similarity.estimatedTP(
    graph=G,
    sources=sources,
    targets=targets,
    window_length=5,
    walks_per_source=1000,
    batch_size=100,
    return_type="matrix",
    degreeNormalization=True,
    progressBar=True
)

3. Compute Node2Vec Similarity

# Compute node2vec-based cosine similarities
node2vec_sim = similarity.node2vec(
    graph=G,
    sources=sources,
    targets=targets,
    dimensions=64,
    window_length=40,
    context_size=5,
    workers=4,
    batch_walks=100,
    return_type="matrix",
    progressBar=True
)

4. Compute Shortest Paths Transition Probabilities

# Compute TP similarities along shortest paths
sp_tp = similarity.shortestPathsTP(
    graph=G,
    sources=sources,
    targets=targets,
    window_length=5
)

Parameters

  • graph (networkx.Graph or igraph.Graph): The graph on which to compute the similarities.
  • sources (list): List of source node indices.
  • targets (list): List of target node indices.
  • window_length (int): The length of the random walks.
  • return_type (str, optional): The format of the output ("list", "matrix", or "dict"). Default is "matrix".
  • degreeNormalization (bool, optional): Whether to normalize by the degree of the target node. Default is True.
  • dimensions (int, optional): Number of dimensions for node embeddings in node2vec. Default is 64.
  • context_size (int, optional): Context size for the node2vec algorithm. Default is 10.
  • workers (int, optional): Number of parallel workers for node2vec. Default is 4.
  • batch_walks (int, optional): Number of walks per batch for node2vec. Default is 10000.
  • progressBar (bool or tqdm, optional): Whether to display a progress bar during computation. Default is True.

Examples

You can find more examples and tutorials in the examples directory or in the Jupyter notebooks provided.

Authors

  • Attila Varga
  • Sadamori Kojaku
  • Filipi N. Silva

License

This project is licensed under the MIT License. See the LICENSE file for details.

Metadata

Release files for tpsimilarity 0.6.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tpsimilarity 0.6.1
File Size Uploaded
tpsimilarity-0.6.1.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tpsimilarity 0.6.1
File Interpreter ABI Platform
tpsimilarity-0.6.1-py3-none-any.whl Python 3 none any Details

Total release size: 15.7 kB

Release files / tpsimilarity-0.6.1.tar.gz

Download URL tpsimilarity-0.6.1.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
92c8ad43c567257a5859e33f71bc9e6459db4ea51db852eb70cedb57ffcf212c
BLAKE2b-256 checksum
How to use checksums
0b477f60010b466e0ab2aa9bffba6fa12c83b8acbc315e11e7239ace86632e33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 20, 2025.

Transparency log

Release files / tpsimilarity-0.6.1-py3-none-any.whl

Download URL tpsimilarity-0.6.1-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
766c76a6684d448cca2855d3a454bc3596ed55d03738c40509b0efc65792071d
BLAKE2b-256 checksum
How to use checksums
c78060d78a8676224a48e0d07e5593199c90a7f68e2f7bd85ebff1c5eada9d9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 20, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.6.1 This release

2 release files

0.6.0

2 release files

0.3.1

1 release file

0.3

1 release file

0.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page