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 / 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)
@chiral
chiral / rbm.R
Created March 30, 2014 13:09
Restricted Boltzmann Machine implementation in R and Julia (Julia version is much faster than R)
### Restricted Boltzmann Machine implementation by isobe
sigmoid <- function(x) 1/(1+exp(-x))
rbm <- function(obs,n_hidden,eta=0.05,
epsilon=0.05,maxiter=100,
CD_k=1,reconstruct_trial=10,
verbose=0) {
L <- nrow(obs)
N <- ncol(obs)
@chiral
chiral / optimize_test.py
Created March 27, 2014 15:59
numpy/scipy optimize and 3d plotting sample
# -*- coding: utf-8 -*-
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
from scipy import optimize
def f(x,y):
r1 = np.sqrt(x**2+y**2)
r2 = np.sqrt((x-15)**2+(y-15)**2)
return np.sin(r1)/np.sqrt(r1) + 1.5*np.exp(-r2)
## 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 / 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
@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 / 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 / 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) =
#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))
(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)))))