This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Efraimidis and Spirakis algorithm | |
# https://www.sciencedirect.com/science/article/abs/pii/S002001900500298 | |
import numpy as np | |
from numba import njit | |
@njit(nogil=True) | |
def one_pass_sampling_without_replacement(n, k, weights): | |
# Draw a uniform random variable for each item | |
u = np.random.rand(n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from scipy import sparse | |
# | |
# Evaluation | |
# | |
def calc_esim(y, ypred, normalize=False): | |
""" | |
Element centric similarity. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Non-backtracking spectral embedding | |
Reference | |
--------- | |
Krzakala, Florent, et al. "Spectral redemption in clustering sparse networks." Proceedings of the National Academy of Sciences 110.52 (2013): 20935-20940. | |
Example | |
------- | |
```python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# @Author: Sadamori Kojaku | |
# @Date: 2022-10-05 06:24:53 | |
# @Last Modified by: Sadamori Kojaku | |
# @Last Modified time: 2023-05-19 13:04:26 | |
import sys | |
from tqdm.auto import tqdm | |
import numpy as np | |
import pandas as pd | |
import torch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def truncated_RBO(S, T, p=0.9): | |
""" | |
Calculate the (truncated) Rank Biased Overlap (RBO) similarity measure between two ranked lists S and T. | |
The original RBO takes the sum over entities beyond the ranking. Since the entities outside of the ranking is unknown, | |
the original paper introduces an exterpolation method. But this gives many complexity with additional assumptions on the input data. | |
So I take a simpler approach: | |
1. Instead of considering a ranking of infinite length, I consider finite ranking and take a sum over the entities in the ranking. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def degreeAssortativity(src, trg, weight=None) -> float: | |
""" | |
Computes the degree assortativity of a graph based on the source and target node degrees and an optional edge weight. | |
Parameters | |
---------- | |
src : array-like | |
The source nodes of the edges. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# @Author: Sadamori Kojaku | |
# @Date: 2023-04-26 12:02:58 | |
# @Last Modified by: Sadamori Kojaku | |
# @Last Modified time: 2023-04-26 12:05:15 | |
import numpy as np | |
class ADAM: | |
def __init__(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import country_converter as coco | |
import networkx as nx | |
import numpy as np | |
import pandas as pd | |
from scipy import sparse | |
from scipy.sparse.csgraph import connected_components | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# @Author: Sadamori Kojaku | |
# @Date: 2023-04-14 17:09:54 | |
# @Last Modified by: Sadamori Kojaku | |
# @Last Modified time: 2023-04-17 06:11:17 | |
import faiss | |
import numpy as np | |
from numba import jit | |
from scipy import sparse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from scipy import sparse | |
import numpy as np | |
def fastRP(net, dim, window_size, beta=-1, s=3.0, edge_direction=False): | |
""" | |
.. function:: fastRP(net: scipy.sparse matrix, dim: int, window_size: int, beta: float = -1, s: float = 3.0, return_context: bool = False) -> numpy.ndarray | |
Fast Random Projection embedding |
NewerOlder