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
module Main where
import Control.Monad
import Data.List
import Data.Char
checkio :: (String,String) -> String
checkio (text, ws) = zip [0..] text >>= trans
where
span = [(i,w) | w<-words $ map toLower ws,
(ns checkio.words-finder
(:use [clojure.string :only [split]]
[clojure.set :only [intersection]]))
(defn- checkio [text, words]
(let [lt (.toLowerCase text)
r (-> text .length range)
index (fn [w]
(filter #(.. lt (substring (first %)) (startsWith w))
(map vector r (iterate inc (.length w)))))
#light
let checkio (text:string,words:string) =
let lt = text.ToLower()
let lw = words.ToLower()
let range = [0..text.Length-1]
let index w =
(fun i -> lt.Substring(i).StartsWith(w))
|> List.filter <| range
|> List.map (fun i -> (i,i+w.Length))
@chiral
chiral / crawl.fs
Created March 23, 2014 09:15
A getting started example in F# for the dotNet-based web crawling framework "abot" (https://code.google.com/p/abot/) implemented in C#
#light
module Crawl
open System
open Abot.Crawler
open Abot.Poco
let Fetch (url: string) =
@chiral
chiral / test1.R
Created March 23, 2014 11:07
simple x-y 2 dimension linear bayes fit for non informed prior .
library(R2WinBUGS)
library(coda)
data <- list(
x=c(1.0,1.5,1.5,1.5,2.5,4.0,5.0,5.0,7.0,8.0,
8.5,9.0,9.5,9.5,10.0,12.0,12.0,13.0,13.0,14.5,
15.5,15.5,16.5,17.0,22.5,29.0,31.5),
y=c(1.80,
1.85,1.87,1.77,2.02,2.27,2.15,2.26,2.47,2.19,
2.26,2.40,2.39,2.41,2.50,2.32,2.32,2.43,2.47,
@chiral
chiral / bench.R
Last active August 29, 2015 13:57
uniform random 3000x3000 matrix inversion and multiply benchmark tests
N <- 3000
pt <- proc.time()
m <- matrix(runif(N*N), nrow=N, ncol=N)
ans <- sum(diag(m %*% solve(m)))
pt <- proc.time()-pt
print(paste("ans =",ans))
print(paste("time = ",pt[3]))
@chiral
chiral / impression.csv
Last active August 29, 2015 13:57
Kalman filter for ad impretion and click response prediction
ad1 ad2 ad3
1000 0 0
1000 0 0
1000 0 0
1000 0 0
1000 0 0
0 0 1000
0 0 1000
0 0 1000
0 0 1000
## particle filter implementation by isobe
particle_filter <- function(x0,y,f_noise,f_like,N,M=1) {
tmax <- nrow(y)
D <- length(x0) # == ncol(y)
do_noise <- function(x) {
x1 <- c()
for (i in 1:N) {
for (j in 1:M) {
@chiral
chiral / torus.R
Created April 4, 2014 04:08
Test program for "pHom" package which can calculate persistent homologies in R
library(phom)
library(scatterplot3d)
N <- 20
R <- 25
r <- 10
sd <- 1
ts <- seq(0,2*pi,pi/N)
ps <- seq(0,2*pi,pi/N)
library(dplyr)
#train <- read.csv("train.csv")
test <- read.csv("test_v2.csv")
last_items <- test %.%
group_by(customer_ID) %.%
filter(shopping_pt==max(shopping_pt)) %.%
mutate(plan=paste(A,B,C,D,E,F,G,sep='')) %.%
select(customer_ID,plan)