-
Notifications
You must be signed in to change notification settings - Fork 0
/
Teaching.hpp
62 lines (56 loc) · 1.62 KB
/
Teaching.hpp
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
#pragma once
using namespace std;
int sign(double x){
if (x >= 0) return 1;
else return -1;
}
template<size_t SIZEW>
void matrixInitialization(array<array<double, SIZEW>, SIZEW> &wMatrix){
for (int i = 0; i < SIZEW; i++) {
for (int j = 0; j < SIZEW; j++) {
wMatrix[i][j] = 0;
}
}
}
template<size_t SIZEW, size_t SIZE>
void fillMatrix(array<array<double, SIZEW>, SIZEW> &wMatrix,
const array<array<int, SIZEW>, SIZE> &sourceMatrix) {
for (const auto &matrix : sourceMatrix) {
int count1 = 0;
for (int i = 0; i < SIZEW; i++) {
for (int j = 0; j < SIZEW; j++) {
wMatrix[i][j] += matrix[count1] * matrix[j];
}
count1++;
}
}
}
template<size_t SIZEW>
void remakeMatrix(array<array<double,SIZEW>, SIZEW> &wMatrix, double coefficient){
for (int i = 0; i < SIZEW; i++){
for (int j = 0; j < SIZEW; j++) {
wMatrix[i][j] *= coefficient;
}
}
}
template<size_t SIZEW>
void fillDiagonalWithZeros(array<array<double, SIZEW>, SIZEW> &wMatrix){
for (int i = 0; i < wMatrix.size(); i++){
wMatrix[i][i] = 0;
}
}
template<size_t SIZEW>
void createIntermediateImage(const array<array<double, SIZEW>, SIZEW> &wMatrix,
array<double, SIZEW> &intermediateImage, const array<int, SIZEW> &distortedImage) {
for (int i = 0; i < SIZEW; i++){
for (int j = 0; j < SIZEW; j++) {
intermediateImage[i] += wMatrix[i][j] * distortedImage[j];
}
}
}
template<size_t SIZEW>
void restoreImage(const array<double, SIZEW> &intermediateImage, array<int, SIZEW> &reconstructedImage){
for (int i = 0; i < SIZEW; i++){
reconstructedImage[i] = sign(intermediateImage[i]);
}
}