Skip to content

Instantly share code, notes, and snippets.

@ybenjo
ybenjo / sample2.txt
Created September 29, 2013 11:40
sample
a x:0.5488135039273248 y:0.7151893663724195
b x:-0.6027633760716439 y:0.5448831829968969
c x:-0.4236547993389047 y:-0.6458941130666561
d x:0.4375872112626925 y:-0.8917730007820798
a x:0.9636627605010293 y:0.3834415188257777
b x:-0.7917250380826646 y:0.5288949197529045
c x:-0.5680445610939323 y:-0.925596638292661
d x:0.07103605819788694 y:-0.08712929970154071
a x:0.02021839744032572 y:0.832619845547938
b x:-0.7781567509498505 y:0.8700121482468192
@ybenjo
ybenjo / multilogreg.cc
Last active December 24, 2015 05:38
Multi-Class Logistic Regression Using SGD.
#include <iostream>
#include <fstream>
#include <sstream>
#include <unordered_map>
#include <vector>
#include <string>
#include <algorithm>
#include <boost/random.hpp>
#include <iomanip>
@ybenjo
ybenjo / mult_logreg.cc
Created September 14, 2013 15:10
multiclass logistic regression(bug)
#include <iostream>
#include <fstream>
#include <sstream>
#include <unordered_map>
#include <vector>
#include <string>
#include <algorithm>
typedef std::pair<int, int> key;
@ybenjo
ybenjo / gmm.rb
Created August 29, 2013 13:22
GMM
# GMM (generalized Mixture Model) of EM
# usage
# gmm = GMM.new([1, 2, 3, 5, 2, 1, 10, 20, 30, 20], {k: 2})
LIM = 10 ** -5
PROB_LIM = 10 ** -100
def dist(x, mu, sigma)
prob = 1.0 / (2 * Math::PI * sigma) ** 0.5 * Math::exp(-(x - mu) ** 2 / (2 * sigma))
# avoid p(x|mu, sigma) = 0.0
@ybenjo
ybenjo / crawl_eventernote.rb
Last active October 15, 2015 13:32
crawler of eventernote.com
# -*- coding: utf-8 -*-
require 'open-uri'
require 'nokogiri'
require 'logger'
require 'time'
require 'set'
require 'pp'
UA = ''
@ybenjo
ybenjo / ikoma.rb
Created November 30, 2012 13:56
生駒日記取得
# usage: ruby ikoma.rb | pbcopy
require 'nokogiri'
require 'open-uri'
doc = Nokogiri::HTML(open("http://d.hatena.ne.jp/mamoruk/archive?word=&of=#{rand(1550)}", :proxy => nil).read)
entries = (doc/'li.archive.archive-section'/'a'); elem = entries[rand(entries.size)]
puts "#{elem.inner_text} #{elem.attribute('href').value}"
@ybenjo
ybenjo / plot.R
Created August 17, 2012 01:53
plot
library('ggplot2')
data <- read.table("/tmp/ret.csv", header = T, sep = ",")
data$topic_id <- as.factor(data$topic_id)
qplot(timestamp, gamma, data = data, color = topic_id)
@ybenjo
ybenjo / get.rb
Created August 1, 2012 06:25
社説比較くん4.0から社説をクロールするスクリプト
# -*- coding: utf-8 -*-
require 'nokogiri'
require 'open-uri'
require 'logger'
$log = Logger.new('./crawl.log')
def get(num)
ret = [ ]
url = "http://shasetsu.ps.land.to/index.cgi/event/#{num}/"
@ybenjo
ybenjo / director_seiyu.tsv
Created July 16, 2012 14:52
director/seiyu
0 千葉紗子 0.144232
0 鈴村健一 0.0596967
0 新井里美 0.0497514
0 鹿野優以 0.0447787
0 井上喜久子 0.0422924
0 松本大 0.0373197
0 私市淳 0.0373197
0 倉田雅世 0.0348334
0 ゆかな 0.0348334
0 石田彰 0.0248881
@ybenjo
ybenjo / studio_seiyu.tsv
Created July 16, 2012 14:51
anime studio/seiyu
0 明坂聡美 0.0740566
0 伊瀬茉莉也 0.0673262
0 南條愛乃 0.0561089
0 保村真 0.0471351
0 岸尾だいすけ 0.0426482
0 高森奈津美 0.0359178
0 片岡あづさ 0.0336743
0 福井裕佳梨 0.0336743
0 三森すずこ 0.0336743
0 金元寿子 0.0291874