-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathK_Fold_CV_L2_Error.h
More file actions
53 lines (40 loc) · 1.6 KB
/
K_Fold_CV_L2_Error.h
File metadata and controls
53 lines (40 loc) · 1.6 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
//
// Created by simon on 01/12/2021.
//
#ifndef DEV_FDAPDE_K_FOLD_CV_L2_ERROR_H
#define DEV_FDAPDE_K_FOLD_CV_L2_ERROR_H
#include "FdaPDE.h"
// This file implements the cross validation error based on the L2 norm useful for the Density Estimation problem
//! @brief A class to compute the L2 error during cross-validation.
template<UInt ORDER, UInt mydim, UInt ndim>
class KfoldCV_L2_error{
private:
// A member to access data problem methods
const DataProblem<ORDER, mydim, ndim>& dataProblem_;
public:
//! A constructor.
KfoldCV_L2_error(const DataProblem<ORDER, mydim, ndim>& dp): dataProblem_(dp) {};
//! A call operator to compute the L2 error.
Real operator()(const SpMat& Psi, const VectorXr& g) {
Real integral = dataProblem_.FEintegrate_exponential(2.*g);
Real test = (Psi*g).array().exp().sum();
return (integral - 2./Psi.rows() *test);
}
};
//! @brief A class to compute the L2 error during cross-validation.
template<UInt ORDER, UInt mydim, UInt ndim>
class KfoldCV_L2_error_time{
private:
// A member to access data problem methods
const DataProblem_time<ORDER, mydim, ndim>& dataProblem_;
public:
//! A constructor.
KfoldCV_L2_error_time(const DataProblem_time<ORDER, mydim, ndim>& dp): dataProblem_(dp) {};
//! A call operator to compute the L2 error.
Real operator()(const SpMat& Upsilon, const VectorXr& g) {
Real integral = dataProblem_.FEintegrate_exponential(2.*g);
Real test = (Upsilon*g).array().exp().sum();
return (integral - 2./Upsilon.rows() * test);
}
};
#endif //DEV_FDAPDE_K_FOLD_CV_L2_ERROR_H