Commit c093b260 authored by Michal Kravcenko's avatar Michal Kravcenko

MOD: added general purpose private members to be used by derived classes (for...

MOD: added general purpose private members to be used by derived classes (for the serialization to work from outside the library without linking boost)
parent 971c4a5f
......@@ -25,21 +25,8 @@ namespace lib4neuro {
}
NeuralNetwork::NeuralNetwork(std::string filepath) {
::std::ifstream ifs(filepath);
if (ifs.is_open()) {
try {
boost::archive::text_iarchive ia(ifs);
ia >> *this;
}
catch (boost::archive::archive_exception& e) {
THROW_RUNTIME_ERROR(
"Serialized archive error: '" + e.what() + "'! Please, check if your file is really "
"the serialized DataSet.");
}
ifs.close();
} else {
THROW_RUNTIME_ERROR("File '" + filepath + "' couldn't be open!");
}
this->init_from_file( filepath );
}
......@@ -131,8 +118,9 @@ namespace lib4neuro {
}
potential = this->neurons.at(si)->activate(this->neuron_potentials.at(si),
bias);
std::cout << " applying bias: " << bias << " to neuron potential: " << this->neuron_potentials.at(si)
<< " -> " << potential << std::endl;
std::cout << "Neuron" << si << " (" << this->neuron_potentials.at(si) << " - " << bias << ") -> (" << potential << ")" << std::endl;
// std::cout << " applying bias: " << bias << " to neuron potential: " << this->neuron_potentials.at(si)
// << " -> " << potential << std::endl;
for (auto c: *this->outward_adjacency.at(si)) {
size_t ti = c.first;
......@@ -140,10 +128,11 @@ namespace lib4neuro {
this->neuron_potentials.at(ti) +=
this->connection_list.at(ci)->eval(this->connection_weights) * potential;
std::cout << " EDGE(" << si << ", " << ti << ")" << this->connection_list.at(ci)->eval(this->connection_weights) << std::endl;
std::cout << " adding input to neuron " << ti << " += "
<< this->connection_list.at(ci)->eval(this->connection_weights) << "*" << potential
<< std::endl;
// std::cout << " adding input to neuron " << ti << " += "
// << this->connection_list.at(ci)->eval(this->connection_weights) << "*" << potential
// << std::endl;
}
}
}
......@@ -157,7 +146,7 @@ namespace lib4neuro {
}
output[i] = this->neurons.at(oi)->activate(this->neuron_potentials.at(oi),
bias);
std::cout << "setting the output[" << i << "] = " << output[i] << "(bias = " << bias << ")" << std::endl;
// std::cout << "setting the output[" << i << "] = " << output[i] << "(bias = " << bias << ")" << std::endl;
++i;
}
}
......@@ -203,7 +192,7 @@ namespace lib4neuro {
NeuralNetwork::add_connection_constant(size_t n1_idx,
size_t n2_idx,
double weight) {
std::shared_ptr<ConnectionFunctionConstant> cfc = std::make_shared<ConnectionFunctionConstant>(ConnectionFunctionConstant());
std::shared_ptr<ConnectionFunctionConstant> cfc = std::make_shared<ConnectionFunctionConstant>(ConnectionFunctionConstant(weight));
size_t conn_idx = this->add_new_connection_to_list(cfc);
......@@ -831,6 +820,25 @@ namespace lib4neuro {
this->layers_analyzed = true;
}
void NeuralNetwork::init_from_file(const std::string &filepath) {
::std::ifstream ifs(filepath);
if (ifs.is_open()) {
try {
boost::archive::text_iarchive ia(ifs);
ia >> *this;
}
catch (boost::archive::archive_exception& e) {
THROW_RUNTIME_ERROR(
"Serialized archive error: '" + e.what() + "'! Please, check if your file is really "
"the serialized DataSet.");
}
ifs.close();
} else {
THROW_RUNTIME_ERROR("File '" + filepath + "' couldn't be open!");
}
}
void NeuralNetwork::save_text(std::string filepath) {
::std::ofstream ofs(filepath);
{
......
......@@ -127,6 +127,13 @@ namespace lib4neuro {
*/
bool delete_biases = true;
/**
* helpful arrays to be used in derived classes which are not neccessarily part of the lib4neauro library
*/
std::vector<size_t> ___ind1, ___ind2;
std::vector<std::vector<size_t>> ___ind_m1, ___ind_m2;
std::vector<std::vector<double>> ___val_m1;
/**
*
*/
......@@ -166,6 +173,12 @@ namespace lib4neuro {
*/
void analyze_layer_structure();
/**
* for loading purposes outside the scope of this library
*/
virtual void init_from_file(const std::string &fn);
public:
/**
......
......@@ -44,6 +44,12 @@ namespace lib4neuro {
ar & nn.delete_weights;
ar & nn.delete_biases;
ar & nn.normalization_strategy;
ar & nn.___ind1;
ar & nn.___ind2;
ar & nn.___ind_m1;
ar & nn.___ind_m2;
ar & nn.___val_m1;
}
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment