Newer
Older
/**
* DESCRIPTION OF THE FILE
*
* @author Michal Kravčenko
* @date 29.09.19 -
*/
#include <random.hpp>
#include <limits>
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "message.h"
#include "MultiGridLearning.h"
namespace lib4neuro {
MultiGridLearning::MultiGridLearning(
LearningMethod &inner_trainer,
double tol,
double res
){
this->inner_method = &inner_trainer;
this->learning_tolerance = tol;
this->resolution_coeff = res;
}
MultiGridLearning::~MultiGridLearning( ) {}
void MultiGridLearning::optimize(
lib4neuro::ErrorFunction& ef,
std::ofstream* ofs
) {
DataSet *ds_orig = ef.get_dataset();
double res = this->resolution_coeff;
double multi_grid_coeff = this->resolution_coeff;
std::vector<DataSet*> data_set_hierarchies;
data_set_hierarchies.push_back( ds_orig );
DataSet *new_data_set = ds_orig->get_approximated_set( 1e-12, 0 );
data_set_hierarchies.push_back( new_data_set );
size_t nref = new_data_set->get_n_elements();
while(new_data_set->get_n_elements() >= nref){
res += multi_grid_coeff;
multi_grid_coeff *= 0.95;
new_data_set = new_data_set->get_approximated_set( res, 0 );
data_set_hierarchies.push_back( new_data_set );
}
for( size_t i = data_set_hierarchies.size() - 1; i > 0; --i ){
ef.set_dataset( data_set_hierarchies[ i ] );
// while( true ){
this->inner_method->optimize( ef, ofs );
// if( ef.eval() < this->learning_tolerance ){
// break;
// }
// }
delete data_set_hierarchies[ i ];
COUT_INFO("--------------------------------------------");
}
// std::vector<double> output(1);
// for(auto e : *ds_orig->get_data()) {
// std::cout << "{";
// for( size_t j = 0; j < e.first.size(); ++j ){
// std::cout << e.first[ j ] << " ";
// }
// std::cout << "} -> {";
//
// std::cout << e.second.at(0) << " ";
// ef.get_nets()[0]->eval_single(e.first, output);
// std::cout << output.at(0) << "}" << std::endl;
// }
//
// for(auto e : *ef.get_dataset()->get_data()) {
// std::cout << "{";
// for( size_t j = 0; j < e.first.size(); ++j ){
// std::cout << e.first[ j ] << " ";
// }
// std::cout << "} -> {";
//
// std::cout << e.second.at(0) << " ";
// ef.get_nets()[0]->eval_single(e.first, output);
// std::cout << output.at(0) << "}" << std::endl;
// }
ef.set_dataset( ds_orig );
this->inner_method->optimize( ef, ofs );
}
}//end of namespace lib4neuro