Newer
Older
1
2
3
4
5
6
7
8
9
10
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
/**
* DESCRIPTION OF THE FILE
*
* @author Michal Kravčenko
* @date 13.10.19 -
*/
#include <random.hpp>
#include <limits>
#include "message.h"
#include "SmoothingLearning.h"
namespace lib4neuro {
SmoothingLearning::SmoothingLearning(
LearningMethod &inner_trainer,
double tol,
double grate
){
this->inner_method = &inner_trainer;
this->learning_tolerance = tol;
this->growth_rate = grate;
}
SmoothingLearning::~SmoothingLearning( ) {}
void SmoothingLearning::optimize(
lib4neuro::ErrorFunction& ef,
std::ofstream* ofs
) {
DataSet *ds_orig = ef.get_dataset();
double res = this->growth_rate;
size_t niters = 1.0 / this->growth_rate;
double the_best_error, current_error;
current_error = ef.eval();
the_best_error = current_error;
for( int i = 0; i < niters; ++i ){
DataSet *new_data_set = ds_orig->get_smoothed_set( i * this->growth_rate );
ef.set_dataset( new_data_set );
this->inner_method->optimize( ef, ofs );
current_error = ef.eval();
if(current_error < the_best_error){
the_best_error = current_error;
}
while(current_error > the_best_error){
this->inner_method->optimize( ef, ofs );
current_error = ef.eval();
if(current_error < the_best_error){
the_best_error = current_error;
}
}
delete new_data_set;
COUT_INFO("--------------------------------------------");
}
ef.set_dataset( ds_orig );
this->inner_method->optimize( ef, ofs );
}
}//end of namespace lib4neuro