无论是深度学习还是机器学习,大多情况下训练中都会遇到这几个参数,今天依据我自己的理解具体的总结一下,可能会存在错误,还请指正.
learning_rate , weight_decay , momentum这三个参数的含义. 并附上demo.
 
我们会使用一个例子来说明一下:
            比如我们有一堆数据aaarticlea/gif;base64,R0lGODlhggEUALMAAP///wAAALq6unZ2dqqqqmZmZlRUVMzMzO7u7tzc3CIiIpiYmBAQEDIyMoiIiERERCH5BAEAAAAALAAAAACCARQAAAT+EEggBpmzXsy7/2AojmRpnmYloJjGvnAsZ8Ma2nM+q15h9D+dcEgslnwvpHHJJCk/j6YU2AkcPNapdsvFIAIIVrZLHn7D0NlAESgMfAX0cN1+G+JecD7R+fLLgIEzfiiEgoeFAX8eUTMPBRhrRo+RCnuXHIaIm5wemiWfnaKYjDkBGxIEY0OnGKpXEp+hALOjtmW1Ibm3iLuNMQJ6EwYMRcFyAMSktIp9za4LNQQLBosm09LU1iTYAtPVLN3f21Pi2iO7H58HBJCpQRPs7gAE8CTyE/Vd+O8ivtDZwKUaYCFSAwwFGMD6wI8ePAIEUQEYcHBCwoXMrCUQhmEjMgH+fBIwuKAQBUgAIkliHHEyJYCSJ1qOfLlSikyVJFaV8DgBwQKaEgwM8PITplATPoEmG7olqVGmIXRy+HVT6QOoGBoY+NbAgb+isI4CuOpBK1evVTDe8bDWlQQBxTAccLAAbYgNcDsk+AUCb9x8Dt6M8MuBAAEH85YQPjHAHom2b1EGmMAABwXJlG3sFbFiY2Z6gRMbwyyh8ojGIH4tnkDxw6oCP2+QfrmiNZaFsD2gpqBANG/frB1XXBD7tONolkrsjoVWrHEOk8cWb7LcxICZLHvrDnIgOofd3SUgJwF+MoLmWI2UV459aofqL68OmB4MwwLvIdbHJ0gf//0P123+8ARCjk3QAH3c8RXCgXolRwKDGQxX0QgQTvDHA9MxUaFyCo4woAQKbODAhBiEKMGIFjoYgokAoCiAhFKwiOJpHU7Q4YZf1DQRiQXgB4KMB+WoG48+SjAAX2c4g0wsz6zgQBAikWAIDgmoqEuT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3omd+MrdQaryzjRdr1RZ7lrkv4L05QJ7eVsOBOGGcfQYG1M/3J3Yyzu1rZ874XbeMfsOIcEfK82R45r+Twk78o5fTzDv+EnzbUvkncZF5B1VfgM+rw2BYCJoKgAAAABJRU5ErkJggg==" alt="" />黑盒中得到的,我们现在要寻找到那个具体的函数f(x),我们定义为目标函数T.
          我们现在假定有存在这个函数并且这个函数为:
                                        aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAARIAAAAVBAMAAAB4a3wcAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEJl2u1Tdic1EZu8yqyJi4sUJAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADSUlEQVRIDbWWPWgUQRTH/5vNfezeZbNoEwzEs7AJiJc0gZDINWmsTmMQg0UsUtjIETCgKJyVHyAcSRRJUBYjXgyKsUgX5IiKhSIHKdQisqDYpLgLFnbGN/Nm4+4mt2A8B+b2zfxm3vvP7My+A/5zGZ6ICjDSG0WbyrRsWyHCYb3VCVONe0w7DP6xbRTNYoQLd6eSFh6uZSKm7Qm5iUiXHYGl76OXNaDCTO8pXNSkuBtBY0MBOHQSKKqeZIA0o/E50klb1oe1TcB0VIee95GGpllqiAg88UO94vqbQWoWzTEfjVGj1VUd6aqPNDT/QslIl3/V5NGv08gmfPG0yeslpGjI6KXRL8BSIPxsBt3aC9EVK9955npMKWlAOZbxEC1OZ9fWVkF5VpP91J6fsH1UXCRSYrgb+RWg7kUTT81ZwQpuCvOBtZyqCEMUVtKIcqwDqUqqkizRaOVZzvT2ZFcqAnynRWNOjD1HtWVdlAL5sOpWHT3p/izyBu3Wq3kxxFOiKL6BqZWTUO1/qYYadJu6pOdYXyaKDgt6kCopAa6KH6HkT0lUzRwKSSwC4o0W5ck+sv7p9vpHGsTUnJQmUB4jg1ZxQ66C3D1CgnqokOf9EDMa0XYcJ3qXaidV3BI/tHJfiefpmmXv4zWQdGBU0zkJ1TlhKpdBFNaYhN6ZHMcadMi8Q57vYWEXKvMOUUsqGaQR4sRqv1BiJdtvB+12PJ+uDGKDts419KrFQpUSplIJ0bCSTYzjvcw7wrOFiYASSSHyjoyrXSO6RpVu8ZxZT7sI3eKU25k30YuasfQcH/QMnRpRlBKmpETSsJKX2jIckXfYMy7Iqd6OSQrKO0xP5YmeF64drJ49fQYIfdmM7qfdPRjEu/ThNxdLejUd2BOmpETSsJKpxdV5G5R32HNbKaCEKTpspnI/xDK1HA/Drl/7GcxIbOQMHqf2RM2Rx53s0DlRNO6yMWDxk++4gl7eWcBjaOz8ikKz6hl4JNHP7aLuSEML4LASO0BV3omd+MrdQaryzjRdr1RZ7lrkv4L05QJ7eVsOBOGGcfQYG1M/3J3Yyzu1rZ874XbeMfsOIcEfK82R45r+Twk78o5fTzDv+EnzbUvkncZF5B1VfgM+rw2BYCJoKgAAAABJRU5ErkJggg==" alt="" />
         我们现在要使用这对数据来训练目标函数. 我们可以设想如果存在一个这个函数,必定满足{x,y}所有的关系,也就是说:     
                                        aaarticlea/gif;base64,R0lGODlhTQASALMAAP///wAAAO7u7mZmZoiIiERERKqqqiIiInZ2djIyMrq6upiYmBAQEMzMzFRUVNzc3CH5BAEAAAAALAAAAABNABIAAAT+EMhJq1g15yW0/2AYDmImkGWqUieBSkSzTgox32FhGC+Q4JIfcDgRBDqUBQZIMBCJhkOm8Bg2HE+cAHFIIBQURsaw+JIdVY84K2nwJgasp7AMVxTVB8PJkHkCbAAXAH0SDggfhRQPUhROAAprjogUB0gVAw6am5yUFGAPgBIMYAAGnoKii40ZCHIsGZaBAK5tqpcSCqxFkhUJdSC9WQePBEIaBK92JgFppckZwhOZnNWoFEcSBZTQFA42U2mQYguiDVUYshNXswDZoWDpuAelFUrrAwZuCAb1D8cwHgUqUyYbgH8VVFkokAIBMB/tKBBgKMGhhA4KKGpA4CeEpTooCh4+ISWB3oSPhMrU09DjAwICaU60k0mrx8sqDsF9GLSCQ0QlFjVEAAA7" alt="" />
         那么最理想的情况下 :  aaarticlea/gif;base64,R0lGODlhbQASALMAAP///wAAAO7u7mZmZoiIiERERKqqqiIiInZ2djIyMrq6upiYmBAQEMzMzFRUVNzc3CH5BAEAAAAALAAAAABtABIAAAT+EMhJq1g15yW0/2AojiQ1lJNwomzreiqxSkTjKsSr75JBLASFp2AwzAAJXZLHRCkKk4TNEuhQFpgXwdDsioiThSNjOGQKD11j7G1rAlOAgkERIA4JhHBCrxgWen8OaR59TA1GEwZsXQ8BhAANVRUFWRSGEgppDwxcDHEZAU0XAJ8SDghtkpCrFaYUD2YUXHKYPakUB1Y7Qo58ewa4Jg7ExcbCE60SyhICohWxHgiMKRm6GQ0F2tvcORrTy88AuzuOcQqTEwqydbZRliDuOge0BEttAXsABrYE1HwanBHa4y+DvBfpCuAqmGGAsYeoNFSawHCCA2+UIM0BsOBZgzRyGK4l+7djkiMhIcnpeBIFkoQD+q5YajDAACIEBvQ9uEeDVhNAgNLt9OJjwYCYEsRZgDICATwkbmgwBeA0qgU5UzMgAPVBlyUFT3cw2ANzglerfAAhrXDkAwIChFR4kUv1yFuXUZ1ihBE2BIc2WKqi9RABADs=" alt="" /> ,那么我们不妨定义这样一个优化目标函数:
                                    aaarticlea/gif;base64,R0lGODlhwgAlALMAAP///wAAAHZ2diIiIlRUVDIyMkRERJiYmLq6utzc3BAQEGZmZu7u7qqqqszMzIiIiCH5BAEAAAAALAAAAADCACUAAAT+EMhJq7046837ZAbijWRpnmiqrlQiHIHIznRt37gU53zv/7UdcEgsGgHCo3LJRCWb0Kh08pxar8Qqdsu1abu5xkOwABu/5hrjISEIjowD6cDwfWUSvCfOoQ/1MggFEgeDRmUkDIg3DAIGAQUCDhUGFJUkixqKQ5cSnQkSZBQCAwFuOQ+TJQhsR50ArxSKD5mpHqxAr7EAA6AUBbs1hibDRboYBg0NmcUczTnHFAR6OnI5B9YmDw2ulhcMAXUU2CTbP9EStr55Aes3Bu4kDgTdE8ENAxbw8vQ+6MoMErQKpSCDmAOSKDTAdmDdQmy+ClJAcGDRAjkMFIibINGYN1n+pCLp6ThhoQAECwm4I5nCwbKS/aIlCEAzwJsJBTJRWNAq4wQENwW0AhqqFUk+ClQllVCAWoB6ni4YyMaxAgJQCRRwW0qFBVJVp2B9zACOm4VCFISIArBxrbgE+X4CmCmBbrqNEgbgnbCAgN+/gG+eQEeB6wS4FcwiYDlB7woRdgEokEH4QoNwFUApyAZOlQOaBlQB+BwgdN24o/od6CS48V4VNWPTHCu2AjgLiC8I6GfBcQUHBoILHz4wtYTP9mhfWID6uIOZDp8qJMCyAXUJPisMMEtgYHEJjM8pB4CgOfbwAApQLUxje7phlXvrLBM5fatkVWGZlZw/rTj3o4n+1l8FfQFmYGslxPcAb+xZAI4v1KBnAmawCBafLAHsBwBPefmyoD3iOICIASEusk9hoGRk1nqjMcjJeN1Jtc5iAMBwnDvz0IDZTHhcGEoBpgjgiAIUJnDRA1RRxNBPDFFFzkQXHSDiAQ+8Zo4R8Q1ADSHZiNiASwI0QM2VLCCEEIW1RQUFCCg8k8t40jkYTAZurvAAYXMakdAqLM5A5QIh6DNWHQjkuScHFNEwWV56+HiEThxsgoMfc2VIyVibnaQBpN9weoKkayUnahR8jEDpDQOIRoB56LzwnYN9VnBqmWYKOmoaRWw2gQBxtiENrhsw6CKwRqxK7LHI2mZpsswqEmvAq81Gi8UD0EprbRRiXKutFYmms+23SoiIwLgvgWvuEETGNuy5HUQAADs=" alt="" />
        对于这堆数据,我们认为当Loss(W)对于所有的pair{x,y}都满足 Loss(W)趋近于或者等于0时,我们认为我们找到这个理想的目标函数T. 也就是此时 aaarticlea/gif;base64,R0lGODlhSAASALMAAP///wAAAO7u7mZmZoiIiERERKqqqiIiInZ2djIyMrq6upiYmBAQEMzMzFRUVNzc3CH5BAEAAAAALAAAAABIABIAAAT+EMhJq1g1gyW0/2AYDiIgkGWqUieBSkSTKsQqLoyDIAyzO75MwWB4ARIrpA3k6EiCEgWGFXBOFtMUwbD0PLiSR0AxaZAphoPwsWo4uhqwZBGgKKwCxCGBOD8zBgt9gQ5sEwxwIQ5KHwVZhxUKbA8MXAwyE3WJHww1IJcVD2poUYgaB1YUAw6sra4IIGKYHgKaFKIeCG+nqZsTBLYeCqMsphkJjxTGvhQFBSEEuxXLE7WGfn8aq67csB8Bnh8O4c2GAAqIdBIN5gBuzBUNAbMeB9hXWQ0DBg0GCAb3tsCDMeBAgAII2lUIxuKZCkYDRXRQ4FADAnogpERMwUDQvQoRRj6c2JgCwQJyGi7c6EVSQwQAOw==" alt="" />.
      以上,我们发现寻找的目标函数的问题,已经成功的转移为求解: 
                                        aaarticlea/gif;base64,R0lGODlhfAASALMAAP///wAAAJiYmIiIiO7u7lRUVLq6uszMzNzc3KqqqiIiIkRERHZ2dmZmZhAQEDIyMiH5BAEAAAAALAAAAAB8ABIAAAT+EMhJq70YEJG7/9vXCURFmqWofs3qsq9FtNRc2fGUOOtwWAxFoMDIfXwTRmCI0BQCDhpAEFAkJoZBJbvVGglN1QPzWBhFY8oiPQkUKW8KezKX1M8eAecS2OMxehUNCjUBUgAGYRQDV4uNE4x/IguKFAYBlZJqmQw8EwIPBRR+FAeipacTphICAwMbAgUGsAU/EgYCUgmutAYUnkDAFrsCDLYSCXoCisl6YcISAwFYCAtmrBnQANo8BIl9yAp7AtchDj/eCOAACXPadocUDV4EwAZvDF73EvkS2lSfABQgBACBLwzTKiSkMM1XAoJTIDI45UvdLXYQB1wrCLHQo1H+cwIcZEAjBQCSElIg6HgL0xR+nkhZUGBSAs0KNwE0iENkwgJSKCfsnFDAC8cLCQLULLjND4EAtg4sWXBMagCqElZakHrAYLRpCZbiXJpzQk4HB7cdfFrp3K+0LlO+G1ThQNe47BYiKwAtAV+5FtTh+qT04wVuFjxZzLoQFKJwjwsufBh52wUF8VostuNlwSNPnicA0/a0gMmkcbIlXj2FDTmhWrwwKOLFsYShRindCPBxns0wA1ItSHGAxnAJxX1mAhDAKACuHlahqnuKgR/rqvIRb3DipJ8D2j8BfTBk9gIHSrNyH0AKlzIsykgFqrAxa2oMkRxVyK8pA4H6/YEwAOAZdxQYoAfGHKhCgn8MZolMDiqIQTwSTvgHDhNgmBKFFWYoU4c3fOhCd58sRWIEADs=" alt="" />
      也就是Loss 越小, f(x)越接近我们寻找的目标函数T.
