GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — NeuralNetwork/NeuralNetwork.hpp at master · 768897663/NeuralNetwork Expand file tree/ Copy pathNeuralNetwork.hppMore file actions 102 lines (89 loc) · 3.07 KB / Copy pathNeuralNetwork.hppFile metadata and controls102 lines (89 loc) · 3.07 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 //------------------------------------------------------------------------------- // NeuralNetwork.hpp // // @author // Millhaus.Chen @time 2017/07/28 15:16 //------------------------------------------------------------------------------- #pragma once #include "math/sigfunc.h" #include "math/Matrix.hpp" #include <tuple> #include <utility> namespace mtl { /// Unpack ints from variadic template /// The compile-time integer array, following RCInt is reverse of ints e.g. /// G{5, 3, 2, 4, 2} the (0, G) is 2 and (4, G) is 5 template<int N, int... Tail> struct RCInt; template<int N, int Tail> struct RCInt<N, Tail> { enum { value = Tail }; }; template<int N, int Head, int... Tail> struct RCInt<N, Head, Tail...> { enum { value = (N == sizeof...(Tail)) ? Head : RCInt<N, Tail...>::value }; }; template<int N, int... Ints> struct UnpackInts { enum { value = RCInt<(int)sizeof...(Ints) - N - 1, Ints...>::value }; }; /// Type helper template<typename I, int... Layers> struct NNType; template<std::size_t... I, int... Layers> struct NNType<std::index_sequence<I...>, Layers...> { typedef /// Weights type std::tuple< Matrix< double, UnpackInts<I, Layers...>::value, UnpackInts<I + 1, Layers...>::value >... > Weights; typedef /// Thresholds type std::tuple< Matrix< double, 1, UnpackInts<I + 1, Layers...>::value >... > Thresholds; }; /// The neural network class template<int... Layers> class BPNeuralNet { using InMatrix = Matrix<double, 1, UnpackInts<0, Layers...>::value>; using OutMatrix = Matrix<double, 1, UnpackInts<sizeof...(Layers) - 1, Layers...>::value>; public: void init(double aberration, double learnrate); template<class LX, class LY, class W, class T> void forward(LX& layerX, LY& layerY, W& weight, T& threshold); template<class LX, class LY, class W, class T, class DX, class DY> void reverse(LX& layerX, LY& layerY, W& weight, T& threshold, DX& deltaX, DY& deltaY); template<std::size_t... I> bool train(const InMatrix& input, OutMatrix& output, int times, std::index_sequence<I...>); bool train(const InMatrix& input, OutMatrix& output, int times = 1) { return train(input, output, times, std::make_index_sequence<sizeof...(Layers) - 1>()); } template<std::size_t... I> void simulat(const InMatrix& input, OutMatrix& output, std::index_sequence<I...>); void simulat(const InMatrix& input, OutMatrix& output) { simulat(input, output, std::make_index_sequence<sizeof...(Layers) - 1>()); } public: std::tuple<Matrix<double, 1, Layers>...> m_layers; typename NNType<std::make_index_sequence<sizeof...(Layers) - 1>, Layers...>::Weights m_weights; typename NNType<std::make_index_sequence<sizeof...(Layers) - 1>, Layers...>::Thresholds m_thresholds; std::tuple<Matrix<double, 1, Layers>...> m_deltas; OutMatrix m_aberrmx; protected: double m_aberration, m_learnrate; }; } #include "NeuralNetwork.inl" |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |