Advertisement
Guest User

Untitled

a guest
May 20th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. #pragma once
  2. #include "Base_Cnn.h"
  3. #include <string>
  4.  
  5.  
  6. template<typename T>
  7. class NeyronСnn : public Base_Cnn<T>
  8. {
  9. public:
  10. // Конструкторы ----------------------------------------------------------
  11. NeyronСnn();
  12. explicit NeyronСnn(const int& step_ );
  13. NeyronСnn(const NeyronСnn<T>& copy) = delete; // Запрет копирования
  14.  
  15. // Методы класса ---------------------------------------------------------
  16. // Операция свертки над матрицей значений
  17. Matrix<T> Svertka(const Matrix<T>& F, const Matrix<T>& a);
  18.  
  19. // Получение доступа к шагу свертки
  20. int& GetStep() { return step; }
  21.  
  22. // Перегрузка операторов -------------------------------------------------
  23. NeyronСnn& operator= (const NeyronСnn<T>& copy) = delete; // Запрет копирования
  24.  
  25. // Деструктор ------------------------------------------------------------
  26. ~NeyronСnn();
  27.  
  28. // Класс исключения ------------------------------------------------------
  29. class NeyronСnnExeption : public Base_Cnn<T>::Base_CnnExeption {
  30. public:
  31. NeyronСnnExeption(std::string str) : Base_Cnn<T>::Base_CnnExeption(str) {};
  32. ~NeyronСnnExeption() {};
  33. };
  34. private:
  35. // Поля класса -----------------------------------------------------------
  36. int step; // Шаг свертки
  37. };
  38.  
  39.  
  40. template<typename T>
  41. NeyronСnn<T>::NeyronСnn() : Base_Cnn<T>(), step(1)
  42. {
  43. }
  44.  
  45. template<typename T>
  46. NeyronСnn<T>::NeyronСnn(const int& step_) : Base_Cnn<T>(), step(step_)
  47. {
  48. }
  49.  
  50.  
  51. template<typename T>
  52. Matrix<T> NeyronСnn<T>::Svertka(const Matrix<T>& F, const Matrix<T>& a)
  53. {
  54.  
  55. if ((step > a.getN()) || (step > a.getM())||(step < 1)) {
  56. throw NeyronСnnExeption("Задан невозможный шаг свертки!");
  57. }
  58.  
  59. Matrix<T> rez((a.getN() - F.getN()) / step + 1, (a.getM() - F.getM()) / step + 1);
  60.  
  61. double sum;
  62. Matrix<T> fokus;
  63. for (int i = 0; i < rez.getN(); i++) {
  64. for (int j = 0; j < rez.getM(); j++) {
  65. sum = 0;
  66. fokus = a.getPodmatrix(i*step, j*step, F.getN(), F.getM());
  67. for (int ii = 0; ii < F.getN(); ii++) {
  68. for (int jj = 0; jj < F.getM(); jj++) {
  69. sum += fokus[ii][jj] * F[ii][jj];
  70. }
  71. }
  72. rez[i][j] = sum;
  73. }
  74. }
  75. return rez;
  76. }
  77.  
  78.  
  79. template<typename T>
  80. NeyronСnn<T>::~NeyronСnn()
  81. {
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement