45 RBLayer(
size_t inSize,
size_t outSize,
46 float var = 1.0f,
float var_td = 10.0f,
47 float k_1 = 1e-3f,
float k_2 = 1e-5f,
48 float lmbda = 1e-6f,
float alpha = 1.0f,
49 size_t batchSize = 64,
int stepSize = 30,
50 void(*act)(
float *,
size_t) =
relu,
void(*dAct)(
float *,
size_t,
bool) =
dRelu);
55 void RunPrediction(
const float *input,
size_t currentBatchSize)
noexcept;
58 void RunInferenceStep(
const float *input,
const float *topDown,
size_t currentBatchSize)
noexcept;
61 void CalcError(
const float *bottomUp,
const float *topDown,
size_t currentBatchSize)
noexcept;
76 void UpdateBeliefs(
const float *bottomUp,
const float *topDown,
size_t currentBatchSize)
noexcept;
112 void Flush()
noexcept override;
114 [[nodiscard]]
const float *
GetErrors() const noexcept
override {
return e_bu; }
120 void Attach(
float *ptr) noexcept;
123 [[nodiscard]]
float *
GetWeights() const noexcept {
return U; }
125 [[nodiscard]]
size_t GetBatchSize() const noexcept override;
126 [[nodiscard]]
size_t GetInputSize() const noexcept override;
127 [[nodiscard]]
size_t GetOutputSize() const noexcept override;
129 [[nodiscard]]
float *
GetBeliefs() noexcept override;
137 void DebugStats(
int layerIndex)
const;
142 void CacheInput(
const float *input,
size_t currentBatchSize)
noexcept;
155 size_t cachedBatchSize = 0;
156 const float *cachedInput =
nullptr;
159 void (*act)(
float *, size_t);
160 void (*dAct)(
float *, size_t, bool);
165 float *e_bu =
nullptr;
166 float *e_td =
nullptr;
169 std::unique_ptr<float[]> inputBuffer;
170 size_t pendingCount = 0;
171 bool ownsMemory =
false;
173 float *tmpBelief =
nullptr;
174 float *tmpWeight1 =
nullptr;
175 float *tmpWeight2 =
nullptr;
176 float *tmpWeight3 =
nullptr;
177 float *tmpWeight4 =
nullptr;
Defines the activation functions of a predictive coding model.
A deepity layer virtual class.
Definition Layer.h:40
void CalcError(const float *bottomUp, const float *topDown, size_t currentBatchSize) noexcept
Computes the precision-weighted prediction errors.
Definition RBLayer.cpp:134
float * GetBeliefs() noexcept override
Should return belief state z.
Definition RBLayer.cpp:299
const float * GetErrors() const noexcept override
Should return errors e.
Definition RBLayer.h:114
void UpdateWeights() noexcept override
Parameter-less override for generic layer weight updates.
Definition RBLayer.cpp:290
const float * GetInferenceError() const noexcept
Same underlying buffer as GetErrors() – the bottom-up prediction error, named separately here for cal...
Definition RBLayer.cpp:300
void UpdateState() noexcept override
Computes the state derivatives and applies them to current beliefs.
Definition RBLayer.cpp:285
size_t GetOutputSize() const noexcept override
Should return output size.
Definition RBLayer.cpp:298
void UpdateBeliefs(const float *bottomUp, const float *topDown, size_t currentBatchSize) noexcept
Updates internal state beliefs via gradient descent on the prediction error.
Definition RBLayer.cpp:168
void Flush() noexcept override
Flushes remaining batches.
Definition RBLayer.cpp:262
~RBLayer() override
Definition RBLayer.cpp:27
float * GetWeights() const noexcept
Returns the synaptic weight matrix U.
Definition RBLayer.h:123
size_t GetTotalSize() const noexcept
Returns the total byte size required by this layer for flat allocation.
Definition RBLayer.cpp:37
size_t GetBatchSize() const noexcept override
Should return batch size.
Definition RBLayer.cpp:296
RBLayer(size_t inSize, size_t outSize, float var=1.0f, float var_td=10.0f, float k_1=1e-3f, float k_2=1e-5f, float lmbda=1e-6f, float alpha=1.0f, size_t batchSize=64, int stepSize=30, void(*act)(float *, size_t)=relu, void(*dAct)(float *, size_t, bool)=dRelu)
Constructs an RBLayer with specified dimensions and hyperparameters.
Definition RBLayer.cpp:13
void RunPrediction(const float *input, size_t currentBatchSize) noexcept
Executes a forward pass prediction without updating internal beliefs.
Definition RBLayer.cpp:88
void Attach(float *ptr) noexcept
Attaches the layer to a pre-allocated, 64-byte aligned memory block.
Definition RBLayer.cpp:52
void RunInferenceStep(const float *input, const float *topDown, size_t currentBatchSize) noexcept
Executes a single bidirectional inference step integrating bottom-up and top-down signals.
Definition RBLayer.cpp:121
size_t GetInputSize() const noexcept override
Should return input size.
Definition RBLayer.cpp:297
float CalculateState() noexcept override
Calculates the total layer energy state.
Definition RBLayer.cpp:279
This file exists to provide both Tensor.h and IComputeBackend.h with device types without introducing...
Definition Backend.cpp:10
static void relu(float *, size_t) noexcept
See Relu.h.
static void dRelu(float *, size_t, bool) noexcept
See Relu.h.