include/vinecopulib/misc/implementation/tools_interpolation.ipp
//! Integrate the grid along one axis
//!
//! @param u Mx2 matrix of evaluation points
//! @param cond_var Either 1 or 2; the axis considered fixed.
//! @return a vector of resulting integral values
Integrate the grid along one axis
Integrate the grid along one axis
inline Eigen::VectorXd
InterpolationGrid::integrate_1d(const Eigen::MatrixXd& u, size_t cond_var)
{
  ptrdiff_t m = grid_points_.size();
  Eigen::VectorXd tmpvals(m);
  Eigen::MatrixXd tmpgrid(m, 2);
  auto f = [this, m, cond_var, &tmpvals, &tmpgrid](double u1, double u2) {
    double upr = 0.0;
    double tmpint = 0.0, int1;
    if (cond_var == 1) {
      upr = u2;
      tmpgrid.col(0) = Eigen::VectorXd::Constant(m, u1);
      tmpgrid.col(1) = grid_points_;
    } else if (cond_var == 2) {
      upr = u1;
      tmpgrid.col(0) = grid_points_;
      tmpgrid.col(1) = Eigen::VectorXd::Constant(m, u2);
    }
    tmpvals = interpolate(tmpgrid).array().max(1e-4);
    tmpint = int_on_grid(upr, tmpvals, grid_points_);
    int1 = int_on_grid(1.0, tmpvals, grid_points_);
    return std::min(std::max(tmpint / int1, 1e-10), 1 - 1e-10);
  };
  return tools_eigen::binaryExpr_or_nan(u, f);
}
inline Eigen :: VectorXd InterpolationGrid :: integrate_1d ( const Eigen :: MatrixXd & u , size_t cond_var ) { ptrdiff_t m = grid_points_ . size ( ) ; Eigen :: VectorXd tmpvals ( m ) ; Eigen :: MatrixXd tmpgrid ( m , 2 ) ; auto f = [ this , m , cond_var , & tmpvals , & tmpgrid ] ( double u1 , double u2 ) { double upr = 0.0 ; double tmpint = 0.0 , int1 ; if ( cond_var == 1 ) { upr = u2 ; tmpgrid . col ( 0 ) = Eigen :: VectorXd :: Constant ( m , u1 ) ; tmpgrid . col ( 1 ) = grid_points_ ; } else if ( cond_var == 2 ) { upr = u1 ; tmpgrid . col ( 0 ) = grid_points_ ; tmpgrid . col ( 1 ) = Eigen :: VectorXd :: Constant ( m , u2 ) ; } tmpvals = interpolate ( tmpgrid ) . array ( ) . max ( 1e-4 ) ; tmpint = int_on_grid ( upr , tmpvals , grid_points_ ) ; int1 = int_on_grid ( 1.0 , tmpvals , grid_points_ ) ; return std :: min ( std :: max ( tmpint / int1 , 1e-10 ) , 1 - 1e-10 ) ; } ; return tools_eigen :: binaryExpr_or_nan ( u , f ) ; }
Integrate the grid along one axis
Integrate the grid along one axis