Skip to content

Instantly share code, notes, and snippets.

@satomacoto
satomacoto / hello.py
Created November 28, 2011 12:29
Hello, world!
#!/usr/bin/env python
# -*- coding: utf-8 -*-
if __name__ == '__main__':
print "Hello, world!"
@satomacoto
satomacoto / gist:1400302
Created November 28, 2011 12:57
A Blogger HTML/JavaScript gadget to add line number to gists, requires jQuery
<!-- add line number to gist -->
<script type="text/javascript">
$('.gist').each(function() {
$('.line',this).each(function(i, e) {
$(this).prepend(
$('<div/>').attr('unselectable','on').css({
'float' : 'left',
'width': '30px',
'font-weight' : 'bold',
'color': 'grey',
@satomacoto
satomacoto / lp.py
Created December 21, 2011 16:52
Linear Programming w/ OpenOpt, FuncDesigner, GLPK, CVXOPT
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from FuncDesigner import *
from openopt import LP
# 変数の定義
x1,x2 = oovars(2)
# 目的関数
f = 3*x1 + 2*x2
# 初期解
@satomacoto
satomacoto / gist:1521244
Created December 26, 2011 14:18
A Blogger HTML/JavaScript gadget to add line number to gists
<!-- add line number to gist -->
<script type="text/javascript">
var gists = document.getElementsByClassName('gist');
for (var i = 0; i < gists.length; i++) {
var lines = gists[i].getElementsByClassName('line');
for (var j = 0; j < lines.length; j++) {
var div = document.createElement('div');
div.innerHTML = j + 1;
div.style.cssFloat = 'left';
div.style.width = '30px';
@satomacoto
satomacoto / gist:1523083
Created December 27, 2011 08:49
LaTeX for Blogger, requires jQuery
<!--
LaTeX for Blogger, requires jQuery
1. Add a HTML/Javascript gadget in the Layout mode and write this code.
2. In the HTML edit mode, write equations as follows:
<div class="equation">
ax^2 + bx + c = 0
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
</div>
@satomacoto
satomacoto / mds.py
Created January 5, 2012 08:48
Multidimensional Scaling
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
多次元尺度構成法
Multidimensional Scaling; MDS
"""
import numpy as np
import matplotlib.pyplot as plt
@satomacoto
satomacoto / kpca.data
Created January 5, 2012 15:08
Kernel principal component analysis
6.040760282116731938e-02 2.003600989193874138e-01 0
-2.180560612167562751e-01 -8.292820699779238636e-01 0
-5.144639589460509033e-01 8.281746425448210935e-01 0
-4.740161490764375866e-03 -3.159114014274040476e-03 0
-1.417081236535422117e-01 -1.966777129492919621e-02 0
6.803427539200110341e-02 7.803962205781220240e-02 0
-1.875352326510989487e-01 2.345321639090314769e-01 0
2.805120457198624351e-01 1.557595199768933847e-01 0
-2.649491374332632043e-01 -3.705041702348287058e-02 0
-1.841101081351155799e-01 -6.072910303536597360e-02 0
@satomacoto
satomacoto / hira.py
Created January 7, 2012 16:50
Extracts rubies of Aozora Bunko
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
regex = u'^[ぁ-ゞ・ー]+$' # ひらがな+・+ーだけ
p = re.compile(regex)
for line in open('ruby.txt'):
file, kanji, yomi = line.strip().split('\t')
@satomacoto
satomacoto / lda.py
Created January 11, 2012 13:18
LDA
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys,getopt
from numpy import array,matrix,diag
from scipy import sum,log,exp,mean,dot,ones,zeros
from scipy.special import polygamma
from scipy.linalg import norm
from random import random
@satomacoto
satomacoto / plsa.py
Created January 11, 2012 13:21
PLSA
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import math
import random
class plsa():
def __init__(self,n,nz=2):