7 #include "../variable/variable.h"
16 std::vector<Variable> _weights;
18 std::string _activate_function;
19 std::vector<Variable> _parameters;
27 Neuron(
size_t n_in, std::string activate_function =
"tanh")
28 : _weights(n_in), _activate_function(activate_function)
30 _parameters.reserve(n_in + 1);
31 unsigned seed =
static_cast<unsigned>(
32 std::chrono::system_clock::now().time_since_epoch().count());
33 std::default_random_engine generator(seed);
34 std::uniform_real_distribution<double> distribution(-1.0, 1.0);
36 for (
size_t i = 0; i < n_in; i++)
38 _weights[i] =
Variable(distribution(generator), 0.0,
"",
"weights");
39 _parameters.push_back(_weights[i]);
41 _bias =
Variable(distribution(generator), 0,
"",
"bias");
42 _parameters.push_back(_bias);
50 : _weights(other._weights), _bias(other._bias),
51 _activate_function(other._activate_function){};
60 _weights = other._weights;
62 _activate_function = other._activate_function;
71 : _weights(other._weights), _bias(other._bias),
72 _activate_function(other._activate_function)
74 for (
auto &weight : other._weights)
78 other._weights.clear();
79 other._bias.set_ref(
nullptr);
80 for (
auto &weight : _weights)
82 weight.set_ref(&weight);
94 _weights = other._weights;
96 _activate_function = other._activate_function;
97 for (
auto &weight : other._weights)
101 other._weights.clear();
102 other._bias.set_ref(
nullptr);
104 for (
auto &weight : _weights)
106 weight.set_ref(&weight);
117 for (
auto &weight : _weights)
119 weight.set_ref(
nullptr);
Neuron(size_t n_in, std::string activate_function="tanh")
Definition: neuron.h:27
Neuron & operator=(Neuron &&other) noexcept
Definition: neuron.h:92
Variable forward(const std::vector< double > &inputs)
Definition: neuron.cc:5
Neuron(Neuron &&other) noexcept
Definition: neuron.h:70
Neuron(const Neuron &other)
Definition: neuron.h:49
const std::vector< Variable > & weights() const
Definition: neuron.h:128
const Variable & bias() const
Definition: neuron.h:137
~Neuron()
Definition: neuron.h:115
Neuron & operator=(const Neuron &other)
Definition: neuron.h:58
const std::vector< Variable > & parameters() const
Definition: neuron.h:146
Definition: variable.h:13
void set_ref(Variable *reference)
Definition: variable.h:200