diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 55e2a83996cb53ba179774141d4cd91f629f7780..ebdb120b32889a9c529555f821d23e763cbe91fb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -34,6 +34,9 @@ target_link_libraries(net_test_1 4neuro) add_executable(net_test_2 net_test_2.cpp) target_link_libraries(net_test_2 4neuro) +add_executable(net_test_3 net_test_3.cpp) +target_link_libraries(net_test_3 4neuro) + ############## # UNIT TESTS # ############## diff --git a/src/ErrorFunction/ErrorFunctions.h b/src/ErrorFunction/ErrorFunctions.h index 448d3c8ea604f028d5213342a55fb0fc08700e90..bb639d587db6db95814cae7a6c514a457fb7aa66 100644 --- a/src/ErrorFunction/ErrorFunctions.h +++ b/src/ErrorFunction/ErrorFunctions.h @@ -72,7 +72,7 @@ public: * @param weights * @return */ - virtual double eval(double* weights); + virtual double eval(double* weights = nullptr); /** * diff --git a/src/net_test_3.cpp b/src/net_test_3.cpp index 4959e46e112638a9148355a9c86f952928044472..ebe4b60840a7fe975e8bff8da45358f6e9f101c6 100644 --- a/src/net_test_3.cpp +++ b/src/net_test_3.cpp @@ -1,6 +1,9 @@ /** * 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) + * */ // // Created by martin on 7/16/18. @@ -17,15 +20,15 @@ int main() { std::vector<std::pair<std::vector<double>, std::vector<double>>> data_vec_01, data_vec_02; std::vector<double> inp, out; - inp = {0, 1, 0}; - out = {0.5, 0}; + inp = {0, 1}; + out = {0.5}; data_vec_01.emplace_back(std::make_pair(inp, out)); - inp = {1, 0.5, 0}; - out = {0.75, 0}; + inp = {1, 0.5}; + out = {0.75}; data_vec_01.emplace_back(std::make_pair(inp, out)); -// DataSet ds_01(&data_vec_01); + DataSet ds_01(&data_vec_01); inp = {1.25}; @@ -101,7 +104,7 @@ int main() { /* TRAINING METHOD SETUP */ unsigned int n_edges = 2; - unsigned int dim = n_edges, max_iters = 5000; + unsigned int dim = n_edges, max_iters = 50; //must encapsulate each of the partial error functions @@ -109,12 +112,13 @@ int main() { double c1 = 0.5, c2 = 1.5, w = 0.8; - unsigned int n_particles = 10; + unsigned int n_particles = 100; ParticleSwarm swarm_01(&mse_sum, domain_bounds, c1, c2, w, n_particles, max_iters); - swarm_01.optimize(0.5, 0.02); + swarm_01.optimize(0.5, 0.02, 0.9); + printf("evaluation of error: %f\n", mse_sum.eval()); delete subnet_02; delete subnet_01;