テーマ1 データの 処 理 と 加 工 後 半 :CUI 編
今日の内容について 次回はひたすらターミナル窓でコマンドを打って 実習になります コマンドについて ターミナルの利用 Gnuplotについて 要ブックマーク http://lowrank.net/gnuplot/intro/basic.html 参考 コマンドについての資料 http://tsubame.gsic.titech.ac.jp/tutorials の UNIX入門 のテキスト
CUIの 特 長 コンピュータはもともとキーボードだけで 使 える コマンド( 命 令 )を 打 ちさえすればやってくれる 明 快 コマンドを 勉 強 すればするほど 熟 練 者 になれる 今 日 はひたすらキーボードを 打 つだけ! 注 意 :コマンドをひとつ 実 行 するたび 何 が 起 きたか よく 確 かめよう
Documentsフォルダの整理 il1kaiという名前のフォルダを作って先週のファイルを移す $ pwd $ ls $ cd Documents ; ls $ mkdir il1kai ; ls $ mv fig2 il1kai $ mv fig5 il1kai $ mv *.xlsx il1kai $ mv *.docx il1kai $ ls $ cd il1kai $ pwd $ ls $ cd.. ; pwd Documentsフォルダへ移動 新しいフォルダができている 移動したファイルはなくなっている il1kaiディレクトリに移動 ファイルがコピーされてきている Documentsフォルダへ戻る pwd print where directory ls list cd change directory mkdir make directory mv move.. ひとつ上のディレクトリ ワイルドカード 任意の文 字列にマッチ
指 の 体 操 開 始!
gnuplot 簡 単 紹 介 以 下 のコマンドをターミナル 窓 に 打 ち 込 んでいきなさい コマンド をひとつ 打 つたび 何 が 起 きるか よく 観 察 しましょう $ cd ~/Documents $ mkdir gnutest $ ls $ cd gnutest $ pwd ; ls sample.dataとsampleplot.plotをダウンロードしてこのディレ クトリに 置 きなさい open a coteditor ファイル 名 で 中 身 を 見 てみましょう $ gnuplot gnuplot 起 動 コマンド gnuplotはcuiツール
gnuplotでサインカーブ gnuplot> plot sin(x) gnuplot> set terminal gnuplot> set terminal pngcairo gnuplot> set output test.png" gnuplot> plot sin(x) gnuplot> set terminal pdfcairo gnuplot> set output test.pdf" gnuplot> plot sin(x) gnuplot> set terminal aqua gnuplot> plot sin(x) gnuplot> exit 終了 $ ls $ open test.png $ open test.pdf png形式の画像 ビットマップ形式画像 pdf形式の画像 ベクトル形式画像 両者の違い 違いの理由 それぞれの用途 教科書2.3 画像ファイル p49
複数グラフ グラフの範囲指定 Terminal type set to 'aqua' gnuplot> plot sin(x) gnuplot> plot cos(x) gnuplot> plot sin(x),cos(x) gnuplot> set xrange [-pi:pi] gnuplot> plot sin(x),cos(x) gnuplot> set autoscal gnuplot> plot sin(x),cos(x)
対数グラフ gnuplot> plot exp(x) gnuplot> set logscale y gnuplot> replot gnuplot> unset logscale y gnuplot> replot gnuplot>
データファイルのデータを散布図に gnuplot> plot "sample.data gnuplot> plot "sample.data" with linespoints sample.data の中身 数値データの並んだプ レーンテキストファイル の行は注釈行 # sample data #xy 0.278 2.4739 0.398 3.6995 0.522 4.1761 0.743 5.5990 0.911 7.1240 0.937 7.4567 1.022 8.2219 1.398 12.481 1.521 13.690 1.843 18.079
近似直線 http://lowrank.net/gnuplot/intro/plotfunc.html gnuplot> f(x)=a*x+b gnuplot> fit f(x) sample.data via a,b gnuplot> print a 9.73401331366569 gnuplot> print b -1.01826094517168 gnuplot> print f(1.3) 11.6359563625937 gnuplot> plot "sample.data",f(x) 多項式あてはめ
出力 gnuplot> set terminal pngcairo Terminal type set to 'pngcairo' Options are ' background "#ffffff" enhanced fontscale 1.0 size 640, 480 ' gnuplot> set output "samplefit.png" gnuplot> plot "sample.data",f(x) gnuplot> exit $ ls fit.log sample.data $ open samplefit.png samplefit.png
スクリプトファイルとその実行 Sampleplot.plot の中身 実行させる命令を 予めファイルに書 いたもの $ gnuplot sampleplot.plot $ ls fit.log sample.data sampleplot.plot $ open samplefit.pdf set terminal pdfcairo set output "samplefit.pdf f(x)=a*x*x+b*x+c fit f(x) "sample.data" via a,b,c print a print b print c plot "sample.data",f(x) スクリプトの実行 samplefit.pdf samplefit.png
指 の 体 操 と gnuplotの 簡 単 説 明 おしまい
共 通 教 材 の 配 布 説 明 http://www.is.c.titech.ac.jp/edu/2016-infoliteracy2/il2adata/dataset/ Il2a-dataフォルダが 解 凍 されてダウンロードされてくる ダウンロードフォルダからDocumentsフォルダに 移 して 作 業 を 行 おう Il2a-dataフォルダの 中 身 をFinderで 確 認 しよう plot/images のフォルダは 最 初 空 っぽなことを 確 認 しておく
実習C 図5と図6の折れ線 http://www.is.c.titech.ac.jp/edu/2016-infoliteracy2/il2a-data/exc-figs56/ plotフォルダのfig5-all-etime-size.plotをテキストエディタで 見てみよう 実行したら何が起きるか $ cd ~/Documents ; ls $ cd il2a-data ; ls README.md he1 cnm he2 tabキー hn plot 長いファイル名を指定すると き全部打つ必要はありません 少し打ってtabキーを押すと あとは自動補完してくれます $ cd plot $ ls fig2-cnm-joins-time-series.plot fig5-all-etime-size.plot fig3-cnm-ratio-joins.plot images $ open -a coteditor fig5-all-etime-size.plot
実習C 図5と図6の折れ線 http://www.is.c.titech.ac.jp/edu/2016-infoliteracy2/il2a-data/exc-figs56/ fig5-all-etime-size.plotを実行しよう $ gnuplot fig5-all-etime-size.plot 起きたことの確認 $ ls fig2-cnm-joins-time-series.plot fig3-cnm-ratio-joins.plot images $ cd images $ ls fig5-all-etime-size.pdf $ open fig5-all-etime-size.pdf fig5-all-etime-size.plot
図6は図5のスクリプトを参考にして 自分で生成すること スクリプトファイルの名前は fig6-tw-etime-size-m2.plot として下さい 図6は図5と同様なので fig6-tw-etime-size-m2.plotはfig5all-etime-size.plotをコピーしたものを修正して作ります ファイルのコピーは cp コマンドで行います cp コピー元ファイル コピー先ファイル
$ cd.. $ ls fig2-cnm-joins-time-series.plot fig5-all-etime-size.plot fig3-cnm-ratio-joins.plot images $ cp fig5-all-etime-size.plot fig6-tw-etime-size-m2.plot $ ls fig2-cnm-joins-time-series.plot fig6-tw-etime-size-m2.plot fig3-cnm-ratio-joins.plot images fig5-all-etime-size.plot $ open -a coteditor fig6-tw-etime-size-m2.plot
fig6-tw-etime-size-m2.plotをエディタで修正 HE のデータは he2/etime-size-m.data です HEのデータは he1/etime-size-m.data です HNのデータは hn/etime-size-m.data です グラフの出力するpdfファイルの名前は images/fig6-tw-etime-size-m.pdf coteditorで修正し 保存します gnuplotコマンドでfig6-tw-etime-size-m2.plot を実行させます
$ cat fig6-tw-etime-size-m2.plot set encoding utf8 set terminal pdf catはファイルの 中 身 をその 場 で 確 認 するコマンド set style line 1 linewidth 4 dashtype 1 linecolor rgb "black" set style line 2 linewidth 4 dashtype 2 linecolor rgb "black" set style line 3 linewidth 4 dashtype 3 linecolor rgb "black" set style line 4 linewidth 4 dashtype 4 linecolor rgb "black" $ gnuplot fig6-tw-etime-size-m2.plot $ cd images $ ls fig5-all-etime-size.pdf fig6-tw-etime-size-m.pdf $ open fig6-tw-etime-size-m.pdf set output "images/fig6-tw-etime-size-m.pdf" set xlabel "Size of Social Network" set ylabel "Elapsed Time [sec]" plot "../he2/etime-size-m.data" title "HE'" with lines linestyle 3, "../he1/etime-size-m.data" title "HE" with lines linestyle 2, "../hn/etime-size-m.data" title "HN" with lines linestyle 1
実習B 図3と図7の散布図 http://www.is.c.titech.ac.jp/edu/2016-infoliteracy2/il2a-data/exb-fig3/ $ cd ~/Documents/il2a-data/plot ; ls fig2-cnm-joins-time-series.plot fig6-tw-etime-size-m2.plot fig3-cnm-ratio-joins.plot images fig5-all-etime-size.plot $ gnuplot fig3-cnm-ratio-joins.plot $ cd images $ ls -l 図3のpdf画像ファ イルは巨大 total 4213 -rw-r--r-- 1 16PT0001 _lpoperator 2109282 6 15 13:56 fig3-cnm-ratio-join.pdf -rw-r--r--@ 1 16PT0001 _lpoperator 24391 6 15 13:13 fig5-all-etime-size.pdf -rw-r--r--@ 1 16PT0001 _lpoperator 22967 6 15 13:43 fig6-tw-etime-size-m.pdf $ open fig3-cnm-ratio-join.pdf
図3の散布図について 図3のデータファイルは cnm/ratio-join.data 11.1MBもあり エディタで表示させるのも時間が掛かる 427,794行のファイル plot/fig3-cnm-ratio-joins.plotを実行して描かれる散布図の pdfファイルの不適切な点を修正する fig3-cnm-ratiojoins2.plotを作成せよ
図3 fig3-cnm-ratio-joins2.plot fig3-cnm-ratio-joins.plot をコピーしてスクリプトファイル fig3-cnm-ratio-joins2.plot を作り 片対数グラフに変更し 画像ファイル形式も.pngに変更します $ cd.. ; pwd ; ls /home/usr0/16pt0001/documents/il2a-data/plot fig2-cnm-joins-time-series.plot fig6-tw-etime-size-m2.plot fig3-cnm-ratio-joins.plotimages fig5-all-etime-size.plot $ cp fig3-cnm-ratio-joins.plot fig3-cnm-ratio-joins2.plot $ open -a coteditor fig3-cnm-ratio-joins2.plot
fig3-cnm-ratio-joins2.plotを 修 正 pdf 画 像 ではなく png 画 像 に 出 力 する 出 力 するファイル 名 は images/fig3-cnm-ratio-join.png 片 対 数 グラフの 設 定 set logscale y 対 数 目 盛 り set format y "10^{%L}"
図7の散布図 fig7-hn-ratio-joins.plot fig7-hn-ratio-joins.plotは plot/fig3-cnm-ratio-joins2.plot をコピーしてきて 以下の2点を修正して描きます 修正1 図7のグラフは images/fig7-hn-ratio-join-500k.png に出力しましょう 修正2 図7のグラフの使用するデータは hn/ratio-join-500k.data です このデータを図3と同じ 片対数グラフで描きましょう
$ cd.. $ ls fig2-cnm-joins-time-series.plot fig6-tw-etime-size-m2.plot fig3-cnm-ratio-joins.plot fig3-cnm-ratio-joins2.plot images fig5-all-etime-size.plot $ cp fig3-cnm-ratio-joins2.plot fig7-hn-ratio-joins.plot $ open -a coteditor fig7-hn-ratio-joins.plot エディタで 修 正 保 存 $ gnuplot fig7-hn-ratio-joins.plot $ cd images ; ls fig3-cnm-ratio-join.pdf fig3-cnm-ratio-join.png fig5-all-etime-size.pdf $ open fig7-hn-ratio-join-500k.png fig6-tw-etime-size-m.pdf fig7-hn-ratio-join-500k.png
本日作成した以下の図とスクリプトを 圧縮ファイルでOCW-iに提出 fig5-all-etime-size.pdf fig6-tw-etime-size-m.pdf fig3-cnm-ratio-join.png fig7-hn-ratio-join-500k.png fig6-tw-etime-size-m2.plot fig7-hn-ratio-joins.plot fig3-cnm-ratio-joins2.plot Imageフォルダにある この4つのグラフ画像ファイルを graph3567.zipに圧縮してまとめ OCW-iのグラフ提出欄から提出 Plotフォルダにある この3つのgnuplotスクリプトファイ ルを script367.zipに圧縮してまと め OCW-iのグラフ提出欄から提出
おまけ Excelで扱える最大データ数 Excelのシート上 CTRL+ を一回押すとデータのある最終行 もう一回押すとシートの最大データ行に飛びます 図6 スケーラビリティの実験 で調べたようなデータの個数 つまり550万個ぶんのデータはExcelでは扱えません