Deepity
Ultra-fast, SIMD-accelerated Predictive Coding
Loading...
Searching...
No Matches
DirectKPPCNetwork.h File Reference

Orchestrates DirectKPPCLayer's Direct Kolen-Pollack predictive coding (DKP-PC) phases in the correct order – the layer class alone cannot produce a correct train step; the ORDER of the phases across layers is what makes this DKP-PC rather than plain PC, and that only exists at this level. More...

#include <vector>
#include <memory>
#include <random>
#include <deepity/layers/DirectKPPCLayer.h>
#include <deepity/utils/MemoryArena.h>
#include <deepity/utils/DeviceMemoryArena.h>
#include <deepity/backend/Backend.h>

Go to the source code of this file.

Classes

class  Deep::DirectKPPCNetwork
 Predictive Coding network built from DirectKPPCLayer, using Direct Kolen-Pollack feedback alignment (DFA) instead of symmetric weight transport. See the file-level warning above on its current verification status. More...

Namespaces

namespace  Deep
 This file exists to provide both Tensor.h and IComputeBackend.h with device types without introducing circular dependencies.

Detailed Description

Orchestrates DirectKPPCLayer's Direct Kolen-Pollack predictive coding (DKP-PC) phases in the correct order – the layer class alone cannot produce a correct train step; the ORDER of the phases across layers is what makes this DKP-PC rather than plain PC, and that only exists at this level.

Per Casnici, Lefebvre, Dauwels & Frenkel, "Accelerated Predictive Coding Networks via Direct Kolen-Pollack Feedback Alignment" (2026), Algorithm 1, a full DKP-PC train step is FOUR phases, in this exact order:

  1. Forward initialization – clamp input, forward-project every hidden layer's z from current weights, clamp the target, then CalculateState() on the terminal layer ALONE to produce a real, non-zero epsilon_L. Every other layer's error is still zero at this point (equilibrium after forward init).
  2. Direct feedback alignment update – DirectFeedbackUpdate() on EVERY non-terminal layer, using epsilon_L (via terminalLayer) and the layer above's Psi. This is a genuine, immediate perturbation of each layer's W, run BEFORE settling begins, and it does not depend on any ordering among layers – each layer's update only reads Psi (which does not change during this phase) and epsilon_L, both already available. Unlike GaussSeidelPCLayer, there is no sweep-ordering constraint here. CONFIRMED by tracing every read/write in DirectFeedbackUpdate(): every layer writes only to its own proj/W, reads only from a shared, read-only terminalLayer error buffer and its own layerAbove's Psi – zero cross-layer RAW/WAW hazard. This is the specific phase intended as the first real parallelism target (multiple CUDA streams, one per layer), once this class is confirmed correct on GPU.
  3. Inference phase – ordinary PC settling (CalculateState() + UpdateState() across every layer), for inferenceSteps steps. Because phase 1 already perturbed every layer's W, every layer now has a genuinely non-zero error from the very first settling step – the paper's central result is that inferenceSteps=1 is sufficient to match or exceed standard PC's full multi-step settle. Larger values trade some of that speed advantage for potentially higher accuracy; this is a real, exposed parameter, not something to hardcode to this codebase's usual (~20) default.
  4. Learning phase – UpdateWeights() on every non-terminal layer, which (per DirectKPPCLayer) now updates both W (from the settled state) and Psi (from the settled state and epsilon_L).
Note
As of this revision, routed through IComputeBackend – same refactor as SimplePCNetwork's own GPU port. device defaults to DEVICE_CPU, preserving existing behavior for anyone not explicitly requesting DEVICE_GPU.
Warning
Not yet gradient-checked at the network level, and not yet tested on GPU at all. The individual layer's math should be independently verified before trusting any accuracy conclusion drawn from real training with this class. This is Stage 1 of a three-stage plan (CPU-correct port -> GPU-correct, sequential -> exploit phase 1's confirmed cross-layer parallelism) – this revision is Stage 1 only.