private void SetupFilterUnits(int noFilterUnits, int noColumns, int noRows) { FilterUnits = new SingleFilterUnit[_depth]; for (int ii = 0; ii < FilterUnits.Length; ii++) { FilterUnits[ii] = new SingleFilterUnit(noColumns, noRows, 0, 0, MaxParallelThreads, WeightBaseValue); } }
//TODO:Set Weight Base function private void SetupFilterUnits(int noOfFilterUnits, int sizeWindow, int sizeStride) { FilterUnits = new SingleFilterUnit[noOfFilterUnits]; for (int ii = 0; ii < FilterUnits.Length; ii++) { FilterUnits[ii] = new SingleFilterUnit( _upstreamLayer, sizeWindow, sizeStride, _maxParallelThreads, WeightBaseValue); } }
/// <summary> /// Computes the FilterMap by convolution over each Input array /// from Upstream layer /// /// This function contains the sliding convolution window logic /// </summary> /// <param name="upStreamLayer"></param> public override void ComputeValueMap() { int filterSize = _weights.Length; //Filter is same as window //Slide the filter Window to compute value for each Cell in ValueMap (VM) for (int idxRowVM = 0; idxRowVM < GetValueMapNoOfRows(); idxRowVM++) { //idxRowVM for (int idxColVM = 0; idxColVM < GetValueMapNoOfColumns(); idxColVM++) { //idxColVM double sum = 0; int idxUpValueMapCol = 0, idxUpValueMapRow = 0; //Set the filter window co-ordinates in the upstream value map //relative to the current Value Map int upMapLeftCol = idxColVM * _stride; int upMapLeftRow = idxRowVM * _stride; //TODO: Assign value for (int idxFilter = 0; idxFilter < _upStreamLayer.GetNumberOfFilterUnits(); idxFilter++) //For each Filter Unit Upstream { SingleFilterUnit upFilterUnit = (SingleFilterUnit)_upStreamLayer.GetFilterUnit(idxFilter); for (int idxFilterRow = 0; idxFilterRow < filterSize; idxFilterRow++) { for (int idxFilterCol = 0; idxFilterCol < filterSize; idxFilterCol++) { //Update value idxUpValueMapCol = upMapLeftCol + idxFilterCol; idxUpValueMapRow = upMapLeftRow + idxFilterRow; //Multiply upStream FilterMap by current Filter weights sum += _weights[idxFilterCol][idxFilterRow] * upFilterUnit.GetValueMapAtIndex(idxUpValueMapCol, idxUpValueMapRow); } //idxFilterCol //Do for bias term sum += _bias * 1.0; } //idxFilterRow } //idxFilter //Normalize Sum sum = sum / (filterSize * 2); //divide sum by filter Grid size //Apply activation function - this saves time sum = _activationFunction.GetValue(sum); ValueMap[idxColVM][idxRowVM] = sum; //Assign value to FilterMap } //idxColFM } //idxRowFM }
/// <summary> /// Computes the ValueMap using the provided Pooling function /// </summary> public override void ComputeValueMap() { int poolSize = _poolSize; //Filter is same as window //Slide the filter Window to compute value for each Cell in ValueMap (VM) for (int idxRowVM = 0; idxRowVM < GetValueMapNoOfRows(); idxRowVM++) { //idxRowVM for (int idxColVM = 0; idxColVM < GetValueMapNoOfColumns(); idxColVM++) { //idxColVM int idxUpValueMapCol = 0, idxUpValueMapRow = 0; //Set the filter window co-ordinates in the upstream value map //relative to the current Value Map int upMapLeftCol = idxColVM * _stride; int upMapLeftRow = idxRowVM * _stride; //TODO: Assign value for (int idxFilter = 0; idxFilter < _upStreamLayer.GetNumberOfFilterUnits(); idxFilter++) //For each Filter Unit Upstream { SingleFilterUnit upFilterUnit = (SingleFilterUnit)_upStreamLayer.GetFilterUnit(idxFilter); for (int idxPoolRow = 0; idxPoolRow < poolSize; idxPoolRow++) { for (int idxPoolCol = 0; idxPoolCol < poolSize; idxPoolCol++) { //Update value idxUpValueMapCol = upMapLeftCol + idxPoolCol; idxUpValueMapRow = upMapLeftRow + idxPoolRow; //Multiply upStream FilterMap by current Filter weights _poolingFunction.AddValue(upFilterUnit.GetValueMapAtIndex(idxUpValueMapCol, idxUpValueMapRow)); } //idxFilterCol } //Compute Value }//idxFilter //Apply pooling function - this saves time ValueMap[idxColVM][idxRowVM] = _poolingFunction.GetValue();; //Assign value to FilterMap } //idxColFM } //idxRowFM }