Advertisement
Guest User

Untitled

a guest
May 20th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. #pragma once
  2. #include "Weights.h"
  3. #include "Func.h"
  4. #include <vector>
  5.  
  6.  
  7. template <typename T, typename Y>
  8. class Base_Perceptron
  9. {
  10. public:
  11. // Конструкторы ----------------------------------------------------------
  12. Base_Perceptron();
  13. Base_Perceptron(const Base_Perceptron& copy) = delete; // Запрет копирования
  14.  
  15. // Методы класса ---------------------------------------------------------
  16. // Операция суммированию произведений входов на веса нейрона
  17. virtual T Summator(const Matrix<T>& a, const Weights<T>& w);
  18. virtual T Summator(std::vector<T> a, const std::vector<T>& w);
  19.  
  20. // Функция активации нейрона
  21. virtual Y FunkActiv(const T&, Func<T,Y>&) = 0;
  22.  
  23. // Перегрузка операторов -------------------------------------------------
  24. Base_Perceptron& operator= (const Base_Perceptron& copy) = delete; // Запрет копирования
  25.  
  26. // Деструктор ------------------------------------------------------------
  27. virtual ~Base_Perceptron();
  28.  
  29. // Класс исключения ------------------------------------------------------
  30. class NeyronPerceptronExeption : public std::runtime_error {
  31. public:
  32. NeyronPerceptronExeption(std::string str) : std::runtime_error(str) {};
  33. ~NeyronPerceptronExeption() {};
  34. };
  35. };
  36.  
  37. template <typename T, typename Y>
  38. Base_Perceptron<T, Y>::Base_Perceptron()
  39. {
  40. }
  41.  
  42. template <typename T, typename Y>
  43. T Base_Perceptron<T, Y>::Summator(const Matrix<T> & a, const Weights<T> & w)
  44. {
  45. if ((a.getN() != w.getN()) || (a.getM() != w.getM())) {
  46. throw Base_Perceptron<T, Y>::NeyronPerceptronExeption("Несовпадение размера матрицы весов и размера матрицы входных сигналов!");
  47. }
  48. T sum = 0;
  49. for (int i = 0; i < a.getN(); i++) {
  50. for (int j = 0; j < a.getM(); j++) {
  51. sum += a[i][j] * w[i][j];
  52. }
  53. }
  54. sum += w.GetWBias();
  55. return sum;
  56. }
  57.  
  58. template <typename T, typename Y>
  59. inline T Base_Perceptron<T, Y>::Summator(std::vector<T> a, const std::vector<T>& w)
  60. {
  61. if (a.size() != w.size()) {
  62. throw Base_Perceptron<T,Y>::NeyronPerceptronExeption("Несовпадение размера матрицы весов и размера матрицы входных сигналов!");
  63. }
  64. T sum = 0;
  65. for (int i = 0; i < a.size(); i++) {
  66. sum += a[i] * w[i];
  67. }
  68. return sum;
  69. }
  70.  
  71. template <typename T, typename Y>
  72. Base_Perceptron<T,Y>::~Base_Perceptron()
  73. {
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement