activation_8hpp_source.tex 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. \hypertarget{activation_8hpp_source}{}\doxysection{activation.\+hpp}
  2. \label{activation_8hpp_source}\index{src/layers/activation.hpp@{src/layers/activation.hpp}}
  3. \mbox{\hyperlink{activation_8hpp}{Go to the documentation of this file.}}
  4. \begin{DoxyCode}{0}
  5. \DoxyCodeLine{1 \textcolor{preprocessor}{\#ifndef ACTIVATION\_LAYER\_HPP}}
  6. \DoxyCodeLine{2 \textcolor{preprocessor}{\#define ACTIVATION\_LAYER\_HPP}}
  7. \DoxyCodeLine{3 }
  8. \DoxyCodeLine{4 \textcolor{preprocessor}{\#include "{}\mbox{\hyperlink{layer_8hpp}{layer.hpp}}"{}}}
  9. \DoxyCodeLine{5 \textcolor{preprocessor}{\#include "{}\mbox{\hyperlink{math_8hpp}{math.hpp}}"{}}}
  10. \DoxyCodeLine{6 }
  11. \DoxyCodeLine{7 \textcolor{keyword}{namespace }\mbox{\hyperlink{namespace_layer}{Layer}}\{}
  12. \DoxyCodeLine{9 \textcolor{keyword}{enum} \mbox{\hyperlink{namespace_layer_a154fb338e15b0326915fb7f9c383ef9f}{ActivationMap}}\{}
  13. \DoxyCodeLine{10 \mbox{\hyperlink{namespace_layer_a154fb338e15b0326915fb7f9c383ef9fa467cf9e29d4001586b13a922da0dc34b}{Sigmoid}} }
  14. \DoxyCodeLine{11 \};}
  15. \DoxyCodeLine{12 }
  16. \DoxyCodeLine{14 \textcolor{keyword}{template}<ActivationMap A> \mbox{\hyperlink{vector_8hpp_a4b04262b81aa7d31eb5d2f607e2a35de}{Real}} \mbox{\hyperlink{namespace_layer_a8bab25d92aa706e26d241614ff6fe81a}{activation\_map}}(\mbox{\hyperlink{vector_8hpp_a4b04262b81aa7d31eb5d2f607e2a35de}{Real}});}
  17. \DoxyCodeLine{15 }
  18. \DoxyCodeLine{17 \textcolor{keyword}{template}<ActivationMap A> \mbox{\hyperlink{vector_8hpp_a4b04262b81aa7d31eb5d2f607e2a35de}{Real}} \mbox{\hyperlink{namespace_layer_ab144999586187c1317641130a7b88013}{activation\_diff\_map}}(\mbox{\hyperlink{vector_8hpp_a4b04262b81aa7d31eb5d2f607e2a35de}{Real}});}
  19. \DoxyCodeLine{18 }
  20. \DoxyCodeLine{23 \textcolor{keyword}{template}<ActivationMap A> \textcolor{keyword}{class }\mbox{\hyperlink{class_layer_1_1_activation_layer}{ActivationLayer}}:\textcolor{keyword}{public} \mbox{\hyperlink{namespace_layer}{Layer}}\{}
  21. \DoxyCodeLine{24 \textcolor{keyword}{public}:}
  22. \DoxyCodeLine{25 \mbox{\hyperlink{class_layer_1_1_activation_layer_a6999fec429ab7f6eafc9ebd5a42a8f76}{ActivationLayer}}(\textcolor{keyword}{const} \textcolor{keywordtype}{size\_t});}
  23. \DoxyCodeLine{26 \mbox{\hyperlink{class_layer_1_1_activation_layer_aa7059282e1e7eeb17b1e36e594e1f2ac}{\string~ActivationLayer}}()\{\};}
  24. \DoxyCodeLine{28 \mbox{\hyperlink{vector_8hpp_ab9855a300a7759f4c0f85067d44e4c38}{Vector}} \mbox{\hyperlink{class_layer_1_1_activation_layer_a9bc3eb83733b4ee5a4a3c5c50e794478}{feed\_forward}}(\mbox{\hyperlink{vector_8hpp_ab9855a300a7759f4c0f85067d44e4c38}{Vector}} \mbox{\hyperlink{class_layer_1_1_layer_af2ebcf019bc0e4b97f41fc9205706665}{x}}) \textcolor{keyword}{override};}
  25. \DoxyCodeLine{30 \textcolor{keywordtype}{void} \mbox{\hyperlink{class_layer_1_1_activation_layer_a230ad43fde65528cc36021e097f111a4}{init\_nabla}}()\textcolor{keyword}{ override }\{\};}
  26. \DoxyCodeLine{32 \mbox{\hyperlink{vector_8hpp_ab9855a300a7759f4c0f85067d44e4c38}{Vector}} \mbox{\hyperlink{class_layer_1_1_activation_layer_aa946acde267d94523d12465ca8976ab9}{back\_propagation}}(\mbox{\hyperlink{vector_8hpp_ab9855a300a7759f4c0f85067d44e4c38}{Vector}} e) \textcolor{keyword}{override};}
  27. \DoxyCodeLine{34 \textcolor{keywordtype}{void} \mbox{\hyperlink{class_layer_1_1_activation_layer_afbc9f12d792008bbaf6d6c2d0177ebf1}{update}}(\mbox{\hyperlink{vector_8hpp_a4b04262b81aa7d31eb5d2f607e2a35de}{Real}} eta)\textcolor{keyword}{ override}\{\};}
  28. \DoxyCodeLine{35 \};}
  29. \DoxyCodeLine{36 }
  30. \DoxyCodeLine{37 \textcolor{keyword}{template}<ActivationMap A>}
  31. \DoxyCodeLine{38 \textcolor{keyword}{inline}}
  32. \DoxyCodeLine{39 \mbox{\hyperlink{class_layer_1_1_activation_layer_a6999fec429ab7f6eafc9ebd5a42a8f76}{ActivationLayer<A>::ActivationLayer}}(\textcolor{keywordtype}{size\_t} n):\mbox{\hyperlink{namespace_layer}{Layer}}(n,n)\{}
  33. \DoxyCodeLine{40 \}}
  34. \DoxyCodeLine{41 }
  35. \DoxyCodeLine{42 \textcolor{keyword}{template}<ActivationMap A>}
  36. \DoxyCodeLine{43 \textcolor{keyword}{inline} \mbox{\hyperlink{vector_8hpp_ab9855a300a7759f4c0f85067d44e4c38}{Vector}}}
  37. \DoxyCodeLine{44 \mbox{\hyperlink{class_layer_1_1_activation_layer_a9bc3eb83733b4ee5a4a3c5c50e794478}{ActivationLayer<A>::feed\_forward}}(\mbox{\hyperlink{vector_8hpp_ab9855a300a7759f4c0f85067d44e4c38}{Vector}} x\_)\{}
  38. \DoxyCodeLine{45 x=x\_;}
  39. \DoxyCodeLine{46 \textcolor{keywordflow}{for}(\textcolor{keywordtype}{size\_t} i=0;i<n;++i)\{}
  40. \DoxyCodeLine{47 y[i]=activation\_map<A>(x[i]);}
  41. \DoxyCodeLine{48 \}}
  42. \DoxyCodeLine{49 \textcolor{keywordflow}{return} y;}
  43. \DoxyCodeLine{50 \}}
  44. \DoxyCodeLine{51 }
  45. \DoxyCodeLine{52 \textcolor{keyword}{template}<ActivationMap A>}
  46. \DoxyCodeLine{53 \textcolor{keyword}{inline} \mbox{\hyperlink{vector_8hpp_ab9855a300a7759f4c0f85067d44e4c38}{Vector}}}
  47. \DoxyCodeLine{54 \mbox{\hyperlink{class_layer_1_1_activation_layer_aa946acde267d94523d12465ca8976ab9}{ActivationLayer<A>::back\_propagation}}(\mbox{\hyperlink{vector_8hpp_ab9855a300a7759f4c0f85067d44e4c38}{Vector}} e)\{}
  48. \DoxyCodeLine{55 \textcolor{keywordflow}{for}(\textcolor{keywordtype}{size\_t} i=0;i<n;++i)\{}
  49. \DoxyCodeLine{56 d[i]=activation\_diff\_map<A>(x[i])*e[i];}
  50. \DoxyCodeLine{57 \}}
  51. \DoxyCodeLine{58 \textcolor{keywordflow}{return} d;}
  52. \DoxyCodeLine{59 \}}
  53. \DoxyCodeLine{60 }
  54. \DoxyCodeLine{61 \textcolor{keyword}{template}<>}
  55. \DoxyCodeLine{62 \textcolor{keyword}{inline} \mbox{\hyperlink{vector_8hpp_a4b04262b81aa7d31eb5d2f607e2a35de}{Real}}}
  56. \DoxyCodeLine{63 \mbox{\hyperlink{namespace_layer_a1cc1cac69c2c7e23cd745cdaaa900265}{activation\_map<Sigmoid>}}(\mbox{\hyperlink{vector_8hpp_a4b04262b81aa7d31eb5d2f607e2a35de}{Real}} x)\{}
  57. \DoxyCodeLine{64 \textcolor{keywordflow}{return} 1.0/(1.0+\mbox{\hyperlink{namespace_math_a7e8411f9880b87ade916aee8531d0c11}{exp}}(-\/x));}
  58. \DoxyCodeLine{65 \}}
  59. \DoxyCodeLine{66 }
  60. \DoxyCodeLine{67 \textcolor{keyword}{template}<>}
  61. \DoxyCodeLine{68 \textcolor{keyword}{inline} \mbox{\hyperlink{vector_8hpp_a4b04262b81aa7d31eb5d2f607e2a35de}{Real}}}
  62. \DoxyCodeLine{69 \mbox{\hyperlink{namespace_layer_a2a722f834e422b77ee155b2bd252c995}{activation\_diff\_map<Sigmoid>}}(\mbox{\hyperlink{vector_8hpp_a4b04262b81aa7d31eb5d2f607e2a35de}{Real}} x)\{}
  63. \DoxyCodeLine{70 \mbox{\hyperlink{vector_8hpp_a4b04262b81aa7d31eb5d2f607e2a35de}{Real}} t=\mbox{\hyperlink{namespace_layer_a1cc1cac69c2c7e23cd745cdaaa900265}{activation\_map<Sigmoid>}}(x);}
  64. \DoxyCodeLine{71 \textcolor{keywordflow}{return} t*(1.0-\/t);}
  65. \DoxyCodeLine{72 \}}
  66. \DoxyCodeLine{73 \}}
  67. \DoxyCodeLine{74 \textcolor{preprocessor}{\#endif}}
  68. \end{DoxyCode}