Skip to content

Instantly share code, notes, and snippets.

View ytakashina's full-sized avatar
🌊

Yuya Takashina ytakashina

🌊
View GitHub Profile
  • IO
N = int(input())
l = len(str(N))-1
print(l*9 + ((N+1)//(10**l)-1))
@ytakashina
ytakashina / bayesian_networks.py
Last active April 8, 2018 02:36
Discrete bayesian_networks
def counts_given_parents(adj, X):
n, d = X.shape
states_list = [set(col) for col in X.T]
pstates_list = [Counter(map(tuple, X[:, adj.T[i]])).keys() for i in range(d)]
counts = {i: {j: {k: np.count_nonzero(X[:, i] == k)
for k in states_list[i]}
for j in pstates_list[i]}
for i in range(d)}
return counts
@ytakashina
ytakashina / gao2017estimating.ipynb
Last active April 8, 2018 02:36
追試: Gao, Weihao, et al. "Estimating mutual information for discrete-continuous mixtures." Advances in Neural Information Processing Systems. 2017.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Networks

g = ig.Graph.Adjacency((pre_h_pred != 0).tolist())
g.es['weight'] = pre_h_pred[pre_h_pred.nonzero()]
g.vs['label'] = list(geos.values())
layt = g.layout('kk', dim=2)
N = len(pre_h_pred)
Xn = [layt[n][0] for n in range(N)]
Yn = [layt[n][1] for n in range(N)]
  • 全組み合わせ列挙
np.hstack([np.repeat(X, len(Y), axis=0), np.tile(Y, [len(X), 1])])
  • マハラノビス距離計算

Pandas

gb = df.groupby('category')
gb.groups
gb.get_group(1)

Debug

@ytakashina
ytakashina / plotly-network.py
Created August 25, 2017 11:12
plotly でネットワークを描画しようとした
import plotly
import plotly.offline as py
import plotly.graph_objs as go
plotly.offline.init_notebook_mode(connected=True)
# pos = nx.spring_layout(graph)
pos = nx.circular_layout(graph)
Xv = [v[0] for v in pos.values()]
Yv = [v[1] for v in pos.values()]
@ytakashina
ytakashina / pip
Last active August 17, 2017 01:25
pip install tqdm numpy cupy scipy scikit-learn pandas seaborn bokeh graphviz pystan chainer tensorflow keras
@ytakashina
ytakashina / setup.sh
Last active September 25, 2017 12:30
if [ "$(id -u)" != "0" ]; then
echo "Installation was failed. Run as a super user!" 1>&2
return 1
fi
apt update && apt -y upgrade
apt install -y git vim w3m wget tmux vsftpd graphviz openssh-server build-essential
apt upgrade gcc cmake