那么说了这么多,这个和我们说的学习率learning_rate有什么关系呢?
                既然我们知道了我们当前的f(x)和目标函数的T的误差,那么我们可以将这个误差转移到每一个参数上,也就是变成每一个参数w和目标函数T的参数w_t的误差. 然后我们就以一定的幅度stride来缩小和真实值的距离,我们称这个stride为学习率learning_rate 而且我们就是这么做的.
                我们用公式表述就是:
                        我们的误差(损失)Loss:    
                                        aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUYAAABxBAMAAABb8RdiAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAid2rzbtmRCLvmRBUMnZ/MwGQAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAIn0lEQVR4Ae1bXYwTVRQ+7XZn2p22u4ouCVHZB6PGrLGICT6RGv8eTEx9UDQa7QquRuJSw58QYirGB3xw+wQmQhwlwoMGSyIoPLhVIiaIa40hQYJSghKDP6lBhWTFes69d+bOTGf7O7OtoXczM2fO33w9c2c6O18PQBtDW9ZG8NyEhocvzM2B2jpKD2Nb5TODe3U0S9GW0KtjW+Uzg5uvY/S0bkbPjdA8xk9gkR/Q9htJVxqCuSWMKkDGUAjXakcgVQZ918AKw9nLrW4kO2gIYqtd/ee1AP0AKcOgc8HpiFpSpdA3DAu4TxvrwK3OcxEvGunUkiFZtwKjtkcHw9XFkVSEEeAmXNoc9zjjQ1KRlKKUBMb+ozqYri6OqGIY+8yJIVM0K/3tDBiXil+lKCWBcSoPYLq6OKKKYfwtLENblNSLzsBHpOJbKUpJYPwMNaariyOqCGP0y9dlaItSIEeB02NFiI4/yxZUrNNhl/YmQMQtKce49/r5AO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UfhQMjC8XOmywnJwy+W2DkViwfsypJZQRiOKEsQxle6Nq4ZOMVlpsByXiaySE4y7YCo7DTuabhwMiVIMoHBt8tMAorlQ+HWsILR0kxWa5+MqadVKFk4xUOmKZvxrgYGx5igmZaUFA/+Jnvbvw3ywSc/XIY5TP5bquVlY/5TizIQygjw1DaBje6YrTxCgMFW0xrO0b5XKNZ+UyLcT64QtPphy8u9x4br6ClzPCWBbN87hmofObYbUpMGB/GjQtGO68wty91sSmrerhSHFMF6Wg0AUuNnxL11zQ2erxCY3Wq4zW3U7AOGHdzj1dwr0uz2m7lFf4D3ABZdMksEzwAAAAASUVORK5CYII=" alt="" />
 
 
 
 
                我们这一个凸函数. 我们先对这个函数进行各个分量求偏导.
            aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAacAAAAqBAMAAADlmIkZAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAdmaJqyKZVES7EN0y780nl6jHAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAGgklEQVRoBe1YXYhbVRD+cvN39242m/7Yh1Iku6kFUWr8oQqKpFihTxJBBZGy6Vao6IPZWqwV0dvaVnxoiYqIghALlvpQW4RaEcEUbaWgNAhSkT5E8UH7FH+KdSmsM3POuX+bzf4lpaVOuOfOnW9mzpl75p5zMsCCKNlAsrYgyxmN0ssqM2JAeqIbqg0n1uFwFx+zQY8AhWOzKc0P/wAPdDEYxptdUAU5uUQxXp1VbUaF94AkB+XCZh0nz+3i6ADWdnGQDARl1acr0jBcu2W1QCPrRgc12MGHVdRB1TDAWqlufuaIJbGum6ZzwUOdisd6DA2jhnK8gj2eqCNT0dIOPgbL4aBWdXQwX+HxbgY7qz66y2cNJ0GBxsVDY1qaA+JfRjM61hCQmuk+DpBU0k/PVMuoLuaecLtar/fRrM8aTgW1kQIpiiiOB+n+u4HN3bf0OYNtISYQlJU3QPRuuVFJ8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R+Xi5Uv3FvFB6qvpKscrZqFwavQs1Irl5Z7FUrnroITnoBRFviktTbiK4S2UKWxLnyyTnaPVIius38Tk3apBWN5YfNznPvLYqA+AVwZJfTVTuM/oflVQXOaOojCOAfhuP3uDepR9m9gQCn1MUltoFPWOSSPr6tit3Oh2yB10/ZnKuiEw8hBvGEHYB0tTVWo49XVQKRYukqYdk0L+gsckpxKCDvF/Fm9JN9kQUvEfjGnEBytwvknq66B68SeRj0kzEx+TDEX+4FmFfCCop4xW5/tBLY74EOkEIKlfQqKz8ZWW0jBK3CetcAumWMNL/QX76Ivhob54vbacpjYwqUXtah85nUvnQKEo+Cx7NVM7NNrr7+FaSr/rb3b+j/gqfgO6YnLFRhgb6X9XqrLZ/368HoqJssf3i1GVzX557+A3Lyf+DkAPRVLZ7KG/WV25A/lZdRanoCqbu7166uK8zcF6JOcMNgLV3TmYzFtFKpumnjpv6/kbOHubybGqru7O33xuFlLZ9GqYc7NZjJadblHNTld3F+Ooq61UNk0Ns6tmb8BUkUufUt3tjcNOXqSyqeupnfBeywZdLulKdbfXrn1/Utk0NUxf3DduuJ7Kcz2Vqrt960NVNnUNs2+9BBwfxdf0JNXdgLTHrFQ2TcW0x747ubM250gs1d1O8AJl/wGuqnKTq02j6QAAAABJRU5ErkJggg==" alt="" />
对于w0的偏导数:
                aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAcsAAABFBAMAAADX4dBoAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAdmaJqyKZVES7EN0y780nl6jHAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAJ5ElEQVRoBe1bXYgkVxU+1T39MzXd081uDBgW6ZkJkqDEZl02ShQ77Aj7orTgi2iYyipEfLF3FaMi2LskkTwkjoqEiA/tgsE8rLMIIeJTi7ohkOC8yIos2AkiwQcdUVEGYfzOOfdW1a2q7pnpnwqLe+BW3Tr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2XNHyPNB8kZ/WUnBhqnkjZg6tVOuifWZXx+SxtOqXkJ7bjMLucnujBfnMUmqz/WXZ7oYRawOuJUglk82Lb2i7PddtbRF2dWv9/BdIN16U/jGYZTqfAGxu9E4+S+cQDrTQ6FMUl+cXZQ54szPZPhlXXpRIcMw6lUKz28haGMkaPTTH3zdGhS/Isz7QzS3bGu1knrZ9DEEiUbQ7yFoVzJzqJUmrFJoksfuPRR27MhEjWlI6L1vnXB69pXqNIh0e3G9TPXY4mSO11OzRqbRak0zSQRkier3Ud6tzibkkVp2hRLKAStnAwYHIdeBLrSYgMr8L7UVt2e1c2wjj5rxRIltwZEKOOyKJWmmSTauE4VPq84m5JFaZqmrBDU/myRjcrPFqtNtrYC7wil6JIJgtZkynWxQyZR8rfwwCUrizKZJymZS5yozNmLyRRLDSJQ/dkikYCpf8wAlZ8thFKNsyifZ8JneASLoLkaJkqaaOIylJlFaS5BMkmkCVpvWpo2mqapBhGo/dnCnLnqWP+Y4bb8s4V70CI5ERmvotuFwawSHbSxRElzbtKYLEpDUzMhOZpIwOzbNCNDRJtKEAU1TxsOKkEUlH+2qKPEZJ++Z3TzoBk6jidK8gVOSnYWpaGpmZCg+Uxhr9ZN0NQUSw6ioktwCTE0TQImgqgo8mep0RULu9gv/Ud1872hxBMll5t4ckcZk0VpaGomJGje+MaXvhqmGRoiJsUSQVTU/GzhogiioPKzxeuWoK43NvaJWLeIx4OR14LnQkcLqpBUFqWhqahcgrgql6AwXgrSUl8r9mcLQ1OVxEFkkZ8t7td6uPS2Cbngi3nY05kJTuLmopLKohxYhNc2edJmU/pxkOwfM/yzBYuDhn/M8M8W9JbTsN5f6avuiqOf68Zj8MZlVrFBzPbj/DETHhVq+wL/B8c6P8huPA/ti3DCZVaxQcz2I0G0ULlva7IubLTw+gDdIl+rK008vaDkKDcy+srSZZhNrzqFplxyk6xjM0uX24Bux47+BxyNnK0hUBBIAAAAAElFTkSuQmCC" alt="" />
