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

DiscriminativePCLayer with precision entirely removed. More...

#include <vector>
#include <stdexcept>
#include <random>
#include <memory>
#include <cstdlib>
#include <deepity/utils/Activations.h>
#include <deepity/utils/AdamOptimizer.h>
#include <deepity/layers/Layer.h>
#include <deepity/utils/DeviceMemoryArena.h>
#include <deepity/utils/MemoryArena.h>
#include <deepity/backend/IComputeBackend.h>

Go to the source code of this file.

Classes

class  Deep::SimplePCLayer
 Predictive Coding layer without precision weighting – the simpler, unweighted-energy counterpart to DiscriminativePCLayer. More...

Namespaces

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

Detailed Description

DiscriminativePCLayer with precision entirely removed.

Precision weighting (p, log_p, UpdatePrecision()) was found this session to be an unused cost, not a benefit: every real training run used pr=0.0 (precision inert – p stays permanently at 1, log_p at 0), yet UpdatePrecision() was still called unconditionally every train_step(), and every layer paid for the p buffer, the log_p buffer, and the precision-weighted energy formula's extra multiply/log term on every single CalculateState()/UpdateState() call, for zero behavioral benefit.

This class removes all of that: energy reduces to plain E = 0.5*sum(e^2) (no precision weighting, no -0.5*log(p) term), and UpdateState()'s own term reduces to dz_dt = -e (no p multiplier, since p=1 always made that multiplication a no-op anyway).

Mirrors DiscriminativePCLayer's public interface as closely as possible (same AddLayer-style construction pattern, same ActivationType-based constructor, same GetBeliefs/GetErrors/GetWeights/GetBiases accessors) so it's a near-drop-in swap for anyone not using precision – which, per the above, was everyone.

Warning
Not yet gradient-checked independently – this is a direct strip-down of DiscriminativePCLayer's already-verified math (same CalculateState/UpdateState/UpdateWeights formulas, precision terms removed), not new math, but the removal itself hasn't been re-verified via finite-difference check. Do that before trusting this for real training – same discipline as every other change this session.
Note
Optionally uses Adam (see AdamOptimizer.h) instead of plain SGD for weight updates, selected via SetOptimizer(); Adam's moment buffers are only allocated when selected, keeping the SGD-only path free of their memory/compute cost.
Optionally caches a CLAMPED layer's outgoing prediction (mu) across settling steps via SetMuCaching() – a clamped layer's z is fixed for the whole settling loop, and W/b don't change until UpdateWeights() runs afterward, so mu=f(W@z+b) is PROVABLY IDENTICAL every step while clamped. This is an EXACT optimization, not an approximation – default OFF so both behaviors coexist for direct correctness/timing comparison before trusting it.
As of this revision, all math is routed through an IComputeBackend rather than calling cblas_/Deep::* functions directly, so this layer can run on either CPUBackend or CUDABackend. backend defaults to nullptr, in which case the layer constructs and owns its own CPUBackend internally – every existing call site (SimplePCNetwork::AddLayer, nanobind bindings, hand-written C++) keeps working completely unchanged, silently getting today's exact CPU-only behavior. Passing a real backend explicitly is only needed for new, GPU-aware call sites.
Version
1.1
Date
2026-09-05
Author
Jack Rose