PHP FANN (Fast Artificial Neural Network) ã使ã£ã¦å²ãã¦ã¿ã
ãã¼ã¿è§£æãåå¼·ããã«ããã£ã¦ãä½ãã¢ããã¼ã·ã§ã³ã«ãªããã®ã¯ãªããã¨æã£ã¦ãã¾ããããããªã¨ãããå²ãã£ããããããããï¼ãã¨ã®èãã«ãããã¾ããã
ããã§ãé¡ã«ãããã ãã®ãã競馬äºæ³ãã§ããã¨ãã§ããã¼ãªã¨æã£ã¦ããã¨ããããã¼ã¿è§£æã®ãé¡ã¨ãã¦ã¯ãéèãã¨ãªããã§ãã¿ã®ãé¡ã¨ãããã¨ãå¤æãå ¥åã¨ãªããã¼ã¿ã¨çãã®å¤ãã¯ã£ãããã¦ããã®ã§ããé¡ã¨ãã¦é©åãªãã ããã§ãã
ä»åã¯ããããã20å¹´åã«å¤§å¦ã§ããã£ããã¥ã¼ã©ã«ãããã¯ã¼ã¯ã使ã£ã¦ã®ãã£ã¼ãã©ã¼ãã³ã°ï¼ãã£ãããé¿ãï¼ã§äºæ¸¬ãã¦ã¿ã¾ããã
åç½®ã
ãã¥ã¼ã©ã«ãããã¯ã¼ã¯ã«è©³ããããã¾ãããå¦çã®ã¨ããã¾ããã«åå¼·ãã¦ããã°ããã£ãã¨å¾æãã¦ãç¶æ ã§ãã
æ ¹ã£ããã®PHPerãªã®ã§PHPã使ãã¾ããPHPã«ã¯PHP-FANNã¨ããã®ãPECLã«ããã®ã§ããã使ãã¾ãã
æ¦è¦ã¯ãã®ã¹ã©ã¤ããåèã«ãªãã¾ããã
FANNã«ã¤ãã¦ã®æ¥æ¬èªããã¥ã¡ã³ãã¯ãã¡ããã¿ããã¦ããã ãã¾ããã
Momma's Wiki: FANN - Fast Artificial Neural Network Librar...
ã¤ã³ã¹ãã¼ã«
HomeBrewã使ã£ã¦ã¤ã³ã¹ãã¼ã«ãã¾ããPHPã¯5.6ãã¤ã³ã¹ãã¼ã«ããã¦ããåæã§ãã
$ brew install homebrew/science/fann $ pecl install fann
ãµã³ãã«ã§åä½ãã¹ã
ãã¡ãã®ãµã³ãã«ã³ã¼ããã³ãããã¦ãã¾ãåä½ãããã確èªãã¾ãã
å ¥åãã¼ã¿
幸ã競馬ã§ã¯èªåã§ææ°åããªãã¦ããä¸ã®ä¸ã«ããªãã¡ããææ°ãã¨ãããã®ãããµãã¦ãã¾ãããããããéãã¦ãåã¡é¦¬ã®ãã¿ã¼ã³ãæ½åºãããã¨æãã¾ãããï¼ç«¶é¦¬æ°èã®ãã¼ã¿ããããã£ãããåã¡é¦¬ã赤ãã³ã§å°ãã¤ããã¤ã¡ã¼ã¸ï¼
ãã¼ã¿éãã«ã¯ãã
$ php composer.phar require fabpot/goutte:~2.0
PHPã«åªç§ãªã¯ãã¼ã©ã¼ãç»å ´ãã¦ãã¾ãã
å ¥åãã¼ã¿ã®è¦æ ¼å
ä»åã®ä»æ§ã§ã¯ãããã¬ã¼ã¹ã«åºé¦¬ãã1é ã®åææ°ã®ãã¿ã¼ã³ã解æãã¦ã3ç以å ã®ç¢ºçãæ±ãã¾ãã
ææ°ãã¼ã¿ã¨ããã®ã¯ãJRAã«ç»é²ããã¦ãããã¹ã¦ã®é¦¬ã®ä¸ã§ã©ã®ãããã®è½åå¤ã¨ãã£ããã®ãªã®ã§ãåã¬ã¼ã¹æ¯ã«ãã®ã¬ã¼ã¹ã§ã©ã®ãããã®è½åå¤ãã¨ãã£ãããã«è¦æ ¼åãã¾ããè¦æ ¼åã®ããã«ã¯åå·®å¤ã使ç¨ãã¾ããã
PHPã§åå·®å¤ãç®åºããã«ã¯ã以ä¸ã®æ¡å¼µãã¤ã³ã¹ãã¼ã«ãã¾ãã
$ brew install php56-stats
åå·®å¤ã®ç®åºä¾
<?php $values = [1, 2, 3, 4, 5]; $std = stats_standard_deviation($values); $avg = array_sum($values) / count($values); $results = []; foreach ($values as $value) { $results[] = 10 * ($value - $avg) / $std + 50; } var_export($results); ?> array ( 0 => 35.857864376269049, 1 => 42.928932188134524, 2 => 50, 3 => 57.071067811865476, 4 => 64.142135623730951, )
éå»ãã¼ã¿ã®å¦ç¿
ãã¥ã¼ã©ã«ãããã¯ã¼ã¯ã«éå»ãã¼ã¿ãå¦ç¿ããã¾ãã試è¡é¯èª¤ã®çµæãè©ä¾¡é¢æ°ã¯ FANN_ELLIOT_SYMMETRIC
ãããã£ãã§ããä¸è¬çã«ã¯ FANN_SIGMOID_SYMMETRIC
ã使ããããã¨ãå¤ãã¿ããã§ãã
å ¥åãã¼ã¿ã®ç¯å²ã¯ä¸è¬çã«[-1ãã1]ããããä»åã¯[0ãã1]ã¨ãªã£ã¦ãã¾ããã¾ãçãã¯[-1,0,1]ãä¸ãããã¨ãå¤ããä»åã¯[0,1]ï¼5ç以å ã¯1ããã以å¤ã¯0ï¼ã¨ãã¾ããã
å¦ç¿åæ°ã¯ãMSEã®æ¨ç§»ãã¿ãªãã決å®ãã¾ããã
<?php $layers = [3, 2, 1]; $ann = fann_create_standard_array(count($layers), $layers); if ($ann) { fann_set_activation_function_hidden($ann, FANN_ELLIOT_SYMMETRIC); fann_set_activation_function_output($ann, FANN_ELLIOT_SYMMETRIC); $sql = 'SELECT index1, index2, index3, order FROM keiba_indexes'; for ($i = 0; $i < 10; $i++) { fann_reset_MSE($ann); $query = $this->query($sql); while ($row = $query->fetch()) { $order = $row['order']; unset($row['order']); $out = ($order <= 5) ? [1] : [0]; fann_train($ann, array_values($row), $out); } $mse = fann_get_MSE($ann); echo $mse . PHP_EOL; $query->closeCursor(); fann_save($ann, 'keiba_float.net'); } } ?>
äºæ³ãã¼ã¿ã®è§£æ
éæã®å¤ãåæã®å¤ã«ãªãã¨æ¬¡ã®æ¥ã®ã¬ã¼ã¹ã®åºé¦¬è¡¨ãçºè¡¨ããã¾ãããã®å¾ææ°ãã¼ã¿ãå ¬éãããããã®ã§å ¥æãã¦è¦æ ¼åãã¦ããã¾ãã
ãã¨ã¯ãå¦ç¿ã«ãã£ã¦å¾ãããé¢æ°ã§æ°å¤ãç®åºãã¾ãã
<?php $ann = fann_create_from_file('keiba_float.net'); if ($ann) { $results = []; $sql = 'SELECT index1, index2, index3 FROM keiba_indexes'; $query = $this->query($sql); while ($row = $query->fetch()) { $results[] = fann_run($ann, array_values($data)); } var_export($results); } ?>
ç®åºãããæ°å¤ãéé ã§ä¸¦ã³æ¿ããã°ãåã¤ç¢ºçã®é«ãé ã«ãªãã¾ãã
æ°ã«ãªãææã¯ï¼
ã¾ããåç´ã«æ°å¤ãåºããã ãã§ã¯å²ãããããããã¾ããã è³¼å ¥ã¬ã¼ã¹ã®ãã£ã«ã¿ãªã³ã°ããè³¼å ¥å¸ç¨®ã®æ¤è¨ãè³é管çã«ã¼ã«ãå¿ è¦ã§ããã
ã§ã¯ãã¸ã£ã¼ã³ï¼
æ¥ç¨ | çä¸ç | ååç |
---|---|---|
2/14,2/15 | 54.17% | 207.28% |
2/21,2/22 | 40.00% | 122.70% |
ã¨ããããã競馬ã«ã¯åã£ã¦ã¾ãããªããæ®é«ãå¢ãã¦ã¾ãããâ¦
欲æé§åéçºã§ã¢ãã¯ã§ããã®ã§ãããè³¼å ¥ã®éã¯æ©æ¢°çã«æ¬²æãæã¡åã£ã¦è¡ã£ãã»ããããããã§ããï¼æ¶ï¼