Skip to content

Instantly share code, notes, and snippets.

@ybenjo
ybenjo / test.py
Created May 4, 2020 05:36
scipy.sparse.csgraph.maximum_bipartite_matching is broken when get complete bipartite graph
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 June 8, 2019 07:36
converts foursquare's (dumped) check-ins data to ics file.
# 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 March 19, 2018 23:52
neural factorization machines (SIGIR 2017) unofficial code by Chainer
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 July 27, 2017 23:44
xgboost bug (Classifier can't handle nested array)
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 July 27, 2017 23:41
xgboost bug (handling nested array)
# 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 April 27, 2016 08:39
cut with column names
#!/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 December 30, 2015 08:52
The Web as a Jungle: Non-Linear Dynamical Systems for Co-evolving Online Activities (WWW 2015)
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
require 'json'
class Hoge
def initialize
@a=1
@b='hoge'
@c={:a => 1}
end
def to_json
// 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);
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