Rubyãåãéãç§å¦ã®æªæ¥
ãã®è¨äºã¯Ruby Advent Calendar 2014ã®13æ¥ç®ã®è¨äºã§ãã
åãã«
Rubyãæè²ã»ç 究ã«ä½¿ããã¨ãã試ã¿ã¯Rubyã®é»ææããããã¾ããã ãã®ææã®æåãªããã±ã¼ã¸ã¨ãã¦ã¯ãã¤ãªã¤ã³ãã©ããã£ã¯ã¹ã®BioRubyãå°çç§å¦ã®é»è³Rubyããã¸ã§ã¯ããæåã§ãã
å è¿°ã®BioRubyãGPhys(é»è³Rubyã®ææç©)ã¯ç¾å¨ãæ´æ°ãç¶ãããã¦ãããå¤æ°ã®å©ç¨è ãæ±ãã¦ãã¾ãã ãããå ¨ä½ã¨ãã¦è¦ãå ´åãç§å¦ã®åéã§ä½¿ãããLLè¨èªã¨ãã¦Rubyã¯PythonãRã®å¾å¡µãæãã¦ããå°è±¡ãããã¾ãã
è¨äºã®ããã«ãã®åéã§ã¯Pythonã³ãã¥ããã£ãé常ã«æ´»çºã§ãæ©æ¢°å¦ç¿ãªã©æ°ããæè¡ã¯çã£å ã«Pythonã§å®è£ ãããããã«ãªã£ã¦ãã¾ãã
ãããæè¿Rubyã§ãå°ããã¤ã§ããç°å¢ãå å®ãã¦ãã¦ãããå®éã«Pythonããä¹ãæãã人ãããããã§ãã
I hail from the world of Python
ãã®è¨äºã§ã¯2ã¤ã®ç°¡åãªä¾ãéãã¦gemãç´¹ä»ããªãããç§å¦ç 究ã®åéã«Rubyãåãè¾¼ãå¯è½æ§ãæ¢ã£ã¦ã¿ããã¨æãã¾ãã
ãã¼ã¿è§£æã¨å¯è¦å
Rubyã§ãã¼ã¿è§£æãããéã«ã¯Statsampleãæåã§ãããå®éã®ãã¼ã¿ã®åæ±ããå¯è¦åãé常ã«é¢åãªã®ãããã¯ã§ãããRã§ã¯ãã¼ã¿ã®èªã¿è¾¼ã¿ãæä½ãdata.frameã§è¡ããRStudioä¸ã§ãã¼ã¿ã¨ã°ã©ãã確èªããªããå¦çãé²ãããã¾ãã(åè: YouTube)
data.frameã®æè»æ§ãRubyã§å®ç¾ããã®ãMikon, RStudioã®ãããªçµ±åéçºç°å¢ãWebä¸ã§å®ç¾ããã®ãIRubyã§ãã ãããã使ããæåãªIrisãã¼ã¿ã»ãããIRubyä¸ã§Mikon, Statsampleã使ã解æã»å¯è¦åãè¡ã£ãéã®IRubyãã¼ãããã¯ã以ä¸ã«ç¤ºãã¾ãã*1
(å¥ã®ã¿ãã§éãã«ã¯ãã¡ã)
ä¸ã¯ãã¼ãããã¯ä¸ã§ä½æ¥ãã¦ããã¨ãã®åç»ã§ãã
ä½æ¥ä¸ã®ç¶æ ã«Markdownã§ã³ã¡ã³ããæ¸ãããã®ãä¸ã®iframeã§ãããããã®ç»åãMarkdownã§å ¥ã£ã¦ãã¾ãã
ãã®ããã«å ±æããéã«ã¯ãã¼ãããã¯(ipynb)ã¨å¼ã°ããjsonãã¡ã¤ã«ãGitHubãDropboxãªã©ã«ã¢ãããã¼ãããnbviewerã¨ããå¤é¨ãµã¼ãã¹ã使ã£ã¦ãªã³ã¯ãä½æãã¾ãã
ã³ã¼ãã®è§£èª¬ã¯çç¥ãã¾ãããå¯è¦åã»è§£æã¨ãã«é常ã«ç°¡åãªAPIã§å®ç¾ããã¦ãã¾ãã ä¾ãã°æ£å¸å³ãæ¸ãã³ã¼ãã¯ä¸ã®ä¸è¡ã ãã§ãã
plot = df.plot(type: :scatter, x: :sepal_length, y: :petal_length, fill_by: :species, color: :qual)
speciesã«ã©ã ã®å¤ã«ãã£ã¦ç¹ãå¡ãåããå¡ãã¤ã¶ãè²ã¯é¢æ£ãã¼ã¿ç¨(qual)ãªã©ç´°ããæå®ããã¦ããã«ãé¢ãããä¸è¡ã§ã§ãã¦ãã¾ããè²ãæ°ã«å ¥ããªããã°åå®è¡ããã°ãã¿ã¾ãã
以ä¸ã®ããã«ãã¼ã¿è§£æã»å¯è¦åã«ã¤ãã¦ã¯é常ã«ç°¡åã«ã§ããç°å¢ãæ´ã£ã¦ãã¦ãã¾ãã
åå¦ã·ãã¥ã¬ã¼ã·ã§ã³ã¨å¯è¦å
ããã¾ã§Rubyã§è»½ãã·ãã¥ã¬ã¼ã·ã§ã³ãæ¸ãã®ã¯ããªãå°é£ãªãã¨ã§ãããå¾®åæ¹ç¨å¼ã¯Ruby-GSLã§è§£ãã¾ããã¤ã³ã¹ãã¼ã«ã¯é常ã«ç ©éã§ãããå¯è¦åã«é¢ãã¦ã¯æ±ºå®çãªæ¹æ³ããªãã£ãããã«æãã¾ãã (ç§ãããç¥ããªãã ãããããã¾ãããâ¦)
ä»ã§ã¯Fortranãã©ããããODE gem (gem install ode
ã ãã§ã¤ã³ã¹ãã¼ã«å¯è½)ã§å¸¸å¾®åæ¹ç¨å¼ã解ããã¨ãã§ãã¾ãã
ã¾ããIRubyã«æ°ããå ãã£ãCustomWidgetã使ããã¨ã§ãRubyã¨ãã¤ãã£ãæ¡å¼µã®åºããçµæããªã¢ã«ã¿ã¤ã ã«ãã©ã¦ã¶ä¸ã«è¡¨ç¤ºã§ãã¾ãããã®å ´åJavaScriptã®æåãªdomæä½ã©ã¤ãã©ãªãjQueryãd3.jsã使ã£ã¦å¯è¦åé¨åãç°¡åã«æ¸ããã¨ãã§ãã¾ãã
以ä¸ã®ãããªäºéæ¯ãåãã·ãã¥ã¬ã¼ã·ã§ã³ãã¦ã¿ã¾ãã
ã¦ã£ãããã£ã¢ã®å·çè ï¼2014ï¼ãäºéæ¯ãåããã¦ã£ãããã£ã¢æ¥æ¬èªçãï¼ï¼2014å¹´12æ13æ¥åå¾ï¼linkï¼ï¼
ãã®ç³»ã®éåæ¹ç¨å¼ã¯äºé常微åæ¹ç¨å¼ã§æ¸ã表ããã¾ãã
ãã®å¼ãå¤æ¬¡å é åã©ã¤ãã©ãªNMatrixã®ç·å½¢ä»£æ°ã¢ã¸ã¥ã¼ã«ã¨ODE gemã§ã¨ããd3.jsã§è¡¨ç¤ºããã®ã以ä¸ã®åç»ã§ãã
ãã®ããã«åæå¤ããã©ã¡ã¼ã¿ãå¤ããªããä½åº¦ãã·ãã¥ã¬ã¼ã·ã§ã³ããããã¨ãã§ãã¾ãã
ãã¼ãããã¯ã¨ãã¦å ¬éããã¨ãã¯ããã¯ã¨ã³ãã®Rubyã¤ã³ã¿ããªã¿ã¨ã®æ¥ç¶ã¯åãã¦ãã¾ããããå®è¡å¯è½ãªã¾ã¾å ¬éãããã¨ã¯ã§ãã¾ãããçµæã®ä¸é¨ããã¼ãããã¯ã®jsonãã¡ã¤ã«ã«åãè¾¼ãã§è¡¨ç¤ºãããã¨ã«ãªãã¾ãã *2
(ãã¿ã³ãæ¼ãã¨åçã§ãã¾ããå¥ã®ã¿ãã§éãã«ã¯ãã¡ãã)
ãã®ããã«ãGUIæä½ããã¾ãå¾æã§ãªãRubyã«ä»£ããå¯è¦ååãã®ã©ã¤ãã©ãªããããã¨å å®ãã¦ããJavaScriptã§å¯è¦åé¨åãæ¸ããã¨ãã§ãã¾ããã¾ããIRubyä¸ãªãã°å ±æãç°¡åã§ãã
Ruby製ã®ã·ãã¥ã¬ã¼ã¿ã»JavaScript製ã®ãã¸ã¥ã¢ã©ã¤ã¶å ±ã«GitHubä¸ã«ã³ã¼ããå ¬éãã¦ãã¾ãã
ã¾ã¨ã
ããã¾ã§æ¸ãã¦ããããã«ãRubyã§æè²ã»ç 究ãè¡ãããã®ç°å¢ã¯ããªãæ´ã£ã¦ãã¦ããã¨æãã¾ãããã®è¨äºã§ç´¹ä»ãã2ã¤ã®ä¾ã¯é常ã«åç´ãªãã®ã§ãããåæ¹ã¨ãã«RãMATLABã§ãåããã¨ãã§ããã¯ãã§ãã
ããã両è ã«æ¯ã¹ã¦Rubyãææãªã®ã¯IRubyã®åå¨ã§ããRubyãCã§æ¸ãããã³ã¼ããWebã«æ¥ç¶ã§ããã¨ããã®ã¯ã¨ã¦ã大ããªãã¨ã ã¨æãã¾ãã(ãã®ç¹ã«é¢ãã¦ã¯Rã«ãåããããã¾ãããã¾ã ãã»ã©çãä¸ãã£ã¦ããªãããã§ãã)
IRubyã使ãã°æå ã«ç°å¢ãæ§ç¯ãã¦ããªã人ã§ãéããã¦ãããªã³ã¯ããã©ã¦ã¶ã§éãã ãã§çµæãè¦ããã¨ãã§ãã¾ããã³ã¼ããå«ã¾ãã¦ããã®ã§ç°å¢ãæ§ç¯ããã°æå ã§åç¾ãããã¨ãã§ãã¾ãã
ããã¯é常ã«å¤§ããªã¤ã³ãã¯ãããããç 究ã®ä¸çã§ãæ´»ç¨ããå§ãã¦ããããã§ãã
nbviewer - Finding shape consensus among multiple geo polygons
nbviewer - E-cell4
ãããæ®å¿µãªã®ã¯ãã®æµãã主å°ãã¦ããã®ã¯Rubyçã§ãªãã¨ãããã¨ã§ãã ç´¹ä»ããIRubyã¯Pythonã®ã³ãã¥ããã£ããçã¾ããIPythonã«ä¾åãã¦ãã¾ãããåããã¨ãã»ã¼ãã¹ã¦Pythonã§å®ç¾å¯è½ã§ãã ã¾ãBokehãVincentãªã©æ¬¡ã çã¾ããWebä¸ã®ããããã©ã¤ãã©ãªãå ¨ã¦Pythonåãã§ãã
ãããå®éã«çããªããç´ä¸å¹´éRubyã§å¯è¦åã©ã¤ãã©ãªãæ¸ããPythonã§ã·ãã¥ã¬ã¼ã¿ã»ååãã¸ã¥ã¢ã©ã¤ã¶ãæ¸ãã¦ãã¦æããã®ã¯ä¸¡è ã«ã¯ã©ã¡ãã®è¨èªä»æ§ãç 究ã«åãã¦ããã¨ãã£ãå·®ãç¹ã«è¦ãããªãã¨ãããã¨ã§ããããããããã«Rubyã§ãã®åéã®ç°å¢ãå å®ãã¦ãããã¨ãæå¾ ãã¾ãã
GSoC@SciRuby
åãä»å¹´ãä¸è©±ã«ãªã£ãSciRubyã§ã¯æ¥å¹´åº¦ãGoogle Summer of Code (GSoC)ã®åéãããã¯ãã§ããèå³ãæãããæ¹ããããæ¯éãé¡ããã¾ãã
è¨äºä¸ã®gemã®ãªã¹ã
ãã®è¨äºã§ã¯ä»¥ä¸ã®6ã¤ã®gemãç´¹ä»ãã¾ããã
IRuby
Webä¸ã®Rubyå®è¡ç°å¢ãè¨äºä¸ã«ç´¹ä»ããéããèªåã§çæãããipynb(å®ä½ã¯json)ãã¢ãããã¼ããããã¨ã§ã³ã¼ãã¨å®è¡çµæãå ±ã«å ±æã§ãã¾ãã Pryãä¸ç·ã«ã¤ã³ã¹ã-ã«ããã¨è£å®ãå¹ãããã«ãªãããªã使ãå¿å°ãããã§ããã³ããã¿ãã£ã¦ã¾ãã
ã¤ã³ã¹ãã¼ã«æ¹æ³ã«ã¤ãã¦ã¯ãã¡ã
Mikon
Ruby製ãã¼ã¿ãã¬ã¼ã gemãRubyã¢ã½ã·ã¨ã¼ã·ã§ã³2014年度å©æéã®å¯¾è±¡ã«ããªã£ã¦ãã¾ãã IRubyä¸ã§ã®ã·ã¼ã ã¬ã¹ãªå¯è¦åãStatsampleã®æã¤è±å¯ãªçµ±è¨å¦çã¡ã½ãããé©å¿ã§ãããã¨ãç¹å¾´ã§ãã ããã¯ã¨ã³ãã«ã¯ä¸ã§ç´¹ä»ããç·å½¢ä»£æ°ã©ã¤ãã©ãªã®NMatrixã使ã£ã¦ãã¾ãã ããããå©æéã®æéä¸Nyaplotã»IRubyã¨ã®çµ±åãããã«é²ãã¦ããäºå®ã§ãã
Nyaplot
æä½ã®IRubyä¸ã§åãå¯è¦åç¨gemã§ãã 使ãå¿å°ã¯Pythonã®Bokehã«è¿ãã§ããã3Dãããããå°å³ãçç©åãã®ããããã¾ã§å¤ãã®ç¨®é¡ã®ããããããµãã¼ããã¦ããããã®ç¹ã§ã¯matplotlibã«è¿ããã¨æãã¾ãã æ¥æ¬èªã®ç´¹ä»è¨äºã¯ãã¡ãã
Statsample
SciRubyããã¸ã§ã¯ãã®ä¸é¨ã®çµ±è¨å¦çç¨gemã§ãã ããã¤ãæ¥æ¬èªã§ã®ç´¹ä»è¨äºãããã¾ãã
ODE
æä½ã®ODE(常微åæ¹ç¨å¼)ã®ã½ã«ããããã±ã¼ã¸ããgemã§ãã Fortranã§æ¸ãããODEPACKã®Rubyã©ããã¨ãã¦å®è£ ããã¦ããã®ã§scipy.integrate.odeã¨åç¨åº¦ã®é度ãæå¾ ã§ããã¯ãã§ãã æªã ODEPACKã«å«ã¾ããã½ã«ãã®å lsodaã®APIããç¨æã§ãã¦ãã¾ããããããã¯ä»ã®ã½ã«ããâ¦
NMatrix
SciRubyã§éçºãé²ãããã¦ããç·å½¢ä»£æ°ã©ã¤ãã©ãªã§ãã Pythonã®Numpyã¨åãBLAS, LAPACKãã©ãããã¦ãã¾ãã 両ã©ã¤ãã©ãªã®æã¤æ©è½ã®å ããªãããµãã¼ãããã¦ãã¾ãããå®éã«ä½¿ã£ã¦ã¿ãã¨Numpyã¨æ¯ã¹ã¦ä½æ©è½ã§ãã£ãããä¸å®å®ã§ãããã¨ããããã¾ããSciRubyã§ãç¾å¨çµ¶è³éçºè åéä¸ã§ãã
ã¤ã³ã¹ãã¼ã«æ¹æ³ã¯ãã¡ãã
ç°å¢æ§ç¯ã«ã¤ãã¦
ä¸è¨ã®gemã大ä½ã¤ã³ã¹ãã¼ã«æ¸ã¿ãªdockerã¤ã¡ã¼ã¸ãSciRuby-dockerã¨ãã¦å ¬éãã¦ãã¾ãã ã°ãã°ãã«ã¤ã³ã¹ãã¼ã«ããã®ãããã©ãããã¨ããæ¹ã¯dockerãå ¥ã£ãç°å¢ã§ä»¥ä¸ã®ã³ãã³ã:
docker pull domitry/sciruby-docker docker run -i -p 9999:9999 domitry/sciruby-docker:latest
ãå®è¡ããå¾localhost:9999ããã©ã¦ã¶ã§éãã¨ãµã³ãã«ã®ãã¼ãããã¯ã¨å ±ã«IRubyãèµ·åãã¦ããã¯ãã§ãã