Patch Size and Margin Width Requirements - PetaVision/OpenPV GitHub Wiki
The internals of PetaVision make certain assumptions regarding layers' neuron densities and connections' patch sizes. The code tests for these conditions and exits with an error if they are not met. A connection's patch size also imposes minimum requirements on the width of margin between the restricted layer and extended layer. PetaVision calculates the margin widths internally, but it is helpful to understand how the patch size leads to requirements on the margin width.
The following discusses the x-direction (parameter nxScale in the layers and parameter nxp in the connections), but the same applies to the y-direction parameters. nxp and nyp are independent parameters, and the margin widths in the x- and y- directions can be different.
nxScale must be an integral power of two (1,2,4,... or 1/2, 1/4, 1/8,...). If the input parameters specify an nxScale that is not an integral power of two, then nxScale is effectively replaced with 2^round(log2(nxScale)). (Internally, the scale parameter is converted to xScale = -log2(nxScale) )
nxp is the patch size of each pre-synaptic neuron's connection to the post-synaptic layer. The parameters file does not need to specify the size of the patch in the pre-synaptic layer that each post-synaptic neuron is connected to.
Every connection imposes requirements on the connection's patch size nxp and on its pre-synaptic layer's marginWidth. A connection does not impose a requirement on the post-synaptic marginWidth. The requirements depend on the relative neural densities of the connection's pre-synaptic and post-synaptic layers. For brevity, the descriptions below use the following notation:
Notation | Definition
--------------- | --------------------------------------------- nxScalePre | pre-synaptic layer's nxScale parameter nxScalePost | post-synaptic layer's nxScale parameter nxScaleRatio | nxScalePost/nxScalePre marginWidthPre | the pre-synaptic layer's marginWidth.
===============================================================
Case 1: nxScalePost = nxScalePre
nxp must be odd.
marginWidthPre must be at least (nxp-1)/2.
===============================================================
Case 2: nxScalePost > nxScalePre
(the post-synaptic layer has more neurons than the pre-synaptic layer)
nxp must be a multiple of the nxScaleRatio
marginWidthPre must be at least ( (nxp/nxScaleRatio) - 1 )/2
Example: If the presynaptic layer is 32-by-32 and the postsynaptic layer is 128-by-128, then nxScaleRatio = 4.
Hence, nxp must be a multiple of 4: nxp = 4, 8, 12, etc. If nxp = 20, then marginWidthPre must be at least (20/4 - 1)/2 = 2.
===============================================================
Case 3: nxScalePost < nxScalePre
(the post-synaptic layer has fewer neurons than the pre-synaptic layer)
nxp can be any positive integer.
marginWidthPre must be at least (nxp-1)/2 * (1/nxScaleRatio) (since nxScalePre will be a positive multiple of nxScalePost, 1/nxScaleRatio is a positive integer).
Example: If the presynaptic layer is 128-by-128 and the postsynaptic layer is 64-by-64, then nxScaleRatio = 0.5. If nxp = 7, then marginWidthPre must be at least 3*2 = 6
===============================================================