Skip to content

Instantly share code, notes, and snippets.

@shunsukeaihara
shunsukeaihara / karaoke_spectral_subtruction.py
Last active August 3, 2021 23:07
Singing voice enhancement by spectral subtraction method using karaoke sound
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import scipy as sp
import numpy as np
import math
import optparse
import tempfile
import wave
from itertools import izip
@shunsukeaihara
shunsukeaihara / cabo_wrapper.rb
Created January 23, 2013 08:30
ruby wrapper for japanese dependency parser cabocha 0.5
#!/usr/bin/ruby -Kw
$KCODE="UTF-8"
require "CaboCha"
require "kconv"
class DepAnalyzeByCabocha
@cabo
def initialize(args=[])
@cabo = CaboCha::Parser.new(args)
end
@shunsukeaihara
shunsukeaihara / pic.py
Created January 23, 2013 08:37
power iteration clustering
#!/opt/local/bin/python
# module power iteration clustering
import numpy as NP
from scipy.cluster.vq import kmeans2
def calcNorm1(v):
return NP.sum(NP.fabs(v))
def calcDelta(v,v2):
@shunsukeaihara
shunsukeaihara / mcl.rb
Created January 23, 2013 08:38
markov cluster algorithm in ruby
#!/usr/bin/ruby
class MCL
def initialize(path,min=0.00001,minpred=0.1)
@minimum=min
@minimunPred=minpred
@matrix=Hash.new
id=0
edgelist=Array.new
@shunsukeaihara
shunsukeaihara / gmixture.py
Created January 23, 2013 08:44
Mixture model for graph
# -*- coding: utf-8 -*-
import math
import numpy as NP
from scipy.maxentropy import logsumexp
from operator import itemgetter
class NewmanEM:
def __init__(sel):
pass
@shunsukeaihara
shunsukeaihara / cc.py
Created January 23, 2013 08:45
some of color correction algorithm in python
# -*- coding: utf-8 -*-
import numpy as np
import Image
import sys
def from_pil(pimg):
pimg = pimg.convert(mode='RGB')
nimg = np.asarray(pimg)
nimg.flags.writeable = True
return nimg
@shunsukeaihara
shunsukeaihara / npgraph.py
Last active December 16, 2015 01:19
あとでCとopmempで書きなおす
# -*- coding: utf-8 -*-
import numpy as np
from scipy.special.basic import digamma
import logging
class NpGraph():
def __init__(self,T=10,C=(1.0,1.0),phi=0.001,thresh=0.001,niter = 500):
self._T = T#最大クラスタ数
self._c1 = C[0]
self._c2 = C[1]
self._phi0=phi
@shunsukeaihara
shunsukeaihara / cabocha_warpper.py
Created May 22, 2013 08:32
cabochaのラッパーのベース
# -*- coding: utf-8 -*-
import CaboCha
import chardet
import syslog
import math
from collections import defaultdict
import unicodedata
syslog.openlog('cabocha_wrapper',syslog.LOG_PID|syslog.LOG_PERROR,syslog.LOG_SYSLOG)
AVG_LENGTH = 200.0
@shunsukeaihara
shunsukeaihara / npgraph.pyx
Last active December 17, 2015 18:29
npgraphのcython版 概ねpython版と出力は一致。計算を一部効率化 次の目標は入力のグラフを疎行列化 numpyのpythonオブジェクト使っているとgilのせいでopenmp使えないっぽい。.dataを使って生配列に変更する必要あり。
# -*- coding: utf-8 -*-
import numpy as np
cimport numpy as np
from libc.math cimport log
from scipy.misc import logsumexp
cdef double digamma(double x):
cdef double result = 0.0
cdef double xx, xx2, xx4
assert x>=0, "digamma error"
@shunsukeaihara
shunsukeaihara / crawl.py
Last active April 22, 2016 10:42
rongorongoのThomas Barthel's Transliteration Systemのデータをクローリングしてファイルに保存したり、文字の正規化や分解を行うスクリプト。詳細は以下 http://argmax.jp/index.php?ron
# -*- coding: utf-8 -*-
from BeautifulSoup import BeautifulSoup
import urllib2
import re
URL = "http://kohaumotu.org/rongorongo_org/translit/%s.html"
for i in range(97,123):
url = URL % chr(i)
html = urllib2.urlopen(url).read()