Scalaでヒアドキュメント

プレゼンの原稿考えなきゃいけないのだけど、すすまないので現実逃避

Shizuocala

ScalaはPythonみたいなヒアドキュメントの仕組みが使える

object S_hizuo_cala {
  def main(args : Array[String]) : Unit = {
    println("""                         静
                         岡
                       静岡
                       静岡静
                       静岡岡
                      静岡静岡
                       静岡         富士宮
                      静岡静岡       富士宮   小山小山小山
                     静岡静岡       富士宮富士山御殿場小山小山
                   本川根静岡静岡静      富士宮富士御殿場御殿場
               水窪本川根静岡静岡静岡    芝富士宮富士裾野御殿場
             水窪水窪本川根静岡静岡静岡   川富士宮富士富士裾野裾野
            水窪水窪水窪本川根静岡静岡     富士川富士沼津長泉裾野
            水窪水窪本川根本川根静岡静岡静岡富士川富士沼津長泉三島函南
          佐久間水窪中川根本川根静岡静岡静岡由比蒲原  沼津清水町三島熱海
         佐久間春野春野中川根川静岡静岡静岡エスパルス         沼津韮山熱海
         佐久間春野春野中川根根静岡静岡静岡静岡        沼津伊豆長岡熱海
        佐久間龍山春野中川根川根静岡静岡静岡          沼津大仁大仁伊東
       佐久間龍山春野川根川根藤枝ゴン静岡静岡        戸田修善寺中伊豆伊東
      引佐天竜天竜森森森川根島田藤枝ゴン静岡        土肥天城湯ヶ島中伊豆伊東
    引佐引佐天竜天竜森森金谷島田藤枝ゴン           土肥天城湯ヶ島中伊豆伊東
    引佐引佐天竜豊岡森掛川金谷島田藤枝焼津          賀茂天城湯ヶ島伊東伊東
 三ヶ日引佐浜松浜北森森掛川掛川島田藤枝焼津          賀茂西伊豆河津東伊豆
,,三ヶ日細江浜松浜北磐田掛川掛川空港吉田大井川         西伊豆河津河津東伊豆
湖西   浜松浜松磐田袋井掛川菊川榛原吉田            松崎松崎河津河津河津
湖西   雄踏浜松豊田磐田 大大東小笠相良               松崎松崎下田下田
湖西新居舞阪浜松竜福田浅須大東浜岡相良               南伊豆下田下田
         .浜松洋福田羽賀大東浜岡相良                南伊豆
                     原発御前崎""")
  }
}

参考

Make:08

読んだ

ProductName Make: Technology on Your Time Volume 08

オライリージャパン / ¥ 1,575 ()
在庫あり。

  • はてなって1U自作なのか
  • Garduino面白そう
  • Auduinoも面白そう

今日の畑(091101)

3週間ぶりの畑。こんなに間を空けたのははじめて。

  • ジャガイモ枯れてた。秋撒きはだめなのかなぁ。それとも連作障害?
    • 春蒔きでチャレンジ。
  • ピーマン取れすぎ。20個以上もぎった
  • オクラでかすぎ。あまりにでかいのは固そうなので収穫から除外した。

小松菜はほうれん草と比べて育ちがはやい

1257061922

ほうれん草は雑草に埋もれているので、草取りを小一時間。夏の手強い雑草と違ってさくさくむしれるのでまぁラクチン。

1257061931

その後、近所のホームセンターに行ったら、そらまめとかサヤエンドウ、グリンピースなんかが売ってた。

ソラマメでも植えようかと思ったんだけど、石灰撒いたり肥料撒いたりする時間を考えると結構忙しいスケジュールかも。来年にむけて家庭菜園管理システムでもつくろうかな。

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

Validity of the model

引き続きThe Art of Modelingという章から。

ProductName Pharmacokinetic-Pharmacodynamic Modeling and Simulation
Peter Bonate
Springer / ¥ 8,475 ()
在庫あり。

Validity of the modelとは

  • Face-validity
  • Credibility
  • Internal validity
  • External validity
  • Pragmatic validity

からなる。

二番目のCredibilityはユーザーのモデルに対する信念みたいなもの。

みやさか

真澄の蔵だけど、柔らかくて甘みを感じる。

1256823882

アルコール度数12度ということもあってかすいすい吞める。

酒屋さんに燗つけても美味しいのとリクエストしたら薦められたので最初は燗つけてたんだけど、冷やのほうが美味くなってきてそのまま飲んでた。

あと、来週いわせさんの酒の会にいくことにした。楽しみ

Only a question can point the way forward.

モデルっていうのは仮説をドリブンして、本質に近づくために存在するのであって、正解率をあげるための単なる機械という認識は困るし、仮説ドリブンとか言うといて、その仮説がモチベーションをあげるための単なる虚言で、検証しないことを前提なのも困る。

Hello? / Jostein Gaarder

言葉の定義が揃ってないだけなのかもしれないけど(とか言っておこう)

Properties of useful model

いきなりThe Art of Modelingという章から入って、いいことたくさん書いてある。

ProductName Pharmacokinetic-Pharmacodynamic Modeling and Simulation
Peter Bonate
Springer / ¥ 8,475 ()
在庫あり。

有用なモデルの特性とは

  • Ability characterize the observed data and to include the most important features of the data
  • Makes accurate and precise predictions
  • Increases understanding of the system
  • The model is actually used
  • The model is completed on time
  • Logically consistent, plausible
  • Validated by empirical observations
  • Robust to small changes in the data
  • Appropriate level of precision and detail
  • As simple as possible
  • Judged on what it is intended to do
  • Has flexibility
  • Is effective as a communication tool
  • Serves many different purpose
  • May allow for extrapolation outside the data range

LeadOptimizationのプロジェクトにおいては

  • Ability characterize the observed data and to include the most important features of the data
  • Is effective as a communication tool

の二つが特に重要なんだろうなぁと思う。自分でモデリングできるのであれば、前者だけを重要視するかもしれない。

三文ゴシップ / 椎名林檎

落ち着いた?それとも薄まった?

ProductName 三文ゴシップ
椎名林檎
EMIミュージックジャパン / ¥ 3,059 (2009-06-24)
在庫あり。

危うさというか、アグレッシブというか攻撃的というか斜に構えてるっていうか、そういう鋭さ的なものはあんまないかも。

まぁそんな感じ。嫌いではないけどね。

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,:]

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

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

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