Commit adf34787 authored by Michal Kravcenko's avatar Michal Kravcenko

-corrected subnet construction and example3

parent 76dd9f9c
......@@ -164,6 +164,7 @@ NeuralNetwork* NeuralNetwork::get_subnet(std::vector<size_t> &input_neuron_indic
/* WE FORM THE SET OF NEURONS IN THE OUTPUT NETWORK */
if(n_new_neurons > 0){
// printf("Number of new neurons: %d\n", n_new_neurons);
output_net = new NeuralNetwork();
output_net->set_weight_array( this->connection_weights );
......@@ -174,6 +175,8 @@ NeuralNetwork* NeuralNetwork::get_subnet(std::vector<size_t> &input_neuron_indic
std::vector<Neuron*> local_n_arr(0);
local_n_arr.reserve( n_new_neurons );
std::vector<Neuron*> local_local_n_arr(0);
local_local_n_arr.reserve( n_new_neurons );
int * neuron_local_mapping = new int[ n ];
std::fill(neuron_local_mapping, neuron_local_mapping + n, -1);
......@@ -186,7 +189,8 @@ NeuralNetwork* NeuralNetwork::get_subnet(std::vector<size_t> &input_neuron_indic
Neuron *new_neuron = this->neurons->at(i)->get_copy( );
output_net->add_neuron( new_neuron );
local_n_arr.push_back( new_neuron );
local_local_n_arr.push_back( new_neuron );
local_n_arr.push_back( this->neurons->at(i) );
}
}
for(size_t in: input_neuron_indices){
......@@ -196,6 +200,8 @@ NeuralNetwork* NeuralNetwork::get_subnet(std::vector<size_t> &input_neuron_indic
local_outputs.push_back(neuron_local_mapping[in]);
}
// printf("%d\n", local_n_arr.size());
// printf("inputs: %d, outputs: %d\n", local_inputs.size(), local_outputs.size());
int local_idx_1, local_idx_2;
for(Neuron* source_neuron: local_n_arr){
//we also add the relevant edges
......@@ -206,11 +212,13 @@ NeuralNetwork* NeuralNetwork::get_subnet(std::vector<size_t> &input_neuron_indic
local_idx_2 = neuron_local_mapping[target_neuron->get_idx()];
if(local_idx_2 >= 0){
//this neuron is part of the subnetwork
Connection* new_connection = connection->get_copy( source_neuron, target_neuron );
//this edge is part of the subnetwork
Connection* new_connection = connection->get_copy( local_local_n_arr[local_idx_1], local_local_n_arr[local_idx_2] );
source_neuron->add_connection_out(new_connection);
target_neuron->add_connection_in(new_connection);
local_local_n_arr[local_idx_1]->add_connection_out(new_connection);
local_local_n_arr[local_idx_2]->add_connection_in(new_connection);
// printf("adding a connection between neurons %d, %d\n", local_idx_1, local_idx_2);
}
}
......
......@@ -89,8 +89,7 @@ int main() {
// printf("evaluation of error at point (%f, %f) => %f\n", weights[0], weights[1], mse.eval(weights));
/* TRAINING METHOD SETUP */
unsigned int n_edges = 2;
unsigned int dim = n_edges, max_iters = 5000;
unsigned int max_iters = 5000;
//must encapsulate each of the partial error functions
......
......@@ -2,7 +2,7 @@
* Example of a set of neural networks sharing some edge weights
* The system of equations associated with the net in this example is not regular
* minimizes the function: [(2y+0.5)^2 + (2x+y+0.25)^2] / 2 + [(4.5x + 0.37)^2] / 1
* minimum [0,010024714] at (x, y) = (-333/4370, -9593/43700) = (-0.076201373, -0.219519451)
* minimum [0.010024714] at (x, y) = (-333/4370, -9593/43700) = (-0.076201373, -0.219519451)
* */
//
......@@ -82,6 +82,7 @@ int main() {
/* CONSTRUCTION OF SUBNETWORKS */
//TODO subnetworks retain the number of weights, could be optimized to include only the used weights
std::vector<size_t> subnet_01_input_neurons, subnet_01_output_neurons;
std::vector<size_t> subnet_02_input_neurons, subnet_02_output_neurons;
......@@ -103,8 +104,7 @@ int main() {
mse_sum.add_error_function( &mse_02 );
/* TRAINING METHOD SETUP */
unsigned int n_edges = 2;
unsigned int dim = n_edges, max_iters = 50;
unsigned int max_iters = 50;
//must encapsulate each of the partial error functions
......@@ -114,11 +114,13 @@ int main() {
unsigned int n_particles = 100;
// printf("mse2: %d\n", mse_02.get_dimension());
ParticleSwarm swarm_01(&mse_sum, domain_bounds, c1, c2, w, n_particles, max_iters);
swarm_01.optimize(0.5, 0.02, 0.9);
printf("evaluation of error: %f\n", mse_sum.eval());
// double weights[2] = {0, -0.25};
// printf("evaluation of error at (x, y) = (%f, %f): %f\n", weights[0], weights[1], mse_01.eval(weights));
delete subnet_02;
delete subnet_01;
......
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