Machine Learning: An Algorithmic Perspective 9章

Unsupervised Learning。なかなか面白かった。

ProductName Machine Learning: An Algorithmic Perspective (Chapman & Hall/Crc Machine Learning & Patrtern Recognition)
Stephen Marsland
Chapman & Hall / ¥ 6,593 ()
通常2~3週間以内に発送

K-meansの話から入って、K-Meansは一層のニューラルネットで表現することが出来ることを示していく。ニューラルネットで表現されたK-Meansはオンライン更新できるので、入力を一度に読み込まなくて良い(はず)。

そのあとSOMだったけど、SOMは知ってるので流した。

Machine Learning: An Algorithmic Perspective 8章

EM Algorithmとkd-Tree

ProductName Machine Learning: An Algorithmic Perspective (Chapman & Hall/Crc Machine Learning & Patrtern Recognition)
Stephen Marsland
Chapman & Hall / ¥ 6,593 ()
通常2~3週間以内に発送

内容はPRMLのほうが詳しい。Machine Leaningのほうはコードを読んで実装を理解するって感じだな。

ProductName パターン認識と機械学習 下 - ベイズ理論による統計的予測
C. M. ビショップ
シュプリンガー・ジャパン株式会社 / ¥ 8,190 ()
在庫あり。

kd-Treeは使ったことなかったけど、近傍探索はよく使うので、覚えておいて自由に使えるようにしようかな。

RBFネットワーク

Machine Learning 4章

ProductName Machine Learning: An Algorithmic Perspective (Chapman & Hall/Crc Machine Learning & Patrtern Recognition)
Stephen Marsland
Chapman & Hall / ¥ 6,459 ()
通常1~3週間以内に発送

  • k-meansで初期値決め
  • train
    • パーセプトロンの学習アルゴリズムと大体一緒

scipyにはB-splinesが用意されているのでそれを使ってみる

from pylab import *
from numpy import *
from scipy.signal import cspline1d, cspline1d_eval
x = arange(-3,10,0.05)
y = 2.5 * exp(-(x)**2/9) + 3.2 * exp(-(x-0.5)**2/4) + random.normal(0.0, 1.0, len(x))
spline = cspline1d(y,100)
xbar = arange(-5,15,0.1)
ybar = cspline1d_eval(spline, xbar, dx=x[1]-x[0], x0=x[0])
plot(x,y,'.')
plot(xbar,ybar)

b-splines

Pythonで多層パーセプトロン

Machine Learning 3章

ProductName Machine Learning: An Algorithmic Perspective (Chapman & Hall/Crc Machine Learning & Patrtern Recognition)
Stephen Marsland
Chapman & Hall / ¥ 6,459 ()
通常1~3週間以内に発送

要するにbackwars phaseを実装すればいいんでしょ?的な。実際書いてみると逆に誤差を伝播している感がある。

# Code from Chapter 3 of Machine Learning: An Algorithmic Perspective
# by Stephen Marsland (http://seat.massey.ac.nz/personal/s.r.marsland/MLBook.html)

# You are free to use, change, or redistribute the code in any way you wish for
# non-commercial purposes, but please maintain the name of the original author.
# This code comes with no warranty of any kind.

# Stephen Marsland, 2008
# modifiled by kzfm 2009

from numpy import *

inputs = array([[0,0],[0,1],[1,0],[1,1]])
targets = array([[0],[1],[1],[0]])

ndata,nin   = shape(inputs)
nout        = shape(targets)[1]
nhidden     = 2
beta        = 1
momentum    = 0.9
eta         = 0.25
niterations = 10001

weights1 = (random.rand(nin+1,nhidden)-0.5) * 2/sqrt(nin)
weights2 = (random.rand(nhidden+1,nout)-0.5) * 2/sqrt(nhidden)

# train
inputs = concatenate((inputs,-ones((ndata,1))),axis=1)
change = range(ndata)

updatew1 = zeros((shape(weights1)))
updatew2 = zeros((shape(weights2)))

for n in range(niterations):

    hidden = concatenate((1.0/(1.0+exp(-beta * dot(inputs,weights1))), -ones((shape(inputs)[0],1))),axis=1)
    outputs = 1.0 / (1.0+exp(-beta * dot(hidden,weights2)))
    error = 0.5 * sum((targets-outputs)**2)

    if (mod(n,1000)==0): print "Iteration: ",n, " Error: ",error    

    deltao = (targets-outputs) * outputs * (1.0-outputs)            
    deltah = hidden * (1.0-hidden) * (dot(deltao,transpose(weights2)))

    updatew1 = eta*(dot(transpose(inputs),deltah[:,:-1])) + momentum*updatew1
    updatew2 = eta*(dot(transpose(hidden),deltao)) + momentum*updatew2

    weights1 += updatew1
    weights2 += updatew2

    random.shuffle(change)
    inputs = inputs[change,:]
    targets = targets[change,:]

ちなみに、創薬系でのニューラルネットは論文とかは多いけど、実務ではあんまり使われないと思う(特にケミストよりになればなるほど)。というのは、実務においてはゴールするためにはこういうロジックで合成すればよろしいみたいな指針を提示しないといけないが、ニューラルネットでつくったモデルだとそういう解釈がしづらい。

なんか物がたくさんあって、フィルタリングしたいという要求には答えられるけど、何をどういう指針に従って創るかみたいな、創造(製造)律速な問題には使いにくい。

じゃぁ神経系は創造的ではないのかというと、それはまた違うんじゃないかなぁと思ったりもする。モデル化があれなのかなぁとも思うのだけど、、、、

Pythonでパーセプトロン

Machine Learningを読んでいる

ProductName Machine Learning: An Algorithmic Perspective (Chapman & Hall/Crc Machine Learning & Patrtern Recognition)
Stephen Marsland
Chapman & Hall / ¥ 6,459 ()
通常1~3週間以内に発送

numpyでパーセプトロンでORを訓練してみた(なにげにパーセプトロンとかニューラルネットワークの実装は初めてだったりする)。

from numpy import *
inputs = array([[0,0],[0,1],[1,0],[1,1]])
targets = array([[0],[1],[1],[1]])

nIterations = 6
eta = 0.25
nData = shape(inputs)[0]
nIn = shape(inputs)[1]
nOut  = shape(targets)[1]
weights = random.rand(nIn+1,nOut)

inputs = concatenate((inputs,-ones((nData,1))),axis=1)

for i in range(nIterations):
    outputs = where(dot(inputs,weights)>0,1,0)
    weights += eta*dot(transpose(inputs),targets-outputs)
    print "Iter: %d" % i
    print weights

print "Final outputs are:"
print where(dot(inputs,weights)>0,1,0) 

この本は、アルゴリズムに関して説明するのがメインの本らしいので、コードの解説はあんまなくて、詳しくはサンプルコード読めということらしいが、もう少し読んでみないとわからん。