Deepity
Ultra-fast, SIMD-accelerated Predictive Coding
Loading...
Searching...
No Matches
ConvPCLayer Mathematical Derivation

Design Notes

Conv energy/state/weight derivation, adapted from DiscriminativePCLayer's already-verified formulas:

DiscriminativePCLayer (dense)

\[\begin{align} \mu &= f(z \cdot W^T + b) && \text{GEMM} \\ e &= z_{this} - \mu_{incoming}(\text{from below}) \\ \frac{dz}{dt} &+= -p \cdot e && \text{(own term)} \\ &+ (e_{above} \cdot p_{above}) \cdot W && \text{(feedback, GEMM, no transpose)} \\ dW &+= lr \cdot (e_{above} \cdot p_{above})^T \cdot z && \text{GEMM} \end{align} \]

ConvPCLayer (conv)

\[\begin{align} cols &= \text{Im2Col}(z) && (inC \cdot kH \cdot kW, outH \cdot outW) \\ &\text{stored in colBuffer, REUSED LATER by UpdateWeights()} \\ \mu &= f(W_{flat} \cdot cols + b) && \text{GEMM, same as dense} \\ e &= z_{this} - \mu_{incoming}(\text{from below}) && \text{UNCHANGED, elementwise} \\ feedback\_cols &= W_{flat}^T \cdot (e_{above} \cdot p_{above}) && \text{GEMM, written to feedbackScratch (NOT colBuffer)} \\ \frac{dz}{dt} &+= -p \cdot e && \text{(own term, UNCHANGED)} \\ &+ \text{Col2Im}(feedback\_cols) && \text{(scatter back to $(inC,H,W)$)} \\ dW_{flat} &+= lr \cdot (e_{above} \cdot p_{above}) \cdot cols^T && \text{GEMM, using colBuffer saved by CalculateState()} \\ \end{align} \]

The forward GEMM and the feedback GEMM are transposes of the SAME weight matrix, mirroring how DiscriminativePCLayer's forward and feedback GEMMs both use W with CblasTrans flipped between them.