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
# I found all over the place for a O(n^3) minimum cost bipartite matching | |
# or equivalently maximum weight bipartite matching algorithm but I | |
# cannot find a clean but precise explanation; the Wikipedia ones, | |
# Stack Overflow, and course materials are either too high-level | |
# or only O(n^4). | |
# So I decided to read the original paper of Edmunds and Karp. The | |
# idea is surprisingly simple: just always find a shortest path (that | |
# has minimum cost) to augment and you will be good. In fact they | |
# talked about minimum cost maximum flow problem, but minimum weight | |
# bipartite matching is just a special case of that. |
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
#!/usr/bin/env python | |
# coding: utf-8 | |
import torch | |
import torch.nn as nn | |
import torch.nn.functional as F | |
import tqdm | |
def reverse_permute(x): | |
return torch.zeros_like(x).scatter_( |
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 scipy.sparse as ssp | |
import numpy as np | |
from sklearn.preprocessing import normalize | |
from numba.typed import Dict | |
from numba import jit, types, njit, prange | |
@njit(parallel=True, nogil=True) | |
def reverse_push_bipartite(A_indptr, A_indices, A_data, nL, nR, r_max, alpha): | |
''' |
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 | |
import torch | |
import time | |
import pandas as pd | |
import tqdm | |
B, L, N, H, W = 64, 50, 10, 256, 3 | |
print('warming up') | |
for _ in tqdm.trange(10): |
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 | |
import dgl | |
import os | |
import torch | |
class MovieLens(object): | |
def __init__(self, directory): | |
''' | |
directory: path to movielens directory which should have the three | |
files: |
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
class Node(object): | |
def __init__(self, key, red): | |
self.key = key | |
self.left = self.right = self.parent = None | |
self.red = red | |
@property | |
def grandparent(self): | |
if self.parent is None: |
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 torch | |
import time | |
N = 10000 | |
D = 50 | |
E = 500000 | |
T = 10 | |
t_gather = 0 | |
t_scatter = 0 |
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
#include <unordered_map> | |
#include <map> | |
#include <vector> | |
#include <iostream> | |
#include <utility> | |
#include <cstdint> | |
#include <ctime> | |
#include <cstdlib> | |
using std::uint64_t; |
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
# References: | |
# https://arxiv.org/pdf/1405.5869.pdf | |
# https://arxiv.org/abs/1507.05910 | |
import numpy as np | |
from scipy.spatial.distance import cosine | |
# Rescaling and appending new components to "normalize" data vectors | |
X = np.random.randn(10000, 100) | |
Xn = np.sqrt((X ** 2).sum(1)) |
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 torch as T | |
import numpy as np | |
x = T.autograd.Variable(T.randn(5, 8), requires_grad=True) | |
p = T.nn.functional.softmax(x) | |
y = p.multinomial() | |
y.reinforce(T.ones(y.size())) | |
y.backward() | |
d = x.grad.data.clone().numpy() | |
x.grad.data.zero_() | |
logp = T.nn.functional.log_softmax(x) |
NewerOlder