PFN製ã®æé©åãã¼ã«ãOptunaãã§å¯å£«å±±ãç»é ãã
1. èæ¯
Optunaã¨ã¯ãPreferred Networksï¼ä»¥ä¸PFNï¼ã®ç§èæ°ããéçºãããã¤ãã¼ãã©ã¡ã¼ã¿èªåæé©åãã¼ã«ã§ãã
ハイパーパラメータ自動最適化ツール「Optuna」公開 | Preferred Research
ããã¯å¾é æ³ã®é©ç¨ã§ããªãï¼ããªãï¼ãã¤ãã¼ãã©ã¡ã¼ã¿ããã¤ãºæé©åã¢ã«ã´ãªãºã ã®ä¸ç¨®ã使ã£ã¦èªåã§æé©åãã¦ããããã®ã§ãããChainerã¨å¯çµåãã¦ããããã§ã¯ããã¾ãããä½ããã®Objective functionãä¸ãããã¨ã§ç°¡åã«æé©åãè¡ã£ã¦ãããããã«ãªã£ã¦ãã¾ã*1ã
â â â
Objective...? ç»å±±ã«ã¨ã£ã¦ããã¯æ¨é«ã ãã¨å¤ãã®äººã¯èããã®ã§ã¯ãªãã§ããããï¼ æ¨é«ãå¯ä¸ã®ç®çã§ã¯ãªãã«ãããä¸çæé«å³°ããã¨ãã¬ã¹ããç»å±±å®¶ãæ¹ãã¤ããå½ãçã¿ãªãææ¦ãçã¿åºãã¦ãããã¨ã¯äºå®ã§ãã
ã¨ããããã§ããã®è¨äºã§ã¯Optunaãå°å½¢ã«å¯¾ãã¦é©ç¨ãããã¨ã§å¯å£«å±±ã®å±±é ãç®æãã¾ãã
å±±å·ã®å²©ã«åã£ã¦ä¸æéã
å¯ãã â ã¨ããä¸ã¤ã®è¨èãç²ã¤ã¶ã®ããã«å¿ã«æµ®ããã§ãããã ãç§ã¯ããã声ã«ã§ããªãã
æ²é»ã¯èªèã§ã¯ãªããã§ãããã¯ããããä¸çæ©ããããæ©ãã¤ã¥ãç»ãã¤ã¥ããä»ã«ç»å±±è ã«ã¯çãããããªãã
è¾»ã¾ãã¨ãåå²³ã«ã¦ã
2. æ¹æ³
以ä¸ã§ã¯ãå¯å£«ç»å±±ããå¯å£«å±±ä»è¿ã®æ¨é«ãåããäºæ¬¡å é åã«é¢ãã¦ãæ¨é«ãæ大å¤ãã¨ããããªã¤ã³ããã¯ã¹ãæ¢ç´¢ããåé¡ãã¨ãã¦æãã¾ãã
æé©åã®å¯¾è±¡ã¨ãªãã®ã¯äºæ¬¡å é åã®ã¤ã³ããã¯ã¹(x2)ã§ãããåã¤ã³ããã¯ã¹ã«ãããæ¨é«ã-1åãããã®ãæå°åããããã«Optunaã使ç¨ãã¾ãã
2.1. æ¨é«ã¿ã¤ã«
æ¨é«ã«é¢ãããã¼ã¿ã¯å½åå°çé¢ã®æ¨é«ã¿ã¤ã«ããå ¥æãã¾ãã詳細ã¯ä»¥ä¸ã®Qiitaã®è¨äºã«æ¸ãã¦ãã¾ããã座æ¨ï¼ã¿ã¤ã«åº§æ¨ã¨ããï¼ãæå®ãããã¨ã§ãæ£æ¹é åã®æ¨é«å¤ãäºæ¬¡å é åã¨ãã¦åå¾ãããã¨ãå¯è½ã§ãã
ä»åã¯ãå¯å£«å±±å¨è¾ºã®ã¿ã¤ã«åº§æ¨ã¨ã㦠ãç¨ãã¾ããã
Pythonã§æ¨é«ã¿ã¤ã«ãåå¾ããããã«ã¯ä»¥ä¸ã®ããã«ãã¾ãã
fuji = (10, 906, 404) # Mt. Fuji
fuji_tile = fetch_tile(*fuji)
ããã§ãfetch_tile
é¢æ°ã¯ä»¥ä¸ã®Qiitaã®è¨äºã«è¨è¼ããéãã§ãã
qiita.com
2.2. Optuna
å
¬å¼ã®Tutorialãããã®ã§ãããåèã«ãã¾ãã
trial
ãªãã¸ã§ã¯ããåãåãé¢æ°ã§æå°åãããç®çé¢æ°ãå®ç¾©ãããã®ä¸ã§trial.suggest_***
ã®ããã«ãããã¨ã§æ¢ç´¢ããããã©ã¡ã¼ã¿ã宣è¨ãã¾ãã
ä»åã®å ´åãfuji_tile
ã¨ããäºæ¬¡å
é
åï¼ï¼ã«ããã¦æ¨é«ãæ大åããé¢æ£çãªã¤ã³ããã¯ã¹ ï¼æ´æ°å¤ï¼ãæ¢ãããã®ã§ã以ä¸ã®ããã«ããã°è¯ãã§ãããã
import optuna
def fuji_objective(trial):
x = trial.suggest_discrete_uniform('x', 0, 255, 1)
y = trial.suggest_discrete_uniform('y', 0, 255, 1)
return - fuji_tile[int(y)][int(x)]
study = optuna.create_study()
study.optimize(fuji_objective, n_trials=100)
3. çµæ
3.1. å®è¡ä¾
å®è¡ãããã³ã«çµæã¯ç°ãªãã¾ããã試ãã«ä¸åº¦å®è¡ãã¦ã¿ãçµæãè¨ãã¾ãã
ã¾ããn_trials
ï¼ä»åã¯100åã®trialï¼å
ã§å¾ãããæé©ãªãã©ã¡ã¼ã¿ã¯ä»¥ä¸ã®ããã«å¾ããã¾ããä»åã®å ´åã ã¨ãæ¨é«ãæ大ã«ãªã£ãäºæ¬¡å
é
åã®ã¤ã³ããã¯ã¹ã«ç¸å½ãã¾ãã
study.best_params
# => {'x': 159.0, 'y': 85.0}
ãã®éã®ç®çé¢æ°ã®å¤ï¼ä»åã®å ´åãæ大ã¨ãªã£ãæ¨é«ã®-1åï¼ã¯ä»¥ä¸ã®ããã«ãã¦åå¾ã§ãã¾ãã åã®ã¤ã³ããã¯ã¹ãã100éãï¼n_trials
ï¼ããæ¢ç´¢ãã¦ããªãã®ã§ãããå¯å£«å±±ã®æ¨é«3776mï¼ã®-1åï¼ã«è¿ããã®ãå¾ããã¾ããã
study.best_value
# => -3662.8
ã¾ããä¸ã¤ä¸ã¤ã®trial
ã«ããããã©ã¡ã¼ã¿ãç®çé¢æ°ã®å¤ãªã©ãstudy.trials
ã«å
¥ã£ã¦ããããã以ä¸ã®ããã«éä¸çµéãå¯è¦åãããã¨ãã§ãã¾ãã
plt.imshow(fuji_tile)
plt.scatter([t.params["x"] for t in study.trials], [t.params["y"] for t in study.trials], s=20, marker="+", color="white")
plt.scatter(study.best_params["x"], study.best_params["y"], s=100, color="red")
ãããå®è¡ããã®ãä¸å³ãå¡ãæ½°ãã¯å¯å£«å±±è¿è¾ºã®æ¨é«ã«å¯¾å¿ï¼é»è²ã£ã½ãã»ã©é«ãï¼ããç½ãç¹ãæ¢ç´¢éç¨ã§å¾ããã座æ¨ã赤ãç¹ãæ¢ç´¢éç¨ã§ãã£ã¨ãæ¨é«ãé«ãã£ãç¹ã¨ãªã£ã¦ãã¾ããå±±é è¿è¾ºãä¸å¿ã«æ¢ç´¢ãè¡ããã¦ããããã«æããã¾ãã
3.2. ç»å±±çµè·¯
å ã»ã©ã®æ£å¸å³ã«å ããtrialéã§ã©ã®ããã«ãã©ã¡ã¼ã¿ï¼ä»åã¯x, y座æ¨ã«å¯¾å¿ï¼ã®å¤ãé·ç§»ããã®ããå¯è¦åãããã¨ãã§ãã¾ãã
for i in range(len(study.trials[:])-1):
plt.plot(
[study.trials[i].params["x"], study.trials[i+1].params["x"]],
[study.trials[i].params["y"], study.trials[i+1].params["y"]],
color="gray", linestyle='-', linewidth=1)
å®è¡çµæã¯ä»¥ä¸ã®ããã«ãªãã¾ããå¾é æ³ã¨ã¯ç°ãªããå¿ ãããè¿ãã¸ç§»åãã¦ãã訳ã§ã¯ãªãããã§ããã
æ¨é«ã®æ¨ç§»ãå¯è¦åãã¦ã¿ã¾ãããã
plt.plot([-t.value for t in study.trials])
plt.xlabel("Trial")
plt.ylabel("Elevation")
縦軸ãããã®Trialã«ãããæ¨é«ãã§ã¯ãªããããã¾ã§ã®Trialã«ãããæé«ã®æ¨é«ãã«ããã¨ä»¥ä¸ã®ããã«ãªãã¾ãã
import pandas as pd
plt.plot(pd.DataFrame([-t.value for t in study.trials]).cummax())
plt.xlabel("Trial")
plt.ylabel("Cumlative Max of Elevation")
å ¨ãåãã°ã©ããã10åã®studyã§æç»ããã¨ä»¥ä¸ã®ããã«ãªãã¾ãã横軸ï¼Trialåæ°ï¼ãå ã»ã©ããåºãã«ã¨ã£ã¦ãã¾ãã
for i in range(10):
study = optuna.create_study()
study.optimize(fuji_objective, n_trials=300)
plt.plot(pd.DataFrame([-t.value for t in study.trials]).cummax())
plt.xlabel("Trial")
plt.ylabel("Cumlative Max of Elevation")
200trialãããçµéããã¨ã»ã¼å±±é è¿ãã¾ã§å°éãã¦ããããã§ããã
4. ã¾ã¨ã
å¯å£«ç»å±±ããå¯å£«å±±ä»è¿ã®æ¨é«ãåããäºæ¬¡å é åã«é¢ãã¦ãæ¨é«ãæ大å¤ãã¨ããããªã¤ã³ããã¯ã¹ãæ¢ç´¢ããåé¡ãã¨ãã¦æãããã¨ã«ãããOptunaã§å±±é ãæ¢ããã¨ãã§ãã¾ããã
ç§ã®èªèãæ£ãããã°Optunaã¯å±±é ãæ¢ãããã®ãã¼ã«ã§ã¯ãªãã®ã§ããã åã®ã¤ã³ããã¯ã¹ãã200ã»ã©æ¢ç´¢ããæç¹ã§å±±é ä»è¿ã«å°éãããã¨ã«æåãã¾ãããã©ã³ãã orçééã«ãµã³ããªã³ã°ããå ´åã¨å®éçã«æ¯è¼ãã訳ã§ã¯ããã¾ããããããããâ¦ã¨çªã£è¾¼ã¿å§ãããããªã®ãªãå 容ã§ã¯ããã¾ãããæãã®ã»ããã¾ãè¡ã£ããããªå°è±¡ãåãã¦ãã¾ããOptunaã¯ã¨ã¦ã使ãããããã£ãã®ã§ãä»åº¦ã¯ã¡ããã¨æ©æ¢°å¦ç¿ã«ã使ã£ã¦ã¿ããã¨æã£ã¦ãã¾ãã
以ä¸
å±±ã¨é«åå°å³ å¯å£«å±± 御åã»æ鷹山 (å±±ã¨é«åå°å³ 32)
- ä½è : ææ社å°å³ç·¨éé¨
- åºç社/ã¡ã¼ã«ã¼: ææ社
- çºå£²æ¥: 2018/03/20
- ã¡ãã£ã¢: å°å³
- ãã®ååãå«ãããã°ãè¦ã
*1:ãã¡ãããåé¡ã®æ§è³ªã«ãã£ã¦ã¯ä»ã®æé©åææ³ãç¨ããã¹ãã§ã