Skip to content

Instantly share code, notes, and snippets.

@ybenjo
ybenjo / test.py
Created May 4, 2020
scipy.sparse.csgraph.maximum_bipartite_matching is broken when get complete bipartite graph
View test.py
from scipy.sparse import lil_matrix, csr_matrix
from scipy.sparse.csgraph import maximum_bipartite_matching
import random
N = 10
M = 10
random.seed(0)
for x in range(5):
mat = lil_matrix((N, M))
@ybenjo
ybenjo / convert_checkins_json_to_ics.rb
Last active Jun 8, 2019
converts foursquare's (dumped) check-ins data to ics file.
View convert_checkins_json_to_ics.rb
# coding: utf-8
require 'json'
require 'time'
require 'digest/md5'
srand(0)
data = JSON.load(open("#{__dir__}/checkins.json").read)
output_file = "#{__dir__}/checkins.ics"
@ybenjo
ybenjo / nfm.py
Last active Mar 19, 2018
neural factorization machines (SIGIR 2017) unofficial code by Chainer
View nfm.py
import numpy as np
import chainer
from chainer import functions as F
from chainer import links as L
class NFMClassifier(chainer.Chain):
def __init__(self, n_feature, n_dim_emb, n_dim_1, n_dim_2):
np.random.seed(6162)
self.n_feature = n_feature
@ybenjo
ybenjo / bug.py
Last active Jul 27, 2017
xgboost bug (Classifier can't handle nested array)
View bug.py
from xgboost import XGBClassifier
model = XGBClassifier(seed = 1)
# XOR Pattern
train_data = [
[1, 0],
[0, 1],
[1, 1],
[0, 0],
@ybenjo
ybenjo / bug.py
Last active Jul 27, 2017
xgboost bug (handling nested array)
View bug.py
# Version: 0.6a2
from xgboost import XGBRegressor
model = XGBRegressor(seed = 1)
# XOR pattern + [0, 0, 0]
train_data = [
[1, 0] + [0] * 3,
[0, 1] + [0] * 3,
[1, 1] + [0] * 3,
@ybenjo
ybenjo / ccut
Last active Apr 27, 2016
cut with column names
View ccut
#!/usr/bin/env ruby
# cat data.tsv | ccut -d delim -c name,name,name...
require 'trollop'
opts = Trollop::options do
opt :delim, 'delimitor', default: "\t"
opt :column, 'column name(s)', type: String
end
delim = opts[:delim]
@ybenjo
ybenjo / ecoweb.py
Created Dec 30, 2015
The Web as a Jungle: Non-Linear Dynamical Systems for Co-evolving Online Activities (WWW 2015)
View ecoweb.py
import numpy as np
import sys
from collections import defaultdict
from lmfit import minimize, Parameters
from sklearn.decomposition import FastICA
import math
# This script is (incomplete and buggy) implementation of
# The Web as a Jungle: Non-Linear Dynamical Systems for Co-evolving Online Activities, (WWW 2015).
# http://www.cs.kumamoto-u.ac.jp/~yasuko/PUBLICATIONS/www15-ecoweb.pdf
View test.rb
require 'json'
class Hoge
def initialize
@a=1
@b='hoge'
@c={:a => 1}
end
def to_json
View mecab.js
// Generated by CoffeeScript 1.9.2
(function() {
module.exports = function(robot) {
return robot.hear(/mecab (.*)/i, function(msg) {
var MeCab, mecab, ret, text;
text = msg.match[1];
MeCab = new require('mecab-async');
mecab = new MeCab();
ret = mecab.parseSync(text);
return msg.send(text);
View mecab.coffee
module.exports = (robot) ->
robot.hear /mecab (.*)/i, (msg) ->
text = msg.match[1]
MeCab = new require 'mecab-async'
mecab = new MeCab()
ret = mecab.parseSync(text)
msg.send text