我有很多Transforms.h
这样定义的方法:
#ifndef TRANSFORMS_H
#define TRANSFORMS_H
namespace Transforms
{
long double asech(long double x);
long double acsch(long double x);
long double asechDerivative(long double x);
long double acschDerivative(long double x);
long double identity(long double x);
long double identityDerivative(long double x);
};
#endif //!TRANSFORMS_H
我尝试创建一个这样的模板类:
// Layer.h
template<typename Forward, typename Backward>
class Layer
{
protected:
Matrix* previousActivation{ nullptr }, * error{ nullptr }, * delta{ nullptr };
Matrix& weights;
Vector& bias;
public:
const int inputs, neurons;
Forward applyActivation;
Backward applyActivationDerivative;
Layer(int inputs, int neurons, Matrix& weights, Vector& bias);
~Layer();
Matrix& activate(Matrix& x);
/*virtual Matrix& applyActivation(Matrix& x) = 0;
virtual Matrix& applyActivationDerivative(Matrix& x) = 0;*/
};
尝试并能够通过做来创建新图层
class Sigmoid: public Layer<sigmoid, sigmoidDerivative>;
这样我就不必使用纯虚拟方法覆盖。但我似乎无法弄清楚如何设置成员变量applyActivation
和构造函数applyActivationDerivative
内部Layer
我也是 C++ 模板的新手,我来自 Java,所以请多多包涵。