Deepity
Ultra-fast, SIMD-accelerated Predictive Coding
Loading...
Searching...
No Matches
Layer.h
Go to the documentation of this file.
1#pragma once
2#include <cstddef>
3#include <sleef.h>
4#ifdef DEEPITY_USE_MKL
5#include <mkl_cblas.h>
6#else
7#include <cblas.h>
8#endif
9#include <map>
10#include <vector>
11#include <string>
12
21
22// Adam: default hyperparameters. Currently unused -- AdamOptimizer.h
23// defines its own equivalents and is what's actually wired up.
24#define ALPHA 0.001
25#define BETA1 0.9
26#define BETA2 0.999
27#define EPS 1e-8
28
29namespace Deep
30{
34 {
35 float *data;
36 std::vector<size_t> shape;
37 };
38
39 class Layer
40 {
41 public:
42 virtual ~Layer() = default;
43
46 virtual float *GetBeliefs() noexcept = 0;
49 virtual const float *GetErrors() const noexcept = 0;
52 virtual size_t GetInputSize() const noexcept = 0;
55 virtual size_t GetOutputSize() const noexcept = 0;
58 virtual size_t GetBatchSize() const noexcept = 0;
59
62 virtual float CalculateState() noexcept = 0;
64 virtual void UpdateState() noexcept = 0;
66 virtual void UpdateWeights() noexcept = 0;
68 virtual void Flush() noexcept {}
70 virtual std::map<std::string, TensorDescriptor> GetStateDict() const { return {}; }
71
72 protected:
74 size_t size;
76 size_t nextSize;
77 };
78}
A deepity layer virtual class.
Definition Layer.h:40
virtual float * GetBeliefs() noexcept=0
Should return belief state z.
size_t nextSize
Size of output.
Definition Layer.h:76
virtual std::map< std::string, TensorDescriptor > GetStateDict() const
Returns a dictionary of this.
Definition Layer.h:70
virtual void UpdateWeights() noexcept=0
Updates the weights after state updates.
virtual ~Layer()=default
size_t size
Size of input.
Definition Layer.h:74
virtual void Flush() noexcept
Flushes remaining batches.
Definition Layer.h:68
virtual size_t GetBatchSize() const noexcept=0
Should return batch size.
virtual const float * GetErrors() const noexcept=0
Should return errors e.
virtual size_t GetOutputSize() const noexcept=0
Should return output size.
virtual void UpdateState() noexcept=0
Updates the states after calculation.
virtual float CalculateState() noexcept=0
Calculates the internal state of the layer.
virtual size_t GetInputSize() const noexcept=0
Should return input size.
This file exists to provide both Tensor.h and IComputeBackend.h with device types without introducing...
Definition Backend.cpp:10
A named, shaped view into a layer's weight/bias data, for ModelIO's save/load (see Layer::GetStateDic...
Definition Layer.h:34
std::vector< size_t > shape
Tensor's dimensions, e.g. {out, in}.
Definition Layer.h:36
float * data
Pointer to the tensor's first element.
Definition Layer.h:35