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
|
#include <iostream>
#include <vector>
#include <map>
using namespace std;
struct Example
{
Example(double val, vector<double> ys) :
val(val),
ys(ys)
{
}
double val = 0;
vector<double> ys;
};
void Show(const vector<vector<Example>>& layers)
{
for(auto& row : layers)
{
for (auto& e : row)
{
cout << e.val << ": {";
for (auto& y : e.ys)
cout << y << " ";
cout << "}, ";
}
cout << endl;
}
}
int main()
{
vector<vector<Example>> layers =
{
{ {1.0, {1.1, 2.2, 3.3}}, {2.0, {0.0, 2.9, 4.5}}, {3.0, {6.5, 5.9, 6.6}} },
{ {86.3, {0.2, 0.1, 0.5}}, {23.5, {0.6, 0.7, 0.7}}, {9.4, {0.3, 1.0, 0.5}} },
{ {0.0, {}}, {0.0, {}}, {0.0, {}} }
};
Show(layers);
double valsum;
for (int r=0; r<layers.size()-1; ++r)
{
for (int c=0; c<layers[r].size(); ++c)
{
valsum = 0;
Example& ex = layers[r][c];
for (auto& y : ex.ys)
{
valsum += ex.val * y;
}
layers[r+1][c].val = valsum;
}
}
cout << endl << endl;
Show(layers);
return 0;
}
| |