那么对于分量w0承担的误差为:
                      aaarticlea/png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CkQgGYEAJCkgpFYEoYQipIcREuS4WijaXC/9lfNjLtKGPwYP0AAAAASUVORK5CYII=" alt="" />  并且这个误差带方向.
那么我们需要使我们当前的w0更加接近目标函数的T的w0_t参数.我们需要做运算:
                aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXQAAAAqCAMAAACUTlBSAAAAM1BMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADxgEwMAAAAEHRSTlMARGaZEO8yzSJ2iau73VRQ1C+tCQAAAAlwSFlzAAAOxAAADsQBlSsOGwAABYpJREFUaAXtWoF2qyAMRaQoWJ3//7XvJgF0FVprtdv65JwKDSGEACFcVepMRudtoE2eflJ3sEBdkGFKFQX+/5zstBML+H7s/ANjOFtiqIKUUv1Jn1kAZu5a+d9cZ/R8scmTiXqnqtzoP62Bj64HGftY8NeTZfQdDhekTNxnqWSBSqmrmLIaw4ovsYLzDoftyu3OmskC2sERG9WLo/aXVDM47Zk4aK3J0CEXjkrTqVlrZS7zmGVqnuSchYUFTNXCUG07imNoUgBS01yQDSt4fI8/MWe7Imq8YEbo12CfpDSm0lkoW6BSA51+To5AE2yvlGbCCIN6zAMt5pC3PQmrVAv70k85o2yKfvr5sifGM2UtUFOI2IhLH0YxWqsuRDAjVrIdxyu5mZCL0TEHcN+aQh00xwSF4/U0OiyyIvVYzeRiKNW8jJW1LR+og3iLoZNqztnlgLWHP+ooLneqgv2thJpBDsk60x0L0OLGgcipF5dei+NQDYx6JWcPW8acypSoGRneWuVg9DBtp9HFOg+eBqs5RnrBpdMZ2iNeIWOqK4xrMRcxjyHjpcU5C6Njuhyq2b0nQQ/6LFYvUZ2j8ZyWNuv7k64paKTkG2AA/nqhRdzW2vHyrxAwUiHm0XtXtdYWTOClybG8xl+9HMlGY2XC42A8x/PZNe+wXB7Wb+OWDsE9k1kABRUo9LsLA2xFdQ7Gc2hHr0xmPWu4aq4UvIZNrkxzTkQvvC2qcD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PmKcv2kQ88+QVgN3v2kAf1KX6TMktR64+5Mj/fVKHwzc/frx/4yCxwJ3PzOmX9/rYcBdceT/ACtELoCjGB/KAAAAAElFTkSuQmCC" alt="" />(梯度下降算法)
