Moved to: https://github.com/urigoren/nre
use
pip install nre
from itertools import combinations | |
from functools import reduce | |
from pprint import pprint as pr | |
def all_arrangements(k): | |
m=k*(k+1)/2 | |
m_bits_on=set([tuple(reduce(lambda x,y:x[:y]+[1]+x[y+1:],c,[0]*(2*m+1))) for c in combinations(range(2*m+1),m)]) | |
return set([tuple(sorted(filter(lambda i:i>0,reduce(lambda x,y: x+[y] if y==0 else x[:-1]+[x[-1]+1,],p,[0])))) for p in m_bits_on]) | |
def move(t,n=1): |
<?php | |
define('SLACK_WEBHOOK', 'https://hooks.slack.com/services/xxx/yyy/zzz'); | |
define('TELEGRAM_BOT_TOKEN', '...'); | |
define('TELEGRAM_CHAT_ID', '12345'); | |
function slack($txt) { | |
$msg = array('text' => $txt); | |
$c = curl_init(SLACK_WEBHOOK); | |
curl_setopt($c, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false); |
import numpy as np | |
from scipy import sparse | |
import collections | |
""" | |
#SPARK Co-Occurence Matrix | |
#Format: (vertex, vertex) : count | |
import json, operator, itertools | |
def cooccur_matrix(srcHdfs, product2vertex): | |
ret = sc.textFile(srcHdfs)\ |
from keras.layers import Dense, Dropout, LSTM, Embedding | |
from keras.preprocessing.sequence import pad_sequences | |
from keras.models import Sequential | |
import pandas as pd | |
import numpy as np | |
input_file = 'input.csv' | |
def load_data(test_split = 0.2): | |
print ('Loading data...') |
from itertools import chain | |
from functools import reduce | |
import operator | |
""" | |
Usage of this module: | |
<iterable> >> function3 * function2 * function1 >> aggregation | |
for example: |
hadoop fs -text $1>hvim.txt | |
vim hvim.txt | |
hadoop fs -rm -skipTrash $1 | |
hadoop fs -copyFromLocal hvim.txt $1 | |
rm hvim.txt | |
hadoop fs -chmod 777 $1 |
import numpy as np | |
from scipy.sparse import linalg, eye, csr_matrix | |
from sklearn.preprocessing import normalize | |
from sklearn.metrics.pairwise import pairwise_distances | |
from collections import defaultdict | |
class MarkovClustering: | |
def __init__(self, matrix, metric="cosine", bias=1): |
import ast, inspect, textwrap | |
whitelist = {'math', 'itertools', 'collections', 'functools', 'operator', | |
'json', 'pickle', 'string', 'types', 'statistics', 'fractions', 'decimal'} | |
def pure(f): | |
"""pure decorator""" | |
f.pure = True | |
return f |
import numpy as np | |
from matplotlib import pyplot as plt | |
def polyfit_plot(x, y, p=1): | |
plt.scatter(x, y) | |
axes = plt.gca() | |
coeff = np.polyfit(x, y, p) | |
X_plot = np.linspace(axes.get_xlim()[0],axes.get_xlim()[1],100) | |
print (np.corrcoef(x,y)[0,1]) | |
Y_plot = 0 |
Moved to: https://github.com/urigoren/nre
use
pip install nre