Neural Network I
neural network 1:
5 * 5 sqare have 1?
hidder layer:0
C++#include <iostream>
#include <cstdio>
#include <vector>
#define VD vector<double>
using namespace std;
double R(double p) {
return (p < 0) ? 0 : p;
}
vector<VD > w;
void init() {
w.push_back({0, 0, 0, 0, 0, 0, 0.5, 1, 0.5, 0, 0, 0.5, 1, 0.5, 0, 0, 0.5, 1, 0.5, 0, 0, 0, 0, 0, 0});
return ;
}
VD mul(vector<VD > a, VD b, double bias) {
VD h;
double sum;
int s1 = a.size(), s2 = b.size(); //s1:size 1,s2:size 2.
for (int i = 0; i < s1; i++) {
sum = 0;
for (int j = 0; j < s2; j++) {
sum += a[i][j] * b[j];
}
h.push_back(R(sum - bias));
}
return h;
}
VD H;
VD s;
double p;
int main() {
for (int i = 0; i < 25; i++) {
scanf("%lf", &p);
s.push_back(p);
}
init();
H = mul(w, s, 1.6);
putchar(H[0] ? '#' : '*');
return 0;
}
neural network 2:
5 * 5 sqare have 7?
hidder layer:0
C++#include <iostream>
#include <cstdio>
#include <vector>
#define VD vector<double>
using namespace std;
double R(double p) {
return (p < 0) ? 0 : p;
}
vector<VD > w;
void init() {
w.push_back({0, 0.2, 0.5, 0.5, 0, 0, 0.5, 1, 1, 0, 0, 0, 0, 1, 0.2, 0, 0, 0.5, 0.9, 0.5, 0, 0, 0.5, 0.5, 0.5});
return ;
}
VD mul(vector<VD > a, VD b, double bias) {
VD h;
double sum;
int s1 = a.size(), s2 = b.size(); //s1:size 1,s2:size 2.
for (int i = 0; i < s1; i++) {
sum = 0;
for (int j = 0; j < s2; j++) {
sum += a[i][j] * b[j];
}
h.push_back(R(sum - bias));
}
return h;
}
VD H;
VD s;
double p;
int main() {
for (int i = 0; i < 25; i++) {
scanf("%lf", &p);
s.push_back(p);
}
init();
H = mul(w, s, 3.4);
putchar(H[0] ? '#' : '*');
return 0;
}
< writter∣∣next >