来更新wo的值. 同理其他参数w,而这个学习率就是来控制我们每次靠近真实值的幅度,为什么要这么做呢?
因为我们表述的误差只是一种空间表述形式我们可以使用均方差也可以使用绝对值,还可以使用对数,以及交叉熵等等,所以只能大致的反映,并不精确,就想我们问路一样,别人告诉我们直走五分钟,有的人走的快,有的人走的慢,所以如果走的快的话,当再次问路的时候,就会发现走多了,而折回来,这就是我们训练过程中的loss曲线震荡严重的原因之一. 所以学习率要设置在合理的大小.

好了说了这么多,这是学习率. 那么什么是权重衰减weight_decay呢? 有什么作用呢?
          我们接着看上面的这个Loss(w),我们发现如果参数过多的话,对于高位的w3,我们对其求偏导:
            aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAcsAAABFBAMAAADX4dBoAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAdmaJqyKZVES7EN0y780nl6jHAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAKHUlEQVRoBe1aX4gkRxn/emZ6prdnZme4ixHDIb17QUyUOJ7hYozixFsxiEoLvoiG7VyEqC/OnWKMCE6OJJKHnKsgweDDeGAwD+sewnHi0wTjHYEE90UuhAMnIYSQB13REAjC+v2p6q7q7pmd/+HIFfT0V9/vq++rr6q6u7b2BzCn4vbB3ZqTL+Wmcjga4bByahSqGp46Dr8f4WNy6GsAR89P3mxUi9/CiRFwA345AhXIb5Zaxc6BZhMYPAXgYpoeQJdanZug6TDTs3DbMAj1rpFmoZc1pJ54g8IAsGfjFz9IbHO8FlqS5grAFhlGifXUkgvHR7X134xRP4rFWOCehMUIHolVYwhlwybHazW00nT6hvn04oVRTR/qJOjDiaglGXDsF3UtW5w11N3131YKOWLWs17PIkyLV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riXTP6crU9ztN+qHBmyR6ZaNvgqc/efrzOoxK88w0jMsRbetdHYDul4lUCaQjhtJM5YdfNOmHzH1kYhxTuHZCDT67Bl54b+cqkSupSFeHcSptFM0tTmU+ylGrATlXRUiVQLqG1k10N/+t9WJfHfyQB+ZNMkGP6ZWbPX0qhFzKCj05RK6kIl0dxqm0UDK3OJW5qKLjma9UIVXCKuqqPfIySyntKvqhzW4keiX8DS8+FRIuJTKTmVw5mlOZRnlPi2wloeNl0FOR8DHDlQBHkdK0SZVzSfNLUHxL0Q95ElcxFhP09GwKKFzKVwHpeEiuxCIzgu8oYlwyC4daat6WhfKeltCwGAEVC+U9bRzVWrTo3RngTAbTPpvxonXfhtKeoh/ycMbsRv1sCshcSlR1mVyZdHUIp1IlIijvaU1OpYXynjaOWu+g77gwqRJIN+sr6FOw3VT0Q4vdKGRxesnxqRBxKZ8o7NVCJFdyL1RXh3AqLRT3tDan0kLBfzPhVEIjjHNEgUmVrJv1g+J8/AuafmixG5leCStNBRKX8tJPvv8jIleaaQ7hVKpEFAoXbE6ljT7USTiVagx1qkyqZN3s2wPtE8BkNwq9stDW6MAJWNTkStVV1mU5lTZa6oqZpuPZqNrTyvHILcqhviGpEqnhs2/2tD98MRBFlYscVGyjTLxuKZpLqcmVvgbonuFUWiioPW1MCLPQeE/LUd8w3QqpElDnBZZ+lkr6tInplQ/M4lG1zexpLZ/Wnla/qcVCSJWke9pqMlslddrkb6G7Z2Zzya0ze1rLp7WnLXctjEmVpLvVUs+3gvRKqDTn6/MAb5dy8DxdjtnUKqePTY9M3XyKhn6UbZSny1q9lzX/B2wwvASWxSMGAAAAAElFTkSuQmCC" alt="" />
我们发现w3开始大于1的时候,w3会调节的很快,幅度很大,从而使得特征x3变为异常敏感.从而出现过拟合(overfitting).
       这个时候,我们需要约束一下w2,w3等高阶参数的大小,于是我们对Loss增加一个惩罚项,使得Loss的正反方向,不应该只由f(x) -y 决定,而还应该加上一个aaarticlea/png;base64,iVBORw0KGgoAAAANSU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ASUVORK5CYII=" alt="" />
我们继续对Loss求解偏导数:
对wo求偏导:
                aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAApgAAABDBAMAAADKeWg/AAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAdmaJqyKZVES7EN0y780nl6jHAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAMCklEQVR4Ae1cTYhkVxU+VdXV9bqqursyiRFDkOruEGKUWAxDVKJY0i30RikXLkSGrrSBgBt7ohgV0cpgIllEG10ExUUpOGQzzmwkQVy0qBOEiL2RBBmwDCLiQktUIr1pz8+9991733k1PdVVmReZC/X63XPuOee73/upd/udUwCzb9X92fucjcfiIsud38bVXNXNKmp39ieY1C5M0qJhbD49sifvVnC4+BceVrQzENXbUCUyB5DMwNsPYXOCl1X4Tr6WAMTm0yMbL7WzoSg+znJQby10ysOs3kqQE6UZKRk+qKhJtAhC5j4s5Yy4GfG34KEJw6uTyCQAsTmTORWynkYmxcdZ7iej8qjezweKnCjNSMnwkqI+0wK4d6ZkVmHiBVT/m4LCiIiz2Hx6MuEnQyUUxicyoVfpw1OKHkprJEVO4JF/d6IBJKWGhgkSF7UKfBRgNFMyAX4aBQm6X94LukFHTsDQfHoya88Hzk0H4zOZ0OjBijags9BD8Qg/K/uxnqTUyHBEO0Erw+NQbt+YzPIgMIs6oXYhGhtq4SORsddlMq35A6LII9OoPWvcDYULcvKEQowvZG4DlLQD215EKXECq7TxG0tJQIZv9zW8n9AtpDdbMu+thmECMh+Cd4dav8dkWnPDwdRklkflq+w8IJPiM5mlgx40u350sz9YagNzAt9GYoJGTHEjw1+ZffunfAcMfw7L2H3mnziO5pLcD4vty0Ma8cT7n8B7gDRDyMU+7Nb/QKLaxjfvs64h0Na+8glNaxw/BedCrQnwch++wADInJvhQENGelF7cGPhC61Kl2ThSIrPZD754xbAIQ/wN2uteuMAmBP4EClqZz6IVKz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c+11bIsjOtyLZldEZutnQzbiZzSxhx680quz43JVC4UloEG8GlDQ6YWGjhKWOLcPDn0ZFmKllQcsLn1uXE5bFyom0TEd0z7L4bsRM5V4v9DM6t1el4p9bkxmcqFdvyTbfEpw3w4rmmpc/M4sFqWcsiMDfbfCXIYh9EcxmLg+txsMrkUtBC+IJxS5+bJQbi9UHmsq3/L+838wtmS8R0g3P8A1DtKuCbXPMcAAAAASUVORK5CYII=" alt="" />
 
我们发现当x3值过大时,会改变Loss的导数的方向.而来抑制w2,w3等高阶函数的继续增长. 然而这样抑制并不是很灵活,所以我们在前面加入一个系数aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAAMBAMAAABGh1qtAAAAKlBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADmU0mKAAAADXRSTlMAVHbNMhBEIpndZom7PT/yAwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAEpJREFUCB1jYFR2YGBNYGDnMGBgYmBgYL/OoACkGCZxBYCozSIgksFXAEzVLgBRrCsOgKggtgsgSoHhIpAEam1mZWAoZWAI3sUAAJNqCsiGl5EyAAAAAElFTkSuQmCC" alt="" />,这个系数在数学上称之为拉格朗日乘子系数,也就是我们用到的weight_decay. 这样我们可以通过调节weight_decay系数,来调节w3,w2等高阶的增长程度。加入weight_decay后的公式:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAApgAAABZBAMAAABoNEnCAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAdmaJqyKZVES7EN0y780nl6jHAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAPIklEQVR4Ae1cXWxkVR3/z1dnemfazsIKAYm52xKCgDg2BBQUZt2a7As6Rn0wuHaoG0l8sQvqilEcVsGgQUd8IBIfrhI3PIjdFwIxPtSgu5CgVCJiyCaOaJRgovVjg+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0XW5cqGt50TeF+8xUdg+rvZ5XWrqgFsK6F3HMAl0FpjKkd/TeSm+ZdgpP/08iZuuRaTBFR4/IDjXFXhpZz5St6kAU1nW50MmEeAgQ8VZttOsYTIurMQQ9rzS5MYbuIo5doCuXl+mT+vTeSmtTrXLLy4v/J5Fw45FFprQekUU0BQbpxzNlWlLh21y04rpcXahrGdPlsHGhrsXVGHbPK1EswdBexOlRoKuN34zv8fR2Mu2fycX/k0h045FZpvSILOJWD6yZsgHmVu0Y8l4ME76NYUJPL9DVMncdq+muZ5+dCz1UJOn/SeTn7hg1v8N1q/0D9xXo9tfqL7FTI/Mu1u36kmH/8e8JCe9i3a4vGe4JqPoH6V2s2/Ulw/5x7gkJaz0yjhiXDEvDWZuMTf5/dIz1yHjA8X8ujSnjziAI5Fs+KWuW4BMY03wImOuRmu/MEjR5vO+DgF6PtGa/ziyhj4kxWyOg1yMtMM/TLEHHtPf2xsoiBa/APBH/P+DhTCb3Hi7bithYHUzA1Ot/SBmDuQVY1Tqc1pAr01ikHIOpoRlkL5Vdsv7qrP/R3HwM5iAgahleWYzzetUzM1mkHIOpgRpkb6wdorgCM1mkHIM5CIhaJl47ZIICM16kHN/mGqeB9vHaoQlmvEg5BnMgEB0htXaorkzNHM/NNRJb2eu1Q2v9bzw33wqEiaxeO0wo2BvPzS04Bj3wrx2O5+aD4jeg3E6t4A3ofk+J/Rcuw7iKGiDwQwAAAABJRU5ErkJggg==" alt="" />
 
 
从公式可以看出 ,weight_decay越大,抑制越大,w2,w3等系数越小,weight_decay越小,抑制越小,w2,w3等系数越大

