-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFE_Density_Estimation_imp.h
More file actions
100 lines (73 loc) · 3.4 KB
/
FE_Density_Estimation_imp.h
File metadata and controls
100 lines (73 loc) · 3.4 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//
// Created by simonepanzeri on 01/12/2021.
//
#ifndef DEV_FDAPDE_FE_DENSITY_ESTIMATION_IMP_H
#define DEV_FDAPDE_FE_DENSITY_ESTIMATION_IMP_H
//! *** internal use
#include <filesystem>
void deleteDirectoryContents(const std::string& dir_path)
{
for (const auto& entry : std::filesystem::directory_iterator(dir_path))
std::filesystem::remove_all(entry.path());
}
//! ***
template<UInt ORDER, UInt mydim, UInt ndim>
FEDE<ORDER, mydim, ndim>::
FEDE(const DataProblem<ORDER, mydim, ndim>& dp,
const FunctionalProblem<ORDER, mydim, ndim>& fp,
std::shared_ptr<MinimizationAlgorithm<ORDER, mydim, ndim>> ma, const std::string& p):
dataProblem_(dp), funcProblem_(fp), minAlgo_(ma){
preprocess_ = Preprocess_factory<ORDER, mydim, ndim>::createPreprocessSolver(dp, fp, ma, p);
}
template<UInt ORDER, UInt mydim, UInt ndim>
void
FEDE<ORDER, mydim, ndim>::apply(){
// perform the preprocess phase
// Rprintf("##### PREPROCESS PHASE #####\n");
preprocess_ -> performPreprocessTask();
// collect preprocess results
VectorXr gInit;
std::tie(fInit_, gInit, bestLambda_) = preprocess_ -> getPreprocessParameter();
CV_errors_ = preprocess_ -> getCvError();
// final minimization descent
// Rprintf("##### FINAL STEP #####\n");
gcoeff_ = minAlgo_->apply_core(dataProblem_.getGlobalPsi(), bestLambda_, gInit);
}
//! ####################################################################################################################
//! ######################################## SPACE-TIME PROBLEM ########################################################
//! ####################################################################################################################
template<UInt ORDER, UInt mydim, UInt ndim>
FEDE_time<ORDER, mydim, ndim>::
FEDE_time(const DataProblem_time<ORDER, mydim, ndim>& dp,
const FunctionalProblem_time<ORDER, mydim, ndim>& fp,
std::shared_ptr<MinimizationAlgorithm_time<ORDER, mydim, ndim>> ma, const std::string& p):
dataProblem_(dp), funcProblem_(fp), minAlgo_(ma){
preprocess_ = Preprocess_factory_time<ORDER, mydim, ndim>::createPreprocessSolver(dp, fp, ma, p);
}
template<UInt ORDER, UInt mydim, UInt ndim>
void
FEDE_time<ORDER, mydim, ndim>::apply(){
std::cout << "==== PREPROCESS PHASE ====" << std::endl;
// perform the preprocess phase
// Rprintf("##### PREPROCESS PHASE #####\n");
preprocess_ -> performPreprocessTask();
std::cout << "==== COLLECT PREPROCESS RESULT ====" << std::endl;
// collect preprocess results
VectorXr gInit;
std::tie(fInit_, gInit, bestLambda_S, bestLambda_T) = preprocess_ -> getPreprocessParameter();
std::cout << "best lambda_S: " << bestLambda_S << ", best lambda_T: " << bestLambda_T << std::endl;
std::cout << "==== CV PREPROCESS PHASE ====" << std::endl;
CV_errors_ = preprocess_ -> getCvError();
std::cout << "CV_errors: ";
for (Real i : CV_errors_)
std::cout << i << " ";
std::cout << std::endl;
// final minimization descent
// Rprintf("##### FINAL STEP #####\n");
std::cout << "==== FINAL STEP ====" << std::endl;
//! .txt DATA CLEANING
deleteDirectoryContents("../data/space_time/g_sol");
deleteDirectoryContents("../data/space_time/solution");
gcoeff_ = minAlgo_->apply_core(dataProblem_.getUpsilon(), bestLambda_S, bestLambda_T, gInit);
}
#endif //DEV_FDAPDE_FE_DENSITY_ESTIMATION_IMP_H