<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>.COM-POUND</title>
	<atom:link href="http://www.yasutomo57jp.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.yasutomo57jp.com</link>
	<description>technical notebook</description>
	<lastBuildDate>Wed, 22 Feb 2012 11:42:00 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Ubuntu上のphpでcURLを使う</title>
		<link>http://www.yasutomo57jp.com/2012/02/22/ubuntu%e4%b8%8a%e3%81%aephp%e3%81%a7curl%e3%82%92%e4%bd%bf%e3%81%86/</link>
		<comments>http://www.yasutomo57jp.com/2012/02/22/ubuntu%e4%b8%8a%e3%81%aephp%e3%81%a7curl%e3%82%92%e4%bd%bf%e3%81%86/#comments</comments>
		<pubDate>Wed, 22 Feb 2012 11:35:53 +0000</pubDate>
		<dc:creator>yasutomo57jp</dc:creator>
				<category><![CDATA[未分類]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.yasutomo57jp.com/?p=246</guid>
		<description><![CDATA[curlは指定したURLからデータを取ってくるコマンドですが，それをphp5から利用する場合，php5-curlが必要になります． コマンドライン上で を実行することでphp5のcurlモジュールをインストールすることが &#8230; <a href="http://www.yasutomo57jp.com/2012/02/22/ubuntu%e4%b8%8a%e3%81%aephp%e3%81%a7curl%e3%82%92%e4%bd%bf%e3%81%86/">続きを読む <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>curlは指定したURLからデータを取ってくるコマンドですが，それをphp5から利用する場合，php5-curlが必要になります．</p>
<p>コマンドライン上で</p>
<pre class="brush: bash; title: ; notranslate">
sudo apt-get install php5-curl
</pre>
<p>を実行することでphp5のcurlモジュールをインストールすることができ，利用できます．</p>
<p>何に使うかというと…wordpressにSimple Tweetというプラグインを入れたのですが，</p>
<blockquote><p>Twitter OAuth は PHP5 以降でのみ利用できます。</p></blockquote>
<p>というエラーメッセージが出て使えなかったからです．<br />
このエラーメッセージはそのサーバのPHPでcurlが使えないときにも出るようです．</p>

<a href="http://twitter.com/?status=RT%20%40%3A%20Ubuntu%E4%B8%8A%E3%81%AEphp%E3%81%A7cURL%E3%82%92%E4%BD%BF%E3%81%86%20-%20.COM-POUND%20http%3A%2F%2Fwww.yasutomo57jp.com%2F2012%2F02%2F22%2Fubuntu%25e4%25b8%258a%25e3%2581%25aephp%25e3%2581%25a7curl%25e3%2582%2592%25e4%25bd%25bf%25e3%2581%2586%2F" class="tweet-this" ><img src="http://www.yasutomo57jp.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="ツイート" alt="ツイート" />ツイート</a>]]></content:encoded>
			<wfw:commentRss>http://www.yasutomo57jp.com/2012/02/22/ubuntu%e4%b8%8a%e3%81%aephp%e3%81%a7curl%e3%82%92%e4%bd%bf%e3%81%86/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[shogun 1] shogunを使ってみよう</title>
		<link>http://www.yasutomo57jp.com/2012/02/22/shogun%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%88%e3%81%86/</link>
		<comments>http://www.yasutomo57jp.com/2012/02/22/shogun%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%88%e3%81%86/#comments</comments>
		<pubDate>Wed, 22 Feb 2012 06:32:32 +0000</pubDate>
		<dc:creator>yasutomo57jp</dc:creator>
				<category><![CDATA[未分類]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[shogun]]></category>

		<guid isPermaLink="false">http://www.yasutomo57jp.com/?p=233</guid>
		<description><![CDATA[最近Shogun &#8211; A Large Scale Machine Learning Toolbox という機械学習のツールボックスを使い始めたので，shogunについて紹介します． まず紹介ページの英語を適当 &#8230; <a href="http://www.yasutomo57jp.com/2012/02/22/shogun%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%88%e3%81%86/">続きを読む <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>最近<a href="http://www.shogun-toolbox.org/">Shogun &#8211; A Large Scale Machine Learning Toolbox</a> という機械学習のツールボックスを使い始めたので，shogunについて紹介します．</p>
<p>まず紹介ページの英語を適当に日本語に訳してみます．</p>
<blockquote><p>SHOGUNは大規模なカーネル法と特にサポートベクタマシン(Support Vector Machine: SVM)[1]に重点を置いている機械学習ツールボックスである．いろいろなSVM実装（OCAS [21], Liblinear [20], LibSVM [2], SVMLight, [3] SVMLin [4] and GPDT [5]）に対するインターフェースになる汎用的なSVMオブジェクトを提供する．SVMは様々なカーネルと組み合わせることができる．このツールボクスは線形カーネル，多項式カーネル，ガウシアンカーネル，シグモイドカーネルだけでなく，Locality Improved [6], Fischer [7], TOP [8], Spectrum [9], Weighted Degree Kernel (with shifts) [10] [11] [12]なども提供する．また効率的なLINADD [12]最適化法も実装している．線形SVMに対して，COFFIN framework [22][23]は疎行列，密行列他様々なデータタイプの混合に対してもオンデマンドで処理ができる．さらにSHOGUNは様々なpre-computedなカーネルで動くようになっている．重要なものとしては，サブカーネルの重み付き線形和による結合カーネルがある．この各サブカーネルは必ずしも同じドメインである必要はない．最適なサブカーネルの重みはMultiple Kernel Learning (MKL) [13][14][18][19]で学習できる．現在SVMは，1クラス，2クラス，多クラス分類，回帰問題を扱える．SHOGUNは線形判別分析(Linear Discriminant Analysis: LDA)，線形計画マシン(Linear Programming Machine: LPM)，パーセプトロン((Kernel) Perceptrons)，隠れマルコフモデル(Hidden Markov Model)も実装されている．入力データは様々な型の疎・密行列を利用することができる．平均を引くなどの一連の前処理を各入力データに適用することもできる．<br />
SHOGUNはC++で実装されており，Matlab, R, Octave, Python, Java, Ruby向けのインタフェースが用意されており，機械学習のオープンソースソフトウェアとして公開されている．</p></blockquote>
<p>長々と書きましたが，重要なのは以下のポイントになります．</p>
<ul>
<li>様々なSVM実装が利用できる</li>
<li>様々なカーネルを使える</li>
<li>SVM以外にもLDAとかHMMとかいろいろ使える</li>
<li>C++/Matlab/R/Octave/Python/Ruby/Javaなどで使える</li>
<li>オープンソースソフトウェアである</li>
</ul>
<p>関西CV・PRML勉強会で紹介した時のスライドは<a href="http://www.slideshare.net/yasutomo57jp/shogun">こちら</a>にあります．</p>
<div id="__ss_7707283" style="width: 425px;">
<p><strong style="display: block; margin: 12px 0 4px;"><a title="SHOGUN使ってみました" href="http://www.slideshare.net/yasutomo57jp/shogun" target="_blank">SHOGUN使ってみました</a></strong> <iframe src="http://www.slideshare.net/slideshow/embed_code/7707283" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" width="425" height="355"></iframe></p>
<div style="padding: 5px 0 12px;">View more <a href="http://www.slideshare.net/" target="_blank">presentations</a> from <a href="http://www.slideshare.net/yasutomo57jp" target="_blank">Yasutomo Kawanishi</a></div>
</div>
<p>僕はこのツールボックスを，Pythonから利用しはじめました．スライド中ではapt-getやMacPortsでインストールできると言っていますが，サンプルコードなどを入手したい場合は，gitを使ってソースコードをダウンロードし，コンパイルしてインストールするのがお勧めです．</p>
<p>gitがインストールされているならば</p>
<pre class="brush: bash; title: ; notranslate">
git clone git://github.com/shogun-toolbox/shogun.git
git clone git://github.com/shogun-toolbox/shogun-data.git
</pre>
<p>のコマンドで，shogunディレクトリとshogun-dataディレクトリができます．shogunディレクトリにはshogunのソースコードとサンプルコードが，shogun-dataディレクトリにはサンプルのデータが入っています．</p>
<p>ソースコードをダウンロードしたら，</p>
<pre class="brush: bash; title: ; notranslate">
cd shogun/src
./configure
make
</pre>
<p>し，管理者権限で</p>
<pre class="brush: bash; title: ; notranslate">
make install
</pre>
<p>することでインストールすることができます．<br />
./configureの前に，swigがインストールされていないとpythonなどからの利用ができないので，先にインストールしておく必要があります．これはapt-getやMacPortsなどでインストールすることができます．</p>
<p>サンプルコードを動かすためには，サンプルデータのディレクトリの設定をする必要があります．shogunディレクトリ中で</p>
<pre class="brush: bash; title: ; notranslate">
rmdir data
ln -s ../shogun-data data
</pre>
<p>としてリンクを張っておく，もしくはshogun-dataの中身をshogun/dataへ移動すると完了です．</p>
<p>次のエントリではPython版のサンプルコードを動かすためのノウハウについて書きます．</p>

<a href="http://twitter.com/?status=RT%20%40%3A%20%5Bshogun%201%5D%20shogun%E3%82%92%E4%BD%BF%E3%81%A3%E3%81%A6%E3%81%BF%E3%82%88%E3%81%86%20-%20.COM-POUND%20http%3A%2F%2Ftinyurl.com%2F853bqfo" class="tweet-this" ><img src="http://www.yasutomo57jp.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="ツイート" alt="ツイート" />ツイート</a>]]></content:encoded>
			<wfw:commentRss>http://www.yasutomo57jp.com/2012/02/22/shogun%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%88%e3%81%86/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>X.orgの設定ファイル xorg.conf を晒してみる</title>
		<link>http://www.yasutomo57jp.com/2011/12/20/x-org%e3%81%ae%e8%a8%ad%e5%ae%9a%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab-xorg-conf-%e3%82%92%e6%99%92%e3%81%97%e3%81%a6%e3%81%bf%e3%82%8b/</link>
		<comments>http://www.yasutomo57jp.com/2011/12/20/x-org%e3%81%ae%e8%a8%ad%e5%ae%9a%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab-xorg-conf-%e3%82%92%e6%99%92%e3%81%97%e3%81%a6%e3%81%bf%e3%82%8b/#comments</comments>
		<pubDate>Tue, 20 Dec 2011 02:26:46 +0000</pubDate>
		<dc:creator>yasutomo57jp</dc:creator>
				<category><![CDATA[未分類]]></category>

		<guid isPermaLink="false">http://www.yasutomo57jp.com/?p=222</guid>
		<description><![CDATA[はじめに LinuxでのウインドウシステムであるX.orgの設定ファイルを晒します． X.orgの設定ファイルは， /etc/X11/xorg.conf にあり，マウスとキーボードの設定，ディスプレイドライバ，解像度，画 &#8230; <a href="http://www.yasutomo57jp.com/2011/12/20/x-org%e3%81%ae%e8%a8%ad%e5%ae%9a%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab-xorg-conf-%e3%82%92%e6%99%92%e3%81%97%e3%81%a6%e3%81%bf%e3%82%8b/">続きを読む <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>はじめに</h2>
<p>LinuxでのウインドウシステムであるX.orgの設定ファイルを晒します．<br />
X.orgの設定ファイルは， /etc/X11/xorg.conf にあり，マウスとキーボードの設定，ディスプレイドライバ，解像度，画面の回転，マルチスクリーンなどの設定を書くようになっています．</p>
<p>マルチスクリーンにして回転させる時はさすがに自前でこのファイルをいじらないと上手く行かなかったので，メモがわりに貼っておこうと思いました．</p>
<h2>環境</h2>
<ul>
<li>グラフィックボード：NVIDIA Quadro FX 580</li>
<li>ディスプレイ：DELLの24inch2枚を90度回転させ，縦にして2枚横に並べています．</li>
<li>OS：Ubuntu 11.10 64bit</li>
<li>デスクトップマネージャ：Gnome 3</li>
</ul>
<h2>設定ファイル</h2>
<p>では晒します．注意：使用している環境によっていろいろ異なる所があるので，このままコピペしても使えるかどうかは微妙です．/etc/X11/xorg.confのバックアップをとっておくことをお勧めします．</p>
<pre>Section "ServerLayout" # ここは画面配置の設定
    Identifier     "Layout0"
    Screen      0  "Screen0" 0 0
    InputDevice    "Keyboard0" "CoreKeyboard"
    InputDevice    "Mouse0" "CorePointer"
    Option         "Xinerama" "0"
EndSection

Section "InputDevice" # ここはマウスの設定
    Identifier     "Mouse0"
    Driver         "mouse"
    Option         "Protocol" "auto"
    Option         "Device" "/dev/psaux"
    Option         "Emulate3Buttons" "no"
    Option         "ZAxisMapping" "4 5"
EndSection

Section "InputDevice" # ここはキーボードの設定
    Identifier     "Keyboard0"
    Driver         "kbd"
EndSection

Section "Monitor" # ここはディスプレイの設定
    Identifier     "Monitor0"
    VendorName     "Unknown"
    ModelName      "DELL 2405FPW"
    HorizSync       30.0 - 81.0
    VertRefresh     56.0 - 76.0
    Option         "DPMS"
EndSection

Section "Device" # ここはグラフィックボードの設定
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
    BoardName      "Quadro FX 580"
EndSection

Section "Screen" # ここはスクリーンの設定「どのディスプレイにどのデバイスの映像を出力するか」など．
    Identifier     "Screen0"
    Device         "Device0"
    Monitor        "Monitor0"
    DefaultDepth    24
    Option         "Rotate" "CCW" # これにより，画面を回転
    Option         "NoLogo" "True"
    Option         "TwinView" "1" # これにより，マルチディスプレイを実現
    Option         "TwinViewXineramaInfoOrder" "DFP-0"
    Option         "metamodes" "DFP-0: nvidia-auto-select +0+1200, DFP-1: 1920x1200 +0+0"
    SubSection     "Display"
        Depth       24
    EndSubSection
EndSection</pre>
<h2>おわりに</h2>
<p>失敗して分けわからなくなった場合は，<br />
<code>$ sudo nvidia-xconfig</code><br />
コマンドで自動的にファイルを復元することができます．</p>

<a href="http://twitter.com/?status=RT%20%40%3A%20X.org%E3%81%AE%E8%A8%AD%E5%AE%9A%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%20xorg.conf%20%E3%82%92%E6%99%92%E3%81%97%E3%81%A6%E3%81%BF%E3%82%8B%20-%20.COM-POUND%20http%3A%2F%2Ftinyurl.com%2F7vu5orw" class="tweet-this" ><img src="http://www.yasutomo57jp.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="ツイート" alt="ツイート" />ツイート</a>]]></content:encoded>
			<wfw:commentRss>http://www.yasutomo57jp.com/2011/12/20/x-org%e3%81%ae%e8%a8%ad%e5%ae%9a%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab-xorg-conf-%e3%82%92%e6%99%92%e3%81%97%e3%81%a6%e3%81%bf%e3%82%8b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PythonでのORマッパー：SQLAlchemy</title>
		<link>http://www.yasutomo57jp.com/2011/11/30/python%e3%81%a7%e3%81%aeor%e3%83%9e%e3%83%83%e3%83%91%e3%83%bc%ef%bc%9asqlalchemy/</link>
		<comments>http://www.yasutomo57jp.com/2011/11/30/python%e3%81%a7%e3%81%aeor%e3%83%9e%e3%83%83%e3%83%91%e3%83%bc%ef%bc%9asqlalchemy/#comments</comments>
		<pubDate>Wed, 30 Nov 2011 00:02:40 +0000</pubDate>
		<dc:creator>yasutomo57jp</dc:creator>
				<category><![CDATA[未分類]]></category>

		<guid isPermaLink="false">http://www.yasutomo57jp.com/?p=217</guid>
		<description><![CDATA[Pythonでデータベースを扱うときには，ORマッパーが便利． ORマッパーとは，Pythonのクラスのインスタンスとデータベースのレコードとを対応付けるもの． これを使うと，DBアクセスがとても簡単になるし，SQLを書 &#8230; <a href="http://www.yasutomo57jp.com/2011/11/30/python%e3%81%a7%e3%81%aeor%e3%83%9e%e3%83%83%e3%83%91%e3%83%bc%ef%bc%9asqlalchemy/">続きを読む <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Pythonでデータベースを扱うときには，ORマッパーが便利．<br />
ORマッパーとは，Pythonのクラスのインスタンスとデータベースのレコードとを対応付けるもの．<br />
これを使うと，DBアクセスがとても簡単になるし，SQLを書かなくてすむ．</p>
<p>使用例</p>
<pre class="brush: python; title: ; notranslate">
from sqlalchemy import Table, Column, Integer, String, Date
from sqlalchemy.ext.declarative import declarative_base
from datetime import datetime

class User(declarative_base()):
    __tablename__ = 'observation'

    id = Column(Integer, primary_key=True)
    date = Date()
    pos_x = Integer()
    pos_y = Integer()
    def __init__(self, date, x, y):
        self.date = date
        self.pos_x = x
        self.pos_y = y

    def __repr__(self):
return &quot;&lt;Task('%s', '%d', '%d')&gt;&quot; % (self.date, self.pos_x, self.pos_y)
</pre>
<p>こんな感じで，クラス定義にちょこっと追加するだけで，このクラスに対応したデータベースが作成される．</p>

<a href="http://twitter.com/?status=RT%20%40%3A%20Python%E3%81%A7%E3%81%AEOR%E3%83%9E%E3%83%83%E3%83%91%E3%83%BC%EF%BC%9ASQLAlchemy%20-%20.COM-POUND%20http%3A%2F%2Ftinyurl.com%2F7p4y2rq" class="tweet-this" ><img src="http://www.yasutomo57jp.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="ツイート" alt="ツイート" />ツイート</a>]]></content:encoded>
			<wfw:commentRss>http://www.yasutomo57jp.com/2011/11/30/python%e3%81%a7%e3%81%aeor%e3%83%9e%e3%83%83%e3%83%91%e3%83%bc%ef%bc%9asqlalchemy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rubyスクリプト中から別のRubyスクリプトを呼び出した時の標準出力</title>
		<link>http://www.yasutomo57jp.com/2011/11/29/ruby%e3%82%b9%e3%82%af%e3%83%aa%e3%83%97%e3%83%88%e4%b8%ad%e3%81%8b%e3%82%89%e5%88%a5%e3%81%aeruby%e3%82%b9%e3%82%af%e3%83%aa%e3%83%97%e3%83%88%e3%82%92%e5%91%bc%e3%81%b3%e5%87%ba%e3%81%97%e3%81%9f/</link>
		<comments>http://www.yasutomo57jp.com/2011/11/29/ruby%e3%82%b9%e3%82%af%e3%83%aa%e3%83%97%e3%83%88%e4%b8%ad%e3%81%8b%e3%82%89%e5%88%a5%e3%81%aeruby%e3%82%b9%e3%82%af%e3%83%aa%e3%83%97%e3%83%88%e3%82%92%e5%91%bc%e3%81%b3%e5%87%ba%e3%81%97%e3%81%9f/#comments</comments>
		<pubDate>Tue, 29 Nov 2011 06:27:52 +0000</pubDate>
		<dc:creator>yasutomo57jp</dc:creator>
				<category><![CDATA[未分類]]></category>

		<guid isPermaLink="false">http://www.yasutomo57jp.com/?p=210</guid>
		<description><![CDATA[Rubyスクリプトから別のRubyスクリプトを呼び出したい時がある． そういう場合， とすると，hoge.rbが標準出力へ出力した文字列すべてを変数msgで受け取ることが出来る． 1行ずつ受け取って処理したい場合は， と &#8230; <a href="http://www.yasutomo57jp.com/2011/11/29/ruby%e3%82%b9%e3%82%af%e3%83%aa%e3%83%97%e3%83%88%e4%b8%ad%e3%81%8b%e3%82%89%e5%88%a5%e3%81%aeruby%e3%82%b9%e3%82%af%e3%83%aa%e3%83%97%e3%83%88%e3%82%92%e5%91%bc%e3%81%b3%e5%87%ba%e3%81%97%e3%81%9f/">続きを読む <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Rubyスクリプトから別のRubyスクリプトを呼び出したい時がある．</p>
<p>そういう場合，</p>
<pre class="brush: ruby; title: ; notranslate">
msg=`hoge.rb`
</pre>
<p>とすると，hoge.rbが標準出力へ出力した文字列すべてを変数msgで受け取ることが出来る．<br />
1行ずつ受け取って処理したい場合は，</p>
<pre class="brush: ruby; title: ; notranslate">
IO.popen(&quot;hoge.rb&quot;) do |pipe|
    pipe.each do | line |
         print line
    end
end
</pre>
<p>という感じにすれば，1行ずつとって表示することが出来る．</p>
<p>しかし，デフォルトだと，Rubyスクリプトの標準出力はバッファリングされるため，hoge.rbの処理に時間がかかる場合，長い時間立った後に，まとめてhoge.rbの出力をどかっと渡されるようになる．<br />
（受け取ったプログラムは，それを1行ずつ処理することはできるけれど）</p>
<p>これは標準出力がバッファリングされているのが原因なので，バッファリングしないようにすればOK．<br />
つまり，呼び出される側のスクリプトhoge.rbの最初に，</p>
<pre class="brush: ruby; title: ; notranslate">
STDOUT.sync = true
</pre>
<p>と書けば良い．<br />
（<a title="こせきの技術日記：[Ruby] Rubyの標準出力をバッファしない" href="http://d.hatena.ne.jp/koseki2/20070111/rubystdout">[Ruby] Rubyの標準出力をバッファしない</a>を参考にしました．）</p>
<p>これで，ばっちり動く．</p>
<p>例（STDOUT.sync=trueの有無での挙動の違いを確認）<br />
呼び出される側：hoge.rb</p>
<pre class="brush: ruby; title: ; notranslate">
#!/usr/bin/ruby

STDOUT.sync = true
puts &quot;hoge&quot;
sleep 3 # 長時間かかる処理
puts &quot;hoge&quot;
</pre>
<p>呼び出す側：main.rb</p>
<pre class="brush: ruby; title: ; notranslate">
#!/usr/bin/ruby

puts &quot;start&quot;

IO.popen(&quot;test.rb&quot;) do |f|
        f.each do |line|
                print line
        end
end

puts &quot;finish&quot;
</pre>

<a href="http://twitter.com/?status=RT%20%40%3A%20Ruby%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%97%E3%83%88%E4%B8%AD%E3%81%8B%E3%82%89%E5%88%A5%E3%81%AERuby%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%97%E3%83%88%E3%82%92%E5%91%BC%E3%81%B3%E5%87%BA%E3%81%97%E3%81%9F%E6%99%82%E3%81%AE%E6%A8%99%E6%BA%96%E5%87%BA%E5%8A%9B%20-%20.COM-POUND%20http%3A%2F%2Ftinyurl.com%2F85roa8a" class="tweet-this" ><img src="http://www.yasutomo57jp.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="ツイート" alt="ツイート" />ツイート</a>]]></content:encoded>
			<wfw:commentRss>http://www.yasutomo57jp.com/2011/11/29/ruby%e3%82%b9%e3%82%af%e3%83%aa%e3%83%97%e3%83%88%e4%b8%ad%e3%81%8b%e3%82%89%e5%88%a5%e3%81%aeruby%e3%82%b9%e3%82%af%e3%83%aa%e3%83%97%e3%83%88%e3%82%92%e5%91%bc%e3%81%b3%e5%87%ba%e3%81%97%e3%81%9f/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SubversionユーザがMercurialを使ってみた</title>
		<link>http://www.yasutomo57jp.com/2011/11/21/subversion%e3%83%a6%e3%83%bc%e3%82%b6%e3%81%8cmercurial%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%81%bf%e3%81%9f/</link>
		<comments>http://www.yasutomo57jp.com/2011/11/21/subversion%e3%83%a6%e3%83%bc%e3%82%b6%e3%81%8cmercurial%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%81%bf%e3%81%9f/#comments</comments>
		<pubDate>Sun, 20 Nov 2011 16:27:00 +0000</pubDate>
		<dc:creator>yasutomo57jp</dc:creator>
				<category><![CDATA[未分類]]></category>

		<guid isPermaLink="false">http://www.yasutomo57jp.com/?p=204</guid>
		<description><![CDATA[Subversionといえば，かなり有名なバージョン管理システムです． また，MercurialはPythonで書かれている，最近よくみかける分散リポジトリ型のバージョン管理システムです． それぞれがどんな物かはここでは &#8230; <a href="http://www.yasutomo57jp.com/2011/11/21/subversion%e3%83%a6%e3%83%bc%e3%82%b6%e3%81%8cmercurial%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%81%bf%e3%81%9f/">続きを読む <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Subversionといえば，かなり有名なバージョン管理システムです．<br />
また，MercurialはPythonで書かれている，最近よくみかける分散リポジトリ型のバージョン管理システムです．<br />
それぞれがどんな物かはここでは触れませんので各自調べてください．</p>
<p>今回は，中央リポジトリとしてSubversionを使い各自のローカルにリポジトリをMercurialで持つ，いいかえれば，Mercurialとしてリポジトリを管理するけどもマスターリポジトリとしてSubversionのリポジトリを利用する方法について説明します．</p>
<p>これをやるには，gitの場合だとgit-svnというのがあるように，HgSubversionというのがあります．<br />
それをeasy_installで入れるだけでOK．</p>
<p>sudo easy_install hgsubversion</p>
<p>これで，hgにsubversionの拡張が入ったはずです．</p>
<p>次に，設定ファイル ~/.hgrc に，hgsubversion…eggをインストールしたパスを指定します．</p>
<p>Macの場合，~/.hgrcに以下を追記します<br />
<code>[extensions]<br />
hgsubversion=/Library/Python/2.7/site-packages/hgsubversion-1.3-py2.7.egg/hgsubversion/<br />
</code></p>
<p>あとは，<br />
hg clone svn+http://hogehoge/fuga .<br />
とか<br />
hg clone svn+ssh://hogehoge//fuga .<br />
とやれば，Subversionのリポジトリからhgのローカルリポジトリを作成できるはず！</p>

<a href="http://twitter.com/?status=RT%20%40%3A%20Subversion%E3%83%A6%E3%83%BC%E3%82%B6%E3%81%8CMercurial%E3%82%92%E4%BD%BF%E3%81%A3%E3%81%A6%E3%81%BF%E3%81%9F%20-%20.COM-POUND%20http%3A%2F%2Fwww.yasutomo57jp.com%2F2011%2F11%2F21%2Fsubversion%25e3%2583%25a6%25e3%2583%25bc%25e3%2582%25b6%25e3%2581%258cmercurial%25e3%2582%2592%25e4%25bd%25bf%25e3%2581%25a3%25e3%2581%25a6%25e3%2581%25bf%25e3%2581%259f%2F" class="tweet-this" ><img src="http://www.yasutomo57jp.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="ツイート" alt="ツイート" />ツイート</a>]]></content:encoded>
			<wfw:commentRss>http://www.yasutomo57jp.com/2011/11/21/subversion%e3%83%a6%e3%83%bc%e3%82%b6%e3%81%8cmercurial%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%81%bf%e3%81%9f/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Macでnumpyモジュールのインストール</title>
		<link>http://www.yasutomo57jp.com/2011/11/13/mac%e3%81%a7numpy%e3%83%a2%e3%82%b8%e3%83%a5%e3%83%bc%e3%83%ab%e3%81%ae%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%bc%e3%83%ab/</link>
		<comments>http://www.yasutomo57jp.com/2011/11/13/mac%e3%81%a7numpy%e3%83%a2%e3%82%b8%e3%83%a5%e3%83%bc%e3%83%ab%e3%81%ae%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%bc%e3%83%ab/#comments</comments>
		<pubDate>Sat, 12 Nov 2011 17:00:32 +0000</pubDate>
		<dc:creator>yasutomo57jp</dc:creator>
				<category><![CDATA[未分類]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.yasutomo57jp.com/?p=195</guid>
		<description><![CDATA[Pythonのモジュールはeasy_installを使ってインストールしています． easy_install nose easy_install numpy という感じ． ただし，numpyはインストールする際にCのコー &#8230; <a href="http://www.yasutomo57jp.com/2011/11/13/mac%e3%81%a7numpy%e3%83%a2%e3%82%b8%e3%83%a5%e3%83%bc%e3%83%ab%e3%81%ae%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%bc%e3%83%ab/">続きを読む <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Pythonのモジュールはeasy_installを使ってインストールしています．</p>
<p><code>easy_install nose<br />
easy_install numpy</code></p>
<p>という感じ．</p>
<p>ただし，numpyはインストールする際にCのコード，Fortranのコードのコンパイルが必要です．<br />
ここで詰まったのでメモ．</p>
<p>Cのコードのコンパイル<br />
Cのコードをコンパイルするためには，Python.hが必要です．<br />
Python.hは /usr/include/python2.7/Python.h にありますが，インクルードのパスが通ってないので，Python.hがないと言われます．<br />
なので，<br />
<code>sudo ln -s /usr/include/python2.7/Python.h /usr/include/Python.h</code><br />
してやります．</p>
<p>Fortranのコードのコンパイル<br />
デフォルトではFortranコンパイラのgfortranが入っていないので，<br />
http://hpc.sourceforge.net/ から，gfortran-lion.tar.gzを取ってきて，<br />
<code>sudo tar zxvf gfortran-lion.tar.gz /</code><br />
してやります．</p>
<p>この2点を済ませば，numpyがインストールできると思います．</p>

<a href="http://twitter.com/?status=RT%20%40%3A%20Mac%E3%81%A7numpy%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB%20-%20.COM-POUND%20http%3A%2F%2Ftinyurl.com%2F73sa75x" class="tweet-this" ><img src="http://www.yasutomo57jp.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="ツイート" alt="ツイート" />ツイート</a>]]></content:encoded>
			<wfw:commentRss>http://www.yasutomo57jp.com/2011/11/13/mac%e3%81%a7numpy%e3%83%a2%e3%82%b8%e3%83%a5%e3%83%bc%e3%83%ab%e3%81%ae%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%bc%e3%83%ab/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>seq コマンド</title>
		<link>http://www.yasutomo57jp.com/2011/09/05/%e4%be%bf%e5%88%a9%e3%81%aalinux%e3%82%b3%e3%83%9e%e3%83%b3%e3%83%89/</link>
		<comments>http://www.yasutomo57jp.com/2011/09/05/%e4%be%bf%e5%88%a9%e3%81%aalinux%e3%82%b3%e3%83%9e%e3%83%b3%e3%83%89/#comments</comments>
		<pubDate>Mon, 05 Sep 2011 06:04:41 +0000</pubDate>
		<dc:creator>yasutomo57jp</dc:creator>
				<category><![CDATA[未分類]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[zsh]]></category>
		<category><![CDATA[シェルスクリプト]]></category>

		<guid isPermaLink="false">http://www.yasutomo57jp.com/?p=189</guid>
		<description><![CDATA[seqコマンドという便利なLinuxコマンドがあったのでメモ．ちなみに僕はシェルはzshを使っています． seqコマンドは基本的には開始と終了を指定すれば，開始から終了までの数列を出力してくれるコマンド．使い方は以下のと &#8230; <a href="http://www.yasutomo57jp.com/2011/09/05/%e4%be%bf%e5%88%a9%e3%81%aalinux%e3%82%b3%e3%83%9e%e3%83%b3%e3%83%89/">続きを読む <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>seqコマンドという便利なLinuxコマンドがあったのでメモ．ちなみに僕はシェルはzshを使っています．</p>
<p>seqコマンドは基本的には開始と終了を指定すれば，開始から終了までの数列を出力してくれるコマンド．使い方は以下のとおり．</p>
<pre class="brush: bash; title: ; notranslate">
seq -f &quot;%03g&quot; 0 100
</pre>
<p>これで 000～100までの数値が作れる．ここで -f &#8220;%03g&#8221; は，C言語等でもおなじみprintfのフォーマットと同じで，3桁になるように0で埋めるという意味です．別にかならず必要というわけではなく，これがないと，0~9,10~99,100という感じに出力されます．実は0で埋めるだけだったら，-wというオプションでもOK．</p>
<pre class="brush: bash; title: ; notranslate">
seq -w 0 100
</pre>
<p>これで0で整えられた文字列が出力される．ところで，普通にseqコマンドを実行すると指定した数字が改行区切りで出力されるけど，-sオプションを使えば区切り文字も変更できる．</p>
<pre class="brush: bash; title: ; notranslate">
seq -w -s , 5 15
</pre>
<p>この場合，05,06,07,08,09,10,11,12,13,14,15 という文字列が出力されるはず．</p>
<p>使用例：forループと組み合わせたりして</p>
<pre class="brush: bash; title: ; notranslate">
for x in `seq -f &quot;%03g&quot; 0 100`; echo $x
</pre>
<p>こんな感じ．でもforループで使うなら，</p>
<pre class="brush: bash; title: ; notranslate">
for x in {000..100}; echo $x
</pre>
<p>のほうが簡単。まぁでもstepも設定できるのは便利。</p>
<pre class="brush: bash; title: ; notranslate">
for x in `seq -f &quot;%03g&quot; 0 5 100`; echo $x
</pre>
<p>この場合だと，000から100まで5飛びで000 005 010 015 … 100が出力される．</p>

<a href="http://twitter.com/?status=RT%20%40%3A%20seq%20%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%20-%20.COM-POUND%20http%3A%2F%2Fwww.yasutomo57jp.com%2F2011%2F09%2F05%2F%25e4%25be%25bf%25e5%2588%25a9%25e3%2581%25aalinux%25e3%2582%25b3%25e3%2583%259e%25e3%2583%25b3%25e3%2583%2589%2F" class="tweet-this" ><img src="http://www.yasutomo57jp.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="ツイート" alt="ツイート" />ツイート</a>]]></content:encoded>
			<wfw:commentRss>http://www.yasutomo57jp.com/2011/09/05/%e4%be%bf%e5%88%a9%e3%81%aalinux%e3%82%b3%e3%83%9e%e3%83%b3%e3%83%89/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenCVでカラーでスカラー場を可視化する場合</title>
		<link>http://www.yasutomo57jp.com/2011/06/01/opencv%e3%81%a7%e3%82%ab%e3%83%a9%e3%83%bc%e3%81%a7%e3%82%b9%e3%82%ab%e3%83%a9%e3%83%bc%e5%a0%b4%e3%82%92%e5%8f%af%e8%a6%96%e5%8c%96%e3%81%99%e3%82%8b%e5%a0%b4%e5%90%88/</link>
		<comments>http://www.yasutomo57jp.com/2011/06/01/opencv%e3%81%a7%e3%82%ab%e3%83%a9%e3%83%bc%e3%81%a7%e3%82%b9%e3%82%ab%e3%83%a9%e3%83%bc%e5%a0%b4%e3%82%92%e5%8f%af%e8%a6%96%e5%8c%96%e3%81%99%e3%82%8b%e5%a0%b4%e5%90%88/#comments</comments>
		<pubDate>Wed, 01 Jun 2011 05:12:10 +0000</pubDate>
		<dc:creator>yasutomo57jp</dc:creator>
				<category><![CDATA[未分類]]></category>

		<guid isPermaLink="false">http://www.yasutomo57jp.com/?p=184</guid>
		<description><![CDATA[何かしらのスカラー場を表現しようとしたときに，各画素に対してグレースケールで値をセットしてやれば一応可視化は出来るのですが，やはりカラーで表現したほうがきれいです．その場合，値の大小に対して，赤←→青で表現すると見やすい &#8230; <a href="http://www.yasutomo57jp.com/2011/06/01/opencv%e3%81%a7%e3%82%ab%e3%83%a9%e3%83%bc%e3%81%a7%e3%82%b9%e3%82%ab%e3%83%a9%e3%83%bc%e5%a0%b4%e3%82%92%e5%8f%af%e8%a6%96%e5%8c%96%e3%81%99%e3%82%8b%e5%a0%b4%e5%90%88/">続きを読む <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>何かしらのスカラー場を表現しようとしたときに，各画素に対してグレースケールで値をセットしてやれば一応可視化は出来るのですが，やはりカラーで表現したほうがきれいです．その場合，値の大小に対して，赤←→青で表現すると見やすいです．</p>
<p>そんな時にはRGB色空間ではなめらかに赤←→青の変化をつけるのが難しいので，HSV色空間を使います．処理としては，画像を一旦HSV色空間へ変換し，値をセットした後でRGB色空間へ戻せばOK．実際のコードは次のようになります．</p>
<pre class="brush: cpp; title: ; notranslate">
﻿﻿﻿#include &lt;cv.h&gt;
#include &lt;highgui.h&gt;

// h は 0から180までの値で1周なので，120までを使う
const double max_hue=120.0;
unsigned char func(int x, int y, int cols){
	// 今回は，x座標に応じてhの値を設定
	return max_hue*x/cols;
}

int main(){
	// 出力用画像
	cv::Mat img=cv::Mat::zeros(480,640,CV_8UC3);

//// HSV色空間での色表示ここから
	// HSVの画像へ変換
	cv::cvtColor(img,img,CV_BGR2HSV);

	unsigned char h,s,v;
	h=0;   // 値に応じて変化させる
	s=255; // 固定
	v=255; // 固定

	for(int y=0;y&lt;img.rows;y++){
		for(int x=0;x&lt;img.cols;x++){
			h=func(x,y,img.cols); // 適当な関数で値を決める

			// 画像の(y,x)位置に値をセット
			img.at&lt;cv::Vec3b&gt;(y,x)=cv::Vec3b(h,s,v);
		}
	}
	// BGRの画像へもどす
	cv::cvtColor(img,img,CV_HSV2BGR);
//// ここまで

	// 表示
	cv::imshow(&quot;Result&quot;,img);
	cv::waitKey();
	return 0;
}
</pre>

<a href="http://twitter.com/?status=RT%20%40%3A%20OpenCV%E3%81%A7%E3%82%AB%E3%83%A9%E3%83%BC%E3%81%A7%E3%82%B9%E3%82%AB%E3%83%A9%E3%83%BC%E5%A0%B4%E3%82%92%E5%8F%AF%E8%A6%96%E5%8C%96%E3%81%99%E3%82%8B%E5%A0%B4%E5%90%88%20-%20.COM-POUND%20http%3A%2F%2Ftinyurl.com%2F872rhbk" class="tweet-this" ><img src="http://www.yasutomo57jp.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="ツイート" alt="ツイート" />ツイート</a>]]></content:encoded>
			<wfw:commentRss>http://www.yasutomo57jp.com/2011/06/01/opencv%e3%81%a7%e3%82%ab%e3%83%a9%e3%83%bc%e3%81%a7%e3%82%b9%e3%82%ab%e3%83%a9%e3%83%bc%e5%a0%b4%e3%82%92%e5%8f%af%e8%a6%96%e5%8c%96%e3%81%99%e3%82%8b%e5%a0%b4%e5%90%88/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rubyで多項分布からのサンプリング</title>
		<link>http://www.yasutomo57jp.com/2011/01/24/ruby%e3%81%a7%e5%a4%9a%e9%a0%85%e5%88%86%e5%b8%83%e3%81%8b%e3%82%89%e3%81%ae%e3%82%b5%e3%83%b3%e3%83%97%e3%83%aa%e3%83%b3%e3%82%b0/</link>
		<comments>http://www.yasutomo57jp.com/2011/01/24/ruby%e3%81%a7%e5%a4%9a%e9%a0%85%e5%88%86%e5%b8%83%e3%81%8b%e3%82%89%e3%81%ae%e3%82%b5%e3%83%b3%e3%83%97%e3%83%aa%e3%83%b3%e3%82%b0/#comments</comments>
		<pubDate>Sun, 23 Jan 2011 17:35:35 +0000</pubDate>
		<dc:creator>yasutomo57jp</dc:creator>
				<category><![CDATA[未分類]]></category>

		<guid isPermaLink="false">http://www.yasutomo57jp.com/?p=173</guid>
		<description><![CDATA[多項分布を扱うことがあったので、Rubyでサクッと多項分布からのサンプリングを書いてみた。ただし、何も見ずにカンで書いたので合ってるかどうかはまったく保証しません。 何回か実行してみたけど、それっぽい結果が出ているのでよ &#8230; <a href="http://www.yasutomo57jp.com/2011/01/24/ruby%e3%81%a7%e5%a4%9a%e9%a0%85%e5%88%86%e5%b8%83%e3%81%8b%e3%82%89%e3%81%ae%e3%82%b5%e3%83%b3%e3%83%97%e3%83%aa%e3%83%b3%e3%82%b0/">続きを読む <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>多項分布を扱うことがあったので、Rubyでサクッと多項分布からのサンプリングを書いてみた。ただし、何も見ずにカンで書いたので合ってるかどうかはまったく保証しません。</p>
<pre class="brush: ruby; title: ; notranslate">
#!/usr/bin/ruby

# 多項分布からのサンプリングを行う関数
# probは、各項の確率（総和は１とする）
def samplingFromMultinomialDistribution(prob)
# 累積確率にする
prev=0.0
accprob=prob.map{|x| prev=prev+x }

# 一様乱数生成
r=rand()

# 要素を選択する
return accprob.index{|v| v &gt; r}
end

# 適当な多項分布
p prob=[0.6,0.2,0.1,0.05,0.04,0.01]

# サンプリングして
index=samplingFromMultinomialDistribution(prob)

# その項を出力する
p index
</pre>
<p>何回か実行してみたけど、それっぽい結果が出ているのでよしとするか…。今回は厳密さとか全くいらないので。</p>
<p>厳密さが要求されるシーンで多項分布を扱っている方々はどんなふうにサンプリングしているのだろう？</p>

<a href="http://twitter.com/?status=RT%20%40%3A%20Ruby%E3%81%A7%E5%A4%9A%E9%A0%85%E5%88%86%E5%B8%83%E3%81%8B%E3%82%89%E3%81%AE%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0%20-%20.COM-POUND%20http%3A%2F%2Fwww.yasutomo57jp.com%2F2011%2F01%2F24%2Fruby%25e3%2581%25a7%25e5%25a4%259a%25e9%25a0%2585%25e5%2588%2586%25e5%25b8%2583%25e3%2581%258b%25e3%2582%2589%25e3%2581%25ae%25e3%2582%25b5%25e3%2583%25b3%25e3%2583%2597%25e3%2583%25aa%25e3%2583%25b3%25e3%2582%25b0%2F" class="tweet-this" ><img src="http://www.yasutomo57jp.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="ツイート" alt="ツイート" />ツイート</a>]]></content:encoded>
			<wfw:commentRss>http://www.yasutomo57jp.com/2011/01/24/ruby%e3%81%a7%e5%a4%9a%e9%a0%85%e5%88%86%e5%b8%83%e3%81%8b%e3%82%89%e3%81%ae%e3%82%b5%e3%83%b3%e3%83%97%e3%83%aa%e3%83%b3%e3%82%b0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