那么冲量momentum又是啥?
     我们在使用梯度下降法,来调整w时公式是这样的:
        aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXQAAAAqCAMAAACUTlBSAAAAM1BMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADxgEwMAAAAEHRSTlMARGaZEO8yzSJ2iau73VRQ1C+tCQAA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hHCLH78SNyMnvHXYpUex0quDmhTpHZy+d7MR1SEdGVrIow75IRR47TWlGJzzTeSC4Jc8I0ePvPQZGWHZXOKLN2NPmGSaWiZUFFlXmJ7IndpXHFtGsUFH12NeQxr3T1H0vBu1EdUhWWz0POoQu/qer+clh2JCqMHIhxyBF3LinLgkDISoYmaoigmOtgOhgIF7ak+TnsSiiKR7W9sm7EUhHfG86WYbqsOK8brJow4591JCKHKDHFvTGhINI1mGTK/BkQg337PhbGBpec4IbNpmCHdxnAqpPabSVFGsCIIAOLE0l0Lc/3nTzTZUh9WSzZpDHQpaZxGKHC8gECx1fiGgrcLbmBaLUQdYmxqwm4b7gDvy/JwRBnh6jTUvIDiYU3u8EEKDKDZ2zMOIf47LZ91sRHVINwGGsqhDQfX1vF4DPULkxz698sPQ0mnH8R7L5pL1dAIC8sBzRsCbncFhiIk7tR88vWmLYqOSyaNHwjH51M1WVIf0WlyOJtThsdrP8D6WtuBgF7Og/inCEtUh9ZcwACgCxq0Y3TO8K8TdsIR3PzfUl/+mF3EvS1ohYInq4PCB171JAXW4oeb/PsObl1CgUhjObzoL9S+QEeTEz5BekLK66QLVeYDnrBa8P+PgB3dQCIhlFj9D2l/vpcQlqnOL5yzbfB4FgR9dIM70LgvMPkN6Brh7l3of2c/sM6SngLuPNMa7BjX7DOkZ4O5d6n1qPwyfSShaAO4+deQ/OK7ZZ0jrgbsf1Pcjuib4LXyGVAL5PmKcv2kQ88+QVgN3v2kAf1KX6TMktR64+5Mj/fVKHwzc/frx/4yCxwJ3PzOmX9/rYcBdceT/ACtELoCjGB/KAAAAAElFTkSuQmCC" alt="" />
我们每一次都是计算当前的梯度:
                aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAANYAAAAqBAMAAAA9nbh/AAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEIlmmXYi3UTNq1S77zJPBy8JAAAACXB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cO8qHwoU5zY6IrL2nkn18b3uCyc9vxxuV9xhF5u73jYRuTqzq9P6UfOHdqfuBB9JXx+ctdvutKYJhmpm8LpLF/+7sw3/rcPzWKKJnV9cqFR4rLbeLVpe+O5nEnHWhjp5Q6QWsSwDEgC4ljgTjnTMeKMhIx9sfJxp7vyP5hU0rL/x+QZ6G/iqIWGdDHtiltn8epNyVzBCj5Ju1bzLHItVenT59R+rWOlW+4Z0BHJtOUujGraK/cGZumL2i3asJW0a62iAfo+zbuVHqQPUp1Dqc+fDWVnwpWBb91Ua+GxGeJXG082WKJPpVsrwL4Xjwda6YbHhld7ukV8dvn5p+PV+Rf3yhhhcm8BPgAAAABJRU5ErkJggg==" alt="" />
这样会发现对于那些梯度比较小的地方,参数w更新的幅度比较小,训练变得漫长,或者收敛慢.有时候遇到非最优的凸点,会出现冲不出去的现象.
而冲量加进来是一种快速效应.借助上一次的势能来和当前的梯度来调节当前的参数w.
公式表达为:
            aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUMAAAB3BAMAAABrgT87AAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEIlmmXYi3UTNq1S77zJPBy8JAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAJr0lEQVR4Ae1bfWgcxxX/7X1pT6s7LVYpDtToYkWklptw0VlO7YTksCtKGyjnqCY0TsuWlqYNuKekpRQC7jp23UIxOeKmH7RQ1cahqDQcdhXXdtuoGPpP2nAlxQQM6TWI0C8nEqHCpKXp783eru9O96FdKdL9sQ/N3MybN2+e3szu7O5vHhCEtGyrXjVu1ATuatW+obxYy9FqXC0PvK+lwAYxpwoc6DNMt7+TaRpSuELfBHSR2iSK4DmOXGJKzjebIFyhJJNbVoyNzaJ4AIhmOeigZPWkuMKIl4FD9S0bW9ZxBRiwOOjTktWT4gojPQP8o75lI8vRgzCPACkZ8w7JjKk7gfM5S5Jwz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FHdor28SJGT15E+6g16F8HVor2tKV7xKxiu1LdRJt5VxGzqHCJwh+pjLMGbxIgQ8NIhp2iA4qTBMeJgi29M7nsgKuik0LZkHeTJU0UMwqUzpEGmquXRTqkPoYucQgauyxP7GNEsIsz8jaGWJ4KTgmfwo7WKK0i64HNFNm0eTMzOEu0REQZ4SquihnFSmdFBUYZyeVNpsH4tF2EpCBOT/9sgLWePh90hJu5WgzxndoG+IRMbnCWVJhRimiylKOwiJE90URQ/PHiCESREFeRLoueEimKJM6aC0wjg9qaTljb6y4IQIkJ/+g1ChXiI+g9T+nKliFgU8FCSygEhekERimC6mqNpPQqGbFIo/IYZSREGeKlTRRTCpzNFBaYVxulIuDMOOK8kJEYiP2yubZPKGLTgxiwQPBYmks1JVB8N0MUWnfUwC9YWiRz7xDH9qkCcBR2PRRTBFmaNjjDi7YJw1Kf1jdHxbckIEfu6scUfKm+jBz1rDJjQVs0jwUJDIC7r8KQzTxRSh2q9oRwXd5BSjxFhEiijIk1my4CKYoszRcUWzFcZZk4IKsG9nowoRSE9jsYXAcBRJG/epmEUBD7no9sWxPU4kkRimhymq9iMOuilaKpK5QKWEKrKfwkJFmaOD0grjdKVe7hS6qEIEonm9JHqbKHIPbyw5U8UsjrCNSCRBzIUahulhiqr93G6FbooGuhIEGx1pCVVkSaGeoszhUlphnK5UpWvoop5vwkhlkO4kiPq6kFZirEcXTaN3dhFo2ZzMtmQHYO6vBgxd7DzWSkyxs3yX1nKX9iDNG4Qp/h/D2gSPs73VwwAAAABJRU5ErkJggg==" alt="" />
这样可以有效的避免掉入凸点无法冲出来,而且收敛速度也快很多.
 
附上demo: 使用mxnet编码.
 //
