Vector process(const Vector &input, NetworkContext &ctx) { assert(input.rows() == numInputs); ctx.layerOutputs.resize(layerWeights.NumLayers()); ctx.layerOutputs[0] = getLayerOutput(input, layerWeights(0)); for (unsigned i = 1; i < layerWeights.NumLayers(); i++) { ctx.layerOutputs[i] = getLayerOutput(ctx.layerOutputs[i-1], layerWeights(i)); } assert(ctx.layerOutputs[ctx.layerOutputs.size()-1].rows() == numOutputs); return ctx.layerOutputs[ctx.layerOutputs.size()-1]; }
NetworkImpl(const vector<unsigned> &layerSizes) { assert(layerSizes.size() >= 2); this->numLayers = layerSizes.size() - 1; this->numInputs = layerSizes[0]; this->numOutputs = layerSizes[layerSizes.size() - 1]; for (unsigned i = 0; i < numLayers; i++) { layerWeights.AddLayer(createLayer(layerSizes[i], layerSizes[i+1])); } zeroGradient = layerWeights; for (unsigned i = 0; i < zeroGradient.NumLayers(); i++) { zeroGradient(i).setZero(); } }