Skip to content

Instantly share code, notes, and snippets.

@ybenjo
ybenjo / make_trans_prob.rb
Created April 24, 2015 00:12
markov chain table
# -*- coding: utf-8 -*-
require 'natto'
require 'msgpack'
require 'mongo'
texts = ['shirobako★が3巻が見たい', '大久保瑠美さんに会いたい']
trans_freq = Hash.new{|h, k| h[k] = Hash.new{0.0}}
texts.each do |txt|
@ybenjo
ybenjo / README.md
Last active December 13, 2023 08:04 — forked from yagays/agqr.rb
save AGQR radio programs.

agqr.rb

これは何

AGQR の放送を保存するスクリプト.

fork 元との違いは

yagays / agqr.rb には

  • 31日まである月に翌日の指定が失敗する

というバグが存在する.

@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 / sample2.ret
Created September 29, 2013 11:40
sample
0 a 0.545564
0 b 0.235328
0 c 0.0589112
0 d 0.160196
1 a 0.282141
1 b 0.400634
1 c 0.227655
1 d 0.0895693
2 a 0.0782046
2 b 0.155836
@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 / biterm_topic_model.rb
Last active June 3, 2023 03:16
biterm topic model(www2013)
# Xiaohui Yan, A biterm topic model for short texts(WWW 2013)
require 'set'
class Biterm
def initialize(alpha, beta, k)
@alpha = alpha
@beta = beta
@k = k
@doc_w = { }
@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}"