// Created by xijun1 on 2017/12/14.
// #include <iostream>
#include <vector>
#include <string>
#include <mxnet/mxnet-cpp/MxNetCpp.h>
#include <mxnet/mxnet-cpp/op.h> namespace mlp{
class MlpNet{
public:
static mx_float OutputAccuracy(mx_float* pred, mx_float* target) {
int right = ;
for (int i = ; i < ; ++i) {
float mx_p = pred[i * + ];
float p_y = ;
for (int j = ; j < ; ++j) {
if (pred[i * + j] > mx_p) {
mx_p = pred[i * + j];
p_y = j;
}
}
if (p_y == target[i]) right++;
}
return right / 128.0;
} static void net(){
using mxnet::cpp::Symbol;
using mxnet::cpp::NDArray; Symbol x = Symbol::Variable("X");
Symbol y = Symbol::Variable("label"); std::vector<std::int32_t> shapes({ , });
//定义一个两层的网络. wx + b
Symbol weight_0 = Symbol::Variable("weight_0");
Symbol biases_0 = Symbol::Variable("biases_0"); Symbol fc_0 = mxnet::cpp::FullyConnected("fc_0",x,weight_0,biases_0
,); Symbol output_0 = mxnet::cpp::LeakyReLU("relu_0",fc_0,mxnet::cpp::LeakyReLUActType::kLeaky); Symbol weight_1 = Symbol::Variable("weight_1");
Symbol biases_1 = Symbol::Variable("biases_1");
Symbol fc_1 = mxnet::cpp::FullyConnected("fc_1",output_0,weight_1,biases_1,);
Symbol output_1 = mxnet::cpp::LeakyReLU("relu_1",fc_1,mxnet::cpp::LeakyReLUActType::kLeaky);
Symbol pred = mxnet::cpp::SoftmaxOutput("softmax",output_1,y); //目标函数,loss函数
mxnet::cpp::Context ctx = mxnet::cpp::Context::cpu( ); //定义输入数据
std::shared_ptr< mx_float > aptr_x(new mx_float[*] , [](mx_float* aptr_x){ delete [] aptr_x ;});
std::shared_ptr< mx_float > aptr_y(new mx_float[] , [](mx_float * aptr_y){ delete [] aptr_y ;}); //初始化数据
for(int i= ; i< ; i++){
for(int j=;j< ; j++){
//定义x
aptr_x.get()[i*+j]= i % +0.1f;
} //定义y
aptr_y.get()[i]= i % ;
}
std::map<std::string, mxnet::cpp::NDArray> args_map;
//导入数据
NDArray arr_x(mxnet::cpp::Shape(,),ctx, false);
NDArray arr_y(mxnet::cpp::Shape( ),ctx,false);
//将数据转换到NDArray中
arr_x.SyncCopyFromCPU(aptr_x.get(),*);
arr_x.WaitToRead(); arr_y.SyncCopyFromCPU(aptr_y.get(),);
arr_y.WaitToRead(); args_map["X"]=arr_x.Slice(,).Copy(ctx) ;
args_map["label"]=arr_y.Slice(,).Copy(ctx);
NDArray::WaitAll();
//绑定网络
mxnet::cpp::Executor *executor = pred.SimpleBind(ctx,args_map);
//选择优化器
mxnet::cpp::Optimizer *opt = mxnet::cpp::OptimizerRegistry::Find("sgd");
mx_float learning_rate = 0.0001; //学习率
mx_float weight_decay = 1e-; //权重
opt->SetParam("momentum", 0.9)
->SetParam("lr", learning_rate)
->SetParam("wd", weight_decay);
//定义各个层参数的数组
NDArray arr_w_0(mxnet::cpp::Shape(,),ctx, false);
NDArray arr_b_0(mxnet::cpp::Shape( ),ctx,false);
NDArray arr_w_1(mxnet::cpp::Shape( , ) , ctx , false);
NDArray arr_b_1(mxnet::cpp::Shape( ) , ctx , false); //初始化权重参数
arr_w_0 = 0.01f;
arr_b_1 = 0.01f;
arr_w_1 = 0.01f;
arr_b_1 = 0.01f; //初始化参数
executor->arg_dict()["weight_0"]=arr_w_0;
executor->arg_dict()["biases_0"]=arr_b_0;
executor->arg_dict()["weight_1"]=arr_w_1;
executor->arg_dict()["biases_1"]=arr_b_1; mxnet::cpp::NDArray::WaitAll();
//训练
std::cout<<" Training "<<std::endl; int max_iters = ; //最大迭代次数
//获取训练网络的参数列表
std::vector<std::string> args_name = pred.ListArguments();
for (int iter = ; iter < max_iters ; ++iter) {
executor->Forward(true);
executor->Backward(); if(iter % == ){
std::vector<NDArray> & out = executor->outputs;
std::shared_ptr<mx_float> tp_x( new mx_float[*] ,
[](mx_float * tp_x){ delete [] tp_x ;});
out[].SyncCopyToCPU(tp_x.get(),*);
NDArray::WaitAll();
std::cout<<"epoch "<<iter<<" "<<"Accuracy: "<< OutputAccuracy(tp_x.get() , aptr_y.get())<<std::endl;
}
//args_name.
for(size_t arg_ind=; arg_ind<args_name.size(); ++arg_ind){
//执行
if(args_name[arg_ind]=="X" || args_name[arg_ind]=="label")
continue; opt->Update(arg_ind,executor->arg_arrays[arg_ind],executor->grad_arrays[arg_ind]);
}
NDArray::WaitAll(); } }
};
} int main(int argc , char * argv[]){
mlp::MlpNet::net();
MXNotifyShutdown();
return EXIT_SUCCESS;
}

结果:

Training
epoch Accuracy: 0.09375
epoch Accuracy: 0.304688
epoch Accuracy: 0.195312
epoch Accuracy: 0.203125
epoch Accuracy: 0.304688
epoch Accuracy: 0.296875
epoch Accuracy: 0.304688
epoch Accuracy: 0.304688
epoch Accuracy: 0.398438
epoch Accuracy: 0.5
epoch Accuracy: 0.5
epoch Accuracy: 0.40625
epoch Accuracy: 0.5
epoch Accuracy: 0.398438
epoch Accuracy: 0.40625
epoch Accuracy: 0.703125
epoch Accuracy: 0.609375
epoch Accuracy: 0.507812
epoch Accuracy: 0.703125
epoch Accuracy: 0.703125
epoch Accuracy: 0.804688
epoch Accuracy: 0.703125
epoch Accuracy: 0.804688
epoch Accuracy: 0.804688
epoch Accuracy: 0.804688
epoch Accuracy: 0.90625
epoch Accuracy: 0.90625
epoch Accuracy: 0.90625
epoch Accuracy:
epoch Accuracy:
04-14 09:44