Commit 083d2be6 authored by Michal Kravcenko's avatar Michal Kravcenko

Commit before merge

parent 0802a4da
......@@ -111,108 +111,121 @@ depend:
.PHONY : depend
#=============================================================================
# Target rules for targets named NeuralNetworkSum_test
# Target rules for targets named net_test_2
# Build rule for target.
NeuralNetworkSum_test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 NeuralNetworkSum_test
.PHONY : NeuralNetworkSum_test
net_test_2: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 net_test_2
.PHONY : net_test_2
# 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
net_test_2/fast:
$(MAKE) -f build/CMakeFiles/net_test_2.dir/build.make build/CMakeFiles/net_test_2.dir/build
.PHONY : net_test_2/fast
#=============================================================================
# Target rules for targets named particle_test
# Target rules for targets named neuron_test
# Build rule for target.
particle_test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 particle_test
.PHONY : particle_test
neuron_test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 neuron_test
.PHONY : neuron_test
# fast build rule for target.
particle_test/fast:
$(MAKE) -f build/CMakeFiles/particle_test.dir/build.make build/CMakeFiles/particle_test.dir/build
.PHONY : particle_test/fast
neuron_test/fast:
$(MAKE) -f build/CMakeFiles/neuron_test.dir/build.make build/CMakeFiles/neuron_test.dir/build
.PHONY : neuron_test/fast
#=============================================================================
# Target rules for targets named errorfunction_test
# Target rules for targets named net_test_1
# Build rule for target.
errorfunction_test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 errorfunction_test
.PHONY : errorfunction_test
net_test_1: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 net_test_1
.PHONY : net_test_1
# fast build rule for target.
errorfunction_test/fast:
$(MAKE) -f build/CMakeFiles/errorfunction_test.dir/build.make build/CMakeFiles/errorfunction_test.dir/build
.PHONY : errorfunction_test/fast
net_test_1/fast:
$(MAKE) -f build/CMakeFiles/net_test_1.dir/build.make build/CMakeFiles/net_test_1.dir/build
.PHONY : net_test_1/fast
#=============================================================================
# Target rules for targets named neural_network_test
# Target rules for targets named net_test_pde_1
# Build rule for target.
neural_network_test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 neural_network_test
.PHONY : neural_network_test
net_test_pde_1: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 net_test_pde_1
.PHONY : net_test_pde_1
# fast build rule for target.
neural_network_test/fast:
$(MAKE) -f build/CMakeFiles/neural_network_test.dir/build.make build/CMakeFiles/neural_network_test.dir/build
.PHONY : neural_network_test/fast
net_test_pde_1/fast:
$(MAKE) -f build/CMakeFiles/net_test_pde_1.dir/build.make build/CMakeFiles/net_test_pde_1.dir/build
.PHONY : net_test_pde_1/fast
#=============================================================================
# Target rules for targets named logistic_neuron_test
# Target rules for targets named 4neuro
# Build rule for target.
logistic_neuron_test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 logistic_neuron_test
.PHONY : logistic_neuron_test
4neuro: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 4neuro
.PHONY : 4neuro
# fast build rule for target.
logistic_neuron_test/fast:
$(MAKE) -f build/CMakeFiles/logistic_neuron_test.dir/build.make build/CMakeFiles/logistic_neuron_test.dir/build
.PHONY : logistic_neuron_test/fast
4neuro/fast:
$(MAKE) -f build/CMakeFiles/4neuro.dir/build.make build/CMakeFiles/4neuro.dir/build
.PHONY : 4neuro/fast
#=============================================================================
# Target rules for targets named particle_swarm_test
# Target rules for targets named net_test_3
# Build rule for target.
particle_swarm_test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 particle_swarm_test
.PHONY : particle_swarm_test
net_test_3: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 net_test_3
.PHONY : net_test_3
# fast build rule for target.
particle_swarm_test/fast:
$(MAKE) -f build/CMakeFiles/particle_swarm_test.dir/build.make build/CMakeFiles/particle_swarm_test.dir/build
.PHONY : particle_swarm_test/fast
net_test_3/fast:
$(MAKE) -f build/CMakeFiles/net_test_3.dir/build.make build/CMakeFiles/net_test_3.dir/build
.PHONY : net_test_3/fast
#=============================================================================
# Target rules for targets named dataset_test
# Target rules for targets named test_cases
# Build rule for target.
dataset_test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 dataset_test
.PHONY : dataset_test
test_cases: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 test_cases
.PHONY : test_cases
# fast build rule for target.
dataset_test/fast:
$(MAKE) -f build/CMakeFiles/dataset_test.dir/build.make build/CMakeFiles/dataset_test.dir/build
.PHONY : dataset_test/fast
test_cases/fast:
$(MAKE) -f build/CMakeFiles/test_cases.dir/build.make build/CMakeFiles/test_cases.dir/build
.PHONY : test_cases/fast
#=============================================================================
# Target rules for targets named neuron_serialization_example
# Target rules for targets named binary_neuron_test
# Build rule for target.
neuron_serialization_example: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 neuron_serialization_example
.PHONY : neuron_serialization_example
binary_neuron_test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 binary_neuron_test
.PHONY : binary_neuron_test
# fast build rule for target.
neuron_serialization_example/fast:
$(MAKE) -f build/CMakeFiles/neuron_serialization_example.dir/build.make build/CMakeFiles/neuron_serialization_example.dir/build
.PHONY : neuron_serialization_example/fast
binary_neuron_test/fast:
$(MAKE) -f build/CMakeFiles/binary_neuron_test.dir/build.make build/CMakeFiles/binary_neuron_test.dir/build
.PHONY : binary_neuron_test/fast
#=============================================================================
# Target rules for targets named connection_weight_identity_test
# Build rule for target.
connection_weight_identity_test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 connection_weight_identity_test
.PHONY : connection_weight_identity_test
# fast build rule for target.
connection_weight_identity_test/fast:
$(MAKE) -f build/CMakeFiles/connection_weight_identity_test.dir/build.make build/CMakeFiles/connection_weight_identity_test.dir/build
.PHONY : connection_weight_identity_test/fast
#=============================================================================
# Target rules for targets named boost_unit_test
......@@ -228,147 +241,147 @@ boost_unit_test/fast:
.PHONY : boost_unit_test/fast
#=============================================================================
# Target rules for targets named connection_weight_identity_test
# Target rules for targets named dataset_test
# Build rule for target.
connection_weight_identity_test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 connection_weight_identity_test
.PHONY : connection_weight_identity_test
dataset_test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 dataset_test
.PHONY : dataset_test
# fast build rule for target.
connection_weight_identity_test/fast:
$(MAKE) -f build/CMakeFiles/connection_weight_identity_test.dir/build.make build/CMakeFiles/connection_weight_identity_test.dir/build
.PHONY : connection_weight_identity_test/fast
dataset_test/fast:
$(MAKE) -f build/CMakeFiles/dataset_test.dir/build.make build/CMakeFiles/dataset_test.dir/build
.PHONY : dataset_test/fast
#=============================================================================
# Target rules for targets named net_test_ode_1
# Target rules for targets named neuron_serialization_example
# Build rule for target.
net_test_ode_1: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 net_test_ode_1
.PHONY : net_test_ode_1
neuron_serialization_example: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 neuron_serialization_example
.PHONY : neuron_serialization_example
# fast build rule for target.
net_test_ode_1/fast:
$(MAKE) -f build/CMakeFiles/net_test_ode_1.dir/build.make build/CMakeFiles/net_test_ode_1.dir/build
.PHONY : net_test_ode_1/fast
neuron_serialization_example/fast:
$(MAKE) -f build/CMakeFiles/neuron_serialization_example.dir/build.make build/CMakeFiles/neuron_serialization_example.dir/build
.PHONY : neuron_serialization_example/fast
#=============================================================================
# Target rules for targets named binary_neuron_test
# Target rules for targets named particle_swarm_test
# Build rule for target.
binary_neuron_test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 binary_neuron_test
.PHONY : binary_neuron_test
particle_swarm_test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 particle_swarm_test
.PHONY : particle_swarm_test
# fast build rule for target.
binary_neuron_test/fast:
$(MAKE) -f build/CMakeFiles/binary_neuron_test.dir/build.make build/CMakeFiles/binary_neuron_test.dir/build
.PHONY : binary_neuron_test/fast
particle_swarm_test/fast:
$(MAKE) -f build/CMakeFiles/particle_swarm_test.dir/build.make build/CMakeFiles/particle_swarm_test.dir/build
.PHONY : particle_swarm_test/fast
#=============================================================================
# Target rules for targets named test_cases
# Target rules for targets named particle_test
# Build rule for target.
test_cases: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 test_cases
.PHONY : test_cases
particle_test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 particle_test
.PHONY : particle_test
# fast build rule for target.
test_cases/fast:
$(MAKE) -f build/CMakeFiles/test_cases.dir/build.make build/CMakeFiles/test_cases.dir/build
.PHONY : test_cases/fast
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 net_test_3
# Target rules for targets named linear_neuron_test
# Build rule for target.
net_test_3: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 net_test_3
.PHONY : net_test_3
linear_neuron_test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 linear_neuron_test
.PHONY : linear_neuron_test
# fast build rule for target.
net_test_3/fast:
$(MAKE) -f build/CMakeFiles/net_test_3.dir/build.make build/CMakeFiles/net_test_3.dir/build
.PHONY : net_test_3/fast
linear_neuron_test/fast:
$(MAKE) -f build/CMakeFiles/linear_neuron_test.dir/build.make build/CMakeFiles/linear_neuron_test.dir/build
.PHONY : linear_neuron_test/fast
#=============================================================================
# Target rules for targets named 4neuro
# Target rules for targets named connection_weight_test
# Build rule for target.
4neuro: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 4neuro
.PHONY : 4neuro
connection_weight_test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 connection_weight_test
.PHONY : connection_weight_test
# fast build rule for target.
4neuro/fast:
$(MAKE) -f build/CMakeFiles/4neuro.dir/build.make build/CMakeFiles/4neuro.dir/build
.PHONY : 4neuro/fast
connection_weight_test/fast:
$(MAKE) -f build/CMakeFiles/connection_weight_test.dir/build.make build/CMakeFiles/connection_weight_test.dir/build
.PHONY : connection_weight_test/fast
#=============================================================================
# Target rules for targets named net_test_1
# Target rules for targets named net_test_ode_1
# Build rule for target.
net_test_1: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 net_test_1
.PHONY : net_test_1
net_test_ode_1: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 net_test_ode_1
.PHONY : net_test_ode_1
# fast build rule for target.
net_test_1/fast:
$(MAKE) -f build/CMakeFiles/net_test_1.dir/build.make build/CMakeFiles/net_test_1.dir/build
.PHONY : net_test_1/fast
net_test_ode_1/fast:
$(MAKE) -f build/CMakeFiles/net_test_ode_1.dir/build.make build/CMakeFiles/net_test_ode_1.dir/build
.PHONY : net_test_ode_1/fast
#=============================================================================
# Target rules for targets named neuron_test
# Target rules for targets named logistic_neuron_test
# Build rule for target.
neuron_test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 neuron_test
.PHONY : neuron_test
logistic_neuron_test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 logistic_neuron_test
.PHONY : logistic_neuron_test
# fast build rule for target.
neuron_test/fast:
$(MAKE) -f build/CMakeFiles/neuron_test.dir/build.make build/CMakeFiles/neuron_test.dir/build
.PHONY : neuron_test/fast
logistic_neuron_test/fast:
$(MAKE) -f build/CMakeFiles/logistic_neuron_test.dir/build.make build/CMakeFiles/logistic_neuron_test.dir/build
.PHONY : logistic_neuron_test/fast
#=============================================================================
# Target rules for targets named net_test_2
# Target rules for targets named neural_network_test
# Build rule for target.
net_test_2: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 net_test_2
.PHONY : net_test_2
neural_network_test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 neural_network_test
.PHONY : neural_network_test
# fast build rule for target.
net_test_2/fast:
$(MAKE) -f build/CMakeFiles/net_test_2.dir/build.make build/CMakeFiles/net_test_2.dir/build
.PHONY : net_test_2/fast
neural_network_test/fast:
$(MAKE) -f build/CMakeFiles/neural_network_test.dir/build.make build/CMakeFiles/neural_network_test.dir/build
.PHONY : neural_network_test/fast
#=============================================================================
# Target rules for targets named connection_weight_test
# Target rules for targets named errorfunction_test
# Build rule for target.
connection_weight_test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 connection_weight_test
.PHONY : connection_weight_test
errorfunction_test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 errorfunction_test
.PHONY : errorfunction_test
# fast build rule for target.
connection_weight_test/fast:
$(MAKE) -f build/CMakeFiles/connection_weight_test.dir/build.make build/CMakeFiles/connection_weight_test.dir/build
.PHONY : connection_weight_test/fast
errorfunction_test/fast:
$(MAKE) -f build/CMakeFiles/errorfunction_test.dir/build.make build/CMakeFiles/errorfunction_test.dir/build
.PHONY : errorfunction_test/fast
#=============================================================================
# Target rules for targets named linear_neuron_test
# Target rules for targets named NeuralNetworkSum_test
# Build rule for target.
linear_neuron_test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 linear_neuron_test
.PHONY : linear_neuron_test
NeuralNetworkSum_test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 NeuralNetworkSum_test
.PHONY : NeuralNetworkSum_test
# fast build rule for target.
linear_neuron_test/fast:
$(MAKE) -f build/CMakeFiles/linear_neuron_test.dir/build.make build/CMakeFiles/linear_neuron_test.dir/build
.PHONY : linear_neuron_test/fast
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:
......@@ -378,26 +391,27 @@ help:
@echo "... depend"
@echo "... rebuild_cache"
@echo "... edit_cache"
@echo "... NeuralNetworkSum_test"
@echo "... particle_test"
@echo "... errorfunction_test"
@echo "... neural_network_test"
@echo "... logistic_neuron_test"
@echo "... particle_swarm_test"
@echo "... net_test_2"
@echo "... neuron_test"
@echo "... net_test_1"
@echo "... net_test_pde_1"
@echo "... 4neuro"
@echo "... net_test_3"
@echo "... test_cases"
@echo "... binary_neuron_test"
@echo "... connection_weight_identity_test"
@echo "... boost_unit_test"
@echo "... dataset_test"
@echo "... neuron_serialization_example"
@echo "... boost_unit_test"
@echo "... connection_weight_identity_test"
@echo "... net_test_ode_1"
@echo "... binary_neuron_test"
@echo "... test_cases"
@echo "... net_test_3"
@echo "... 4neuro"
@echo "... net_test_1"
@echo "... neuron_test"
@echo "... net_test_2"
@echo "... connection_weight_test"
@echo "... particle_swarm_test"
@echo "... particle_test"
@echo "... linear_neuron_test"
@echo "... connection_weight_test"
@echo "... net_test_ode_1"
@echo "... logistic_neuron_test"
@echo "... neural_network_test"
@echo "... errorfunction_test"
@echo "... NeuralNetworkSum_test"
.PHONY : help
......
......@@ -10,16 +10,13 @@
#include "../src/DataSet/DataSet.h"
#include "../src/ErrorFunction/ErrorFunctions.h"
#include "../src/LearningMethods/ParticleSwarm.h"
#include "../src/NetConnection/Connection.h"
#include "../src/NetConnection/ConnectionWeight.h"
#include "../src/NetConnection/ConnectionWeightIdentity.h"
#include "../src/NetConnection/ConnectionFunctionGeneral.h"
#include "../src/NetConnection/ConnectionFunctionIdentity.h"
#include "../src/Network/NeuralNetwork.h"
#include "../src/Network/NeuralNetworkSum.h"
#include "../src/Neuron/Neuron.h"
#include "../src/Neuron/NeuronBinary.h"
#include "../src/Neuron/NeuronLinear.h"
#include "../src/Neuron/NeuronLogistic.h"
#include "../src/Neuron/NeuronNeuralNet.h"
#include "../src/Neuron/NeuronTanh.h"
#endif //INC_4NEURO_4NEURO_H
......@@ -5,15 +5,12 @@ add_library(4neuro SHARED
Neuron/NeuronBinary.cpp
Neuron/NeuronLinear.cpp
Neuron/NeuronLogistic.cpp
Neuron/NeuronTanh.cpp
NetConnection/Connection.cpp
Network/NeuralNetwork.cpp
Neuron/NeuronNeuralNet.cpp
NetConnection/ConnectionWeight.cpp
NetConnection/ConnectionWeightIdentity.cpp
NetConnection/ConnectionFunctionGeneral.cpp
NetConnection/ConnectionFunctionIdentity.cpp
LearningMethods/ParticleSwarm.cpp
DataSet/DataSet.cpp
ErrorFunction/ErrorFunctions.cpp Network/NeuralNetworkSum.cpp Network/NeuralNetworkSum.h Solvers/DESolver.cpp Solvers/DESolver.h)
ErrorFunction/ErrorFunctions.cpp Network/NeuralNetworkSum.cpp Network/NeuralNetworkSum.h Solvers/DESolver.cpp Solvers/DESolver.h Neuron/NeuronConstant.cpp Neuron/NeuronConstant.h)
target_link_libraries(4neuro boost_serialization)
......@@ -40,6 +37,9 @@ target_link_libraries(net_test_3 4neuro)
add_executable(net_test_ode_1 net_test_ode_1.cpp)
target_link_libraries(net_test_ode_1 4neuro)
add_executable(net_test_pde_1 net_test_pde_1.cpp)
target_link_libraries(net_test_pde_1 4neuro)
##############
# UNIT TESTS #
##############
......@@ -57,15 +57,10 @@ target_link_libraries(binary_neuron_test boost_unit_test 4neuro)
add_executable(logistic_neuron_test tests/NeuronLogistic_test.cpp)
target_link_libraries(logistic_neuron_test boost_unit_test 4neuro)
add_executable(tanh_neuron_test tests/NeuronTanh.cpp)
target_link_libraries(tanh_neuron_test boost_unit_test 4neuro)
add_executable(connection_weight_test tests/ConnectionWeight_test.cpp)
target_link_libraries(connection_weight_test boost_unit_test 4neuro)
add_executable(connection_test tests/Connection_test.cpp)
target_link_libraries(connection_test boost_unit_test 4neuro)
add_executable(neural_network_test tests/NeuralNetwork_test.cpp)
target_link_libraries(neural_network_test boost_unit_test 4neuro)
......
......@@ -3,7 +3,6 @@
//
#include <vector>
#include <utility>
#include "ErrorFunctions.h"
......@@ -14,10 +13,10 @@ size_t ErrorFunction::get_dimension() {
MSE::MSE(NeuralNetwork *net, DataSet *ds) {
this->net = net;
this->ds = ds;
this->dimension = net->get_n_weights();
this->dimension = net->get_n_weights() + net->get_n_biases();
}
double MSE::eval(double *weights) {
double MSE::eval(std::vector<double> *weights) {
unsigned int dim_out = this->ds->get_output_dim();
// unsigned int dim_in = this->ds->get_input_dim();
size_t n_elements = this->ds->get_n_elements();
......@@ -66,7 +65,7 @@ ErrorSum::~ErrorSum(){
}
}
double ErrorSum::eval(double *weights) {
double ErrorSum::eval(std::vector<double> *weights) {
double output = 0.0;
for( unsigned int i = 0; i < this->summand->size(); ++i ){
......
......@@ -20,7 +20,7 @@ public:
* @param weights
* @return
*/
virtual double eval(double* weights) = 0;
virtual double eval(std::vector<double>* weights = nullptr) = 0;
/**
*
......@@ -51,7 +51,7 @@ public:
* @param weights
* @return
*/
virtual double eval(double* weights = nullptr);
virtual double eval(std::vector<double>* weights = nullptr);
private:
......@@ -76,7 +76,7 @@ public:
* @param weights
* @return
*/
virtual double eval(double* weights = nullptr);
virtual double eval(std::vector<double>* weights = nullptr);
/**
*
......
......@@ -6,7 +6,6 @@
*/
#include "ParticleSwarm.h"
#include "../ErrorFunction/ErrorFunctions.h"
/**
* TODO
......@@ -19,30 +18,32 @@ Particle::Particle(ErrorFunction* ef, double *domain_bounds) {
//TODO better generating of random numbers
this->coordinate_dim = ef->get_dimension();
this->coordinate = new double[this->coordinate_dim];
this->velocity = new double[this->coordinate_dim];
this->coordinate = new std::vector<double>(this->coordinate_dim);
this->velocity = new std::vector<double>(this->coordinate_dim);
this->optimal_coordinate = new std::vector<double>(this->coordinate_dim);
std::random_device seeder;
std::mt19937 gen(seeder());
std::uniform_real_distribution<double> dist_vel(0.5, 1.0);
for(unsigned int i = 0; i < this->coordinate_dim; ++i){
this->velocity[i] = (rand() % 100001 - 50000) / (double) 50000;
(*this->velocity)[i] = dist_vel(gen);
}
// this->r1 = (rand() % 100001) / (double) 100000;
// this->r2 = (rand() % 100001) / (double) 100000;
this->r1 = 1.0;
this->r2 = 1.0;
this->r3 = 1.0;
this->optimal_coordinate = new double[this->coordinate_dim];
this->r1 = dist_vel(gen);
this->r2 = dist_vel(gen);
this->r3 = dist_vel(gen);
this->ef = ef;
this->ef = ef;
std::uniform_real_distribution<double> dist_coord(-1.0, 1.0);
this->domain_bounds = domain_bounds;
for(unsigned int i = 0; i < this->coordinate_dim; ++i){
this->coordinate[i] = (rand() % 100001) / (double)100000 + domain_bounds[2 * i] / (domain_bounds[2 * i + 1] - domain_bounds[2 * i]);
this->optimal_coordinate[i] = this->coordinate[i];
(*this->coordinate)[i] = dist_coord(gen);
(*this->optimal_coordinate)[i] = (*this->coordinate)[i];
}
// (*this->coordinate) = {-6.35706416, -1.55399893, -1.05305639, 3.07464411};
// printf("coordinate_dim: %d\n", this->coordinate_dim);
this->optimal_value = this->ef->eval(this->coordinate);
......@@ -53,20 +54,20 @@ Particle::Particle(ErrorFunction* ef, double *domain_bounds) {
Particle::~Particle() {
if( this->optimal_coordinate ){
delete [] this->optimal_coordinate;
delete this->optimal_coordinate;
}
if( this->coordinate ){
delete [] this->coordinate;
delete this->coordinate;
}
if( this->velocity ){
delete [] this->velocity;
delete this->velocity;
}
}
double* Particle::get_coordinate() {
std::vector<double>* Particle::get_coordinate() {
return this->coordinate;
}
......@@ -80,11 +81,11 @@ double Particle::get_optimal_value() {
void Particle::get_optimal_coordinate(std::vector<double> &ref_coordinate) {
for( unsigned int i = 0; i < this->coordinate_dim; ++i ){
ref_coordinate[i] = this->optimal_coordinate[i];
ref_coordinate[i] = (*this->optimal_coordinate)[i];
}
}
double Particle::change_coordinate(double w, double c1, double c2, std::vector<double> glob_min_coord, std::vector<std::vector<double>> global_min_vec, double penalty_coef) {
double Particle::change_coordinate(double w, double c1, double c2, std::vector<double> &glob_min_coord, std::vector<std::vector<double>> &global_min_vec, double penalty_coef) {
/**
* v = w * v + c1r1(p_min_loc - x) + c2r2(p_min_glob - x) + c3r3(random_global_min - x)
......@@ -92,32 +93,33 @@ double Particle::change_coordinate(double w, double c1, double c2, std::vector<d
*/
double vel_mem;
double output;
double output = 0.0;
bool in_domain;
double compensation_coef = 1;
/* Choose random global minima */
std::vector<double> random_global_best(this->coordinate_dim);
std::vector<double> *random_global_best;
std::random_device rand_dev;
std::mt19937 engine{rand_dev()};
std::uniform_int_distribution<int> dist(0, global_min_vec.size() - 1);
random_global_best = global_min_vec[dist(engine)];
random_global_best = &global_min_vec[dist(engine)];
// TODO use std::sample to choose random vector
//std::sample(global_min_vec.begin(), global_min_vec.end(), std::back_inserter(random_global_best), 1, std::mt19937{std::random_device{}()});
for(unsigned int i = 0; i < this->coordinate_dim; ++i){
vel_mem = w * this->velocity[i]
+ c1 * this->r1 * (this->optimal_coordinate[i] - this->coordinate[i])
+ c2 * this->r2 * (glob_min_coord[i] - this->coordinate[i])
+ (c1+c2)/2 * this->r3 * (random_global_best[i] - this->coordinate[i]);
vel_mem = w * (*this->velocity)[i]
+ c1 * this->r1 * ((*this->optimal_coordinate)[i] - (*this->coordinate)[i])
+ c2 * this->r2 * (glob_min_coord[i] - (*this->coordinate)[i])
+ (c1+c2)/2 * this->r3 * ((*random_global_best)[i] - (*this->coordinate)[i]);
do{
if (this->coordinate[i] + vel_mem > this->domain_bounds[2 * i + 1]) {
// printf("%f + %f ?? %f, %f\n", (*this->coordinate)[i], vel_mem, this->domain_bounds[2 * i + 1], this->domain_bounds[2 * i]);
if ((*this->coordinate)[i] + vel_mem > this->domain_bounds[2 * i + 1]) {
in_domain = false;
vel_mem = -penalty_coef * compensation_coef * w * vel_mem;
compensation_coef /= 2;
} else if (this->coordinate[i] + vel_mem < this->domain_bounds[2 * i]) {
} else if ((*this->coordinate)[i] + vel_mem < this->domain_bounds[2 * i]) {
in_domain = false;
vel_mem = penalty_coef * compensation_coef * w * vel_mem;
compensation_coef /= 2;
......@@ -127,8 +129,8 @@ double Particle::change_coordinate(double w, double c1, double c2, std::vector<d
}
}while(!in_domain);
this->velocity[i] = vel_mem;
this->coordinate[i] += vel_mem;
(*this->velocity)[i] = vel_mem;
(*this->coordinate)[i] += vel_mem;
output += std::abs(vel_mem);
}
......@@ -139,7 +141,7 @@ double Particle::change_coordinate(double w, double c1, double c2, std::vector<d
if(vel_mem < this->optimal_value){
this->optimal_value = vel_mem;
for(unsigned int i = 0; i < this->coordinate_dim; ++i){
this->optimal_coordinate[i] = this->coordinate[i];
(*this->optimal_coordinate)[i] = (*this->coordinate)[i];
}
}
......@@ -148,17 +150,17 @@ double Particle::change_coordinate(double w, double c1, double c2, std::vector<d
void Particle::print_coordinate() {
for(unsigned int i = 0; i < this->coordinate_dim - 1; ++i){
printf("%10.8f, ", this->coordinate[i]);