dmatrix3 ConvLayer::think(dmatrix3 mat) { dmatrix3 slab(mat.size(), dmatrix2(Fshape[1], dvec(Fshape[0]))); ivec step(4); dvec exc(OutShape[1]*OutShape[2]); dvec act(OutShape[1]*OutShape[2]); ivec foldshape(2); foldshape[0] = OutShape[1]; foldshape[1] = OutShape[2]; Inputs = &mat; for(int f=0;f<Filters.size();f++) { dmatrix3 filt = Filters[f]; for(int i=0;i<Steps.size();i++) { step = Steps[i]; slab = invert<real>(slice<real>(invert<real>(mat), step)); exc[i] = frobenius(slab, filt); // This is the "convolve" step act[i] = sigmoid(exc[exc.size()-1]); } Excitations[f] = fold2<real>(exc, foldshape); Activations[f] = fold2<real>(act, foldshape); } return Activations; }
// Feedforward void PoolLayer::think(dmatrix3 &mat) { ThoughtBubble bubble; int index=0; dvec activationVec(OutShape[0]*OutShape[1]*OutShape[2]); reset(); for(int z=0;z<mat.size();z++) { for(int i=0;i<Steps.size();i++, index++) { imatrix2 exc(Fshape[0], Fshape[1]); int* step(Steps.atp(i)); bubble = max_pool(slice<real>(mat[z], step)); activationVec[index] = bubble.activation; exc = fold2<int>(bubble.excitation, Fshape); apply_exc(exc, step, z); } } *Activations.point() = activationVec; return Activations; }