Commit 32b7bce3 authored by Michal Kravcenko's avatar Michal Kravcenko

commit before merge

parent dccfbaaf
......@@ -625,6 +625,34 @@
<DistClean command="/usr/bin/make -f &quot;/home/fluffymoo/4NEURO_BIATCH/4Neuro/build/Makefile&quot; VERBOSE=1 clean"/>
</MakeCommands>
</Target>
<Target title="NeuralNetworkSum_test">
<Option output="/home/fluffymoo/4NEURO_BIATCH/4Neuro/build/bin/unit-tests/NeuralNetworkSum_test" prefix_auto="0" extension_auto="0"/>
<Option working_dir="bin/unit-tests"/>
<Option object_output="./"/>
<Option type="1"/>
<Option compiler="gcc"/>
<Compiler/>
<MakeCommands>
<Build command="/usr/bin/make -f &quot;/home/fluffymoo/4NEURO_BIATCH/4Neuro/build/Makefile&quot; VERBOSE=1 NeuralNetworkSum_test"/>
<CompileFile command="/usr/bin/make -f &quot;/home/fluffymoo/4NEURO_BIATCH/4Neuro/build/Makefile&quot; VERBOSE=1 &quot;$file&quot;"/>
<Clean command="/usr/bin/make -f &quot;/home/fluffymoo/4NEURO_BIATCH/4Neuro/build/Makefile&quot; VERBOSE=1 clean"/>
<DistClean command="/usr/bin/make -f &quot;/home/fluffymoo/4NEURO_BIATCH/4Neuro/build/Makefile&quot; VERBOSE=1 clean"/>
</MakeCommands>
</Target>
<Target title="NeuralNetworkSum_test/fast">
<Option output="/home/fluffymoo/4NEURO_BIATCH/4Neuro/build/bin/unit-tests/NeuralNetworkSum_test" prefix_auto="0" extension_auto="0"/>
<Option working_dir="bin/unit-tests"/>
<Option object_output="./"/>
<Option type="1"/>
<Option compiler="gcc"/>
<Compiler/>
<MakeCommands>
<Build command="/usr/bin/make -f &quot;/home/fluffymoo/4NEURO_BIATCH/4Neuro/build/Makefile&quot; VERBOSE=1 NeuralNetworkSum_test/fast"/>
<CompileFile command="/usr/bin/make -f &quot;/home/fluffymoo/4NEURO_BIATCH/4Neuro/build/Makefile&quot; VERBOSE=1 &quot;$file&quot;"/>
<Clean command="/usr/bin/make -f &quot;/home/fluffymoo/4NEURO_BIATCH/4Neuro/build/Makefile&quot; VERBOSE=1 clean"/>
<DistClean command="/usr/bin/make -f &quot;/home/fluffymoo/4NEURO_BIATCH/4Neuro/build/Makefile&quot; VERBOSE=1 clean"/>
</MakeCommands>
</Target>
</Build>
<Unit filename="/home/fluffymoo/4NEURO_BIATCH/4Neuro/src/DataSet/DataSet.cpp">
<Option target="4neuro"/>
......@@ -752,6 +780,9 @@
<Unit filename="/home/fluffymoo/4NEURO_BIATCH/4Neuro/src/tests/ErrorFunctions_test.cpp">
<Option target="errorfunction_test"/>
</Unit>
<Unit filename="/home/fluffymoo/4NEURO_BIATCH/4Neuro/src/tests/NeuralNetworkSum_test.cpp">
<Option target="NeuralNetworkSum_test"/>
</Unit>
<Unit filename="/home/fluffymoo/4NEURO_BIATCH/4Neuro/src/tests/NeuralNetwork_test.cpp">
<Option target="neural_network_test"/>
</Unit>
......
......@@ -383,6 +383,19 @@ particle_test/fast:
$(MAKE) -f build/CMakeFiles/particle_test.dir/build.make build/CMakeFiles/particle_test.dir/build
.PHONY : particle_test/fast
#=============================================================================
# Target rules for targets named NeuralNetworkSum_test
# Build rule for target.
NeuralNetworkSum_test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 NeuralNetworkSum_test
.PHONY : NeuralNetworkSum_test
# fast build rule for target.
NeuralNetworkSum_test/fast:
$(MAKE) -f build/CMakeFiles/NeuralNetworkSum_test.dir/build.make build/CMakeFiles/NeuralNetworkSum_test.dir/build
.PHONY : NeuralNetworkSum_test/fast
# Help Target
help:
@echo "The following are some of the valid targets for this Makefile:"
......@@ -412,6 +425,7 @@ help:
@echo "... errorfunction_test"
@echo "... linear_neuron_test"
@echo "... particle_test"
@echo "... NeuralNetworkSum_test"
.PHONY : help
......
......@@ -5,20 +5,104 @@
* y(0) = 1
* (d/dt)y(0) = 1
*
* -------------------------------------------
* Analytical solution: e^(-2x) * (3x + 1)
*
* @author Michal Kravčenko
* @date 17.7.18 -
*/
#include <random>
#include <vector>
#include <utility>
#include <iostream>
#include "../include/4neuro.h"
#include "Solvers/DESolver.h"
int main() {
void test_analytical_gradient_y(unsigned int n_inner_neurons) {
unsigned int n_inputs = 1;
}
void test_analytical_y(unsigned int n_inner_neurons){
unsigned int n_inputs = 1;
unsigned int n_outputs = 1;
unsigned int n_equations = 1;
/* SETUP OF THE TRAINING DATA */
std::vector<double> inp, out;
double d1_s = 0.0, d1_e = 1.0, frac, alpha, x;
/* TRAIN DATA FOR THE GOVERNING DE */
std::vector<std::pair<std::vector<double>, std::vector<double>>> data_vec_g;
unsigned int train_size = 150;
/* ISOTROPIC TRAIN SET */
frac = (d1_e - d1_s) / (train_size - 1);
// for(unsigned int i = 0; i < train_size; ++i){
// x = frac * i;
// inp = {x};
// out = {std::pow(E, -2 * x) * (3 * x + 1)};
// data_vec_g.emplace_back(std::make_pair(inp, out));
//
// std::cout << i + 1 << " " << x << " " << out[0] << std::endl;
// }
/* CHEBYSCHEV TRAIN SET */
alpha = PI / (train_size - 1);
frac = 0.5 * (d1_e - d1_s);
for(unsigned int i = 0; i < train_size; ++i){
x = (std::cos(PI - alpha * i) + 1.0) * frac + d1_s;
inp = {x};
out = {std::pow(E, -2 * x) * (3 * x + 1)};
data_vec_g.emplace_back(std::make_pair(inp, out));
std::cout << i + 1 << " " << x << " " << out[0] << std::endl;
}
DataSet ds_00(&data_vec_g);
// return;
DESolver solver_01( n_equations, n_inputs, n_inner_neurons, n_outputs );
NeuralNetwork * solution = solver_01.get_solution();
/* PARTICLE SWARM TRAINING METHOD SETUP */
unsigned int max_iters = 150;
//must encapsulate each of the partial error functions
double *domain_bounds = new double[ 2 * n_inner_neurons * (n_inputs + n_outputs) ];
for(unsigned int i = 0; i < n_inner_neurons * (n_inputs + n_outputs); ++i){
domain_bounds[2 * i] = -800.0;
domain_bounds[2 * i + 1] = 800.0;
}
double c1 = 0.5, c2 = 0.8, w = 0.8;
unsigned int n_particles = 100;
double gamma = 0.5, epsilon = 0.001, delta = 0.9;
MSE mse(solution, &ds_00);
ParticleSwarm swarm_01(&mse, domain_bounds, c1, c2, w, n_particles, max_iters);
swarm_01.optimize( gamma, epsilon, delta );
unsigned int n_test_points = 100;
std::vector<double> input(1), output(1);
double error = 0.0;
for(unsigned int i = 0; i < n_test_points; ++i){
input[0] = i * ((d1_e - d1_s) / (n_test_points - 1)) + d1_s;
solution->eval_single(input, output);
std::cout << i + 1 << " " << std::abs(output[0] - std::pow(E, -2 * input[0]) * (3 * input[0] + 1))<< " " << output[0] << std::endl;
}
delete [] domain_bounds;
}
void test_odr(unsigned int n_inner_neurons){
unsigned int n_inputs = 1;
unsigned int n_inner_neurons = 4;
unsigned int n_outputs = 1;
unsigned int n_equations = 3;
......@@ -118,7 +202,30 @@ int main() {
NeuralNetwork *solution = solver_01.get_solution();
unsigned int n_test_points = 100;
std::vector<double> input(1), output(1);
for(unsigned int i = 0; i < n_test_points; ++i){
input[0] = i * ((d1_e - d1_s) / (n_test_points - 1)) + d1_s;
solution->eval_single(input, output);
std::cout << i + 1 << " " << output[0] << std::endl;
}
delete [] domain_bounds;
}
int main() {
unsigned int n_inner_neurons = 20;
// test_odr(n_inner_neurons);
test_analytical_y(n_inner_neurons);
test_analytical_gradient_y(n_inner_neurons);
return 0;
}
\ No newline at end of file
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