include/vinecopulib/misc/implementation/tools_interpolation.ipp
//! Integrate the grid along the two axis
//!
//! @param u Mx2 matrix of evaluation points
//! @return a vector of resulting integral values
Integrate the grid along the two axis
Integrate the grid along the two axis
inline Eigen::VectorXd
InterpolationGrid::integrate_2d(const Eigen::MatrixXd& u)
{
  ptrdiff_t m = grid_points_.size();
  Eigen::VectorXd tmpvals(m), tmpvals2(m);
  Eigen::MatrixXd tmpgrid(m, 2);
  tmpgrid.col(1) = grid_points_;
  auto f = [this, m, &tmpvals, &tmpvals2, &tmpgrid](double u1, double u2) {
    double upr, tmpint, tmpint1;
    upr = u2;
    for (ptrdiff_t k = 0; k < m; ++k) {
      tmpgrid.col(0) = Eigen::VectorXd::Constant(m, grid_points_(k));
      tmpvals = interpolate(tmpgrid);
      tmpint = int_on_grid(upr, tmpvals, grid_points_);
      tmpvals2(k) = tmpint;
    }
    upr = u1;
    tmpint = int_on_grid(upr, tmpvals2, grid_points_);
    tmpint1 = int_on_grid(1.0, tmpvals2, grid_points_);
    return std::min(std::max(tmpint / tmpint1, 1e-10), 1 - 1e-10);
  };
  return tools_eigen::binaryExpr_or_nan(u, f);
}
inline Eigen :: VectorXd InterpolationGrid :: integrate_2d ( const Eigen :: MatrixXd & u ) { ptrdiff_t m = grid_points_ . size ( ) ; Eigen :: VectorXd tmpvals ( m ) , tmpvals2 ( m ) ; Eigen :: MatrixXd tmpgrid ( m , 2 ) ; tmpgrid . col ( 1 ) = grid_points_ ; auto f = [ this , m , & tmpvals , & tmpvals2 , & tmpgrid ] ( double u1 , double u2 ) { double upr , tmpint , tmpint1 ; upr = u2 ; for ( ptrdiff_t k = 0 ; k < m ; ++ k ) { tmpgrid . col ( 0 ) = Eigen :: VectorXd :: Constant ( m , grid_points_ ( k ) ) ; tmpvals = interpolate ( tmpgrid ) ; tmpint = int_on_grid ( upr , tmpvals , grid_points_ ) ; tmpvals2 ( k ) = tmpint ; } upr = u1 ; tmpint = int_on_grid ( upr , tmpvals2 , grid_points_ ) ; tmpint1 = int_on_grid ( 1.0 , tmpvals2 , grid_points_ ) ; return std :: min ( std :: max ( tmpint / tmpint1 , 1e-10 ) , 1 - 1e-10 ) ; } ; return tools_eigen :: binaryExpr_or_nan ( u , f ) ; }
Integrate the grid along the two axis
Integrate the grid along the two axis