mirror of
https://github.com/davidalbertonogueira/MLP.git
synced 2025-12-17 04:14:41 +03:00
added posibility to change internal weights of the network directly
assigning the values
This commit is contained in:
24
src/Layer.h
24
src/Layer.h
@@ -68,6 +68,14 @@ public:
|
||||
return m_nodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the internal list of nodes, but modifiable.
|
||||
*/
|
||||
std::vector<Node> & GetNodesChangeable() {
|
||||
return m_nodes;
|
||||
}
|
||||
|
||||
|
||||
void GetOutputAfterActivationFunction(const std::vector<double> &input,
|
||||
std::vector<double> * output) const {
|
||||
assert(input.size() == m_num_inputs_per_node);
|
||||
@@ -116,6 +124,22 @@ public:
|
||||
};
|
||||
|
||||
|
||||
void SetWeights( std::vector<std::vector<double>> & weights )
|
||||
{
|
||||
if( 0 <= weights.size() && weights.size() <= m_num_nodes )
|
||||
{
|
||||
// traverse the list of nodes
|
||||
size_t node_i = 0;
|
||||
for( Node & node : m_nodes )
|
||||
{
|
||||
node.SetWeights( weights[node_i] );
|
||||
node_i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new std::logic_error("Incorrect layer number in SetWeights call");
|
||||
};
|
||||
|
||||
void SaveLayer(FILE * file) const {
|
||||
fwrite(&m_num_nodes, sizeof(m_num_nodes), 1, file);
|
||||
fwrite(&m_num_inputs_per_node, sizeof(m_num_inputs_per_node), 1, file);
|
||||
|
||||
Reference in New Issue
Block a user