Skip to content

Instantly share code, notes, and snippets.

View chiral's full-sized avatar

Masayuki Isobe chiral

  • Adfive, Inc.
  • Taito-ku, Tokyo, Japan.
View GitHub Profile
@chiral
chiral / lm_test.R
Created October 8, 2011 18:10
verification of PRML fig_1.5
sr <- function() source('lm_test.R')
make_data <- function(n,sd=0.4) {
x <- seq(0,2*pi,length=n)
y <- sin(x) + rnorm(n,0,sd)
return(data.frame(x=x,y=y))
}
my_test <- function(d,m) {
z <- lm(y~poly(x,m),data=d)
@chiral
chiral / get_twitter_json.pl
Created October 8, 2011 18:51
Twitter API sample
use JSON;
use Encode;
if (@ARGV<1) { print "usage: $0 user_id [page]\n"; exit(0); }
my $url="http://twitter.com/statuses/user_timeline.json?id=$ARGV[0]";
$url.="\\&page=$ARGV[1]" if ($ARGV[1]);
open(F,"wget $url -O -|");my $j=<F>;close(F);
@chiral
chiral / CLT_test.R
Created October 8, 2011 18:58
simulation of CLT-theorem applied to unform distribution
# resulting image is
# http://dl.dropbox.com/u/15259519/images/CLT_sim.png
sr <- function() source("CLT_test.R")
sim1 <- function(n,m=500,c=30) {
mat <- matrix(runif(m*n),c(m,n))
res <- (rowSums(mat)-n*0.5)/sqrt(n/12)
hist(res,nclass=c,main='',xlab=sprintf("N=%d, trial num=%d",n,m))
}
@chiral
chiral / zk_queue.pm
Created October 8, 2011 19:09
Producer-Consumer impl on ZooKeeper
package zk_queue;
use Net::ZooKeeper qw(:node_flags :acls);
sub die1 {
die("failed to create node: ".$_[0]."\n");
}
sub die2 {
die("failed to delete node: ".$_[0]."\n");
@chiral
chiral / hinomaru_NN.R
Created October 8, 2011 19:19
nnet applied to noisy circle image
# resulting image is
# http://dl.dropbox.com/u/15259519/images/hinomaru_NN.png
sr <- function() source("hinomaru_NN.R")
W <<- 300
H <<- 200
R <<- 60
N <<- 6000
E <<- 20
@chiral
chiral / RBF_sigma_test.R
Created October 15, 2011 13:14
examination of how sigma parameters in RBF kernel affect results.
# ガウスカーネルのσパラメータの意味を調べるテスト
# examination of how sigma parameters in RBF kernel affect results.
# resulting image is,
# http://dl.dropbox.com/u/15259519/images/RBF_sigma.swf
sr <- function() source('RBF_sigma_test.R')
library(kernlab)
N <<- 100
sigmas <<- c(0.0001,0.0005,0.001,0.005,0.01,0.05,0.1,0.5,1,5,10,50)
@chiral
chiral / youtube.pl
Created October 22, 2011 09:58
YouTube Schene Thumbnailer (Perl & R)
# YouTubeの動画のダイジェスト画像集を自動的に作成
use GD;
use WWW::YouTube::Download;
use FFmpeg::Thumbnail;
use Statistics::R;
sub p { print STDERR $_[0]; }
my $video_id=shift or die "Usage: $0 video_id [ouput_dir] [skip] [threashold]";
my $out_dir=shift or $out_dir='.';
@chiral
chiral / html_body_text.pl
Created November 14, 2011 16:51
HTML body text extractor
#!/usr/bin/perl
use HTML::TreeBuilder;
our $alpha = 0.5;
our ($best,$best_rate);
our %special_alpha=('div',0.8,'span',1,'p',1,'a',0.1,
'ul',0.9,'ol',0.9,'li',0.9,
'style',0.1,'script',0.1,'noscript',0.1,
'b',1,'i',1,'h1',1,'h2',1,'h3',1,'font',1);
@chiral
chiral / json_rpn.pl
Created November 24, 2011 15:23
A Reverse Polish Notation for JSON processing.
use JSON;
use Encode;
#--------------------------------------------------
sub pop1{pop@{$_[0]}}
sub pop2{$_=shift;(pop@$_,pop@$_)}
sub pop3{$_=shift;(pop@$_,pop@$_,pop@$_)}
sub popN{my($n,$_)=@_;map{pop@$_}(1..$n)}
sub popL{
@chiral
chiral / monad.R
Created December 9, 2012 13:44
Monads on R
"%<-%" <- function(x,y) call("<-",substitute(x),substitute(y))
returm <- function(x) call("return",substitute(x))
exec <- quote
join <- function(ss,sep) {
res <- ""
for (s in ss) {
res <- paste(res,s,sep=sep)
}
res