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
def smart_procrustes_align_gensim(base_embed, other_embed, words=None): | |
""" | |
Original script: https://gist.github.com/quadrismegistus/09a93e219a6ffc4f216fb85235535faf | |
Procrustes align two gensim word2vec models (to allow for comparison between same word across models). | |
Code ported from HistWords <https://github.com/williamleif/histwords> by William Hamilton <[email protected]>. | |
First, intersect the vocabularies (see `intersection_align_gensim` documentation). | |
Then do the alignment on the other_embed model. | |
Replace the other_embed model's syn0 and syn0norm numpy matrices with the aligned version. | |
Return other_embed. |
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
from matplotlib import font_manager | |
fontprop = font_manager.FontProperties(fname='path\to\font\msyh.ttf') | |
plt.legend(prop=fontprop) | |
plt.xlabel('XXX',fontproperties=fontprop) | |
plt.ylabel('XXX',fontproperties=fontprop) | |
plt.title('XXX',fontproperties=fontprop) |
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
# radius of gyration | |
from collections import Counter | |
import math | |
def radius_of_gyration(positions): | |
""" | |
position : tuple | |
A tuple (lat, lon) with the latitude and longitude of the antenna, | |
encoded as floating point numbers. |
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
def plotDegreeDistribution(G): | |
from collections import defaultdict | |
import numpy as np | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
degs = defaultdict(int) | |
for i in G.degree().values(): degs[i]+=1 | |
items = sorted ( degs.items () ) | |
x, y = np.array(items).T | |
y = [float(i) / sum(y) for i in y] |