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 / adult.R
Created June 5, 2017 10:29
comparison between LogisticRegression and RandomForest with "Census Income" dataset. please refer to http://archive.ics.uci.edu/ml/datasets/Adult
library(randomForest)
library(ROCR)
init <- function() {
df1 <- read.csv("adult.data",header=F)
df2 <- read.csv("adult.test",header=F)
df2$V15 <- gsub("\\.$","",df2$V15)
df <- rbind(df1,df2)
@chiral
chiral / mycmp.py
Last active January 30, 2017 16:57
custom comparison function generator for sorted in Python
import numpy as np
from random import random
def cmp0(d):
def cmp(a,b):
return int(a[d]-b[d])
return cmp
def cmp1(dd):
def cmp(a,b):
@chiral
chiral / show_jsons.py
Last active July 23, 2016 11:41
json viewer which can show unicode and top level array
# redirect to stdin to use
# % python show_jsons.py < hoge.json
import sys
import json
import pprint
lines = sys.stdin.readlines()
data = json.loads(''.join(lines),'utf8')
p = sys.stdout.write
@chiral
chiral / jupyter_client_sample.py
Created April 11, 2016 18:33
sample code for jupyter_client
from subprocess import PIPE
from jupyter_client import KernelManager
import time
try:
from queue import Empty # Py 3
except ImportError:
from Queue import Empty # Py 2
km = KernelManager(kernel_name='ir')
km.start_kernel()
@chiral
chiral / common.h
Created April 10, 2016 15:14
code example of AIBOX DroneBrain
#ifndef SLAM_COMMON_H
#define SLAM_COMMON_H
#include <opencv2/opencv.hpp>
#include <vector>
using namespace cv;
#define FOCAL_LENGTH 374.6706070969281
@chiral
chiral / decompose_fmatrix.cpp
Last active February 1, 2016 11:46
convert from fundamental matrix to camera pose (R1, R2, T) in OpenCV2 (similar to decomposeEssentialMat() in OpenCV 3)
/*
you can use the result matrix (rot1,rot2,tvec) as:
candidate1: rot1, tvec
candidate2: rot1, -tvec
candidate3: rot2, tvec
candidate4: rot2, -tvec
*/
bool convertF2RT(Mat &F,Mat &K,Mat &rot1,Mat &rot2,Mat &tvec) {
if (F.empty() || K.empty()) return false;
@chiral
chiral / xgbdump_formatter.py
Created December 18, 2015 08:43
pretty print for xgboost gbtree booster dump
import sys
import re
import unicodedata
depth={}
yn={}
f1=None
f=open(sys.argv[1])
@chiral
chiral / trivial_opt_ceres.cpp
Created December 2, 2015 15:19
example of trivial optimization problem on 2-d circle for the purpose of comparison between ceres-solver and TensorFlow
#include "ceres/ceres.h"
#include "glog/logging.h"
using ceres::CostFunction;
using ceres::AutoDiffCostFunction;
using ceres::Problem;
using ceres::Solver;
using ceres::Solve;
struct CostFunctor {
@chiral
chiral / example.py
Last active May 4, 2016 12:10
RDF generation helper built on rdflib
from rdfhelper import *
AD5 = 'http://adfive.net/o/v1#'
def make_recipe1():
g = GraphEx(AD5)
b = g.BNodeEx()
b.load_csv.a(g.LoadCSV).source(
b.in_file.a(g.DataSource)
).destination(
@chiral
chiral / iris.lua
Created October 1, 2015 11:49
3 layer perceptron for iris data by torch7. iris.csv can be obtained from https://gist.github.com/chiral/5b3609e884e3af8b412a
-- loarocks install csv
csv = require "csv"
nn = require "nn"
-- prepare data set
dataset={}
size=0
ans={setosa=1,versicolor=2,virginica=3}