誤差éä¼æ¬æ³ãå®è£ ãã¦MNISTã®å¦ç¿ã¨èªèããã°ã©ã ãCè¨èªã§ãã«ã¹ã¯ã©ããã§ä½ãã åä½ããã³ã¼ãã¯å®æããä»åº¦ã¯ãããåºå®å°æ°ç¹åããªããã°ãªããªããä»åã¯åºå®å°æ°ç¹åã®æ¤è¨ãè¡ãã
double –> float ã§ç²¾åº¦ã確èªããã
ã¾ããããã¾ã§ã«å®è£ ããMNISTããã°ã©ã ã®åããã¹ã¦doubleããfloatã«å¤æãã精度ããã§ãã¯ãã¦ããã
ãã£ã¦ãããã¨ã¯ãåç´ã«replaceãã¦ããã ãã ãããã§åæ§ã«ã³ã³ãã¤ã«ããå®è¡ããã¨ãçµæãå¾ãããã
=== TestNetwork === Correct = 1342 === TestNetwork === Correct = 5293 === TestNetwork === Correct = 6388 === TestNetwork === Correct = 7874 === TestNetwork === Correct = 8447 === TestNetwork === Correct = 8637 === TestNetwork === Correct = 8700 === TestNetwork === Correct = 8865 === TestNetwork === Correct = 8924 === TestNetwork === Correct = 8907 === TestNetwork === Correct = 8966 === TestNetwork === Correct = 9053
doubleã®ãã®ã¨å ¨ãå¤ãããªãã
double –> åºå®å°æ°ç¹
åºå®å°æ°ç¹åãè¡ãããã«ãã¾ãã¯ãã¬ã¼ã ã¯ã¼ã¯ãå°å ¥ãããåèã«ããã®ã¯ä»¥ä¸ã®ããã°ã ã
ä¸è¨ã®ãµã¤ããåèã«ã以ä¸ã®ããã«union
ãå°å
¥ããã
typedef union { int32_t i; struct { unsigned int fraction: 16; unsigned int decimal : 15; unsigned int sign : 1; } st_fix16; } fix16_t; #define FX16_RAW(fx16) (fx16.i) #define FX16_SIGN(fx16) (fx16.st_fix16.sign)
ããã§doubleã§è¡¨ç¾ããã¦ããã¨ããããã¹ã¦fix16_t
ã«æ¸ãæãããC++ã®templateã使ãã°ããç°¡åã«ãªãã ããããããã§ã¯ãªãã¹ãå¹³æãªã¢ã»ã³ããªè¨èªã«å¤æããããã¨ãæ³å®ãã¦ãèªåã§æ¼ç®ãè¨è¿°ãã¦ããã
å ç®ã¯åç´ã«ãã®ã¾ã¾ã®å¤ã足ãã ãã§ããããä¹ç®ãé¤ç®ã«ã¤ãã¦ã¯æ¡ãåãããããã«ã²ã¨å·¥å¤«å¿ è¦ã«ãªãã
// å ç® A.i + B.i // æ¸ç® A.i - B.i // ä¹ç® (A.i * B.i) >> 16 // é¤ç® ((A.i << 32) / B.i) >> 16
ã¨ããããã®æ¼ç®ãå®ç¾©ãã¦æ¤è¨¼ãã¦ããã®ã ããã©ãããã¾ããããªããã©ãã«ããã¦åºå®å°æ°ç¹ã§ã®MNISTãåä½ãããããããã«ãç¶ç¶ãã¦ãããã°ãã¦ããã