Skip to content

Instantly share code, notes, and snippets.

View syou6162's full-sized avatar

Yasuhisa Yoshida syou6162

View GitHub Profile
@syou6162
syou6162 / wip.md
Last active August 29, 2015 13:56
@syou6162
syou6162 / rand.clj
Created March 5, 2014 09:57
rand-intなどの関数に無理やり再現性を持たせる(seedを設定する)
(let [seed (java.util.Random. 1)]
(with-redefs [rand (fn [n] (* n (. seed nextDouble)))]
(mapv (fn [_] (rand-int 2)) (range 10))))
@syou6162
syou6162 / k_best_MIRA.md
Last active August 29, 2015 14:05
k-best MIRA

Hildreth algorithm

k-best MIRAはk=1のときはclosed-formで重み更新式が書けるが、k>1のときはclosed-formでは解くことができない。k>1のときに解が欲しければ、真面目にQPを解く必要がある。MSTParserの中で使われているQPを解くアルゴリズムにはHildreth algorithmが使われている。

Hildreth algorithm自体について説明しているWeb上のリソースはあまりないが、以下のサイトは雰囲気がつかめる。SMOのようにひとつの変数に着目して、それ以外は止めて一変数について最適化、というのを繰り返すようである。

Hildreth algorithmで出力されるのは双対変数なので、主問題の変数には変換する必要があることに注意。

参考になるプログラム

(function(){
var datePattern = new RegExp("(\\d{4})年(\\d{1,2})月(\\d{1,2})日");
function formatEntry(entry) {
entry.date.match(datePattern);
var year = RegExp.$1;
var month = RegExp.$2; if (month.length <= 1) month = "0" + month;
var day = RegExp.$3; if (day.length <= 1) day = "0" + day;
var item = entry.item.split("\"").join("\"\"");
return year + month + day + ",,," + entry.price + ",\"Amazon: " + item + "\"\n";
}
@syou6162
syou6162 / aitter.js
Last active August 29, 2015 14:07 — forked from moroya/aitter.js
(function(){
var total = {};
var year = '2012';
var all = false;
function init(num) {
if(typeof num !== 'number') {
num = 0;
$('<div/>').css({
position: 'fixed',
left: 0,
;;; dabbrev-expand-multiple.el --- dabbrev-expand for multiple
;; Copyright (C) 2007 khiker
;; Author: khiker <khiker+elisp@gmail.com>
;; plus <MLB33828@nifty.com>
;; Keywords: dabbrev
;; This file is free software; you can redistribute it and/or modify
@syou6162
syou6162 / gist:10544
Created September 13, 2008 01:36
集合を扱う関数などなど
#直積を書き出す関数
write.direct.product <- function(x,y){
e <- expand.grid(x,y)
m <- mapply(function(x,y){paste("(",x,",",y,")",sep="")},e[,1],e[,2])
return(paste("{",paste(m,collapse=","),"}",sep=""))
}
write.direct.product(1:3,4:6)
#R \times RからRへの写像の例
apply(expand.grid(1:3,4:6),1,function(x){x[1]*x[2]})
@syou6162
syou6162 / gist:10566
Created September 13, 2008 06:46
Tsukuba.Rの資料用
library(scatterplot3d)
steepest_descent <- function(epsilon,tau,x_bar1=-10,x_bar2=-20,beta=1,n=2000){
#関数内関数の定義
f <- function(x){x1 <- x[1];x2 <- x[2];return(100*(x1-x2)^2+(x1-1)^2)}
#数式微分
trig.exp <- expression(100*(x1-x2)^2+(x1-1)^2)
D.sc1 <- D(trig.exp, "x1")
D.sc2 <- D(trig.exp, "x2")
@syou6162
syou6162 / update_incanter_window.clj
Created January 5, 2012 21:26
incanterでwindowを閉じずにplotの内容を変更していく方法
(use '(incanter core stats charts))
(def min-val 1)
(def max-val 10)
(def chart-before (function-plot sin min-val max-val))
(def x (view chart-before))
(def chart-after (function-plot log min-val max-val))