From bf1e35382c30fe4f5b2870c390001e0657a3fa25 Mon Sep 17 00:00:00 2001 From: "D. Sharp" Date: Wed, 12 Jun 2024 11:02:07 -0600 Subject: [PATCH 01/11] Create basic compact monotone component --- MParT/MonotoneComponent.h | 259 ++++++++++++++++++++++++-------------- 1 file changed, 163 insertions(+), 96 deletions(-) diff --git a/MParT/MonotoneComponent.h b/MParT/MonotoneComponent.h index 65097100..2d1deec8 100644 --- a/MParT/MonotoneComponent.h +++ b/MParT/MonotoneComponent.h @@ -44,7 +44,7 @@ T(x_1, x_2, ..., x_D) = f(x_1,x_2,..., x_{D-1}, 0) + \int_0^{x_D} g\left( \part @tparam PosFuncType A class defining the function \f$g\f$. This class must have `Evaluate` and `Derivative` functions accepting a double and returning a double. The MParT::SoftPlus and MParT::Exp classes in PositiveBijectors.h are examples of classes defining this interface. @tparam QuadratureType A class defining the integration scheme used to approximate \f$\int_0^{x_N} g\left( \frac{\partial f}{\partial x_d}(x_1,x_2,..., x_{N-1}, t) \right) dt\f$. The type must have a function `Integrate(f,lb,ub)` that accepts a functor `f`, a double lower bound `lb`, a double upper bound `ub`, and returns a double with an estimate of the integral. The MParT::AdaptiveSimpson and MParT::RecursiveQuadrature classes provide this interface. */ -template +template class MonotoneComponent : public ConditionalMapBase { @@ -70,8 +70,6 @@ class MonotoneComponent : public ConditionalMapBase useContDeriv_(useContDeriv), nugget_(nugget){}; - - MonotoneComponent(ExpansionType const& expansion, QuadratureType const& quad, bool useContDeriv, @@ -215,9 +213,6 @@ class MonotoneComponent : public ConditionalMapBase ContinuousMixedInputJacobian(pts,this->savedCoeffs, output); ContinuousDerivative(pts, this->savedCoeffs, derivs); }else{ - // Kokkos::View evals("Evaluations", pts.extent(1)); - // DiscreteMixedJacobian(pts,this->savedCoeffs, output); - // DiscreteDerivative(pts, this->savedCoeffs, evals, derivs); std::stringstream msg; msg << "Discrete derivative version is not implemented yet (To Do)"; throw std::invalid_argument(msg.str()); @@ -285,10 +280,12 @@ class MonotoneComponent : public ConditionalMapBase // Fill in entries in the cache that are independent of x_d. By passing DerivativeFlags::None, we are telling the expansion that no derivatives with wrt x_1,...x_{d-1} will be needed. expansion_.FillCache1(cache.data(), pt, DerivativeFlags::None); output(ptInd) = EvaluateSingle(cache.data(), workspace.data(), pt, pt(dim_-1), coeffs, quad_, expansion_); + if constexpr(isCompact) { + output(ptInd) /= EvaluateSingle(cache.data(), workspace.data(), pt, 1., coeffs, quad_, expansion_); + } } }; - // Create a policy with enough scratch memory to cache the polynomial evaluations unsigned int cacheBytes = Kokkos::View::shmem_size(cacheSize+workspaceSize); auto policy = GetCachedRangePolicy(numPts, cacheBytes,functor); @@ -298,21 +295,6 @@ class MonotoneComponent : public ConditionalMapBase } - - // template< typename ExecutionSpace=typename MemoryToExecution::Space> - // void InverseImpl(StridedMatrix const& xs, - // StridedVector const& ys, - // StridedVector const& coeffs, - // StridedVector output, - // std::map options=std::map()) - // { - // StridedMatrix constXs = xs; - // StridedVector constYs = ys; - // StridedVector constCoeffs = coeffs; - - // InverseImpl(constXs,constYs,constCoeffs,output,options); - // } - /** @brief Evaluates the inverse of the diagonal of the monotone component. @details This function solve the nonlinear equation \f$y_D = T(x_1,\ldots,x_D)\f$ for \f$x_D\f$ given \f$N\f$ different @@ -432,7 +414,9 @@ class MonotoneComponent : public ConditionalMapBase // Compute the inverse Kokkos::View workspace(team_member.thread_scratch(1), workspaceSize); auto eval = SingleEvaluator(workspace.data(), cache.data(), pt, coeffs, quad_, expansion_, nugget_); - output(ptInd) = RootFinding::InverseSingleBracket(ys(ptInd), eval, pt(pt.extent(0)-1), xtol, ytol, info); + double y_scale = ys(ptInd); + if constexpr(isCompact) y_scale *= eval(1); + output(ptInd) = RootFinding::InverseSingleBracket(y_scale, eval, pt(pt.extent(0)-1), xtol, ytol, info); } }; @@ -463,16 +447,6 @@ class MonotoneComponent : public ConditionalMapBase return derivs; } - // template::Space> - // Kokkos::View ContinuousDerivative(StridedMatrix const& pts, - // StridedVector const& coeffs) - // { - // StridedMatrix pts2 = pts; - // StridedVector coeffs2 = coeffs; - // return ContinuousDerivative(pts2,coeffs2); - // } - - /** @brief Approximates the "continuous derivative" \f$\frac{\partial T}{\partial x_D}\f$ derived from the exact integral form of the transport map. @@ -521,6 +495,12 @@ class MonotoneComponent : public ConditionalMapBase // Compute g(df/dx) derivs(ptInd) = PosFuncType::Evaluate(derivs(ptInd)); + + // If compact, normalize by part independent of x_d + if constexpr(isCompact) { + expansion_.FillCache2(cache.data(), pt, 1, DerivativeFlags::None); + derivs(ptInd) /= expansion_.Evaluate(cache.data(), coeffs); + } } }; @@ -530,16 +510,6 @@ class MonotoneComponent : public ConditionalMapBase Kokkos::parallel_for(policy, functor); } - // template::Space> - // void ContinuousDerivative(StridedMatrix const& pts, - // StridedVector const& coeffs, - // StridedVector derivs) - // { - // StridedMatrix pts2 = pts; - // StridedVector coeffs2 = coeffs; - // ContinuousDerivative(pts2,coeffs2, derivs); - // } - /** @brief Approximates the "discrete derivative" of the quadrature-based approximation \f$\tilde{T}\f$. @details See the mathematical background section for more details on discrete and continuous map derivatives. @@ -562,16 +532,6 @@ class MonotoneComponent : public ConditionalMapBase return derivs; } - // template::Space> - // Kokkos::View DiscreteDerivative(StridedMatrix const& pts, - // StridedVector const& coeffs) - // { - // StridedMatrix pts2 = pts; - // StridedVector coeffs2 = coeffs; - // return DiscreteDerivative(pts2,coeffs2); - // } - - /** @brief Approximates the "discrete derivative" of the quadrature-based approximation \f$\tilde{T}\f$. @details See the mathematical background section for more details on discrete and continuous map derivatives. @@ -629,6 +589,9 @@ class MonotoneComponent : public ConditionalMapBase // Add f(x_1,x_2,...,x_{d-1},0) to the evaluation output expansion_.FillCache2(cache.data(), pt, 0.0, DerivativeFlags::None); evals(ptInd) += expansion_.Evaluate(cache.data(), coeffs); + if constexpr(isCompact) { + ProcAgnosticError("Discrete derivative not supported for compact map"); + } } }; @@ -637,17 +600,6 @@ class MonotoneComponent : public ConditionalMapBase Kokkos::parallel_for(policy, functor); } - // template::Space> - // void DiscreteDerivative(StridedMatrix const& pts, - // StridedVector const& coeffs, - // StridedVector evals, - // StridedVector derivs) - // { - // StridedMatrix pts2 = pts; - // StridedVector coeffs2 = coeffs; - // DiscreteDerivative(pts2, coeffs2, evals, derivs); - // } - bool isJacobianInputValid(int jacRows, int jacCols, int evalRows, int expectJacRows, int expectJacCols, int expectEvalRows) { bool isJacRowsCorrect = jacRows == expectJacRows; bool isJacColsCorrect = jacCols == expectJacCols; @@ -671,7 +623,7 @@ class MonotoneComponent : public ConditionalMapBase @details Consider \f$N\f$ points \f$\{\mathbf{x}^{(1)},\ldots,\mathbf{x}^{(N)}\}\f$ and let - \f$y_d^{(i)} = T_d(\mathbf{x}^{(i)}; \mathbf{w})\f$. This function computes \f$\nabla_{\mathbf{w}} y_d^{(i)}\f$ + \f$y_d^{(i)} = T_d(\mathbf{x}^{(i)}; \mathbf{w})\f$. This function computes \f$\nabla_{\mathbf{w}} y_d^{(i)}\f$ for each output \f$y_d^{(i)}\f$. @param[in] pts A \f$D\times N\f$ matrix containing the points \f$x^{(1)},\ldots,x^{(N)}\f$. Each column is a point. @@ -697,8 +649,10 @@ class MonotoneComponent : public ConditionalMapBase quad_.SetDim(numTerms+1); const unsigned int workspaceSize = quad_.WorkspaceSize(); + unsigned int integral_space = (numTerms + 1)*(1+isCompact); + // Create a policy with enough scratch memory to cache the polynomial evaluations - auto cacheBytes = Kokkos::View::shmem_size(cacheSize+workspaceSize+numTerms+1); + auto cacheBytes = Kokkos::View::shmem_size(cacheSize+workspaceSize+integral_space); auto functor = KOKKOS_CLASS_LAMBDA (typename Kokkos::TeamPolicy::member_type team_member) { @@ -713,24 +667,51 @@ class MonotoneComponent : public ConditionalMapBase Kokkos::View cache(team_member.thread_scratch(1), cacheSize); Kokkos::View workspace(team_member.thread_scratch(1), workspaceSize); Kokkos::View integral(team_member.thread_scratch(1), numTerms+1); + Kokkos::View integral_frac; + if constexpr(isCompact) integral_frac = Kokkos::View(team_member.thread_scratch(1), numTerms+1); // Fill in the cache with anything that doesn't depend on x_d - expansion_.FillCache1(cache.data(), pt, DerivativeFlags::None); + expansion_.FillCache1(cache.data(), pt, DerivativeFlags::Parameters); // Create the integrand g( \partial_D f(x_1,...,x_{D-1},t)) - MonotoneIntegrand integrand(cache.data(), expansion_, pt, coeffs, DerivativeFlags::Parameters, nugget_); + MonotoneIntegrand integrand(cache.data(), expansion_, pt, pt(pt.extent(0)- 1), coeffs, DerivativeFlags::Parameters, nugget_); // Compute \int_0^x g( \partial_D f(x_1,...,x_{D-1},t)) dt as well as the gradient of this term wrt the coefficients of f quad_.Integrate(workspace.data(), integrand, 0, 1, integral.data()); + + // Do the same work for the denominator if needed + if constexpr(isCompact) { + MonotoneIntegrand integrand_frac(cache.data(), expansion_, pt, 1., coeffs, DerivativeFlags::Parameters, nugget_); + quad_.Integrate(workspace.data(), integrand_frac, 0, 1, integral_frac.data()); + } + - evaluations(ptInd) = integral(0); + expansion_.FillCache2(cache.data(), pt, 0.0, DerivativeFlags::Parameters); - expansion_.FillCache2(cache.data(), pt, 0.0, DerivativeFlags::None); - evaluations(ptInd) += expansion_.CoeffDerivative(cache.data(), coeffs, jacView); + // Evaluates the offdiagonal basis and stores the coeffgrad of it into jacView + double offdiag_eval = expansion_.CoeffDerivative(cache.data(), coeffs, jacView); + + double numer_eval = integral(0) + offdiag_eval; + evaluations(ptInd) = numer_eval; + + double denom_eval; + if constexpr(isCompact) { + denom_eval = integral_frac(0) + offdiag_eval; + evaluations(ptInd) /= denom_eval; + } // Add the Integral to the coefficient gradient - for(unsigned int termInd=0; termInd const unsigned int cacheSize = expansion_.CacheSize(); quad_.SetDim(dim_+1); const unsigned int workspaceSize = quad_.WorkspaceSize(); - + unsigned int integral_size = dim_+1; + if(isCompact) integral_size *= 2; // Create a policy with enough scratch memory to cache the polynomial evaluations - auto cacheBytes = Kokkos::View::shmem_size(cacheSize+workspaceSize+dim_+1); + auto cacheBytes = Kokkos::View::shmem_size(cacheSize+workspaceSize+integral_size); auto functor = KOKKOS_CLASS_LAMBDA (typename Kokkos::TeamPolicy::member_type team_member) { @@ -786,27 +768,54 @@ class MonotoneComponent : public ConditionalMapBase Kokkos::View cache(team_member.thread_scratch(1), cacheSize); Kokkos::View workspace(team_member.thread_scratch(1), workspaceSize); Kokkos::View integral(team_member.thread_scratch(1), dim_+1); + Kokkos::View integral_denom; + if constexpr(isCompact) integral_denom = Kokkos::View(team_member.thread_scratch(1), dim_+1); // Fill in the cache with anything that doesn't depend on x_d expansion_.FillCache1(cache.data(), pt, DerivativeFlags::Input); // Create the integrand g( \partial_D f(x_1,...,x_{D-1},t)) MonotoneIntegrand integrand(cache.data(), expansion_, pt, coeffs, DerivativeFlags::Input, nugget_); + // Create the integrand g( \partial_D f(x_1,...,x_{D-1},1)) + MonotoneIntegrand integrand_denom(cache.data(), expansion_, pt, 1, coeffs, DerivativeFlags::Input, nugget_); // Compute \int_0^x g( \partial_D f(x_1,...,x_{D-1},t)) dt as well as the gradient of this term wrt the map input quad_.Integrate(workspace.data(), integrand, 0, 1, integral.data()); + if constexpr(isCompact) { + // Compute \int_0^1 g( \partial_D f(x_1,...,x_{D-1},t)) dt as well as the gradient of this term wrt the map input + quad_.Integrate(workspace.data(), integrand_denom, 0, 1, integral_denom.data()); + } - evaluations(ptInd) = integral(0); + double numer_diag_eval = integral(0); - expansion_.FillCache2(cache.data(), pt, 0.0, DerivativeFlags::Input); - evaluations(ptInd) += expansion_.InputDerivative(cache.data(), coeffs, jacView); + expansion_.FillCache2(cache.data(), pt, 0.0, DerivativeFlags::Input); + double offdiag_eval = expansion_.InputDerivative(cache.data(), coeffs, jacView); + + double denom_eval, denom_eval_sq; + double numer_eval = numer_diag_eval + offdiag_eval; + evaluations(ptInd) = numer_eval; + if constexpr(isCompact) { + denom_eval = integral_denom(0) + offdiag_eval; + denom_eval_sq = denom_eval*denom_eval; + evaluations(ptInd) /= denom_eval; + } // Add the Integral to the coefficient gradient for(unsigned int d=0; d checkMixedJacobianInput("ContinuousMixedJacobian", jacobian.extent(0), jacobian.extent(1), numTerms, numPts); // Ask the expansion how much memory it would like for it's one-point cache - const unsigned int cacheSize = expansion_.CacheSize(); + const unsigned int workspaceSize = quad_.WorkspaceSize(); + const unsigned int cacheSize = expansion_.CacheSize() + isCompact*(2*numTerms+1+workspaceSize); // Create a policy with enough scratch memory to cache the polynomial evaluations auto cacheBytes = Kokkos::View::shmem_size(cacheSize); @@ -848,24 +858,52 @@ class MonotoneComponent : public ConditionalMapBase auto pt = Kokkos::subview(pts, Kokkos::ALL(), ptInd); auto jacView = Kokkos::subview(jacobian, Kokkos::ALL(), ptInd); - // Evaluate the orthgonal polynomials in each direction (except the last) for all possible orders - Kokkos::View cache(team_member.thread_scratch(1), cacheSize); + Kokkos::View integral_denom; + Kokkos::View workspace; + Kokkos::View jac_denom; + if constexpr(isCompact) { + integral_denom = Kokkos::View(team_member.thread_scratch(1), numTerms+1); + jac_denom = Kokkos::View(team_member.thread_scratch(1), numTerms); + workspace = Kokkos::View(team_member.thread_scratch(1), workspaceSize); + } - // Precompute anything that does not depend on x_d. The DerivativeFlags::None arguments specifies that we won't want to derivative wrt to x_i for i cache(team_member.thread_scratch(1), cacheSize); + // Precompute anything that does not depend on x_d. The DerivativeFlags::MixedCoeff arguments specifies that we won't want to derivative wrt to x_i for i integrand_denom(cache.data(), expansion_, pt, 1., coeffs, DerivativeFlags::Parameters, nugget_); + quad_.Integrate(workspace.data(), integrand_denom, 0, 1, integral_denom.data()); + } + + // Fill in parts of the cache that depend on x_d. Tell the expansion we're going to want first derivatives wrt x_d + expansion_.FillCache2(cache.data(), pt, pt(dim-1), DerivativeFlags::MixedCoeff); // Compute \partial_d f double df = expansion_.MixedCoeffDerivative(cache.data(), coeffs, 1, jacView); double dgdf = PosFuncType::Derivative(df); + double offdiag_eval, numer_diag_deriv, denom_eval, denom_eval_sq; + if constexpr(isCompact) { + expansion_.FillCache2(cache.data(), pt, 1., DerivativeFlags::Parameters); + offdiag_eval = expansion_.CoeffDerivative(cache.data(), coeffs, jac_denom); + numer_diag_deriv = PosFuncType::Evaluate(df); + denom_eval = integral_denom(0) + offdiag_eval; + denom_eval_sq = denom_eval*denom_eval; + } + // Scale the jacobian by dg(df) - for(unsigned int i=0; i checkMixedJacobianInput("ContinuousMixedInputJacobian", jacobian.extent(0), jacobian.extent(1), dim, numPts); - // Ask the expansion how much memory it would like for it's one-point cache - const unsigned int cacheSize = expansion_.CacheSize(); + // Ask the expansion how much memory it would like for its one-point cache + const unsigned int workspaceSize = quad_.WorkspaceSize(); + const unsigned int cacheSize = expansion_.CacheSize() + isCompact*(workspaceSize + 2*dim_ + 1); // Create a policy with enough scratch memory to cache the polynomial evaluations auto cacheBytes = Kokkos::View::shmem_size(cacheSize); @@ -898,8 +937,17 @@ class MonotoneComponent : public ConditionalMapBase // Create a subview containing only the current point auto pt = Kokkos::subview(pts, Kokkos::ALL(), ptInd); auto jacView = Kokkos::subview(jacobian, Kokkos::ALL(), ptInd); + + Kokkos::View integral_denom; + Kokkos::View workspace; + Kokkos::View jac_denom; + if constexpr(isCompact) { + integral_denom = Kokkos::View(team_member.thread_scratch(1), dim_+1); + jac_denom = Kokkos::View(team_member.thread_scratch(1), dim_); + workspace = Kokkos::View(team_member.thread_scratch(1), workspaceSize); + } - // Evaluate the orthgonal polynomials in each direction (except the last) for all possible orders + // Evaluate the orthogonal polynomials in each direction (except the last) for all possible orders Kokkos::View cache(team_member.thread_scratch(1), cacheSize); // Precompute anything that does not depend on x_d. The DerivativeFlags::None arguments specifies that we won't want to derivative wrt to x_i for i double df = expansion_.MixedInputDerivative(cache.data(), coeffs, jacView); double dgdf = PosFuncType::Derivative(df); + double offdiag_eval, numer_diag_deriv, denom_eval, denom_eval_sq; + if constexpr(isCompact) { + expansion_.FillCache2(cache.data(), pt, 1., DerivativeFlags::Input); + offdiag_eval = expansion_.InputDerivative(cache.data(), coeffs, jac_denom); + numer_diag_deriv = PosFuncType::Evaluate(df); + denom_eval = integral_denom(0) + offdiag_eval; + denom_eval_sq = denom_eval*denom_eval; + } - // Scale the jacobian by dg(df) - for(unsigned int i=0; i StridedVector const& coeffs, StridedMatrix jacobian) { + if constexpr(isCompact) { + throw std::runtime_error("Cannot use discrete derivatives with compact basis"); + } const unsigned int numPts = pts.extent(1); const unsigned int numTerms = coeffs.extent(0); From 422df41f943d10ad7715766cd019b7d8f6166326 Mon Sep 17 00:00:00 2001 From: "D. Sharp" Date: Wed, 12 Jun 2024 15:42:43 -0600 Subject: [PATCH 02/11] Working compact univariate bases --- MParT/OrthogonalPolynomial.h | 19 +++- MParT/UnivariateBases.h | 155 +++++++++++++++++++++++++++ tests/CMakeLists.txt | 1 + tests/Test_OrthogonalPolynomials.cpp | 113 ++++++++++++++++++- tests/Test_UnivariateBases.cpp | 118 ++++++++++++++++++++ 5 files changed, 401 insertions(+), 5 deletions(-) create mode 100644 MParT/UnivariateBases.h create mode 100644 tests/Test_UnivariateBases.cpp diff --git a/MParT/OrthogonalPolynomial.h b/MParT/OrthogonalPolynomial.h index bc81d80f..33bf7212 100644 --- a/MParT/OrthogonalPolynomial.h +++ b/MParT/OrthogonalPolynomial.h @@ -1,5 +1,5 @@ -#ifndef ORTHOGONALPOLYNOMIAL_H -#define ORTHOGONALPOLYNOMIAL_H +#ifndef MPART_ORTHOGONALPOLYNOMIAL_H +#define MPART_ORTHOGONALPOLYNOMIAL_H #include #include @@ -327,6 +327,21 @@ class PhysicistHermiteMixer{ typedef OrthogonalPolynomial PhysicistHermite; +class ShiftedLegendreMixer{ // Polynomials orthogonal on U[0,1] +public: + KOKKOS_INLINE_FUNCTION double Normalization(unsigned int polyOrder) const { return 1./(2*polyOrder+1);} +protected: + // \f[ p_{k}(x) = (a_k x + b_k) p_{k-1}(x) - c_k p_{k-2}(x) \f] + KOKKOS_INLINE_FUNCTION double ak(unsigned int k) const {return 2. * (2. * k - 1)/k;} + KOKKOS_INLINE_FUNCTION double bk(unsigned int k) const {return -(2. * k - 1)/k;} + KOKKOS_INLINE_FUNCTION double ck(unsigned int k) const {return (k-1.)/k;} + KOKKOS_INLINE_FUNCTION double phi0(double) const {return 1.0;} + KOKKOS_INLINE_FUNCTION double phi1(double x) const {return 2*x-1;} + KOKKOS_INLINE_FUNCTION double phi1_deriv(double) const{return 2.0;}; +}; + +using ShiftedLegendre = OrthogonalPolynomial; + } // namespace mpart #endif \ No newline at end of file diff --git a/MParT/UnivariateBases.h b/MParT/UnivariateBases.h new file mode 100644 index 00000000..c2814c34 --- /dev/null +++ b/MParT/UnivariateBases.h @@ -0,0 +1,155 @@ +#ifndef MPART_UNIVARIATEBASES_H +#define MPART_UNIVARIATEBASES_H + +#include +#include + +#include + +#include "MParT/Utilities/MathFunctions.h" + +namespace mpart{ + +/** + * @brief Generic class to represent functions + * \f[p_0(x)\equiv 1,p_k(x)=sin(2\pi k x)\f] + */ +class SineBasis +{ +public: + static constexpr double PI2 = 2*M_PI; + + /* Evaluates all polynomials up to a specified order. */ + KOKKOS_FUNCTION void EvaluateAll(double* output, + unsigned int maxOrder, + double x) const + { + output[0] = 1.; + + double sin_x, cos_x, cos_kx; + + if(maxOrder>0) { + sin_x = sin(PI2*x); + cos_x = cos(PI2*x); + cos_kx = cos_x; + output[1] = sin_x; + } + + for(unsigned int order=2; order<=maxOrder; ++order) { + output[order] = output[order-1]*cos_x + cos_kx*sin_x; + cos_kx = cos_kx*cos_x - output[order-1]*sin_x; + } + } + + /** Evaluates the derivative of every polynomial in this family up to degree maxOrder (inclusive). + The results are stored in the memory pointed to by the derivs pointer. + */ + KOKKOS_FUNCTION void EvaluateDerivatives(double* derivs, + unsigned int maxOrder, + double x) const + { + derivs[0] = 0.; + + double sin_x, cos_x, sin_kx; + + if(maxOrder>0) { + sin_x = sin(PI2*x); + cos_x = cos(PI2*x); + sin_kx = sin_x; + derivs[1] = cos_x; + } + + // d_x sin(2pi k x) = 2pi k cos(2pi k x) + for(unsigned int order=2; order<=maxOrder; ++order) { + derivs[order] = derivs[order-1]*cos_x - sin_kx*sin_x; + sin_kx = sin_kx*cos_x + derivs[order-1]*sin_x; + derivs[order-2] *= PI2*(order-2); + } + if(maxOrder>0) derivs[maxOrder-1] *= PI2*(maxOrder-1); + derivs[maxOrder] *= PI2*(maxOrder); + } + + /** Evaluates the value and derivative of every polynomial in this family up to degree maxOrder (inclusive). + The results are stored in the memory pointed to by the derivs pointer. + */ + KOKKOS_FUNCTION void EvaluateDerivatives(double* vals, + double* derivs, + unsigned int maxOrder, + double x) const + { + vals[0] = 1.; + derivs[0] = 0.; + + double sin_x, cos_x; + + if(maxOrder>0) { + sin_x = sin(PI2*x); + cos_x = cos(PI2*x); + vals[1] = sin_x; + derivs[1] = cos_x; + } + + for(unsigned int order=2; order<=maxOrder; ++order) { + vals[order] = vals[order-1]*cos_x + derivs[order-1]*sin_x; + derivs[order] = derivs[order-1]*cos_x - vals[order-1]*sin_x; + derivs[order-2] *= PI2*(order-2); + } + if(maxOrder>0) derivs[maxOrder-1] *= PI2*(maxOrder-1); + derivs[maxOrder] *= PI2*(maxOrder); + } + + KOKKOS_FUNCTION void EvaluateSecondDerivatives(double* vals, + double* derivs, + double* secondDerivs, + unsigned int maxOrder, + double x) const + { + vals[0] = 1.; + derivs[0] = 0.; + secondDerivs[0] = 0.; + + double sin_x, cos_x; + + if(maxOrder>0) { + sin_x = sin(PI2*x); + cos_x = cos(PI2*x); + vals[1] = sin_x; + derivs[1] = cos_x; + secondDerivs[1] = -PI2*PI2*vals[1]; + } + + for(unsigned int order=2; order<=maxOrder; ++order) { + vals[order] = vals[order-1]*cos_x + derivs[order-1]*sin_x; + derivs[order] = derivs[order-1]*cos_x - vals[order-1]*sin_x; + derivs[order-2] *= PI2*(order-2); + secondDerivs[order] = -(PI2*order)*(PI2*order)*vals[order]; + } + if(maxOrder > 0) derivs[maxOrder-1] *= PI2*(maxOrder-1); + derivs[maxOrder] *= PI2*(maxOrder); + } + + + + KOKKOS_FUNCTION double Evaluate(unsigned int const order, + double const x) const + { + return order == 0 ? 1. : sin(PI2*order*x); + } + + KOKKOS_FUNCTION double Derivative(unsigned int const order, + double const x) const + { + return order == 0 ? 0. : PI2*order*cos(PI2*order*x); + } + + KOKKOS_FUNCTION double SecondDerivative(unsigned int const order, + double const x) const + { + return -(PI2*order)*(PI2*order)*sin(PI2*order*x); + } + +}; + +} // namespace mpart + +#endif \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f3e9486f..72538d39 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -29,6 +29,7 @@ set (TEST_SOURCES tests/Distributions/Test_TransportSampler.cpp tests/Test_OrthogonalPolynomials.cpp + tests/Test_UnivariateBases.cpp tests/Test_RootFinding.cpp tests/Test_HermiteFunctions.cpp tests/Test_Sigmoid.cpp diff --git a/tests/Test_OrthogonalPolynomials.cpp b/tests/Test_OrthogonalPolynomials.cpp index 2e8d7e73..7ce8a0c1 100644 --- a/tests/Test_OrthogonalPolynomials.cpp +++ b/tests/Test_OrthogonalPolynomials.cpp @@ -146,8 +146,6 @@ TEST_CASE( "Testing Probabilist Hermite polynomials", "[ProbabilistHermite]" ) { } - - TEST_CASE( "Testing Physicist Hermite normalization", "[PhysicistHermiteNorm]" ) { PhysicistHermite poly(false); @@ -202,7 +200,6 @@ TEST_CASE( "Testing Physicist Hermite normalization", "[PhysicistHermiteNorm]" ) } - TEST_CASE( "Testing Physicist Hermite polynomials", "[PhysicistHermite]" ) { const double floatTol = 1e-15; @@ -229,6 +226,116 @@ TEST_CASE( "Testing Physicist Hermite polynomials", "[PhysicistHermite]" ) { } } +TEST_CASE( "Testing Shifted Legendre polynomials", "[ShiftedLegendre]" ) { + + const double floatTol = 1e-14; + + ShiftedLegendre poly; + + std::vector xs{0.0, 0.1, 0.5, 0.75, 1.0}; + std::vector allvals(5); + std::vector allderivs(5); + std::vector allderivs2(5); + auto shifted_legendre_eval = [](double x){return std::vector { + 1.0, + 2.0*x-1.0, + 6.0*x*x - 6.0*x + 1.0, + 20.0*x*x*x - 30.0*x*x + 12.0*x - 1.0, + 70.0*x*x*x*x - 140.0*x*x*x + 90.0*x*x - 20.0*x + 1.0 + }; + }; + // Check the evaluation + for(auto& x : xs){ + auto shifted_eval = shifted_legendre_eval(x); + CHECK( poly.Evaluate(0, x) == shifted_eval[0] ); + CHECK( poly.Evaluate(1, x) == Approx(shifted_eval[1]).epsilon(floatTol) ); + CHECK( poly.Evaluate(2, x) == Approx(shifted_eval[2]).epsilon(floatTol) ); + CHECK( poly.Evaluate(3, x) == Approx(shifted_eval[3]).epsilon(floatTol) ); + CHECK( poly.Evaluate(4, x) == Approx(shifted_eval[4]).epsilon(floatTol) ); + + poly.EvaluateAll(&allvals[0], 4, x); + CHECK( allvals[0] == shifted_eval[0]); + CHECK( allvals[1] == Approx(shifted_eval[1]).epsilon(floatTol) ); + CHECK( allvals[2] == Approx(shifted_eval[2]).epsilon(floatTol) ); + CHECK( allvals[3] == Approx(shifted_eval[3]).epsilon(floatTol) ); + CHECK( allvals[4] == Approx(shifted_eval[4]).epsilon(floatTol) ); + } + + auto shifted_legendre_deriv = [](double x){return std::vector { + 0.0, + 2.0, + 12.0*x - 6.0, + 60.0*x*x - 60.0*x + 12.0, + 280.0*x*x*x - 420.0*x*x + 180.0*x - 20.0 + }; + }; + // Check the derivative + for(auto& x : xs){ + auto shifted_deriv = shifted_legendre_deriv(x); + CHECK( poly.Derivative(0, x) == shifted_deriv[0] ); + CHECK( poly.Derivative(1, x) == shifted_deriv[1] ); + CHECK( poly.Derivative(2, x) == Approx(shifted_deriv[2]).epsilon(floatTol) ); + CHECK( poly.Derivative(3, x) == Approx(shifted_deriv[3]).epsilon(floatTol) ); + CHECK( poly.Derivative(4, x) == Approx(shifted_deriv[4]).epsilon(floatTol) ); + + auto shifted_eval = shifted_legendre_eval(x); + poly.EvaluateDerivatives(&allvals[0], &allderivs[0], 4, x); + CHECK( allvals[0] == shifted_eval[0] ); + CHECK( allvals[1] == Approx(shifted_eval[1]).epsilon(floatTol) ); + CHECK( allvals[2] == Approx(shifted_eval[2]).epsilon(floatTol) ); + CHECK( allvals[3] == Approx(shifted_eval[3]).epsilon(floatTol) ); + CHECK( allvals[4] == Approx(shifted_eval[4]).epsilon(floatTol) ); + CHECK( allderivs[0] == shifted_deriv[0] ); + CHECK( allderivs[1] == shifted_deriv[1] ); + CHECK( allderivs[2] == Approx(shifted_deriv[2]).epsilon(floatTol) ); + CHECK( allderivs[3] == Approx(shifted_deriv[3]).epsilon(floatTol) ); + CHECK( allderivs[4] == Approx(shifted_deriv[4]).epsilon(floatTol) ); + + poly.EvaluateDerivatives(&allderivs[0], 4, x); + CHECK( allderivs[0] == shifted_deriv[0] ); + CHECK( allderivs[1] == shifted_deriv[1] ); + CHECK( allderivs[2] == Approx(shifted_deriv[2]).epsilon(floatTol) ); + CHECK( allderivs[3] == Approx(shifted_deriv[3]).epsilon(floatTol) ); + CHECK( allderivs[4] == Approx(shifted_deriv[4]).epsilon(floatTol) ); + } + + auto shifted_legendre_deriv2 = [](double x){return std::vector { + 0.0, + 0.0, + 12.0, + 120.0*x - 60.0, + 840.0*x*x - 840.0*x + 180.0 + }; + }; + // Check the second derivatives + for(auto& x : xs){ + auto shifted_deriv2 = shifted_legendre_deriv2(x); + CHECK( poly.SecondDerivative(0, x) == shifted_deriv2[0] ); + CHECK( poly.SecondDerivative(1, x) == shifted_deriv2[1] ); + CHECK( poly.SecondDerivative(2, x) == Approx(shifted_deriv2[2]).epsilon(floatTol) ); + CHECK( poly.SecondDerivative(3, x) == Approx(shifted_deriv2[3]).epsilon(floatTol) ); + CHECK( poly.SecondDerivative(4, x) == Approx(shifted_deriv2[4]).epsilon(floatTol) ); + + auto shifted_eval = shifted_legendre_eval(x); + auto shifted_deriv = shifted_legendre_deriv(x); + poly.EvaluateSecondDerivatives(&allvals[0], &allderivs[0], &allderivs2[0], 4, x); + CHECK( allvals[0] == shifted_eval[0] ); + CHECK( allvals[1] == Approx(shifted_eval[1]).epsilon(floatTol) ); + CHECK( allvals[2] == Approx(shifted_eval[2]).epsilon(floatTol) ); + CHECK( allvals[3] == Approx(shifted_eval[3]).epsilon(floatTol) ); + CHECK( allvals[4] == Approx(shifted_eval[4]).epsilon(floatTol) ); + CHECK( allderivs[0] == shifted_deriv[0]); + CHECK( allderivs[1] == shifted_deriv[1]); + CHECK( allderivs[2] == Approx(shifted_deriv[2]).epsilon(floatTol) ); + CHECK( allderivs[3] == Approx(shifted_deriv[3]).epsilon(floatTol) ); + CHECK( allderivs[4] == Approx(shifted_deriv[4]).epsilon(floatTol) ); + CHECK( allderivs2[0] == shifted_deriv2[0]); + CHECK( allderivs2[1] == shifted_deriv2[1]); + CHECK( allderivs2[2] == Approx(shifted_deriv2[2]).epsilon(floatTol) ); + CHECK( allderivs2[3] == Approx(shifted_deriv2[3]).epsilon(floatTol) ); + CHECK( allderivs2[4] == Approx(shifted_deriv2[4]).epsilon(floatTol) ); + } +} #if defined(KOKKOS_ENABLE_CUDA ) || defined(KOKKOS_ENABLE_SYCL) diff --git a/tests/Test_UnivariateBases.cpp b/tests/Test_UnivariateBases.cpp new file mode 100644 index 00000000..ef7c9646 --- /dev/null +++ b/tests/Test_UnivariateBases.cpp @@ -0,0 +1,118 @@ +#include + +#include "MParT/UnivariateBases.h" +using namespace mpart; + +using namespace Catch::Matchers; + +TEST_CASE( "Testing Sine basis", "[SineBasis]" ) { + + const double floatTol = 1e-12; + + SineBasis sine; + + std::vector xs{0.0, 0.1, 0.5, 0.75, 1.0}; + std::vector allvals(5); + std::vector allderivs(5); + std::vector allderivs2(5); + auto sine_evaluation = [](double x){return std::vector { + 1.0, + sin(2*M_PI*x), + sin(2*M_PI*2*x), + sin(2*M_PI*3*x), + sin(2*M_PI*4*x) + }; + }; + // Check the evaluation + for(auto& x : xs){ + auto sine_eval = sine_evaluation(x); + // CHECK_THAT(inv(0, i), WithinAbs(points(0, i), 1e-10)); + CHECK ( sine.Evaluate(0, x) == sine_eval[0] ); + CHECK_THAT( sine.Evaluate(1, x), WithinAbs(sine_eval[1], floatTol) ); + CHECK_THAT( sine.Evaluate(2, x), WithinAbs(sine_eval[2], floatTol) ); + CHECK_THAT( sine.Evaluate(3, x), WithinAbs(sine_eval[3], floatTol) ); + CHECK_THAT( sine.Evaluate(4, x), WithinAbs(sine_eval[4], floatTol) ); + + sine.EvaluateAll(&allvals[0], 4, x); + CHECK ( allvals[0] == sine_eval[0] ); + CHECK_THAT( allvals[1], WithinAbs(sine_eval[1], floatTol) ); + CHECK_THAT( allvals[2], WithinAbs(sine_eval[2], floatTol) ); + CHECK_THAT( allvals[3], WithinAbs(sine_eval[3], floatTol) ); + CHECK_THAT( allvals[4], WithinAbs(sine_eval[4], floatTol) ); + } + + auto sine_derivative = [](double x){return std::vector { + 0.0, + 1*2*M_PI*cos(1*2*M_PI*x), + 2*2*M_PI*cos(2*2*M_PI*x), + 3*2*M_PI*cos(3*2*M_PI*x), + 4*2*M_PI*cos(4*2*M_PI*x) + }; + }; + // CHECK_THAT the derivative + for(auto& x : xs){ + auto sine_deriv = sine_derivative(x); + CHECK ( sine.Derivative(0, x) == sine_deriv[0] ); + CHECK ( sine.Derivative(1, x) == sine_deriv[1] ); + CHECK_THAT( sine.Derivative(2, x), WithinAbs(sine_deriv[2], floatTol) ); + CHECK_THAT( sine.Derivative(3, x), WithinAbs(sine_deriv[3], floatTol) ); + CHECK_THAT( sine.Derivative(4, x), WithinAbs(sine_deriv[4], floatTol) ); + + auto sine_eval = sine_evaluation(x); + sine.EvaluateDerivatives(&allvals[0], &allderivs[0], 4, x); + CHECK ( allvals[0] == sine_eval[0] ); + CHECK_THAT( allvals[1], WithinAbs(sine_eval[1], floatTol) ); + CHECK_THAT( allvals[2], WithinAbs(sine_eval[2], floatTol) ); + CHECK_THAT( allvals[3], WithinAbs(sine_eval[3], floatTol) ); + CHECK_THAT( allvals[4], WithinAbs(sine_eval[4], floatTol) ); + CHECK ( allderivs[0] == sine_deriv[0] ); + CHECK ( allderivs[1] == sine_deriv[1] ); + CHECK_THAT( allderivs[2], WithinAbs(sine_deriv[2], floatTol) ); + CHECK_THAT( allderivs[3], WithinAbs(sine_deriv[3], floatTol) ); + CHECK_THAT( allderivs[4], WithinAbs(sine_deriv[4], floatTol) ); + + sine.EvaluateDerivatives(&allderivs[0], 4, x); + CHECK ( allderivs[0] == sine_deriv[0] ); + CHECK ( allderivs[1] == sine_deriv[1] ); + CHECK_THAT( allderivs[2], WithinAbs(sine_deriv[2], floatTol) ); + CHECK_THAT( allderivs[3], WithinAbs(sine_deriv[3], floatTol) ); + CHECK_THAT( allderivs[4], WithinAbs(sine_deriv[4], floatTol) ); + } + + auto sine_derivative2 = [](double x){return std::vector { + 0.0, + -(1*2*M_PI)*(1*2*M_PI)*sin(1*2*M_PI*x), + -(2*2*M_PI)*(2*2*M_PI)*sin(2*2*M_PI*x), + -(3*2*M_PI)*(3*2*M_PI)*sin(3*2*M_PI*x), + -(4*2*M_PI)*(4*2*M_PI)*sin(4*2*M_PI*x) + }; + }; + // CHECK_THAT the second derivatives + for(auto& x : xs){ + auto sine_deriv2 = sine_derivative2(x); + CHECK ( sine.SecondDerivative(0, x) == sine_deriv2[0] ); + CHECK ( sine.SecondDerivative(1, x) == sine_deriv2[1] ); + CHECK_THAT( sine.SecondDerivative(2, x), WithinAbs(sine_deriv2[2], floatTol) ); + CHECK_THAT( sine.SecondDerivative(3, x), WithinAbs(sine_deriv2[3], floatTol) ); + CHECK_THAT( sine.SecondDerivative(4, x), WithinAbs(sine_deriv2[4], floatTol) ); + + auto sine_eval = sine_evaluation(x); + auto sine_deriv = sine_derivative(x); + sine.EvaluateSecondDerivatives(&allvals[0], &allderivs[0], &allderivs2[0], 4, x); + CHECK ( allvals[0] == sine_eval[0] ); + CHECK_THAT( allvals[1], WithinAbs(sine_eval[1], floatTol) ); + CHECK_THAT( allvals[2], WithinAbs(sine_eval[2], floatTol) ); + CHECK_THAT( allvals[3], WithinAbs(sine_eval[3], floatTol) ); + CHECK_THAT( allvals[4], WithinAbs(sine_eval[4], floatTol) ); + CHECK ( allderivs[0] == sine_deriv[0] ); + CHECK ( allderivs[1] == sine_deriv[1] ); + CHECK_THAT( allderivs[2], WithinAbs(sine_deriv[2], floatTol) ); + CHECK_THAT( allderivs[3], WithinAbs(sine_deriv[3], floatTol) ); + CHECK_THAT( allderivs[4], WithinAbs(sine_deriv[4], floatTol) ); + CHECK ( allderivs2[0] == sine_deriv2[0] ); + CHECK ( allderivs2[1] == sine_deriv2[1] ); + CHECK_THAT( allderivs2[2], WithinAbs(sine_deriv2[2], floatTol) ); + CHECK_THAT( allderivs2[3], WithinAbs(sine_deriv2[3], floatTol) ); + CHECK_THAT( allderivs2[4], WithinAbs(sine_deriv2[4], floatTol) ); + } +} \ No newline at end of file From adfef6075568c0fc58315a0211a2115ebf13cab4 Mon Sep 17 00:00:00 2001 From: "D. Sharp" Date: Wed, 12 Jun 2024 16:32:09 -0600 Subject: [PATCH 03/11] Adding compact to create component --- MParT/MapFactory.h | 5 +++-- MParT/MonotoneComponent.h | 2 +- MParT/Utilities/Serialization.h | 4 ++-- src/MapFactoryImpl1.cpp | 33 ++++++++++++++++++++----------- src/MapFactoryImpl10.cpp | 18 ++++++++--------- src/MapFactoryImpl11.cpp | 18 ++++++++--------- src/MapFactoryImpl12.cpp | 18 ++++++++--------- src/MapFactoryImpl13.cpp | 18 ++++++++--------- src/MapFactoryImpl14.cpp | 18 ++++++++--------- src/MapFactoryImpl15.cpp | 18 ++++++++--------- src/MapFactoryImpl16.cpp | 18 ++++++++--------- src/MapFactoryImpl17.cpp | 18 ++++++++--------- src/MapFactoryImpl18.cpp | 18 ++++++++--------- src/MapFactoryImpl2.cpp | 31 +++++++++++++++++++---------- src/MapFactoryImpl3.cpp | 31 +++++++++++++++++++---------- src/MapFactoryImpl4.cpp | 31 +++++++++++++++++++---------- src/MapFactoryImpl5.cpp | 31 +++++++++++++++++++---------- src/MapFactoryImpl6.cpp | 30 ++++++++++++++++++---------- src/MapFactoryImpl7.cpp | 31 +++++++++++++++++++---------- src/MapFactoryImpl8.cpp | 35 ++++++++++++++++++++++----------- src/MapFactoryImpl9.cpp | 31 +++++++++++++++++++---------- 21 files changed, 278 insertions(+), 179 deletions(-) diff --git a/MParT/MapFactory.h b/MParT/MapFactory.h index 61ba09f4..e9f8d3e7 100644 --- a/MParT/MapFactory.h +++ b/MParT/MapFactory.h @@ -217,14 +217,15 @@ namespace mpart{ */ template struct CompFactoryImpl{ - typedef std::tuple OptionsKeyType; + typedef std::tuple OptionsKeyType; typedef std::function>(FixedMultiIndexSet const&, MapOptions options)> FactoryFunctionType; typedef std::map FactoryMapType; static FactoryFunctionType GetFactoryFunction(MapOptions opts) { bool isLinearized = (!isinf(opts.basisLB)) ||(!isinf(opts.basisUB)); - OptionsKeyType optionsKey(opts.basisType, isLinearized, opts.posFuncType, opts.quadType); + bool isCompact = false; // TODO: Create Options type here + OptionsKeyType optionsKey(opts.basisType, isLinearized, opts.posFuncType, opts.quadType, isCompact); auto factoryMap = GetFactoryMap(); diff --git a/MParT/MonotoneComponent.h b/MParT/MonotoneComponent.h index 2d1deec8..b309288e 100644 --- a/MParT/MonotoneComponent.h +++ b/MParT/MonotoneComponent.h @@ -1110,7 +1110,7 @@ class MonotoneComponent : public ConditionalMapBase } template - static void load_and_construct( Archive & ar, cereal::construct> & construct ) + static void load_and_construct( Archive & ar, cereal::construct> & construct ) { ExpansionType expansion; QuadratureType quad; diff --git a/MParT/Utilities/Serialization.h b/MParT/Utilities/Serialization.h index 8c945e10..4f71a7da 100644 --- a/MParT/Utilities/Serialization.h +++ b/MParT/Utilities/Serialization.h @@ -11,8 +11,8 @@ // A macro that can be used for registering the various MonotoneComponent classes with CEREAL // This macro is used in the MapFactoryImpl*.cpp files -#define REGISTER_MONO_COMP(BASIS_HOMOGENEITY, BASIS_TYPE, POS_TYPE, QUAD_TYPE, MEMORY_SPACE) \ - CEREAL_REGISTER_TYPE(mpart::MonotoneComponent, MEMORY_SPACE>, mpart::POS_TYPE, mpart::QUAD_TYPE, MEMORY_SPACE>) +#define REGISTER_MONO_COMP(BASIS_HOMOGENEITY, BASIS_TYPE, POS_TYPE, QUAD_TYPE, MEMORY_SPACE, IS_COMPACT) \ + CEREAL_REGISTER_TYPE(mpart::MonotoneComponent, MEMORY_SPACE>, mpart::POS_TYPE, mpart::QUAD_TYPE, MEMORY_SPACE, IS_COMPACT>) namespace cereal { diff --git a/src/MapFactoryImpl1.cpp b/src/MapFactoryImpl1.cpp index dc6ed1d6..a582d3e3 100644 --- a/src/MapFactoryImpl1.cpp +++ b/src/MapFactoryImpl1.cpp @@ -13,7 +13,7 @@ using namespace mpart; -template +template std::shared_ptr> CreateComponentImpl_Phys_ACC(FixedMultiIndexSet const& mset, MapOptions opts) { BasisEvaluator basis1d(opts.basisNorm); @@ -24,27 +24,38 @@ std::shared_ptr> CreateComponentImpl_Phys_ACC(Fi MultivariateExpansionWorker,MemorySpace> expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); return output; } -static auto reg_host_phys_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_Phys_ACC)); -static auto reg_host_phys_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_Phys_ACC)); +static auto reg_host_phys_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_Phys_ACC)); +static auto reg_host_phys_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_Phys_ACC)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_phys_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_Phys_ACC)); - static auto reg_device_phys_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_Phys_ACC)); + static auto reg_device_phys_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_Phys_ACC)); + static auto reg_device_phys_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_Phys_ACC)); +#endif + +static auto reg_host_phys_acc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_Phys_ACC)); +static auto reg_host_phys_acc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_Phys_ACC)); +#if defined(MPART_ENABLE_GPU) + static auto reg_device_phys_acc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_Phys_ACC)); + static auto reg_device_phys_acc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_Phys_ACC)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, true) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, true) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace) -#endif +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, true) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, true) +#endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory1) #endif diff --git a/src/MapFactoryImpl10.cpp b/src/MapFactoryImpl10.cpp index c7e2e8a8..df292277 100644 --- a/src/MapFactoryImpl10.cpp +++ b/src/MapFactoryImpl10.cpp @@ -24,7 +24,7 @@ std::shared_ptr> CreateComponentImpl_LinPhys_ACC MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -32,19 +32,19 @@ std::shared_ptr> CreateComponentImpl_LinPhys_ACC return output; } -static auto reg_host_linphys_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_LinPhys_ACC)); -static auto reg_host_linphys_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_LinPhys_ACC)); +static auto reg_host_linphys_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_LinPhys_ACC)); +static auto reg_host_linphys_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_LinPhys_ACC)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_linphys_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_LinPhys_ACC)); - static auto reg_device_linphys_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_LinPhys_ACC)); + static auto reg_device_linphys_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_LinPhys_ACC)); + static auto reg_device_linphys_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_LinPhys_ACC)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory10) #endif diff --git a/src/MapFactoryImpl11.cpp b/src/MapFactoryImpl11.cpp index c4e0299d..9c9c145b 100644 --- a/src/MapFactoryImpl11.cpp +++ b/src/MapFactoryImpl11.cpp @@ -22,7 +22,7 @@ std::shared_ptr> CreateComponentImpl_LinPhys_CC( MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -30,19 +30,19 @@ std::shared_ptr> CreateComponentImpl_LinPhys_CC( return output; } -static auto reg_host_linphys_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis), CreateComponentImpl_LinPhys_CC)); -static auto reg_host_linphys_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis), CreateComponentImpl_LinPhys_CC)); +static auto reg_host_linphys_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_LinPhys_CC)); +static auto reg_host_linphys_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_LinPhys_CC)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_linphys_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis), CreateComponentImpl_LinPhys_CC)); - static auto reg_device_linphys_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis), CreateComponentImpl_LinPhys_CC)); + static auto reg_device_linphys_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_LinPhys_CC)); + static auto reg_device_linphys_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_LinPhys_CC)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory11) #endif diff --git a/src/MapFactoryImpl12.cpp b/src/MapFactoryImpl12.cpp index 8723ce92..93fa6795 100644 --- a/src/MapFactoryImpl12.cpp +++ b/src/MapFactoryImpl12.cpp @@ -21,7 +21,7 @@ std::shared_ptr> CreateComponentImpl_LinPhys_AS( MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -29,19 +29,19 @@ std::shared_ptr> CreateComponentImpl_LinPhys_AS( return output; } -static auto reg_host_linphys_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson), CreateComponentImpl_LinPhys_AS)); -static auto reg_host_linphys_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson), CreateComponentImpl_LinPhys_AS)); +static auto reg_host_linphys_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_LinPhys_AS)); +static auto reg_host_linphys_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_LinPhys_AS)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_linphys_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson), CreateComponentImpl_LinPhys_AS)); - static auto reg_device_linphys_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson), CreateComponentImpl_LinPhys_AS)); + static auto reg_device_linphys_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_LinPhys_AS)); + static auto reg_device_linphys_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_LinPhys_AS)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveSimpson, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, false) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveSimpson, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, false) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory12) #endif diff --git a/src/MapFactoryImpl13.cpp b/src/MapFactoryImpl13.cpp index 757d9fb4..4a73cb9d 100644 --- a/src/MapFactoryImpl13.cpp +++ b/src/MapFactoryImpl13.cpp @@ -23,7 +23,7 @@ std::shared_ptr> CreateComponentImpl_LinProb_ACC MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -31,19 +31,19 @@ std::shared_ptr> CreateComponentImpl_LinProb_ACC return output; } -static auto reg_host_linprob_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_LinProb_ACC)); -static auto reg_host_linprob_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_LinProb_ACC)); +static auto reg_host_linprob_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_LinProb_ACC)); +static auto reg_host_linprob_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_LinProb_ACC)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_linprob_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_LinProb_ACC)); - static auto reg_device_linprob_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_LinProb_ACC)); + static auto reg_device_linprob_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_LinProb_ACC)); + static auto reg_device_linprob_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_LinProb_ACC)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory13) #endif diff --git a/src/MapFactoryImpl14.cpp b/src/MapFactoryImpl14.cpp index 794b70b9..0257c99e 100644 --- a/src/MapFactoryImpl14.cpp +++ b/src/MapFactoryImpl14.cpp @@ -21,7 +21,7 @@ std::shared_ptr> CreateComponentImpl_LinProb_CC( MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -29,19 +29,19 @@ std::shared_ptr> CreateComponentImpl_LinProb_CC( return output; } -static auto reg_host_linprob_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis), CreateComponentImpl_LinProb_CC)); -static auto reg_host_linprob_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis), CreateComponentImpl_LinProb_CC)); +static auto reg_host_linprob_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_LinProb_CC)); +static auto reg_host_linprob_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_LinProb_CC)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_linprob_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis), CreateComponentImpl_LinProb_CC)); - static auto reg_device_linprob_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis), CreateComponentImpl_LinProb_CC)); + static auto reg_device_linprob_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_LinProb_CC)); + static auto reg_device_linprob_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_LinProb_CC)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory14) #endif diff --git a/src/MapFactoryImpl15.cpp b/src/MapFactoryImpl15.cpp index f5ae8513..8390b62d 100644 --- a/src/MapFactoryImpl15.cpp +++ b/src/MapFactoryImpl15.cpp @@ -21,7 +21,7 @@ std::shared_ptr> CreateComponentImpl_LinProb_AS( MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -29,19 +29,19 @@ std::shared_ptr> CreateComponentImpl_LinProb_AS( return output; } -static auto reg_host_linprob_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson), CreateComponentImpl_LinProb_AS)); -static auto reg_host_linprob_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson), CreateComponentImpl_LinProb_AS)); +static auto reg_host_linprob_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_LinProb_AS)); +static auto reg_host_linprob_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_LinProb_AS)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_linprob_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson), CreateComponentImpl_LinProb_AS)); - static auto reg_device_linprob_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson), CreateComponentImpl_LinProb_AS)); + static auto reg_device_linprob_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_LinProb_AS)); + static auto reg_device_linprob_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_LinProb_AS)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveSimpson, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, false) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveSimpson, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, false) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory15) #endif diff --git a/src/MapFactoryImpl16.cpp b/src/MapFactoryImpl16.cpp index 40f9c109..f51c9134 100644 --- a/src/MapFactoryImpl16.cpp +++ b/src/MapFactoryImpl16.cpp @@ -21,7 +21,7 @@ std::shared_ptr> CreateComponentImpl_LinHF_AS(Fi MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -29,19 +29,19 @@ std::shared_ptr> CreateComponentImpl_LinHF_AS(Fi return output; } -static auto reg_host_linhf_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson), CreateComponentImpl_LinHF_AS)); -static auto reg_host_linhf_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson), CreateComponentImpl_LinHF_AS)); +static auto reg_host_linhf_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_LinHF_AS)); +static auto reg_host_linhf_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_LinHF_AS)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_linhf_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson), CreateComponentImpl_LinHF_AS)); - static auto reg_device_linhf_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson), CreateComponentImpl_LinHF_AS)); + static auto reg_device_linhf_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_LinHF_AS)); + static auto reg_device_linhf_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_LinHF_AS)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveSimpson, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, false) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveSimpson, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, false) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory16) #endif diff --git a/src/MapFactoryImpl17.cpp b/src/MapFactoryImpl17.cpp index f14fae97..868a8858 100644 --- a/src/MapFactoryImpl17.cpp +++ b/src/MapFactoryImpl17.cpp @@ -21,7 +21,7 @@ std::shared_ptr> CreateComponentImpl_LinHF_CC(Fi MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -29,19 +29,19 @@ std::shared_ptr> CreateComponentImpl_LinHF_CC(Fi return output; } -static auto reg_host_linhf_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis), CreateComponentImpl_LinHF_CC)); -static auto reg_host_linhf_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis), CreateComponentImpl_LinHF_CC)); +static auto reg_host_linhf_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_LinHF_CC)); +static auto reg_host_linhf_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_LinHF_CC)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_linhf_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis), CreateComponentImpl_LinHF_CC)); - static auto reg_device_linhf_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis), CreateComponentImpl_LinHF_CC)); + static auto reg_device_linhf_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_LinHF_CC)); + static auto reg_device_linhf_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_LinHF_CC)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory17) #endif diff --git a/src/MapFactoryImpl18.cpp b/src/MapFactoryImpl18.cpp index f135404a..ae8c6e6d 100644 --- a/src/MapFactoryImpl18.cpp +++ b/src/MapFactoryImpl18.cpp @@ -22,7 +22,7 @@ std::shared_ptr> CreateComponentImpl_LinHF_ACC(F MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -30,19 +30,19 @@ std::shared_ptr> CreateComponentImpl_LinHF_ACC(F return output; } -static auto reg_host_linhf_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_LinHF_ACC)); -static auto reg_host_linhf_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_LinHF_ACC)); +static auto reg_host_linhf_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_LinHF_ACC)); +static auto reg_host_linhf_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_LinHF_ACC)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_linhf_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_LinHF_ACC)); - static auto reg_device_linhf_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_LinHF_ACC)); + static auto reg_device_linhf_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_LinHF_ACC)); + static auto reg_device_linhf_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_LinHF_ACC)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory18) #endif diff --git a/src/MapFactoryImpl2.cpp b/src/MapFactoryImpl2.cpp index 67ebc2bc..6c29358d 100644 --- a/src/MapFactoryImpl2.cpp +++ b/src/MapFactoryImpl2.cpp @@ -11,7 +11,7 @@ using namespace mpart; -template +template std::shared_ptr> CreateComponentImpl_Phys_CC(FixedMultiIndexSet const& mset, MapOptions opts) { BasisEvaluator basis1d(opts.basisNorm); @@ -20,26 +20,37 @@ std::shared_ptr> CreateComponentImpl_Phys_CC(Fix MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); return output; } -static auto reg_host_phys_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis), CreateComponentImpl_Phys_CC)); -static auto reg_host_phys_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis), CreateComponentImpl_Phys_CC)); +static auto reg_host_phys_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_Phys_CC)); +static auto reg_host_phys_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_Phys_CC)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_phys_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis), CreateComponentImpl_Phys_CC)); - static auto reg_device_phys_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis), CreateComponentImpl_Phys_CC)); + static auto reg_device_phys_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_Phys_CC)); + static auto reg_device_phys_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_Phys_CC)); +#endif + +static auto reg_host_phys_cc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_Phys_CC)); +static auto reg_host_phys_cc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_Phys_CC)); +#if defined(MPART_ENABLE_GPU) + static auto reg_device_phys_cc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_Phys_CC)); + static auto reg_device_phys_cc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_Phys_CC)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, true) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, true) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, true) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, true) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory2) #endif diff --git a/src/MapFactoryImpl3.cpp b/src/MapFactoryImpl3.cpp index b7b19289..b5d20e26 100644 --- a/src/MapFactoryImpl3.cpp +++ b/src/MapFactoryImpl3.cpp @@ -10,7 +10,7 @@ using namespace mpart; -template +template std::shared_ptr> CreateComponentImpl_Phys_AS(FixedMultiIndexSet const& mset, MapOptions opts) { BasisEvaluator basis1d(opts.basisNorm); @@ -19,7 +19,7 @@ std::shared_ptr> CreateComponentImpl_Phys_AS(Fix MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -27,19 +27,30 @@ std::shared_ptr> CreateComponentImpl_Phys_AS(Fix return output; } -static auto reg_host_phys_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson), CreateComponentImpl_Phys_AS)); -static auto reg_host_phys_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson), CreateComponentImpl_Phys_AS)); +static auto reg_host_phys_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_Phys_AS)); +static auto reg_host_phys_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_Phys_AS)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_phys_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson), CreateComponentImpl_Phys_AS)); - static auto reg_device_phys_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson), CreateComponentImpl_Phys_AS)); + static auto reg_device_phys_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_Phys_AS)); + static auto reg_device_phys_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_Phys_AS)); +#endif + +static auto reg_host_phys_as_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, true), CreateComponentImpl_Phys_AS)); +static auto reg_host_phys_as_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, true), CreateComponentImpl_Phys_AS)); +#if defined(MPART_ENABLE_GPU) + static auto reg_device_phys_as_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, true), CreateComponentImpl_Phys_AS)); + static auto reg_device_phys_as_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, true), CreateComponentImpl_Phys_AS)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, AdaptiveSimpson, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, AdaptiveSimpson, Kokkos::HostSpace, true) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, true) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, AdaptiveSimpson, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, AdaptiveSimpson, mpart::DeviceSpace, true) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, true) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory3) #endif diff --git a/src/MapFactoryImpl4.cpp b/src/MapFactoryImpl4.cpp index e1f8edc7..379c5bc1 100644 --- a/src/MapFactoryImpl4.cpp +++ b/src/MapFactoryImpl4.cpp @@ -10,7 +10,7 @@ using namespace mpart; -template +template std::shared_ptr> CreateComponentImpl_Prob_ACC(FixedMultiIndexSet const& mset, MapOptions opts) { BasisEvaluator basis1d(opts.basisNorm); @@ -21,7 +21,7 @@ std::shared_ptr> CreateComponentImpl_Prob_ACC(Fi MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -29,19 +29,30 @@ std::shared_ptr> CreateComponentImpl_Prob_ACC(Fi return output; } -static auto reg_host_prob_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_Prob_ACC)); -static auto reg_host_prob_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_Prob_ACC)); +static auto reg_host_prob_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_Prob_ACC)); +static auto reg_host_prob_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_Prob_ACC)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_prob_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_Prob_ACC)); - static auto reg_device_prob_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_Prob_ACC)); + static auto reg_device_prob_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_Prob_ACC)); + static auto reg_device_prob_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_Prob_ACC)); +#endif + +static auto reg_host_prob_acc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_Prob_ACC)); +static auto reg_host_prob_acc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_Prob_ACC)); +#if defined(MPART_ENABLE_GPU) + static auto reg_device_prob_acc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_Prob_ACC)); + static auto reg_device_prob_acc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_Prob_ACC)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, true) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, true) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, true) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, true) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory4) #endif diff --git a/src/MapFactoryImpl5.cpp b/src/MapFactoryImpl5.cpp index 4bc9a03a..68fff603 100644 --- a/src/MapFactoryImpl5.cpp +++ b/src/MapFactoryImpl5.cpp @@ -10,7 +10,7 @@ using namespace mpart; -template +template std::shared_ptr> CreateComponentImpl_Prob_CC(FixedMultiIndexSet const& mset, MapOptions opts) { BasisEvaluator basis1d(opts.basisNorm); @@ -19,7 +19,7 @@ std::shared_ptr> CreateComponentImpl_Prob_CC(Fix MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -27,19 +27,30 @@ std::shared_ptr> CreateComponentImpl_Prob_CC(Fix return output; } -static auto reg_host_prob_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis), CreateComponentImpl_Prob_CC)); -static auto reg_host_prob_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis), CreateComponentImpl_Prob_CC)); +static auto reg_host_prob_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_Prob_CC)); +static auto reg_host_prob_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_Prob_CC)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_prob_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis), CreateComponentImpl_Prob_CC)); - static auto reg_device_prob_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis), CreateComponentImpl_Prob_CC)); + static auto reg_device_prob_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_Prob_CC)); + static auto reg_device_prob_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_Prob_CC)); +#endif + +static auto reg_host_prob_cc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_Prob_CC)); +static auto reg_host_prob_cc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_Prob_CC)); +#if defined(MPART_ENABLE_GPU) + static auto reg_device_prob_cc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_Prob_CC)); + static auto reg_device_prob_cc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_Prob_CC)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, true) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, true) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, true) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, true) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory5) #endif diff --git a/src/MapFactoryImpl6.cpp b/src/MapFactoryImpl6.cpp index 0e51786e..17dcc1d7 100644 --- a/src/MapFactoryImpl6.cpp +++ b/src/MapFactoryImpl6.cpp @@ -10,7 +10,7 @@ using namespace mpart; -template +template std::shared_ptr> CreateComponentImpl_Prob_AS(FixedMultiIndexSet const& mset, MapOptions opts) { BasisEvaluator basis1d(opts.basisNorm); @@ -19,7 +19,7 @@ std::shared_ptr> CreateComponentImpl_Prob_AS(Fix MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -27,20 +27,30 @@ std::shared_ptr> CreateComponentImpl_Prob_AS(Fix return output; } -static auto reg_host_prob_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson), CreateComponentImpl_Prob_AS)); -static auto reg_host_prob_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson), CreateComponentImpl_Prob_AS)); +static auto reg_host_prob_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_Prob_AS)); +static auto reg_host_prob_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_Prob_AS)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_prob_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson), CreateComponentImpl_Prob_AS)); - static auto reg_device_prob_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson), CreateComponentImpl_Prob_AS)); + static auto reg_device_prob_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_Prob_AS)); + static auto reg_device_prob_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_Prob_AS)); #endif +static auto reg_host_prob_as_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, true), CreateComponentImpl_Prob_AS)); +static auto reg_host_prob_as_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, true), CreateComponentImpl_Prob_AS)); +#if defined(MPART_ENABLE_GPU) + static auto reg_device_prob_as_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, true), CreateComponentImpl_Prob_AS)); + static auto reg_device_prob_as_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, true), CreateComponentImpl_Prob_AS)); +#endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, AdaptiveSimpson, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, AdaptiveSimpson, Kokkos::HostSpace, true) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, true) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, AdaptiveSimpson, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, AdaptiveSimpson, mpart::DeviceSpace, true) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, true) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory6) #endif diff --git a/src/MapFactoryImpl7.cpp b/src/MapFactoryImpl7.cpp index 6a29d336..fafa9996 100644 --- a/src/MapFactoryImpl7.cpp +++ b/src/MapFactoryImpl7.cpp @@ -10,7 +10,7 @@ using namespace mpart; -template +template std::shared_ptr> CreateComponentImpl_HF_ACC(FixedMultiIndexSet const& mset, MapOptions opts) { BasisEvaluator basis1d; @@ -21,7 +21,7 @@ std::shared_ptr> CreateComponentImpl_HF_ACC(Fixe MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -29,20 +29,31 @@ std::shared_ptr> CreateComponentImpl_HF_ACC(Fixe return output; } -static auto reg_host_hf_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_HF_ACC)); -static auto reg_host_hf_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_HF_ACC)); +static auto reg_host_hf_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_HF_ACC)); +static auto reg_host_hf_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_HF_ACC)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_hf_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_HF_ACC)); - static auto reg_device_hf_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_HF_ACC)); + static auto reg_device_hf_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_HF_ACC)); + static auto reg_device_hf_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_HF_ACC)); #endif +static auto reg_host_hf_acc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_HF_ACC)); +static auto reg_host_hf_acc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_HF_ACC)); +#if defined(MPART_ENABLE_GPU) + static auto reg_device_hf_acc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_HF_ACC)); + static auto reg_device_hf_acc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_HF_ACC)); +#endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, true) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, true) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, true) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, true) #endif + CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory7) #endif diff --git a/src/MapFactoryImpl8.cpp b/src/MapFactoryImpl8.cpp index 04a91cc5..338b6d28 100644 --- a/src/MapFactoryImpl8.cpp +++ b/src/MapFactoryImpl8.cpp @@ -10,7 +10,7 @@ using namespace mpart; -template +template std::shared_ptr> CreateComponentImpl_HF_CC(FixedMultiIndexSet const& mset, MapOptions opts) { BasisEvaluator basis1d; @@ -19,7 +19,7 @@ std::shared_ptr> CreateComponentImpl_HF_CC(Fixed MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -27,19 +27,30 @@ std::shared_ptr> CreateComponentImpl_HF_CC(Fixed return output; } -static auto reg_host_hf_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis), CreateComponentImpl_HF_CC)); -static auto reg_host_hf_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis), CreateComponentImpl_HF_CC)); +static auto reg_host_hf_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_HF_CC)); +static auto reg_host_hf_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_HF_CC)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_hf_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis), CreateComponentImpl_HF_CC)); - static auto reg_device_hf_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis), CreateComponentImpl_HF_CC)); + static auto reg_device_hf_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_HF_CC)); + static auto reg_device_hf_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_HF_CC)); +#endif + +static auto reg_host_hf_cc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_HF_CC)); +static auto reg_host_hf_cc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_HF_CC)); +#if defined(MPART_ENABLE_GPU) + static auto reg_device_hf_cc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_HF_CC)); + static auto reg_device_hf_cc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_HF_CC)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, true) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, true) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace) -#endif -CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory8) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, true) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, true) #endif +CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory8) +#endif \ No newline at end of file diff --git a/src/MapFactoryImpl9.cpp b/src/MapFactoryImpl9.cpp index 11313bfc..a3417cad 100644 --- a/src/MapFactoryImpl9.cpp +++ b/src/MapFactoryImpl9.cpp @@ -10,7 +10,7 @@ using namespace mpart; -template +template std::shared_ptr> CreateComponentImpl_HF_AS(FixedMultiIndexSet const& mset, MapOptions opts) { BasisEvaluator basis1d; @@ -19,7 +19,7 @@ std::shared_ptr> CreateComponentImpl_HF_AS(Fixed MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -27,19 +27,30 @@ std::shared_ptr> CreateComponentImpl_HF_AS(Fixed return output; } -static auto reg_host_hf_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson), CreateComponentImpl_HF_AS)); -static auto reg_host_hf_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson), CreateComponentImpl_HF_AS)); +static auto reg_host_hf_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_HF_AS)); +static auto reg_host_hf_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_HF_AS)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_hf_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson), CreateComponentImpl_HF_AS)); - static auto reg_device_hf_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson), CreateComponentImpl_HF_AS)); + static auto reg_device_hf_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_HF_AS)); + static auto reg_device_hf_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_HF_AS)); +#endif + +static auto reg_host_hf_as_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, true), CreateComponentImpl_HF_AS)); +static auto reg_host_hf_as_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, true), CreateComponentImpl_HF_AS)); +#if defined(MPART_ENABLE_GPU) + static auto reg_device_hf_as_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, true), CreateComponentImpl_HF_AS)); + static auto reg_device_hf_as_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, true), CreateComponentImpl_HF_AS)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, Exp, AdaptiveSimpson, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, Exp, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, Exp, AdaptiveSimpson, Kokkos::HostSpace, true) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, true) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, Exp, AdaptiveSimpson, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, Exp, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, Exp, AdaptiveSimpson, mpart::DeviceSpace, true) +REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, true) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory9) #endif From 9bfba95e16718ca2c2825a76863a1c86fac35963 Mon Sep 17 00:00:00 2001 From: "D. Sharp" Date: Wed, 12 Jun 2024 17:07:48 -0600 Subject: [PATCH 04/11] Compiling and running serialization --- MParT/BasisEvaluator.h | 2 +- MParT/MapOptions.h | 3 ++- MParT/Utilities/Serialization.h | 6 +++-- src/CMakeLists.txt | 1 + src/MapFactoryImpl1.cpp | 16 +++++------ src/MapFactoryImpl10.cpp | 8 +++--- src/MapFactoryImpl11.cpp | 8 +++--- src/MapFactoryImpl12.cpp | 8 +++--- src/MapFactoryImpl13.cpp | 8 +++--- src/MapFactoryImpl14.cpp | 8 +++--- src/MapFactoryImpl15.cpp | 8 +++--- src/MapFactoryImpl16.cpp | 8 +++--- src/MapFactoryImpl17.cpp | 8 +++--- src/MapFactoryImpl18.cpp | 8 +++--- src/MapFactoryImpl19.cpp | 48 +++++++++++++++++++++++++++++++++ src/MapFactoryImpl2.cpp | 16 +++++------ src/MapFactoryImpl3.cpp | 16 +++++------ src/MapFactoryImpl4.cpp | 16 +++++------ src/MapFactoryImpl5.cpp | 16 +++++------ src/MapFactoryImpl6.cpp | 16 +++++------ src/MapFactoryImpl7.cpp | 16 +++++------ src/MapFactoryImpl8.cpp | 16 +++++------ src/MapFactoryImpl9.cpp | 16 +++++------ 23 files changed, 164 insertions(+), 112 deletions(-) create mode 100644 src/MapFactoryImpl19.cpp diff --git a/MParT/BasisEvaluator.h b/MParT/BasisEvaluator.h index 66bd731c..fcd859f7 100644 --- a/MParT/BasisEvaluator.h +++ b/MParT/BasisEvaluator.h @@ -234,7 +234,7 @@ class BasisEvaluator, MEMORY_SPACE>, mpart::POS_TYPE, mpart::QUAD_TYPE, MEMORY_SPACE, IS_COMPACT>) +#define REGISTER_HOMOGENEOUS_MONO_COMP(BASIS_TYPE, POS_TYPE, QUAD_TYPE, MEMORY_SPACE, IS_COMPACT) \ + CEREAL_REGISTER_TYPE(mpart::MonotoneComponent, MEMORY_SPACE>, mpart::POS_TYPE, mpart::QUAD_TYPE, MEMORY_SPACE, IS_COMPACT>) +#define REGISTER_OFFDIAGHOMOGENEOUS_MONO_COMP(BASIS_TYPE_1, BASIS_TYPE_2, RECTIFIER, POS_TYPE, QUAD_TYPE, MEMORY_SPACE, IS_COMPACT) \ + CEREAL_REGISTER_TYPE(mpart::MonotoneComponent, RECTIFIER>, MEMORY_SPACE>, mpart::POS_TYPE, mpart::QUAD_TYPE, MEMORY_SPACE, IS_COMPACT>) namespace cereal { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d3fcd002..827949b4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -54,6 +54,7 @@ target_sources(mpart MapFactoryImpl16.cpp MapFactoryImpl17.cpp MapFactoryImpl18.cpp + MapFactoryImpl19.cpp ${MPART_OPT_FILES} Initialization.cpp diff --git a/src/MapFactoryImpl1.cpp b/src/MapFactoryImpl1.cpp index a582d3e3..9ab8f06f 100644 --- a/src/MapFactoryImpl1.cpp +++ b/src/MapFactoryImpl1.cpp @@ -46,15 +46,15 @@ static auto reg_host_phys_acc_splus_compact = mpart::MapFactory::CompFactoryImpl #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, true) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, true) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, true) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, true) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory1) diff --git a/src/MapFactoryImpl10.cpp b/src/MapFactoryImpl10.cpp index df292277..676c0cd3 100644 --- a/src/MapFactoryImpl10.cpp +++ b/src/MapFactoryImpl10.cpp @@ -40,11 +40,11 @@ static auto reg_host_linphys_acc_splus = mpart::MapFactory::CompFactoryImpl, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory10) #endif diff --git a/src/MapFactoryImpl11.cpp b/src/MapFactoryImpl11.cpp index 9c9c145b..39c6d235 100644 --- a/src/MapFactoryImpl11.cpp +++ b/src/MapFactoryImpl11.cpp @@ -38,11 +38,11 @@ static auto reg_host_linphys_cc_splus = mpart::MapFactory::CompFactoryImpl, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory11) #endif diff --git a/src/MapFactoryImpl12.cpp b/src/MapFactoryImpl12.cpp index 93fa6795..dfc0f036 100644 --- a/src/MapFactoryImpl12.cpp +++ b/src/MapFactoryImpl12.cpp @@ -37,11 +37,11 @@ static auto reg_host_linphys_as_splus = mpart::MapFactory::CompFactoryImpl, Exp, AdaptiveSimpson, Kokkos::HostSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, false) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveSimpson, mpart::DeviceSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, false) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory12) #endif diff --git a/src/MapFactoryImpl13.cpp b/src/MapFactoryImpl13.cpp index 4a73cb9d..b1899974 100644 --- a/src/MapFactoryImpl13.cpp +++ b/src/MapFactoryImpl13.cpp @@ -39,11 +39,11 @@ static auto reg_host_linprob_acc_splus = mpart::MapFactory::CompFactoryImpl, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory13) #endif diff --git a/src/MapFactoryImpl14.cpp b/src/MapFactoryImpl14.cpp index 0257c99e..96c79f18 100644 --- a/src/MapFactoryImpl14.cpp +++ b/src/MapFactoryImpl14.cpp @@ -37,11 +37,11 @@ static auto reg_host_linprob_cc_splus = mpart::MapFactory::CompFactoryImpl, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory14) #endif diff --git a/src/MapFactoryImpl15.cpp b/src/MapFactoryImpl15.cpp index 8390b62d..749113b0 100644 --- a/src/MapFactoryImpl15.cpp +++ b/src/MapFactoryImpl15.cpp @@ -37,11 +37,11 @@ static auto reg_host_linprob_as_splus = mpart::MapFactory::CompFactoryImpl, Exp, AdaptiveSimpson, Kokkos::HostSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, false) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveSimpson, mpart::DeviceSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, false) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory15) #endif diff --git a/src/MapFactoryImpl16.cpp b/src/MapFactoryImpl16.cpp index f51c9134..c582f684 100644 --- a/src/MapFactoryImpl16.cpp +++ b/src/MapFactoryImpl16.cpp @@ -37,11 +37,11 @@ static auto reg_host_linhf_as_splus = mpart::MapFactory::CompFactoryImpl, Exp, AdaptiveSimpson, Kokkos::HostSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, false) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveSimpson, mpart::DeviceSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, false) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory16) #endif diff --git a/src/MapFactoryImpl17.cpp b/src/MapFactoryImpl17.cpp index 868a8858..3c80fb03 100644 --- a/src/MapFactoryImpl17.cpp +++ b/src/MapFactoryImpl17.cpp @@ -37,11 +37,11 @@ static auto reg_host_linhf_cc_splus = mpart::MapFactory::CompFactoryImpl, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory17) #endif diff --git a/src/MapFactoryImpl18.cpp b/src/MapFactoryImpl18.cpp index ae8c6e6d..1c3d0616 100644 --- a/src/MapFactoryImpl18.cpp +++ b/src/MapFactoryImpl18.cpp @@ -38,11 +38,11 @@ static auto reg_host_linhf_acc_splus = mpart::MapFactory::CompFactoryImpl, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory18) #endif diff --git a/src/MapFactoryImpl19.cpp b/src/MapFactoryImpl19.cpp new file mode 100644 index 00000000..46b7f910 --- /dev/null +++ b/src/MapFactoryImpl19.cpp @@ -0,0 +1,48 @@ +#include "MParT/MapFactory.h" + +#include "MParT/MonotoneComponent.h" +#include "MParT/TriangularMap.h" +#include "MParT/Quadrature.h" + +#include "MParT/UnivariateBases.h" +#include "MParT/OrthogonalPolynomial.h" +#include "MParT/MultivariateExpansionWorker.h" +#include "MParT/PositiveBijectors.h" + +using namespace mpart; + +using BasisType = Kokkos::pair; + +template +std::shared_ptr> CreateComponentImpl_SL_CC(FixedMultiIndexSet const& mset, MapOptions opts) +{ + BasisEvaluator basis1d(mset.Length()); + ClenshawCurtisQuadrature quad(opts.quadPts, 1); + + MultivariateExpansionWorker expansion(mset, basis1d); + std::shared_ptr> output; + + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + + Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); + output->SetCoeffs(coeffs); + + return output; +} + +static auto reg_host_sl_cc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::SinusoidLegendre, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_SL_CC)); +static auto reg_host_sl_cc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::SinusoidLegendre, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_SL_CC)); +#if defined(MPART_ENABLE_GPU) + static auto reg_device_sl_cc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::SinusoidLegendre, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_SL_CC)); + static auto reg_device_sl_cc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::SinusoidLegendre, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_SL_CC)); +#endif + +#if defined(MPART_HAS_CEREAL) +REGISTER_OFFDIAGHOMOGENEOUS_MONO_COMP(SineBasis, ShiftedLegendre, Identity, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, true) +REGISTER_OFFDIAGHOMOGENEOUS_MONO_COMP(SineBasis, ShiftedLegendre, Identity, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, true) +#if defined(MPART_ENABLE_GPU) +REGISTER_OFFDIAGHOMOGENEOUS_MONO_COMP(SineBasis, ShiftedLegendre, Identity, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, true) +REGISTER_OFFDIAGHOMOGENEOUS_MONO_COMP(SineBasis, ShiftedLegendre, Identity, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, true) +#endif +CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory19) +#endif \ No newline at end of file diff --git a/src/MapFactoryImpl2.cpp b/src/MapFactoryImpl2.cpp index 6c29358d..c297f7d4 100644 --- a/src/MapFactoryImpl2.cpp +++ b/src/MapFactoryImpl2.cpp @@ -42,15 +42,15 @@ static auto reg_host_phys_cc_splus_compact = mpart::MapFactory::CompFactoryImpl< #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, true) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, true) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, true) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, true) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory2) #endif diff --git a/src/MapFactoryImpl3.cpp b/src/MapFactoryImpl3.cpp index b5d20e26..12ccdcfe 100644 --- a/src/MapFactoryImpl3.cpp +++ b/src/MapFactoryImpl3.cpp @@ -42,15 +42,15 @@ static auto reg_host_phys_as_splus_compact = mpart::MapFactory::CompFactoryImpl< #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, AdaptiveSimpson, Kokkos::HostSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, AdaptiveSimpson, Kokkos::HostSpace, true) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, Exp, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, Exp, AdaptiveSimpson, Kokkos::HostSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, true) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, AdaptiveSimpson, mpart::DeviceSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, AdaptiveSimpson, mpart::DeviceSpace, true) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, Exp, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, Exp, AdaptiveSimpson, mpart::DeviceSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, true) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory3) #endif diff --git a/src/MapFactoryImpl4.cpp b/src/MapFactoryImpl4.cpp index 379c5bc1..b30238ef 100644 --- a/src/MapFactoryImpl4.cpp +++ b/src/MapFactoryImpl4.cpp @@ -44,15 +44,15 @@ static auto reg_host_prob_acc_splus_compact = mpart::MapFactory::CompFactoryImpl #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, true) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, true) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, true) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, true) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory4) #endif diff --git a/src/MapFactoryImpl5.cpp b/src/MapFactoryImpl5.cpp index 68fff603..82031fe8 100644 --- a/src/MapFactoryImpl5.cpp +++ b/src/MapFactoryImpl5.cpp @@ -42,15 +42,15 @@ static auto reg_host_prob_cc_splus_compact = mpart::MapFactory::CompFactoryImpl< #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, true) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, true) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, true) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, true) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory5) #endif diff --git a/src/MapFactoryImpl6.cpp b/src/MapFactoryImpl6.cpp index 17dcc1d7..5589a30b 100644 --- a/src/MapFactoryImpl6.cpp +++ b/src/MapFactoryImpl6.cpp @@ -42,15 +42,15 @@ static auto reg_host_prob_as_splus_compact = mpart::MapFactory::CompFactoryImpl< #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, AdaptiveSimpson, Kokkos::HostSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, AdaptiveSimpson, Kokkos::HostSpace, true) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, Exp, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, Exp, AdaptiveSimpson, Kokkos::HostSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, true) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, AdaptiveSimpson, mpart::DeviceSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, false) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, AdaptiveSimpson, mpart::DeviceSpace, true) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, Exp, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, Exp, AdaptiveSimpson, mpart::DeviceSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, true) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory6) #endif diff --git a/src/MapFactoryImpl7.cpp b/src/MapFactoryImpl7.cpp index fafa9996..cc5ae0c3 100644 --- a/src/MapFactoryImpl7.cpp +++ b/src/MapFactoryImpl7.cpp @@ -44,15 +44,15 @@ static auto reg_host_hf_acc_splus_compact = mpart::MapFactory::CompFactoryImpl Date: Wed, 12 Jun 2024 18:02:02 -0600 Subject: [PATCH 05/11] Working inversion --- MParT/MapFactory.h | 2 +- MParT/MapOptions.h | 2 + MParT/MonotoneComponent.h | 3 + tests/CMakeLists.txt | 1 + tests/Test_MonotoneComponent.cpp | 11 - tests/Test_MonotoneComponent_compact.cpp | 801 +++++++++++++++++++++++ 6 files changed, 808 insertions(+), 12 deletions(-) create mode 100644 tests/Test_MonotoneComponent_compact.cpp diff --git a/MParT/MapFactory.h b/MParT/MapFactory.h index e9f8d3e7..3cb02872 100644 --- a/MParT/MapFactory.h +++ b/MParT/MapFactory.h @@ -224,7 +224,7 @@ namespace mpart{ static FactoryFunctionType GetFactoryFunction(MapOptions opts) { bool isLinearized = (!isinf(opts.basisLB)) ||(!isinf(opts.basisUB)); - bool isCompact = false; // TODO: Create Options type here + bool isCompact = opts.isCompact; OptionsKeyType optionsKey(opts.basisType, isLinearized, opts.posFuncType, opts.quadType, isCompact); auto factoryMap = GetFactoryMap(); diff --git a/MParT/MapOptions.h b/MParT/MapOptions.h index 61088eb3..5a89f0f2 100644 --- a/MParT/MapOptions.h +++ b/MParT/MapOptions.h @@ -77,6 +77,8 @@ namespace mpart{ double basisLB = -std::numeric_limits::infinity(); double basisUB = std::numeric_limits::infinity(); + /** Whether the map should be compactly supported (cannot be linearized, only works with certain other map options */ + bool isCompact = false; /** The type of positive bijector used inside the monotonicity-guaranteeing integral formulation. diff --git a/MParT/MonotoneComponent.h b/MParT/MonotoneComponent.h index b309288e..02348211 100644 --- a/MParT/MonotoneComponent.h +++ b/MParT/MonotoneComponent.h @@ -417,6 +417,9 @@ class MonotoneComponent : public ConditionalMapBase double y_scale = ys(ptInd); if constexpr(isCompact) y_scale *= eval(1); output(ptInd) = RootFinding::InverseSingleBracket(y_scale, eval, pt(pt.extent(0)-1), xtol, ytol, info); + if constexpr(isCompact) { + output(ptInd) = fmin(fmax(output(ptInd), 0.0), 1.0); + } } }; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 72538d39..4bd159da 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -36,6 +36,7 @@ set (TEST_SOURCES tests/Test_PositiveBijectors.cpp tests/Test_Quadrature.cpp tests/Test_MonotoneComponent.cpp + tests/Test_MonotoneComponent_compact.cpp tests/Test_MultivariateExpansion.cpp tests/Test_BasisEvaluator.cpp tests/Test_MultivariateExpansionWorker.cpp diff --git a/tests/Test_MonotoneComponent.cpp b/tests/Test_MonotoneComponent.cpp index 87700998..b94a51a1 100644 --- a/tests/Test_MonotoneComponent.cpp +++ b/tests/Test_MonotoneComponent.cpp @@ -11,10 +11,6 @@ #include -// TO REMOVE -#include -#include - using namespace mpart; using namespace Catch; using HostSpace = Kokkos::HostSpace; @@ -108,8 +104,6 @@ TEST_CASE( "MonotoneIntegrand1d", "[MonotoneIntegrand1d]") { } } - - TEST_CASE( "MonotoneIntegrand1d With Nugget", "[MonotoneIntegrand1d]") { const double testTol = 1e-7; @@ -355,8 +349,6 @@ TEST_CASE( "MonotoneIntegrand2d", "[MonotoneIntegrand2d]") { } } - - TEST_CASE( "Testing monotone component evaluation in 1d", "[MonotoneComponent1d]" ) { const double testTol = 1e-7; @@ -439,7 +431,6 @@ TEST_CASE( "Testing monotone component evaluation in 1d", "[MonotoneComponent1d] } } - TEST_CASE( "Testing bracket-based inversion of monotone component", "[MonotoneBracketInverse]" ) { const double testTol = 1e-6; @@ -556,8 +547,6 @@ TEST_CASE( "Testing bracket-based inversion of monotone component", "[MonotoneBr } } - - TEST_CASE( "Testing monotone component derivative", "[MonotoneComponentDerivative]" ) { const double testTol = 1e-4; diff --git a/tests/Test_MonotoneComponent_compact.cpp b/tests/Test_MonotoneComponent_compact.cpp new file mode 100644 index 00000000..a873f47b --- /dev/null +++ b/tests/Test_MonotoneComponent_compact.cpp @@ -0,0 +1,801 @@ +#include + +#include "MParT/MonotoneComponent.h" +#include "MParT/PositiveBijectors.h" +#include "MParT/Quadrature.h" +#include "MParT/OrthogonalPolynomial.h" +#include "MParT/MultivariateExpansionWorker.h" +#include "MParT/MonotoneIntegrand.h" + +#include "MParT/Utilities/ArrayConversions.h" + +#include + +using namespace mpart; +using namespace Catch::Matchers; +using HostSpace = Kokkos::HostSpace; + +TEST_CASE( "Testing compact monotone component evaluation in 1d", "[MonotoneComponentCompact1d]" ) { + + const double testTol = 1e-7; + unsigned int dim = 1; + + // Create points evently space on [lb,ub] + unsigned int numPts = 20; + + Kokkos::View evalPts("Evaluate Points", dim, numPts); + for(unsigned int i=0; i,HostSpace> expansion(mset); + + Kokkos::View coeffs("Expansion coefficients", mset.Size()); + coeffs(0) = 1.0; // Constant term + coeffs(1) = 1.0; // Linear term + + unsigned int maxSub = 3; + double relTol = 1e-7; + double absTol = 1e-7; + AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); + + MonotoneComponent,HostSpace>, Exp, AdaptiveSimpson, HostSpace, true> comp(expansion, quad); + + Kokkos::View output("output", numPts); + comp.EvaluateImpl(evalPts, coeffs, output); + + for(unsigned int i=0; i 0.; + CHECK(isInbounds); + } + } + + /* Create and evaluate a quadratic map + - Set coefficients so that f(x) = 1.0 + x + 0.5*x^2 + - df/dt = 1.0 + t + - f(0) + int_0^x exp( df/dt ) dt = ( 1.0 + int_0^x exp(1+t) dt )/( 1.0 + int_0^1 exp(1+t) dt) = (1+exp(1+x)-exp(1))/(1+exp(2)-exp(1)) + */ + SECTION("Quadratic Map"){ + unsigned int maxDegree = 2; + MultiIndexSet mset = MultiIndexSet::CreateTotalOrder(dim, maxDegree); + + MultivariateExpansionWorker,HostSpace> expansion(mset); + + Kokkos::View coeffs("Expansion coefficients", mset.Size()); + coeffs(1) = 1.0; // Linear term = x ^1 + coeffs(2) = 0.5; // Quadratic term = x^2 - 1.0 + coeffs(0) = 1.0 + coeffs(2); // Constant term = x^0 + + unsigned int maxSub = 30; + double relTol = 1e-7; + double absTol = 1e-7; + AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol,QuadError::First); + + MonotoneComponent,HostSpace>, Exp, AdaptiveSimpson, HostSpace, true> comp(expansion, quad); + + Kokkos::View output("Output", numPts); + comp.EvaluateImpl(evalPts, coeffs, output); + + for(unsigned int i=0; i evalPts("Evaluate Points", dim, numPts); + for(unsigned int i=0; i,HostSpace> expansion(mset); + + Kokkos::View coeffs("Expansion coefficients", mset.Size()); + coeffs(0) = 1.0; // Constant term + coeffs(1) = 1.0; // Linear term + + unsigned int maxSub = 30; + double relTol = 1e-7; + double absTol = 1e-7; + AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); + + MonotoneComponent, HostSpace, true> comp(expansion, quad); + + Kokkos::View ys("ys", numPts); + comp.EvaluateImpl(evalPts, coeffs, ys); + + Kokkos::View testInverse("Test output", numPts); + for(int i = 0; i < 100; i++) + comp.InverseImpl(evalPts, ys, coeffs, testInverse); + + for(unsigned int i=0; i,HostSpace> expansion(mset); + + Kokkos::View coeffs("Expansion coefficients", mset.Size()); + coeffs(1) = 1.0; // Linear term = x ^1 + coeffs(2) = 0.5; // Quadratic term = x^2 - 1.0 + coeffs(0) = 1.0 + coeffs(2); // Constant term = x^0 + + unsigned int maxSub = 30; + double relTol = 1e-7; + double absTol = 1e-7; + AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol,QuadError::First); + + MonotoneComponent, HostSpace, true> comp(expansion, quad); + + Kokkos::View ys("ys",numPts); + comp.EvaluateImpl(evalPts, coeffs,ys); + + Kokkos::View testInverse("inverse", numPts); + comp.InverseImpl(evalPts, ys, coeffs, testInverse); + + for(unsigned int i=0; i x("Evaluate Points", dim, 1); + x(0,0) = 0.5; + + unsigned int maxDegree = 2; + MultiIndexSet mset = MultiIndexSet::CreateTotalOrder(dim, maxDegree); + MultivariateExpansionWorker,HostSpace> expansion(mset); + + Kokkos::View coeffs("Expansion coefficients", mset.Size()); + coeffs(1) = 1.0; // Linear term = x ^1 + coeffs(2) = 0.5; // Quadratic term = x^2 - 1.0 + coeffs(0) = 1.0 + coeffs(2); // Constant term = x^0 + + unsigned int maxSub = 30; + double relTol = 1e-7; + double absTol = 1e-7; + AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol,QuadError::First); + + MonotoneComponent, HostSpace, true> comp(expansion, quad); + + Kokkos::View ys("ys", numPts); + comp.EvaluateImpl(evalPts, coeffs, ys); + + Kokkos::View testInverse("inverse", numPts); + comp.InverseImpl(x, ys, coeffs,testInverse); + + for(unsigned int i=0; i evalPts("Evaluate Points", dim, numPts); + for(unsigned int i=0; i rightEvalPts("Finite difference points", dim, numPts); + for(unsigned int i=0; i,HostSpace> expansion(mset); + + unsigned int numTerms = mset.Size(); + + unsigned int maxSub = 30; + double relTol = 1e-7; + double absTol = 1e-7; + AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol,QuadError::First); + + MonotoneComponent, HostSpace, true> comp(expansion, quad); + + // Create some arbitrary coefficients + Kokkos::View coeffs("Expansion coefficients", mset.Size()); + for(unsigned int i=0; i evals("evals",numPts); + comp.EvaluateImpl(evalPts, coeffs, evals); + Kokkos::View rightEvals("revals", numPts); + comp.EvaluateImpl(rightEvalPts, coeffs, rightEvals); + Kokkos::View contDerivs = comp.ContinuousDerivative(evalPts, coeffs); + + for(unsigned int i=0; i evals2("FD Evals", numPts); +// Kokkos::View jac("Jacobian", numTerms, numPts); + +// comp.CoeffJacobian(evalPts, coeffs, evals2, jac); + +// for(unsigned int i=0; i derivs("Derivatives", numPts); +// Kokkos::View derivs2("Derivatives2", numPts); + +// Kokkos::View jac("Jacobian", numTerms,numPts); + +// comp.DiscreteMixedJacobian(evalPts, coeffs, jac); +// derivs = comp.DiscreteDerivative(evalPts, coeffs); + +// // Perturb the coefficients and recompute +// Kokkos::View coeffs2("Coefficients2", numTerms); +// Kokkos::deep_copy(coeffs2, coeffs); + +// for(unsigned int j=0; j derivs("Derivatives", numPts); +// Kokkos::View derivs2("Derivatives2", numPts); + +// Kokkos::View jac("Jacobian", numTerms,numPts); + +// comp.ContinuousMixedJacobian(evalPts, coeffs, jac); +// derivs = comp.ContinuousDerivative(evalPts, coeffs); + +// // Perturb the coefficients and recompute +// Kokkos::View coeffs2("Coefficients2", numTerms); +// Kokkos::deep_copy(coeffs2, coeffs); + +// for(unsigned int j=0; j evals("Evaluations", numPts); +// Kokkos::View evals2("Evaluations 2", numPts); + +// Kokkos::View jac("Jacobian", dim, numPts); + +// comp.InputJacobian(evalPts, coeffs, evals, jac); + +// Kokkos::View evalPts2("Points2", evalPts.extent(0), evalPts.extent(1)); +// Kokkos::deep_copy(evalPts2, evalPts); + +// for(unsigned int j=0; j evals("Evaluations", 1, numPts); + +// Kokkos::View sens("Jacobian", dim+1, numPts); +// REQUIRE_THROWS_AS(comp.GradientImpl(evalPts, sens, evals), std::invalid_argument); + +// } +// } + + +// TEST_CASE( "Least squares test", "[MonotoneComponentRegression]" ) { + +// unsigned int numPts = 100; +// Kokkos::View pts("Training Points", 1,numPts); +// for(unsigned int i=0; i fvals("Training Vales", numPts); +// for(unsigned int i=0; i,HostSpace> expansion(mset); + +// unsigned int maxSub = 30; +// double relTol = 1e-3; +// double absTol = 1e-3; +// AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); + +// MonotoneComponent, HostSpace> comp(expansion, quad); + +// unsigned int numTerms = mset.Size(); +// Kokkos::View coeffs("Coefficients", numTerms); +// Kokkos::View jac("Gradient", numTerms,numPts); +// Kokkos::View preds("Predictions", numPts); + + +// double objective; + +// Eigen::Map> jacMat(&jac(0,0), numTerms,numPts); + +// Eigen::Map predVec(&preds(0), numPts); +// Eigen::Map obsVec(&fvals(0), numPts); +// Eigen::Map coeffVec(&coeffs(0), numTerms); + +// Eigen::VectorXd objGrad; + +// for(unsigned int optIt=0; optIt<5; ++optIt){ + +// comp.CoeffJacobian(pts, coeffs, preds, jac); + +// objGrad = predVec-obsVec; + +// objective = 0.5*objGrad.squaredNorm(); +// coeffVec -= jacMat.transpose().colPivHouseholderQr().solve(objGrad); +// } + +// CHECK(objective<1e-3); + +// } + + +// TEST_CASE("Testing MonotoneComponent CoeffGrad and LogDeterminantCoeffGrad", "[MonotoneComponent_CoeffGrad]") +// { +// //const double testTol = 1e-4; +// unsigned int dim = 2; + +// // Create points evently spaced on [lb,ub] +// unsigned int numPts = 20; +// //double lb = -0.5; +// //double ub = 0.5; + +// Kokkos::View evalPts("Evaluate Points", dim, numPts); +// for(unsigned int i=0; i,HostSpace> expansion(mset); + +// unsigned int maxSub = 20; +// double relTol = 1e-7; +// double absTol = 1e-7; +// AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); + +// MonotoneComponent, HostSpace> comp(expansion, quad); + +// Kokkos::View coeffs("Expansion coefficients", mset.Size()); +// for(unsigned int i=0; i sens("Sensitivity", 1, numPts); +// for(unsigned int i=0; i grads = comp.CoeffGrad(evalPts, sens); +// REQUIRE(grads.extent(0)==comp.numCoeffs); +// REQUIRE(grads.extent(1)==numPts); + +// for(unsigned int j=1; j logDets = comp.LogDeterminant(evalPts); +// Kokkos::View logDets2; +// Kokkos::View grads = comp.LogDeterminantCoeffGrad(evalPts); +// REQUIRE(grads.extent(0)==comp.numCoeffs); +// REQUIRE(grads.extent(1)==numPts); + +// // Compare with finite difference derivatives +// const double fdstep = 1e-4; + +// for(unsigned int i=0; i indices = comp.DiagonalCoeffIndices(); +// std::vector indices_ref = expansion.NonzeroDiagonalEntries(); +// bool same_indices = indices == indices_ref; +// REQUIRE(same_indices); +// } +// } + +// #if defined(KOKKOS_ENABLE_CUDA ) || defined(KOKKOS_ENABLE_SYCL) + +// TEST_CASE( "MonotoneIntegrand1d on device", "[MonotoneIntegrandDevice]") { + +// typedef Kokkos::DefaultExecutionSpace::memory_space DeviceSpace; + +// const double testTol = 1e-7; + +// unsigned int dim = 1; +// unsigned int maxDegree = 1; +// FixedMultiIndexSet hset(dim, maxDegree); +// FixedMultiIndexSet mset = hset.ToDevice(); // Create a total order limited fixed multindex set + +// MultivariateExpansionWorker,DeviceSpace> expansion(mset); + +// MultivariateExpansionWorker,HostSpace> hexpansion(hset); + +// // Make room for the cache +// unsigned int cacheSize = hexpansion.CacheSize(); +// Kokkos::View dcache("device cache", cacheSize); + +// Kokkos::View hcoeffs("Expansion coefficients", mset.Size()); +// hcoeffs(0) = 1.0; // Constant term +// hcoeffs(1) = 1.0; // Linear term + +// Kokkos::View dcoeffs = ToDevice(hcoeffs); + +// Kokkos::View hpt("evaluation point", dim); +// hpt(0) = 1.0; + +// Kokkos::View dpt = ToDevice(hpt); + +// SECTION("Integrand Only") { +// Kokkos::View dres("result", 1); + +// Kokkos::RangePolicy::Space> policy(0,1); +// Kokkos::parallel_for(policy, KOKKOS_LAMBDA(const int i){ +// MonotoneIntegrand integrand(dcache.data(), expansion, dpt, dcoeffs, DerivativeFlags::None, 0.0); +// integrand(0.5, &dres(0)); +// }); + +// Kokkos::View hres = ToHost(dres); + +// CHECK(hres(0) == Approx(exp(1)).epsilon(testTol)); +// } + +// SECTION("Integrand Derivative") { +// Kokkos::View dres("result", 2); + +// Kokkos::RangePolicy::Space> policy(0,1); +// Kokkos::parallel_for(policy, KOKKOS_LAMBDA(const int i){ +// MonotoneIntegrand integrand(dcache.data(), expansion, dpt, dcoeffs, DerivativeFlags::Diagonal, 0.0); +// integrand(0.5, dres.data()); +// }); + +// Kokkos::View hres = ToHost(dres); + +// CHECK(hres(0) == Approx(exp(1)).epsilon(testTol)); +// } + +// SECTION("Integrand Parameters Gradient") { + +// Kokkos::View dres("result", hset.Size()); +// Kokkos::View dres_fd("result_fd", hset.Size()); +// Kokkos::View testVal("integrand", 1+hset.Size()); + +// Kokkos::RangePolicy::Space> policy(0,1); +// Kokkos::parallel_for(policy, KOKKOS_LAMBDA(const int i){ + +// MonotoneIntegrand integrand(dcache.data(), expansion, dpt, dcoeffs, DerivativeFlags::Parameters, 0.0); +// MonotoneIntegrand integrand2(dcache.data(), expansion, dpt, dcoeffs, DerivativeFlags::None, 0.0); + +// integrand(0.5, testVal.data()); + +// const double fdStep = 1e-4; +// double testVal2; +// for(unsigned int termInd=0; termInd hres = ToHost(dres); +// Kokkos::View hres_fd = ToHost(dres_fd); + +// for(unsigned int termInd=0; termInd dres("result", hset.Size()); +// Kokkos::View dres_fd("result_fd", hset.Size()); +// Kokkos::View testVal("integrand", 1+hset.Size()); +// Kokkos::View workspace("workspace", hset.Size()); + +// Kokkos::RangePolicy::Space> policy(0,1); +// Kokkos::parallel_for(policy, KOKKOS_LAMBDA(const int i){ + +// MonotoneIntegrand integrand(dcache.data(), expansion, dpt, dcoeffs, DerivativeFlags::MixedCoeff, 0.0, workspace); +// MonotoneIntegrand integrand2(dcache.data(), expansion, dpt, dcoeffs, DerivativeFlags::Diagonal, 0.0); + +// integrand(0.5, testVal.data()); + +// const double fdStep = 1e-4; +// double testVal2[2]; +// for(unsigned int termInd=0; termInd hres = ToHost(dres); +// Kokkos::View hres_fd = ToHost(dres_fd); + +// for(unsigned int termInd=0; termInd hset(dim,maxDegree); +// FixedMultiIndexSet dset = hset.ToDevice(); // Create a total order limited fixed multindex set + +// MultivariateExpansionWorker,DeviceSpace> dexpansion(dset); + +// // define f(x1,x2) = c0 + c1*x1 + c2*x2 +// Kokkos::View hcoeffs("Expansion coefficients", hset.Size()); +// hcoeffs(0) = 1.0; // Constant term +// hcoeffs(1) = 1.0; // Linear term in x1 +// hcoeffs(2) = 1.0; // Linear in x2 + +// Kokkos::View dcoeffs = ToDevice(hcoeffs); + +// unsigned int cacheSize = dexpansion.CacheSize(); +// CHECK(cacheSize == (maxDegree+1)*(2*dim+1)); + +// // Allocate some memory for the cache +// Kokkos::View dcache("device cache", cacheSize); + +// Kokkos::View hpt("host point", dim); +// hpt(0) = 0.5; +// hpt(1) = 0.5; +// Kokkos::View dpt = ToDevice(hpt); + +// unsigned int maxSub = 20; +// double relTol = 1e-5; +// double absTol = 1e-5; +// AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); + +// Kokkos::View workspace("quadrature workspace", quad.WorkspaceSize()); + +// Kokkos::View dres("Device Evaluation", 1); +// // Run the fill cache funciton, using a parallel_for loop to ensure it's run on the device +// Kokkos::RangePolicy::Space> policy(0,1); +// Kokkos::parallel_for(policy, KOKKOS_LAMBDA(const int i){ +// dexpansion.FillCache1(dcache.data(), dpt, DerivativeFlags::None); +// dres(0) = MonotoneComponent::EvaluateSingle(dcache.data(), workspace.data(), dpt, dpt(dim-1), dcoeffs, quad, dexpansion); +// }); + +// Kokkos::fence(); + +// CHECK(ToHost(dres)(0) == Approx(hcoeffs(0) + hcoeffs(1)*hpt(0) + hpt(1)*exp(hcoeffs(2))).epsilon(1e-4)); + +// } + + +// TEST_CASE( "Testing 1d monotone component evaluation on device", "[MonotoneComponent1d_Device]" ) { + +// typedef Kokkos::DefaultExecutionSpace::memory_space DeviceSpace; + +// const double testTol = 1e-7; +// unsigned int dim = 1; + +// // Create points evently space on [lb,ub] +// unsigned int numPts = 3; +// double lb = -2.0; +// double ub = 2.0; + +// Kokkos::View::HostMirror hevalPts("Evaluation Points", dim, numPts); +// for(unsigned int i=0; i devalPts = ToDevice(hevalPts); + + +// /* Create and evaluate an affine map +// - Set coefficients so that f(x) = 1.0 + x +// - f(0) + int_0^x exp( d f(t) ) dt = 1.0 + int_0^x exp(1) dt = 1 + |x| * exp(1) +// */ +// SECTION("Affine Map"){ +// unsigned int maxDegree = 1; +// FixedMultiIndexSet hset(dim, maxDegree); +// FixedMultiIndexSet mset = hset.ToDevice(); + +// MultivariateExpansionWorker,DeviceSpace> expansion(mset); + +// Kokkos::View hcoeffs("Expansion coefficients", mset.Size()); +// hcoeffs(0) = 1.0; // Constant term +// hcoeffs(1) = 1.0; // Linear term + +// Kokkos::View dcoeffs = ToDevice(hcoeffs); + +// unsigned int maxSub = 10; +// double relTol = 1e-6; +// double absTol = 1e-6; +// AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); + +// MonotoneComponent comp(expansion, quad); + +// Kokkos::View doutput("dout", numPts); +// comp.EvaluateImpl(devalPts, dcoeffs, doutput); +// auto houtput = ToHost(doutput); + +// for(unsigned int i=0; i hset(dim, maxDegree); +// FixedMultiIndexSet mset = hset.ToDevice(); + +// MultivariateExpansionWorker,DeviceSpace> expansion(mset); + +// Kokkos::View hcoeffs("Expansion coefficients", mset.Size()); +// hcoeffs(1) = 1.0; // Linear term = x ^1 +// hcoeffs(2) = 0.5; // Quadratic term = x^2 - 1.0 +// hcoeffs(0) = 1.0 + hcoeffs(2); // Constant term = x^0 + +// Kokkos::View dcoeffs = ToDevice(hcoeffs); + +// unsigned int maxSub = 10; +// double relTol = 1e-6; +// double absTol = 1e-6; +// AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); + +// MonotoneComponent comp(expansion, quad); + +// Kokkos::View doutput("dout",numPts); +// comp.EvaluateImpl(devalPts, dcoeffs, doutput); +// auto houtput = ToHost(doutput); + +// for(unsigned int i=0; i Date: Thu, 13 Jun 2024 09:44:42 -0600 Subject: [PATCH 06/11] Working compact monotone component --- MParT/MonotoneComponent.h | 43 +- tests/Test_MonotoneComponent_compact.cpp | 624 ++++++----------------- 2 files changed, 181 insertions(+), 486 deletions(-) diff --git a/MParT/MonotoneComponent.h b/MParT/MonotoneComponent.h index 02348211..e473c350 100644 --- a/MParT/MonotoneComponent.h +++ b/MParT/MonotoneComponent.h @@ -469,11 +469,13 @@ class MonotoneComponent : public ConditionalMapBase const unsigned int numPts = pts.extent(1); const unsigned int dim = pts.extent(0); - // Ask the expansion how much memory it would like for it's one-point cache + // Ask the expansion how much memory it would like for its one-point cache + quad_.SetDim(1); + const unsigned int workspaceSize = quad_.WorkspaceSize(); const unsigned int cacheSize = expansion_.CacheSize(); // Create a policy with enough scratch memory to cache the polynomial evaluations - auto cacheBytes = Kokkos::View::shmem_size(cacheSize); + auto cacheBytes = Kokkos::View::shmem_size(cacheSize + isCompact*(workspaceSize)); auto functor = KOKKOS_CLASS_LAMBDA (typename Kokkos::TeamPolicy::member_type team_member) { @@ -501,8 +503,8 @@ class MonotoneComponent : public ConditionalMapBase // If compact, normalize by part independent of x_d if constexpr(isCompact) { - expansion_.FillCache2(cache.data(), pt, 1, DerivativeFlags::None); - derivs(ptInd) /= expansion_.Evaluate(cache.data(), coeffs); + Kokkos::View workspace(team_member.thread_scratch(1), workspaceSize); + derivs(ptInd) /= EvaluateSingle(cache.data(), workspace.data(), pt, 1., coeffs, quad_, expansion_); } } }; @@ -551,6 +553,9 @@ class MonotoneComponent : public ConditionalMapBase StridedVector evals, StridedVector derivs) { + if constexpr(isCompact) { + throw std::invalid_argument("Cannot use discrete derivatives with compact monotone component at this time"); + } const unsigned int numPts = pts.extent(1); const unsigned int numTerms = coeffs.extent(0); @@ -779,25 +784,24 @@ class MonotoneComponent : public ConditionalMapBase // Create the integrand g( \partial_D f(x_1,...,x_{D-1},t)) MonotoneIntegrand integrand(cache.data(), expansion_, pt, coeffs, DerivativeFlags::Input, nugget_); - // Create the integrand g( \partial_D f(x_1,...,x_{D-1},1)) - MonotoneIntegrand integrand_denom(cache.data(), expansion_, pt, 1, coeffs, DerivativeFlags::Input, nugget_); // Compute \int_0^x g( \partial_D f(x_1,...,x_{D-1},t)) dt as well as the gradient of this term wrt the map input quad_.Integrate(workspace.data(), integrand, 0, 1, integral.data()); - if constexpr(isCompact) { - // Compute \int_0^1 g( \partial_D f(x_1,...,x_{D-1},t)) dt as well as the gradient of this term wrt the map input - quad_.Integrate(workspace.data(), integrand_denom, 0, 1, integral_denom.data()); - } double numer_diag_eval = integral(0); expansion_.FillCache2(cache.data(), pt, 0.0, DerivativeFlags::Input); double offdiag_eval = expansion_.InputDerivative(cache.data(), coeffs, jacView); - double denom_eval, denom_eval_sq; double numer_eval = numer_diag_eval + offdiag_eval; evaluations(ptInd) = numer_eval; + + double denom_eval, denom_eval_sq; if constexpr(isCompact) { + // Create the integrand g( \partial_D f(x_1,...,x_{D-1},1)) + MonotoneIntegrand integrand_denom(cache.data(), expansion_, pt, 1., coeffs, DerivativeFlags::Input, nugget_); + // Compute \int_0^1 g( \partial_D f(x_1,...,x_{D-1},t)) dt as well as the gradient of this term wrt the map input + quad_.Integrate(workspace.data(), integrand_denom, 0, 1, integral_denom.data()); denom_eval = integral_denom(0) + offdiag_eval; denom_eval_sq = denom_eval*denom_eval; evaluations(ptInd) /= denom_eval; @@ -815,7 +819,7 @@ class MonotoneComponent : public ConditionalMapBase } if constexpr(isCompact) { - jacView(dim_-1) = (integral(dim_)*denom_eval - integral_denom(dim_)*numer_eval)/denom_eval_sq; + jacView(dim_-1) = integral(dim_)/denom_eval; } else { jacView(dim_-1) = integral(dim_); } @@ -845,11 +849,12 @@ class MonotoneComponent : public ConditionalMapBase checkMixedJacobianInput("ContinuousMixedJacobian", jacobian.extent(0), jacobian.extent(1), numTerms, numPts); // Ask the expansion how much memory it would like for it's one-point cache + quad_.SetDim(numTerms+1); const unsigned int workspaceSize = quad_.WorkspaceSize(); - const unsigned int cacheSize = expansion_.CacheSize() + isCompact*(2*numTerms+1+workspaceSize); + const unsigned int cacheSize = expansion_.CacheSize(); // Create a policy with enough scratch memory to cache the polynomial evaluations - auto cacheBytes = Kokkos::View::shmem_size(cacheSize); + auto cacheBytes = Kokkos::View::shmem_size(cacheSize + isCompact*(2*numTerms+1+workspaceSize)); auto functor = KOKKOS_CLASS_LAMBDA (typename Kokkos::TeamPolicy::member_type team_member) { @@ -875,11 +880,6 @@ class MonotoneComponent : public ConditionalMapBase // Precompute anything that does not depend on x_d. The DerivativeFlags::MixedCoeff arguments specifies that we won't want to derivative wrt to x_i for i integrand_denom(cache.data(), expansion_, pt, 1., coeffs, DerivativeFlags::Parameters, nugget_); - quad_.Integrate(workspace.data(), integrand_denom, 0, 1, integral_denom.data()); - } - // Fill in parts of the cache that depend on x_d. Tell the expansion we're going to want first derivatives wrt x_d expansion_.FillCache2(cache.data(), pt, pt(dim-1), DerivativeFlags::MixedCoeff); @@ -889,7 +889,10 @@ class MonotoneComponent : public ConditionalMapBase double offdiag_eval, numer_diag_deriv, denom_eval, denom_eval_sq; if constexpr(isCompact) { - expansion_.FillCache2(cache.data(), pt, 1., DerivativeFlags::Parameters); + MonotoneIntegrand integrand_denom(cache.data(), expansion_, pt, 1., coeffs, DerivativeFlags::Parameters, nugget_); + quad_.Integrate(workspace.data(), integrand_denom, 0, 1, integral_denom.data()); + + expansion_.FillCache2(cache.data(), pt, 0., DerivativeFlags::Parameters); offdiag_eval = expansion_.CoeffDerivative(cache.data(), coeffs, jac_denom); numer_diag_deriv = PosFuncType::Evaluate(df); denom_eval = integral_denom(0) + offdiag_eval; diff --git a/tests/Test_MonotoneComponent_compact.cpp b/tests/Test_MonotoneComponent_compact.cpp index a873f47b..ecfbf06b 100644 --- a/tests/Test_MonotoneComponent_compact.cpp +++ b/tests/Test_MonotoneComponent_compact.cpp @@ -212,8 +212,8 @@ TEST_CASE( "Testing compact monotone component derivative", "[CompactMonotoneCom // Create points evently spaced on [lb,ub] unsigned int numPts = 20; - double lb = 1e-3; - double ub = 1.- 1e-3; + double lb = 0.; + double ub = 1.- fdStep; Kokkos::View evalPts("Evaluate Points", dim, numPts); for(unsigned int i=0; i evals2("FD Evals", numPts); -// Kokkos::View jac("Jacobian", numTerms, numPts); - -// comp.CoeffJacobian(evalPts, coeffs, evals2, jac); - -// for(unsigned int i=0; i derivs("Derivatives", numPts); -// Kokkos::View derivs2("Derivatives2", numPts); - -// Kokkos::View jac("Jacobian", numTerms,numPts); - -// comp.DiscreteMixedJacobian(evalPts, coeffs, jac); -// derivs = comp.DiscreteDerivative(evalPts, coeffs); - -// // Perturb the coefficients and recompute -// Kokkos::View coeffs2("Coefficients2", numTerms); -// Kokkos::deep_copy(coeffs2, coeffs); - -// for(unsigned int j=0; j derivs("Derivatives", numPts); -// Kokkos::View derivs2("Derivatives2", numPts); - -// Kokkos::View jac("Jacobian", numTerms,numPts); - -// comp.ContinuousMixedJacobian(evalPts, coeffs, jac); -// derivs = comp.ContinuousDerivative(evalPts, coeffs); - -// // Perturb the coefficients and recompute -// Kokkos::View coeffs2("Coefficients2", numTerms); -// Kokkos::deep_copy(coeffs2, coeffs); - -// for(unsigned int j=0; j evals("Evaluations", numPts); -// Kokkos::View evals2("Evaluations 2", numPts); - -// Kokkos::View jac("Jacobian", dim, numPts); - -// comp.InputJacobian(evalPts, coeffs, evals, jac); - -// Kokkos::View evalPts2("Points2", evalPts.extent(0), evalPts.extent(1)); -// Kokkos::deep_copy(evalPts2, evalPts); - -// for(unsigned int j=0; j evals("Evaluations", 1, numPts); - -// Kokkos::View sens("Jacobian", dim+1, numPts); -// REQUIRE_THROWS_AS(comp.GradientImpl(evalPts, sens, evals), std::invalid_argument); - -// } -// } - - -// TEST_CASE( "Least squares test", "[MonotoneComponentRegression]" ) { - -// unsigned int numPts = 100; -// Kokkos::View pts("Training Points", 1,numPts); -// for(unsigned int i=0; i fvals("Training Vales", numPts); -// for(unsigned int i=0; i,HostSpace> expansion(mset); - -// unsigned int maxSub = 30; -// double relTol = 1e-3; -// double absTol = 1e-3; -// AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); - -// MonotoneComponent, HostSpace> comp(expansion, quad); - -// unsigned int numTerms = mset.Size(); -// Kokkos::View coeffs("Coefficients", numTerms); -// Kokkos::View jac("Gradient", numTerms,numPts); -// Kokkos::View preds("Predictions", numPts); - - -// double objective; - -// Eigen::Map> jacMat(&jac(0,0), numTerms,numPts); - -// Eigen::Map predVec(&preds(0), numPts); -// Eigen::Map obsVec(&fvals(0), numPts); -// Eigen::Map coeffVec(&coeffs(0), numTerms); - -// Eigen::VectorXd objGrad; - -// for(unsigned int optIt=0; optIt<5; ++optIt){ - -// comp.CoeffJacobian(pts, coeffs, preds, jac); - -// objGrad = predVec-obsVec; - -// objective = 0.5*objGrad.squaredNorm(); -// coeffVec -= jacMat.transpose().colPivHouseholderQr().solve(objGrad); -// } - -// CHECK(objective<1e-3); - -// } - -// TEST_CASE("Testing MonotoneComponent CoeffGrad and LogDeterminantCoeffGrad", "[MonotoneComponent_CoeffGrad]") -// { -// //const double testTol = 1e-4; -// unsigned int dim = 2; + SECTION("Coefficient Jacobian"){ -// // Create points evently spaced on [lb,ub] -// unsigned int numPts = 20; -// //double lb = -0.5; -// //double ub = 0.5; + Kokkos::View evals2("FD Evals", numPts); + Kokkos::View jac("Jacobian", numTerms, numPts); -// Kokkos::View evalPts("Evaluate Points", dim, numPts); -// for(unsigned int i=0; i,HostSpace> expansion(mset); + for(unsigned int i=0; i, HostSpace> comp(expansion, quad); + for(unsigned j=0; j coeffs("Expansion coefficients", mset.Size()); -// for(unsigned int i=0; i sens("Sensitivity", 1, numPts); -// for(unsigned int i=0; i grads = comp.CoeffGrad(evalPts, sens); -// REQUIRE(grads.extent(0)==comp.numCoeffs); -// REQUIRE(grads.extent(1)==numPts); - -// for(unsigned int j=1; j logDets = comp.LogDeterminant(evalPts); -// Kokkos::View logDets2; -// Kokkos::View grads = comp.LogDeterminantCoeffGrad(evalPts); -// REQUIRE(grads.extent(0)==comp.numCoeffs); -// REQUIRE(grads.extent(1)==numPts); - -// // Compare with finite difference derivatives -// const double fdstep = 1e-4; - -// for(unsigned int i=0; i indices = comp.DiagonalCoeffIndices(); -// std::vector indices_ref = expansion.NonzeroDiagonalEntries(); -// bool same_indices = indices == indices_ref; -// REQUIRE(same_indices); -// } -// } - -// #if defined(KOKKOS_ENABLE_CUDA ) || defined(KOKKOS_ENABLE_SYCL) - -// TEST_CASE( "MonotoneIntegrand1d on device", "[MonotoneIntegrandDevice]") { - -// typedef Kokkos::DefaultExecutionSpace::memory_space DeviceSpace; - -// const double testTol = 1e-7; - -// unsigned int dim = 1; -// unsigned int maxDegree = 1; -// FixedMultiIndexSet hset(dim, maxDegree); -// FixedMultiIndexSet mset = hset.ToDevice(); // Create a total order limited fixed multindex set - -// MultivariateExpansionWorker,DeviceSpace> expansion(mset); - -// MultivariateExpansionWorker,HostSpace> hexpansion(hset); - -// // Make room for the cache -// unsigned int cacheSize = hexpansion.CacheSize(); -// Kokkos::View dcache("device cache", cacheSize); - -// Kokkos::View hcoeffs("Expansion coefficients", mset.Size()); -// hcoeffs(0) = 1.0; // Constant term -// hcoeffs(1) = 1.0; // Linear term - -// Kokkos::View dcoeffs = ToDevice(hcoeffs); - -// Kokkos::View hpt("evaluation point", dim); -// hpt(0) = 1.0; - -// Kokkos::View dpt = ToDevice(hpt); - -// SECTION("Integrand Only") { -// Kokkos::View dres("result", 1); - -// Kokkos::RangePolicy::Space> policy(0,1); -// Kokkos::parallel_for(policy, KOKKOS_LAMBDA(const int i){ -// MonotoneIntegrand integrand(dcache.data(), expansion, dpt, dcoeffs, DerivativeFlags::None, 0.0); -// integrand(0.5, &dres(0)); -// }); - -// Kokkos::View hres = ToHost(dres); - -// CHECK(hres(0) == Approx(exp(1)).epsilon(testTol)); -// } - -// SECTION("Integrand Derivative") { -// Kokkos::View dres("result", 2); + coeffs(j) -= fdStep; + } + } -// Kokkos::RangePolicy::Space> policy(0,1); -// Kokkos::parallel_for(policy, KOKKOS_LAMBDA(const int i){ -// MonotoneIntegrand integrand(dcache.data(), expansion, dpt, dcoeffs, DerivativeFlags::Diagonal, 0.0); -// integrand(0.5, dres.data()); -// }); + SECTION("Mixed Continuous Jacobian"){ -// Kokkos::View hres = ToHost(dres); + const double fdStep = 1e-5; -// CHECK(hres(0) == Approx(exp(1)).epsilon(testTol)); -// } + Kokkos::View derivs("Derivatives", numPts); + Kokkos::View derivs2("Derivatives2", numPts); -// SECTION("Integrand Parameters Gradient") { + Kokkos::View jac("Jacobian", numTerms,numPts); -// Kokkos::View dres("result", hset.Size()); -// Kokkos::View dres_fd("result_fd", hset.Size()); -// Kokkos::View testVal("integrand", 1+hset.Size()); + comp.ContinuousMixedJacobian(evalPts, coeffs, jac); + derivs = comp.ContinuousDerivative(evalPts, coeffs); -// Kokkos::RangePolicy::Space> policy(0,1); -// Kokkos::parallel_for(policy, KOKKOS_LAMBDA(const int i){ + // Perturb the coefficients and recompute + Kokkos::View coeffs2("Coefficients2", numTerms); + Kokkos::deep_copy(coeffs2, coeffs); -// MonotoneIntegrand integrand(dcache.data(), expansion, dpt, dcoeffs, DerivativeFlags::Parameters, 0.0); -// MonotoneIntegrand integrand2(dcache.data(), expansion, dpt, dcoeffs, DerivativeFlags::None, 0.0); + for(unsigned int j=0; j hres = ToHost(dres); -// Kokkos::View hres_fd = ToHost(dres_fd); + const double fdStep = 1e-4; -// for(unsigned int termInd=0; termInd evals("Evaluations", numPts); + Kokkos::View evals2("Evaluations 2", numPts); + Kokkos::View jac("Jacobian", dim, numPts); -// SECTION("Integrand Mixed Gradient") { + comp.InputJacobian(evalPts, coeffs, evals, jac); -// Kokkos::View dres("result", hset.Size()); -// Kokkos::View dres_fd("result_fd", hset.Size()); -// Kokkos::View testVal("integrand", 1+hset.Size()); -// Kokkos::View workspace("workspace", hset.Size()); - -// Kokkos::RangePolicy::Space> policy(0,1); -// Kokkos::parallel_for(policy, KOKKOS_LAMBDA(const int i){ + Kokkos::View evalPts2("Points2", evalPts.extent(0), evalPts.extent(1)); + Kokkos::deep_copy(evalPts2, evalPts); -// MonotoneIntegrand integrand(dcache.data(), expansion, dpt, dcoeffs, DerivativeFlags::MixedCoeff, 0.0, workspace); -// MonotoneIntegrand integrand2(dcache.data(), expansion, dpt, dcoeffs, DerivativeFlags::Diagonal, 0.0); + for(unsigned int j=0; j hres = ToHost(dres); -// Kokkos::View hres_fd = ToHost(dres_fd); + for(unsigned int ptInd=0; ptInd evals("Evaluations", 1, numPts); + Kokkos::View sens("Jacobian", dim+1, numPts); + REQUIRE_THROWS_AS(comp.GradientImpl(evalPts, sens, evals), std::invalid_argument); -// TEST_CASE( "Testing MonotoneComponent::EvaluateSingle on Device", "[MonotoneComponentSingle_Device]") { + } +} -// typedef Kokkos::DefaultExecutionSpace::memory_space DeviceSpace; -// unsigned int dim = 2; -// unsigned int maxDegree = 1; -// FixedMultiIndexSet hset(dim,maxDegree); -// FixedMultiIndexSet dset = hset.ToDevice(); // Create a total order limited fixed multindex set +TEST_CASE( "Compact least squares test", "[CompactMonotoneComponentRegression]" ) { -// MultivariateExpansionWorker,DeviceSpace> dexpansion(dset); + unsigned int numPts = 100; + Kokkos::View pts("Training Points", 1,numPts); + for(unsigned int i=0; i hcoeffs("Expansion coefficients", hset.Size()); -// hcoeffs(0) = 1.0; // Constant term -// hcoeffs(1) = 1.0; // Linear term in x1 -// hcoeffs(2) = 1.0; // Linear in x2 -// Kokkos::View dcoeffs = ToDevice(hcoeffs); + Kokkos::View fvals("Training Values", numPts); + for(unsigned int i=0; i dcache("device cache", cacheSize); + // Don't need limiter for compact in one dimension + MultiIndexSet mset = MultiIndexSet::CreateTotalOrder(1, 6); + MultivariateExpansionWorker,HostSpace> expansion(mset); -// Kokkos::View hpt("host point", dim); -// hpt(0) = 0.5; -// hpt(1) = 0.5; -// Kokkos::View dpt = ToDevice(hpt); + unsigned int maxSub = 30; + double relTol = 1e-3; + double absTol = 1e-3; + AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); -// unsigned int maxSub = 20; -// double relTol = 1e-5; -// double absTol = 1e-5; -// AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); + MonotoneComponent, HostSpace, true> comp(expansion, quad); -// Kokkos::View workspace("quadrature workspace", quad.WorkspaceSize()); + unsigned int numTerms = mset.Size(); + Kokkos::View coeffs("Coefficients", numTerms); + Kokkos::View jac("Gradient", numTerms,numPts); + Kokkos::View preds("Predictions", numPts); -// Kokkos::View dres("Device Evaluation", 1); -// // Run the fill cache funciton, using a parallel_for loop to ensure it's run on the device -// Kokkos::RangePolicy::Space> policy(0,1); -// Kokkos::parallel_for(policy, KOKKOS_LAMBDA(const int i){ -// dexpansion.FillCache1(dcache.data(), dpt, DerivativeFlags::None); -// dres(0) = MonotoneComponent::EvaluateSingle(dcache.data(), workspace.data(), dpt, dpt(dim-1), dcoeffs, quad, dexpansion); -// }); -// Kokkos::fence(); + double objective; -// CHECK(ToHost(dres)(0) == Approx(hcoeffs(0) + hcoeffs(1)*hpt(0) + hpt(1)*exp(hcoeffs(2))).epsilon(1e-4)); + Eigen::Map> jacMat(&jac(0,0), numTerms,numPts); -// } + Eigen::Map predVec(&preds(0), numPts); + Eigen::Map obsVec(&fvals(0), numPts); + Eigen::Map coeffVec(&coeffs(0), numTerms); + Eigen::VectorXd objGrad; -// TEST_CASE( "Testing 1d monotone component evaluation on device", "[MonotoneComponent1d_Device]" ) { + for(unsigned int optIt=0; optIt<5; ++optIt){ -// typedef Kokkos::DefaultExecutionSpace::memory_space DeviceSpace; + comp.CoeffJacobian(pts, coeffs, preds, jac); -// const double testTol = 1e-7; -// unsigned int dim = 1; + objGrad = predVec-obsVec; -// // Create points evently space on [lb,ub] -// unsigned int numPts = 3; -// double lb = -2.0; -// double ub = 2.0; + objective = 0.5*objGrad.squaredNorm(); + coeffVec -= jacMat.transpose().colPivHouseholderQr().solve(objGrad); + } -// Kokkos::View::HostMirror hevalPts("Evaluation Points", dim, numPts); -// for(unsigned int i=0; i devalPts = ToDevice(hevalPts); +} -// /* Create and evaluate an affine map -// - Set coefficients so that f(x) = 1.0 + x -// - f(0) + int_0^x exp( d f(t) ) dt = 1.0 + int_0^x exp(1) dt = 1 + |x| * exp(1) -// */ -// SECTION("Affine Map"){ -// unsigned int maxDegree = 1; -// FixedMultiIndexSet hset(dim, maxDegree); -// FixedMultiIndexSet mset = hset.ToDevice(); +TEST_CASE("Testing CompactMonotoneComponent CoeffGrad and LogDeterminantCoeffGrad", "[CompactMonotoneComponent_CoeffGrad]") +{ + //const double testTol = 1e-4; + unsigned int dim = 2; -// MultivariateExpansionWorker,DeviceSpace> expansion(mset); + // Create points evently spaced on [lb,ub] + unsigned int numPts = 20; + //double lb = -0.5; + //double ub = 0.5; -// Kokkos::View hcoeffs("Expansion coefficients", mset.Size()); -// hcoeffs(0) = 1.0; // Constant term -// hcoeffs(1) = 1.0; // Linear term + Kokkos::View evalPts("Evaluate Points", dim, numPts); + for(unsigned int i=0; i dcoeffs = ToDevice(hcoeffs); + unsigned int maxDegree = 3; + MultiIndexSet mset = MultiIndexSet::CreateTotalOrder(dim, maxDegree, [](MultiIndex m){return m.HasNonzeroEnd() || m.Max() == 0;}); + MultivariateExpansionWorker,HostSpace> expansion(mset); -// unsigned int maxSub = 10; -// double relTol = 1e-6; -// double absTol = 1e-6; -// AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); + unsigned int maxSub = 20; + double relTol = 1e-7; + double absTol = 1e-7; + AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); -// MonotoneComponent comp(expansion, quad); + MonotoneComponent, HostSpace, true> comp(expansion, quad); -// Kokkos::View doutput("dout", numPts); -// comp.EvaluateImpl(devalPts, dcoeffs, doutput); -// auto houtput = ToHost(doutput); + Kokkos::View coeffs("Expansion coefficients", mset.Size()); + for(unsigned int i=0; i sens("Sensitivity", 1, numPts); + for(unsigned int i=0; i hset(dim, maxDegree); -// FixedMultiIndexSet mset = hset.ToDevice(); + Kokkos::View grads = comp.CoeffGrad(evalPts, sens); + REQUIRE(grads.extent(0)==comp.numCoeffs); + REQUIRE(grads.extent(1)==numPts); -// MultivariateExpansionWorker,DeviceSpace> expansion(mset); + for(unsigned int j=1; j hcoeffs("Expansion coefficients", mset.Size()); -// hcoeffs(1) = 1.0; // Linear term = x ^1 -// hcoeffs(2) = 0.5; // Quadratic term = x^2 - 1.0 -// hcoeffs(0) = 1.0 + hcoeffs(2); // Constant term = x^0 + SECTION("LogDeterminantCoeffGrad"){ -// Kokkos::View dcoeffs = ToDevice(hcoeffs); + for(unsigned int i=0; i quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); + Kokkos::View logDets = comp.LogDeterminant(evalPts); + Kokkos::View logDets2; + Kokkos::View grads = comp.LogDeterminantCoeffGrad(evalPts); + REQUIRE(grads.extent(0)==comp.numCoeffs); + REQUIRE(grads.extent(1)==numPts); -// MonotoneComponent comp(expansion, quad); + // Compare with finite difference derivatives + const double fdstep = 1e-5; -// Kokkos::View doutput("dout",numPts); -// comp.EvaluateImpl(devalPts, dcoeffs, doutput); -// auto houtput = ToHost(doutput); + for(unsigned int i=0; i Date: Thu, 13 Jun 2024 13:51:20 -0600 Subject: [PATCH 07/11] Working coeffgrad tests --- MParT/MonotoneComponent.h | 106 +++++++++++++++++++---- MParT/MultivariateExpansionWorker.h | 21 +++++ tests/Test_MapFactory.cpp | 91 +++++++++++++++++++ tests/Test_MonotoneComponent_compact.cpp | 57 +++++++----- 4 files changed, 232 insertions(+), 43 deletions(-) diff --git a/MParT/MonotoneComponent.h b/MParT/MonotoneComponent.h index e473c350..448c099b 100644 --- a/MParT/MonotoneComponent.h +++ b/MParT/MonotoneComponent.h @@ -68,7 +68,12 @@ class MonotoneComponent : public ConditionalMapBase quad_(quad), dim_(expansion.InputSize()), useContDeriv_(useContDeriv), - nugget_(nugget){}; + nugget_(nugget){ + if constexpr(isCompact) { + zero_param_grad_ = Kokkos::View("Zero param grad", expansion.NumCoeffs()); + zero_eval_ = Kokkos::View("Evaluation at zero"); + } + }; MonotoneComponent(ExpansionType const& expansion, QuadratureType const& quad, @@ -79,7 +84,13 @@ class MonotoneComponent : public ConditionalMapBase quad_(quad), dim_(expansion.InputSize()), useContDeriv_(useContDeriv), - nugget_(nugget){}; + nugget_(nugget){ + if constexpr(isCompact) { + zero_param_grad_ = Kokkos::View("Zero param grad", expansion.NumCoeffs()); + zero_eval_ = Kokkos::View("Evaluation at zero"); + initializeZeroEval(this->savedCoeffs); + } + }; virtual std::shared_ptr> GetBaseFunction() override{return std::make_shared>(1,expansion_);}; @@ -281,7 +292,8 @@ class MonotoneComponent : public ConditionalMapBase expansion_.FillCache1(cache.data(), pt, DerivativeFlags::None); output(ptInd) = EvaluateSingle(cache.data(), workspace.data(), pt, pt(dim_-1), coeffs, quad_, expansion_); if constexpr(isCompact) { - output(ptInd) /= EvaluateSingle(cache.data(), workspace.data(), pt, 1., coeffs, quad_, expansion_); + double denom_eval = EvaluateSingle(cache.data(), workspace.data(), pt, 1., coeffs, quad_, expansion_); + output(ptInd) = (output(ptInd) - zero_eval_())/(denom_eval - zero_eval_()); } } }; @@ -415,7 +427,7 @@ class MonotoneComponent : public ConditionalMapBase Kokkos::View workspace(team_member.thread_scratch(1), workspaceSize); auto eval = SingleEvaluator(workspace.data(), cache.data(), pt, coeffs, quad_, expansion_, nugget_); double y_scale = ys(ptInd); - if constexpr(isCompact) y_scale *= eval(1); + if constexpr(isCompact) y_scale = y_scale*(eval(1.)-zero_eval_()) + zero_eval_(); output(ptInd) = RootFinding::InverseSingleBracket(y_scale, eval, pt(pt.extent(0)-1), xtol, ytol, info); if constexpr(isCompact) { output(ptInd) = fmin(fmax(output(ptInd), 0.0), 1.0); @@ -429,7 +441,6 @@ class MonotoneComponent : public ConditionalMapBase Kokkos::parallel_for(policy, functor); } - /** @brief Approximates the "continuous derivative" \f$\frac{\partial T}{\partial x_D}\f$ derived from the exact integral form of the transport map. @details See the mathematical background section for more details on discrete and continuous map derivatives. @@ -504,7 +515,7 @@ class MonotoneComponent : public ConditionalMapBase // If compact, normalize by part independent of x_d if constexpr(isCompact) { Kokkos::View workspace(team_member.thread_scratch(1), workspaceSize); - derivs(ptInd) /= EvaluateSingle(cache.data(), workspace.data(), pt, 1., coeffs, quad_, expansion_); + derivs(ptInd) /= (EvaluateSingle(cache.data(), workspace.data(), pt, 1., coeffs, quad_, expansion_) - zero_eval_()); } } }; @@ -675,8 +686,7 @@ class MonotoneComponent : public ConditionalMapBase Kokkos::View cache(team_member.thread_scratch(1), cacheSize); Kokkos::View workspace(team_member.thread_scratch(1), workspaceSize); Kokkos::View integral(team_member.thread_scratch(1), numTerms+1); - Kokkos::View integral_frac; - if constexpr(isCompact) integral_frac = Kokkos::View(team_member.thread_scratch(1), numTerms+1); + Kokkos::View integral_denom; // Fill in the cache with anything that doesn't depend on x_d expansion_.FillCache1(cache.data(), pt, DerivativeFlags::Parameters); @@ -689,11 +699,11 @@ class MonotoneComponent : public ConditionalMapBase // Do the same work for the denominator if needed if constexpr(isCompact) { - MonotoneIntegrand integrand_frac(cache.data(), expansion_, pt, 1., coeffs, DerivativeFlags::Parameters, nugget_); - quad_.Integrate(workspace.data(), integrand_frac, 0, 1, integral_frac.data()); + integral_denom = Kokkos::View(team_member.thread_scratch(1), numTerms+1); + MonotoneIntegrand integrand_denom(cache.data(), expansion_, pt, 1., coeffs, DerivativeFlags::Parameters, nugget_); + quad_.Integrate(workspace.data(), integrand_denom, 0, 1, integral_denom.data()); } - expansion_.FillCache2(cache.data(), pt, 0.0, DerivativeFlags::Parameters); // Evaluates the offdiagonal basis and stores the coeffgrad of it into jacView @@ -704,7 +714,8 @@ class MonotoneComponent : public ConditionalMapBase double denom_eval; if constexpr(isCompact) { - denom_eval = integral_frac(0) + offdiag_eval; + denom_eval = integral_denom(0) + offdiag_eval - zero_eval_(); + numer_eval -= zero_eval_(); evaluations(ptInd) /= denom_eval; } @@ -713,7 +724,8 @@ class MonotoneComponent : public ConditionalMapBase double offdiag_jac_term = jacView(termInd); double numer_jacobian = integral(termInd+1) + offdiag_jac_term; if constexpr(isCompact) { - double denom_jacobian = integral_frac(termInd+1) + offdiag_jac_term; + numer_jacobian -= zero_param_grad_(termInd); + double denom_jacobian = integral_denom(termInd+1) + offdiag_jac_term - zero_param_grad_(termInd); jacView(termInd) = (numer_jacobian*denom_eval - denom_jacobian*numer_eval)/(denom_eval*denom_eval); } else { jacView(termInd) = numer_jacobian; @@ -798,11 +810,12 @@ class MonotoneComponent : public ConditionalMapBase double denom_eval, denom_eval_sq; if constexpr(isCompact) { + numer_eval -= zero_eval_(); // Create the integrand g( \partial_D f(x_1,...,x_{D-1},1)) MonotoneIntegrand integrand_denom(cache.data(), expansion_, pt, 1., coeffs, DerivativeFlags::Input, nugget_); // Compute \int_0^1 g( \partial_D f(x_1,...,x_{D-1},t)) dt as well as the gradient of this term wrt the map input quad_.Integrate(workspace.data(), integrand_denom, 0, 1, integral_denom.data()); - denom_eval = integral_denom(0) + offdiag_eval; + denom_eval = integral_denom(0) + offdiag_eval - zero_eval_(); denom_eval_sq = denom_eval*denom_eval; evaluations(ptInd) /= denom_eval; } @@ -895,7 +908,7 @@ class MonotoneComponent : public ConditionalMapBase expansion_.FillCache2(cache.data(), pt, 0., DerivativeFlags::Parameters); offdiag_eval = expansion_.CoeffDerivative(cache.data(), coeffs, jac_denom); numer_diag_deriv = PosFuncType::Evaluate(df); - denom_eval = integral_denom(0) + offdiag_eval; + denom_eval = integral_denom(0) + offdiag_eval - zero_eval_(); denom_eval_sq = denom_eval*denom_eval; } @@ -903,7 +916,7 @@ class MonotoneComponent : public ConditionalMapBase for(unsigned int i=0; i expansion_.FillCache2(cache.data(), pt, 1., DerivativeFlags::Input); offdiag_eval = expansion_.InputDerivative(cache.data(), coeffs, jac_denom); numer_diag_deriv = PosFuncType::Evaluate(df); - denom_eval = integral_denom(0) + offdiag_eval; + denom_eval = integral_denom(0) + offdiag_eval - zero_eval_(); denom_eval_sq = denom_eval*denom_eval; } @@ -1112,6 +1125,7 @@ class MonotoneComponent : public ConditionalMapBase { ar( cereal::base_class>( this )); ar( expansion_, quad_, useContDeriv_, nugget_); + // TODO: Serialize zero_eval and zero_param_grad ar( this->savedCoeffs ); } @@ -1122,11 +1136,11 @@ class MonotoneComponent : public ConditionalMapBase QuadratureType quad; bool useContDeriv; double nugget; - ar(expansion, quad, useContDeriv, nugget); + ar(expansion, quad, useContDeriv, nugget); + // TODO: Serialize zero_eval and zero_param_grad (needs custom constructor) Kokkos::View coeffs; ar( coeffs ); - if(coeffs.size() == expansion.NumCoeffs()){ construct( expansion, quad, useContDeriv, nugget, coeffs); }else{ @@ -1136,6 +1150,32 @@ class MonotoneComponent : public ConditionalMapBase #endif // MPART_HAS_CEREAL + void SetCoeffs(Kokkos::View coeffs) override { + ConditionalMapBase::SetCoeffs(coeffs); + if constexpr(isCompact) { + initializeZeroEval(this->savedCoeffs); + } + } + + void WrapCoeffs(Kokkos::View coeffs) override { + ConditionalMapBase::WrapCoeffs(coeffs); + if constexpr(isCompact) { + std::cerr << "\033[33m" // yellow + << "WARNING: Changing wrapped coefficients in a Compact MonotoneComponent will give incorrect answers" + << "\033[0m" // reset + << std::endl; + initializeZeroEval(this->savedCoeffs); + } + } + + #if defined(MPART_ENABLE_GPU) + void SetCoeffs(Kokkos::View, mpart::DeviceSpace, Kokkos::HostSpace>> coeffs) override { + ConditionalMapBase::SetCoeffs(coeffs); + if constexpr(isCompact) { + initializeZeroEval(this->savedCoeffs); + } + } + #endif private: ExpansionType expansion_; @@ -1143,7 +1183,35 @@ class MonotoneComponent : public ConditionalMapBase unsigned int dim_; bool useContDeriv_; double nugget_; + Kokkos::View zero_eval_; + Kokkos::View zero_param_grad_; + + template = true> + void initializeZeroEval(StridedVector const& coeffs) { + const unsigned int cacheSize = expansion_.CacheSize(); + auto functor = KOKKOS_CLASS_LAMBDA (typename Kokkos::TeamPolicy::Space>::member_type team_member) { + + unsigned int ptInd = team_member.league_rank () * team_member.team_size () + team_member.team_rank (); + + if(ptInd<1){ + // Get a pointer to the shared memory that Kokkos set up for this team + Kokkos::View cache(team_member.thread_scratch(1), cacheSize); + + // Fill in entries in the cache that are independent of x_d. By passing DerivativeFlags::None, we are telling the expansion that no derivatives with wrt x_1,...x_{d-1} will be needed. + expansion_.FillCache0(cache.data(), DerivativeFlags::Parameters); + zero_eval_() = expansion_.CoeffDerivative(cache.data(), coeffs, zero_param_grad_); + } + }; + + // Create a policy with enough scratch memory to cache the polynomial evaluations + unsigned int cacheBytes = Kokkos::View::shmem_size(cacheSize); + // Only need to evaluate this once + auto policy = GetCachedRangePolicy::Space>(1, cacheBytes, functor); + + // Compute f(0) + Kokkos::parallel_for(policy, functor); + } template struct SingleEvaluator { diff --git a/MParT/MultivariateExpansionWorker.h b/MParT/MultivariateExpansionWorker.h index d2dde344..aa76070e 100644 --- a/MParT/MultivariateExpansionWorker.h +++ b/MParT/MultivariateExpansionWorker.h @@ -129,6 +129,27 @@ class MultivariateExpansionWorker */ KOKKOS_INLINE_FUNCTION unsigned int InputSize() const {return multiSet_.Length();}; + /** + @brief Fills cache to evaluate f(0) + @details + @param polyCache A pointer to the start of the cache. This memory must be allocated before calling this function. + @param derivType + + @see FillCache1, FillCache2 + */ + KOKKOS_FUNCTION void FillCache0(double* polyCache, + DerivativeFlags::DerivativeType derivType) const + { + // Only allowed to evaluate, fail if you want derivatives; while possible this is a safety precaution + if(derivType == DerivativeFlags::None || derivType == DerivativeFlags::Parameters){ + for(unsigned int d=0; d("Cannot get derivatives for FillCache0"); + } + } + /** @brief Precomputes parts of the cache using all but the last component of the point, i.e., using only \f$x_1,x_2,\ldots,x_{d-1}\f$, not \f$x_d\f$. @details diff --git a/tests/Test_MapFactory.cpp b/tests/Test_MapFactory.cpp index 85c93aa4..4bbd650f 100644 --- a/tests/Test_MapFactory.cpp +++ b/tests/Test_MapFactory.cpp @@ -125,6 +125,97 @@ TEST_CASE( "Testing map component factory with linearized basis", "[MapFactoryLi } +TEST_CASE( "Testing compact map component factory", "[MapFactoryCompactComponent]" ) { + + MapOptions options; + options.basisType = BasisTypes::ProbabilistHermite; + options.isCompact = true; + options.basisNorm = false; + + unsigned int dim = 2; + unsigned int maxDegree = 7; + MultiIndexSet mset_h = MultiIndexSet::CreateTotalOrder(dim,maxDegree, [](MultiIndex m){return m.HasNonzeroEnd() || m.Max() == 0;}); + FixedMultiIndexSet mset = mset_h.Fix(true); + + SECTION("AdaptiveSimpson"){ + options.quadType = QuadTypes::AdaptiveSimpson; + + std::shared_ptr> map = MapFactory::CreateComponent(mset, options); + REQUIRE(map!=nullptr); + + Kokkos::View coeffs("Coefficients", map->numCoeffs); + for(unsigned int i=0; inumCoeffs; ++i) + coeffs(i) = 1.0; + map->SetCoeffs(coeffs); + + unsigned int numPts = 5; + Kokkos::View pts("Points", dim, numPts); + pts(0,0) = 0.0; + pts(0,1) = 0.2; + pts(0,2) = 0.5; + pts(0,3) = 0.94; + pts(0,4) = 1.0; + pts(1,0) = 0.0; + pts(1,1) = 0.0; + pts(1,2) = 0.4; + pts(1,3) = 1.0; + pts(1,4) = 1.0; + + Kokkos::View evals = map->Evaluate(pts); + + // This is perhaps broken for certain coefficient values when the polynomial p(x,y) does not have p(x,0) = 0. + SKIP(); + for(unsigned int i=0; i= 0.); + CHECK(evals(0,i) <= 1.); + } + } +} + +TEST_CASE( "Testing compact map component factory, sinusoid-legendre basis", "[MapFactoryCompactComponent_Sinusoid]" ) { + + MapOptions options; + options.basisType = BasisTypes::SinusoidLegendre; + options.isCompact = true; + options.basisNorm = false; + + unsigned int dim = 2; + unsigned int maxDegree = 7; + MultiIndexSet mset_h = MultiIndexSet::CreateTotalOrder(dim,maxDegree); + FixedMultiIndexSet mset = mset_h.Fix(true); + + SECTION("AdaptiveSimpson"){ + options.quadType = QuadTypes::ClenshawCurtis; + + std::shared_ptr> map = MapFactory::CreateComponent(mset, options); + REQUIRE(map!=nullptr); + + Kokkos::View coeffs("Coefficients", map->numCoeffs); + for(unsigned int i=0; inumCoeffs; ++i) + coeffs(i) = i*cos(i*M_PI*2/map->numCoeffs); + map->SetCoeffs(coeffs); + + unsigned int numPts = 5; + Kokkos::View pts("Points", dim, numPts); + pts(0,0) = 0.0; + pts(0,1) = 0.2; + pts(0,2) = 0.5; + pts(0,3) = 0.94; + pts(0,4) = 1.0; + pts(1,0) = 0.0; + pts(1,1) = 0.0; + pts(1,2) = 0.4; + pts(1,3) = 1.0; + pts(1,4) = 1.0; + + Kokkos::View evals = map->Evaluate(pts); + + for(unsigned int i=0; i= 0.); + CHECK(evals(0,i) <= 1.); + } + } +} TEST_CASE( "Testing multivariate expansion factory", "[MapFactoryExpansion]" ) { diff --git a/tests/Test_MonotoneComponent_compact.cpp b/tests/Test_MonotoneComponent_compact.cpp index ecfbf06b..8e06e8c9 100644 --- a/tests/Test_MonotoneComponent_compact.cpp +++ b/tests/Test_MonotoneComponent_compact.cpp @@ -424,51 +424,56 @@ TEST_CASE("Testing CompactMonotoneComponent CoeffGrad and LogDeterminantCoeffGra Kokkos::View evalPts("Evaluate Points", dim, numPts); for(unsigned int i=0; i,HostSpace> expansion(mset); + MultiIndexSet mset = MultiIndexSet::CreateTotalOrder(dim, maxDegree); + MultivariateExpansionWorker,HostSpace> expansion(mset); unsigned int maxSub = 20; double relTol = 1e-7; double absTol = 1e-7; AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); - MonotoneComponent, HostSpace, true> comp(expansion, quad); + MonotoneComponent, HostSpace, true> comp(expansion, quad); Kokkos::View coeffs("Expansion coefficients", mset.Size()); for(unsigned int i=0; i sens("Sensitivity", 1, numPts); - for(unsigned int i=0; i sens ("sensitivities", 1, numPts); + Kokkos::deep_copy(sens, 1.); + Kokkos::View evals = comp.Evaluate(evalPts); + Kokkos::View evals2; Kokkos::View grads = comp.CoeffGrad(evalPts, sens); REQUIRE(grads.extent(0)==comp.numCoeffs); REQUIRE(grads.extent(1)==numPts); - for(unsigned int j=1; j logDets = comp.LogDeterminant(evalPts); Kokkos::View logDets2; Kokkos::View grads = comp.LogDeterminantCoeffGrad(evalPts); @@ -483,8 +488,12 @@ TEST_CASE("Testing CompactMonotoneComponent CoeffGrad and LogDeterminantCoeffGra comp.SetCoeffs(coeffs); logDets2 = comp.LogDeterminant(evalPts); - for(unsigned int ptInd=0; ptInd Date: Thu, 13 Jun 2024 15:08:50 -0600 Subject: [PATCH 08/11] Working tests and create component --- MParT/MapOptions.h | 2 +- MParT/MonotoneComponent.h | 172 +++++++---------------- src/MapFactoryImpl19.cpp | 25 ++-- tests/Test_MapFactory.cpp | 12 +- tests/Test_MonotoneComponent_compact.cpp | 45 +++--- 5 files changed, 92 insertions(+), 164 deletions(-) diff --git a/MParT/MapOptions.h b/MParT/MapOptions.h index 5a89f0f2..66de5f17 100644 --- a/MParT/MapOptions.h +++ b/MParT/MapOptions.h @@ -13,7 +13,7 @@ namespace mpart{ ProbabilistHermite, PhysicistHermite, HermiteFunctions, - SinusoidLegendre + Legendre }; enum class PosFuncTypes diff --git a/MParT/MonotoneComponent.h b/MParT/MonotoneComponent.h index 448c099b..7800443f 100644 --- a/MParT/MonotoneComponent.h +++ b/MParT/MonotoneComponent.h @@ -68,12 +68,7 @@ class MonotoneComponent : public ConditionalMapBase quad_(quad), dim_(expansion.InputSize()), useContDeriv_(useContDeriv), - nugget_(nugget){ - if constexpr(isCompact) { - zero_param_grad_ = Kokkos::View("Zero param grad", expansion.NumCoeffs()); - zero_eval_ = Kokkos::View("Evaluation at zero"); - } - }; + nugget_(nugget){}; MonotoneComponent(ExpansionType const& expansion, QuadratureType const& quad, @@ -84,13 +79,7 @@ class MonotoneComponent : public ConditionalMapBase quad_(quad), dim_(expansion.InputSize()), useContDeriv_(useContDeriv), - nugget_(nugget){ - if constexpr(isCompact) { - zero_param_grad_ = Kokkos::View("Zero param grad", expansion.NumCoeffs()); - zero_eval_ = Kokkos::View("Evaluation at zero"); - initializeZeroEval(this->savedCoeffs); - } - }; + nugget_(nugget){}; virtual std::shared_ptr> GetBaseFunction() override{return std::make_shared>(1,expansion_);}; @@ -293,7 +282,7 @@ class MonotoneComponent : public ConditionalMapBase output(ptInd) = EvaluateSingle(cache.data(), workspace.data(), pt, pt(dim_-1), coeffs, quad_, expansion_); if constexpr(isCompact) { double denom_eval = EvaluateSingle(cache.data(), workspace.data(), pt, 1., coeffs, quad_, expansion_); - output(ptInd) = (output(ptInd) - zero_eval_())/(denom_eval - zero_eval_()); + output(ptInd) /= denom_eval; } } }; @@ -427,10 +416,11 @@ class MonotoneComponent : public ConditionalMapBase Kokkos::View workspace(team_member.thread_scratch(1), workspaceSize); auto eval = SingleEvaluator(workspace.data(), cache.data(), pt, coeffs, quad_, expansion_, nugget_); double y_scale = ys(ptInd); - if constexpr(isCompact) y_scale = y_scale*(eval(1.)-zero_eval_()) + zero_eval_(); + if constexpr(isCompact) y_scale *= eval(1.); output(ptInd) = RootFinding::InverseSingleBracket(y_scale, eval, pt(pt.extent(0)-1), xtol, ytol, info); if constexpr(isCompact) { - output(ptInd) = fmin(fmax(output(ptInd), 0.0), 1.0); + if(output(ptInd) < xtol) output(ptInd) = 0.; + else if(output(ptInd) > 1-xtol) output(ptInd) = 1.; } } }; @@ -515,7 +505,7 @@ class MonotoneComponent : public ConditionalMapBase // If compact, normalize by part independent of x_d if constexpr(isCompact) { Kokkos::View workspace(team_member.thread_scratch(1), workspaceSize); - derivs(ptInd) /= (EvaluateSingle(cache.data(), workspace.data(), pt, 1., coeffs, quad_, expansion_) - zero_eval_()); + derivs(ptInd) /= EvaluateSingle(cache.data(), workspace.data(), pt, 1., coeffs, quad_, expansion_); } } }; @@ -709,26 +699,24 @@ class MonotoneComponent : public ConditionalMapBase // Evaluates the offdiagonal basis and stores the coeffgrad of it into jacView double offdiag_eval = expansion_.CoeffDerivative(cache.data(), coeffs, jacView); - double numer_eval = integral(0) + offdiag_eval; - evaluations(ptInd) = numer_eval; - - double denom_eval; + double numer_eval, denom_eval, denom_eval_sq; if constexpr(isCompact) { - denom_eval = integral_denom(0) + offdiag_eval - zero_eval_(); - numer_eval -= zero_eval_(); - evaluations(ptInd) /= denom_eval; + numer_eval = integral(0); + denom_eval = integral_denom(0); + evaluations(ptInd) = numer_eval / denom_eval; + denom_eval_sq = denom_eval*denom_eval; + } else { + evaluations(ptInd) = integral(0) + offdiag_eval; } // Add the Integral to the coefficient gradient for(unsigned int termInd=0; termInd quad_.SetDim(dim_+1); const unsigned int workspaceSize = quad_.WorkspaceSize(); unsigned int integral_size = dim_+1; - if(isCompact) integral_size *= 2; + if constexpr(isCompact) integral_size *= 2; // Create a policy with enough scratch memory to cache the polynomial evaluations auto cacheBytes = Kokkos::View::shmem_size(cacheSize+workspaceSize+integral_size); @@ -789,7 +777,6 @@ class MonotoneComponent : public ConditionalMapBase Kokkos::View workspace(team_member.thread_scratch(1), workspaceSize); Kokkos::View integral(team_member.thread_scratch(1), dim_+1); Kokkos::View integral_denom; - if constexpr(isCompact) integral_denom = Kokkos::View(team_member.thread_scratch(1), dim_+1); // Fill in the cache with anything that doesn't depend on x_d expansion_.FillCache1(cache.data(), pt, DerivativeFlags::Input); @@ -804,30 +791,30 @@ class MonotoneComponent : public ConditionalMapBase expansion_.FillCache2(cache.data(), pt, 0.0, DerivativeFlags::Input); double offdiag_eval = expansion_.InputDerivative(cache.data(), coeffs, jacView); - - double numer_eval = numer_diag_eval + offdiag_eval; - evaluations(ptInd) = numer_eval; - double denom_eval, denom_eval_sq; + double numer_eval, denom_eval, denom_eval_sq; if constexpr(isCompact) { - numer_eval -= zero_eval_(); + numer_eval = numer_diag_eval; + + integral_denom = Kokkos::View(team_member.thread_scratch(1), dim_+1); // Create the integrand g( \partial_D f(x_1,...,x_{D-1},1)) MonotoneIntegrand integrand_denom(cache.data(), expansion_, pt, 1., coeffs, DerivativeFlags::Input, nugget_); // Compute \int_0^1 g( \partial_D f(x_1,...,x_{D-1},t)) dt as well as the gradient of this term wrt the map input quad_.Integrate(workspace.data(), integrand_denom, 0, 1, integral_denom.data()); - denom_eval = integral_denom(0) + offdiag_eval - zero_eval_(); + + denom_eval = integral_denom(0); denom_eval_sq = denom_eval*denom_eval; - evaluations(ptInd) /= denom_eval; - } + evaluations(ptInd) = numer_eval/denom_eval; + } else evaluations(ptInd) = numer_diag_eval + offdiag_eval; // Add the Integral to the coefficient gradient for(unsigned int d=0; d const unsigned int cacheSize = expansion_.CacheSize(); // Create a policy with enough scratch memory to cache the polynomial evaluations - auto cacheBytes = Kokkos::View::shmem_size(cacheSize + isCompact*(2*numTerms+1+workspaceSize)); + auto cacheBytes = Kokkos::View::shmem_size(cacheSize + isCompact*(numTerms+1+workspaceSize)); auto functor = KOKKOS_CLASS_LAMBDA (typename Kokkos::TeamPolicy::member_type team_member) { @@ -882,11 +869,6 @@ class MonotoneComponent : public ConditionalMapBase Kokkos::View integral_denom; Kokkos::View workspace; Kokkos::View jac_denom; - if constexpr(isCompact) { - integral_denom = Kokkos::View(team_member.thread_scratch(1), numTerms+1); - jac_denom = Kokkos::View(team_member.thread_scratch(1), numTerms); - workspace = Kokkos::View(team_member.thread_scratch(1), workspaceSize); - } // Evaluate the orthogonal polynomials in each direction (except the last) for all possible orders Kokkos::View cache(team_member.thread_scratch(1), cacheSize); @@ -900,15 +882,18 @@ class MonotoneComponent : public ConditionalMapBase double df = expansion_.MixedCoeffDerivative(cache.data(), coeffs, 1, jacView); double dgdf = PosFuncType::Derivative(df); - double offdiag_eval, numer_diag_deriv, denom_eval, denom_eval_sq; + double numer_diag_deriv, denom_eval, denom_eval_sq; if constexpr(isCompact) { + + integral_denom = Kokkos::View(team_member.thread_scratch(1), numTerms+1); + workspace = Kokkos::View(team_member.thread_scratch(1), workspaceSize); + MonotoneIntegrand integrand_denom(cache.data(), expansion_, pt, 1., coeffs, DerivativeFlags::Parameters, nugget_); quad_.Integrate(workspace.data(), integrand_denom, 0, 1, integral_denom.data()); expansion_.FillCache2(cache.data(), pt, 0., DerivativeFlags::Parameters); - offdiag_eval = expansion_.CoeffDerivative(cache.data(), coeffs, jac_denom); numer_diag_deriv = PosFuncType::Evaluate(df); - denom_eval = integral_denom(0) + offdiag_eval - zero_eval_(); + denom_eval = integral_denom(0); denom_eval_sq = denom_eval*denom_eval; } @@ -916,7 +901,7 @@ class MonotoneComponent : public ConditionalMapBase for(unsigned int i=0; i // Ask the expansion how much memory it would like for its one-point cache const unsigned int workspaceSize = quad_.WorkspaceSize(); - const unsigned int cacheSize = expansion_.CacheSize() + isCompact*(workspaceSize + 2*dim_ + 1); + const unsigned int cacheSize = expansion_.CacheSize() + isCompact*(workspaceSize + dim_ + 1); // Create a policy with enough scratch memory to cache the polynomial evaluations auto cacheBytes = Kokkos::View::shmem_size(cacheSize); @@ -959,12 +944,6 @@ class MonotoneComponent : public ConditionalMapBase Kokkos::View integral_denom; Kokkos::View workspace; - Kokkos::View jac_denom; - if constexpr(isCompact) { - integral_denom = Kokkos::View(team_member.thread_scratch(1), dim_+1); - jac_denom = Kokkos::View(team_member.thread_scratch(1), dim_); - workspace = Kokkos::View(team_member.thread_scratch(1), workspaceSize); - } // Evaluate the orthogonal polynomials in each direction (except the last) for all possible orders Kokkos::View cache(team_member.thread_scratch(1), cacheSize); @@ -979,12 +958,14 @@ class MonotoneComponent : public ConditionalMapBase double df = expansion_.MixedInputDerivative(cache.data(), coeffs, jacView); double dgdf = PosFuncType::Derivative(df); - double offdiag_eval, numer_diag_deriv, denom_eval, denom_eval_sq; + double numer_diag_deriv, denom_eval, denom_eval_sq; if constexpr(isCompact) { + integral_denom = Kokkos::View(team_member.thread_scratch(1), dim_+1); + workspace = Kokkos::View(team_member.thread_scratch(1), workspaceSize); + expansion_.FillCache2(cache.data(), pt, 1., DerivativeFlags::Input); - offdiag_eval = expansion_.InputDerivative(cache.data(), coeffs, jac_denom); numer_diag_deriv = PosFuncType::Evaluate(df); - denom_eval = integral_denom(0) + offdiag_eval - zero_eval_(); + denom_eval = integral_denom(0); denom_eval_sq = denom_eval*denom_eval; } @@ -993,7 +974,7 @@ class MonotoneComponent : public ConditionalMapBase double numer_mixed_grad = jacView(i)*dgdf; if constexpr(isCompact) { // TODO: do I need jac_denom in last dimension? - double denom_input_grad = integral_denom(i+1) + jac_denom(i); + double denom_input_grad = integral_denom(i+1); jacView(i) = (numer_mixed_grad*denom_eval - numer_diag_deriv*denom_input_grad)/denom_eval_sq; } else { jacView(i) = numer_mixed_grad; @@ -1096,8 +1077,10 @@ class MonotoneComponent : public ConditionalMapBase nugget); quad.Integrate(workspace, integrand, 0, 1, &output); - expansion.FillCache2(cache, pt, 0.0, DerivativeFlags::None); - output += expansion.Evaluate(cache, coeffs); + if constexpr(!isCompact) { + expansion.FillCache2(cache, pt, 0.0, DerivativeFlags::None); + output += expansion.Evaluate(cache, coeffs); + } return output; } @@ -1125,7 +1108,6 @@ class MonotoneComponent : public ConditionalMapBase { ar( cereal::base_class>( this )); ar( expansion_, quad_, useContDeriv_, nugget_); - // TODO: Serialize zero_eval and zero_param_grad ar( this->savedCoeffs ); } @@ -1138,7 +1120,6 @@ class MonotoneComponent : public ConditionalMapBase double nugget; ar(expansion, quad, useContDeriv, nugget); - // TODO: Serialize zero_eval and zero_param_grad (needs custom constructor) Kokkos::View coeffs; ar( coeffs ); if(coeffs.size() == expansion.NumCoeffs()){ @@ -1150,32 +1131,6 @@ class MonotoneComponent : public ConditionalMapBase #endif // MPART_HAS_CEREAL - void SetCoeffs(Kokkos::View coeffs) override { - ConditionalMapBase::SetCoeffs(coeffs); - if constexpr(isCompact) { - initializeZeroEval(this->savedCoeffs); - } - } - - void WrapCoeffs(Kokkos::View coeffs) override { - ConditionalMapBase::WrapCoeffs(coeffs); - if constexpr(isCompact) { - std::cerr << "\033[33m" // yellow - << "WARNING: Changing wrapped coefficients in a Compact MonotoneComponent will give incorrect answers" - << "\033[0m" // reset - << std::endl; - initializeZeroEval(this->savedCoeffs); - } - } - - #if defined(MPART_ENABLE_GPU) - void SetCoeffs(Kokkos::View, mpart::DeviceSpace, Kokkos::HostSpace>> coeffs) override { - ConditionalMapBase::SetCoeffs(coeffs); - if constexpr(isCompact) { - initializeZeroEval(this->savedCoeffs); - } - } - #endif private: ExpansionType expansion_; @@ -1183,35 +1138,6 @@ class MonotoneComponent : public ConditionalMapBase unsigned int dim_; bool useContDeriv_; double nugget_; - Kokkos::View zero_eval_; - Kokkos::View zero_param_grad_; - - template = true> - void initializeZeroEval(StridedVector const& coeffs) { - const unsigned int cacheSize = expansion_.CacheSize(); - - auto functor = KOKKOS_CLASS_LAMBDA (typename Kokkos::TeamPolicy::Space>::member_type team_member) { - - unsigned int ptInd = team_member.league_rank () * team_member.team_size () + team_member.team_rank (); - - if(ptInd<1){ - // Get a pointer to the shared memory that Kokkos set up for this team - Kokkos::View cache(team_member.thread_scratch(1), cacheSize); - - // Fill in entries in the cache that are independent of x_d. By passing DerivativeFlags::None, we are telling the expansion that no derivatives with wrt x_1,...x_{d-1} will be needed. - expansion_.FillCache0(cache.data(), DerivativeFlags::Parameters); - zero_eval_() = expansion_.CoeffDerivative(cache.data(), coeffs, zero_param_grad_); - } - }; - - // Create a policy with enough scratch memory to cache the polynomial evaluations - unsigned int cacheBytes = Kokkos::View::shmem_size(cacheSize); - // Only need to evaluate this once - auto policy = GetCachedRangePolicy::Space>(1, cacheBytes, functor); - - // Compute f(0) - Kokkos::parallel_for(policy, functor); - } template struct SingleEvaluator { diff --git a/src/MapFactoryImpl19.cpp b/src/MapFactoryImpl19.cpp index 46b7f910..70273c47 100644 --- a/src/MapFactoryImpl19.cpp +++ b/src/MapFactoryImpl19.cpp @@ -11,13 +11,12 @@ using namespace mpart; -using BasisType = Kokkos::pair; - template -std::shared_ptr> CreateComponentImpl_SL_CC(FixedMultiIndexSet const& mset, MapOptions opts) +std::shared_ptr> CreateComponentImpl_LEG_ACC(FixedMultiIndexSet const& mset, MapOptions opts) { - BasisEvaluator basis1d(mset.Length()); - ClenshawCurtisQuadrature quad(opts.quadPts, 1); + BasisEvaluator basis1d(mset.Length()); + unsigned int level = std::log2(opts.quadPts-2); + AdaptiveClenshawCurtis quad(level, opts.quadMaxSub, 1, nullptr, opts.quadAbsTol, opts.quadRelTol, QuadError::First, opts.quadMinSub); MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; @@ -30,19 +29,19 @@ std::shared_ptr> CreateComponentImpl_SL_CC(Fixed return output; } -static auto reg_host_sl_cc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::SinusoidLegendre, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_SL_CC)); -static auto reg_host_sl_cc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::SinusoidLegendre, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_SL_CC)); +static auto reg_host_leg_acc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::Legendre, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_LEG_ACC)); +static auto reg_host_leg_acc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::Legendre, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_LEG_ACC)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_sl_cc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::SinusoidLegendre, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_SL_CC)); - static auto reg_device_sl_cc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::SinusoidLegendre, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_SL_CC)); + static auto reg_device_leg_acc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::Legendre, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_LEG_ACC)); + static auto reg_device_leg_acc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::Legendre, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_LEG_ACC)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_OFFDIAGHOMOGENEOUS_MONO_COMP(SineBasis, ShiftedLegendre, Identity, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, true) -REGISTER_OFFDIAGHOMOGENEOUS_MONO_COMP(SineBasis, ShiftedLegendre, Identity, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(ShiftedLegendre, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(ShiftedLegendre, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, true) #if defined(MPART_ENABLE_GPU) -REGISTER_OFFDIAGHOMOGENEOUS_MONO_COMP(SineBasis, ShiftedLegendre, Identity, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, true) -REGISTER_OFFDIAGHOMOGENEOUS_MONO_COMP(SineBasis, ShiftedLegendre, Identity, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(ShiftedLegendre, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(ShiftedLegendre, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, true) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory19) #endif \ No newline at end of file diff --git a/tests/Test_MapFactory.cpp b/tests/Test_MapFactory.cpp index 4bbd650f..64e1bb66 100644 --- a/tests/Test_MapFactory.cpp +++ b/tests/Test_MapFactory.cpp @@ -163,8 +163,6 @@ TEST_CASE( "Testing compact map component factory", "[MapFactoryCompactComponent Kokkos::View evals = map->Evaluate(pts); - // This is perhaps broken for certain coefficient values when the polynomial p(x,y) does not have p(x,0) = 0. - SKIP(); for(unsigned int i=0; i= 0.); CHECK(evals(0,i) <= 1.); @@ -172,10 +170,10 @@ TEST_CASE( "Testing compact map component factory", "[MapFactoryCompactComponent } } -TEST_CASE( "Testing compact map component factory, sinusoid-legendre basis", "[MapFactoryCompactComponent_Sinusoid]" ) { +TEST_CASE( "Testing compact map component factory, legendre basis", "[MapFactoryCompactComponent_Legendre]" ) { MapOptions options; - options.basisType = BasisTypes::SinusoidLegendre; + options.basisType = BasisTypes::Legendre; options.isCompact = true; options.basisNorm = false; @@ -184,15 +182,15 @@ TEST_CASE( "Testing compact map component factory, sinusoid-legendre basis", "[M MultiIndexSet mset_h = MultiIndexSet::CreateTotalOrder(dim,maxDegree); FixedMultiIndexSet mset = mset_h.Fix(true); - SECTION("AdaptiveSimpson"){ - options.quadType = QuadTypes::ClenshawCurtis; + SECTION("AdaptiveClenshawCurtis"){ + options.quadType = QuadTypes::AdaptiveClenshawCurtis; std::shared_ptr> map = MapFactory::CreateComponent(mset, options); REQUIRE(map!=nullptr); Kokkos::View coeffs("Coefficients", map->numCoeffs); for(unsigned int i=0; inumCoeffs; ++i) - coeffs(i) = i*cos(i*M_PI*2/map->numCoeffs); + coeffs(i) = i*cos(0.5+i*M_PI*2/map->numCoeffs); map->SetCoeffs(coeffs); unsigned int numPts = 5; diff --git a/tests/Test_MonotoneComponent_compact.cpp b/tests/Test_MonotoneComponent_compact.cpp index 8e06e8c9..a87cc731 100644 --- a/tests/Test_MonotoneComponent_compact.cpp +++ b/tests/Test_MonotoneComponent_compact.cpp @@ -29,7 +29,7 @@ TEST_CASE( "Testing compact monotone component evaluation in 1d", "[MonotoneComp /* Create and evaluate an affine map - Set coefficients so that f(x) = 1.0 + x - - (f(0) + int_0^x exp( d f(t) ) dt)/(f(0) + int_0^1 exp( d f(t) ) dt ) = (1 + |x| * exp(1))/(1 + exp(1)) + - (int_0^x exp( d f(t) ) dt)/(int_0^1 exp( d f(t) ) dt ) = x*exp(-1) + 1 */ SECTION("Affine Map"){ unsigned int maxDegree = 1; @@ -53,7 +53,7 @@ TEST_CASE( "Testing compact monotone component evaluation in 1d", "[MonotoneComp comp.EvaluateImpl(evalPts, coeffs, output); for(unsigned int i=0; i 0.; CHECK(isInbounds); } @@ -62,7 +62,7 @@ TEST_CASE( "Testing compact monotone component evaluation in 1d", "[MonotoneComp /* Create and evaluate a quadratic map - Set coefficients so that f(x) = 1.0 + x + 0.5*x^2 - df/dt = 1.0 + t - - f(0) + int_0^x exp( df/dt ) dt = ( 1.0 + int_0^x exp(1+t) dt )/( 1.0 + int_0^1 exp(1+t) dt) = (1+exp(1+x)-exp(1))/(1+exp(2)-exp(1)) + - int_0^x exp( df/dt ) dt = int_0^x exp(1+t) = exp(1+x)-exp(1) => (exp(1+x)-exp(1))/(exp(2)-exp(1)) */ SECTION("Quadratic Map"){ unsigned int maxDegree = 2; @@ -87,14 +87,14 @@ TEST_CASE( "Testing compact monotone component evaluation in 1d", "[MonotoneComp for(unsigned int i=0; i,HostSpace> expansion(mset); unsigned int numTerms = mset.Size(); @@ -248,7 +244,7 @@ TEST_CASE( "Testing compact monotone component derivative", "[CompactMonotoneCom // Create some arbitrary coefficients Kokkos::View coeffs("Expansion coefficients", mset.Size()); for(unsigned int i=0; i evals("evals",numPts); comp.EvaluateImpl(evalPts, coeffs, evals); @@ -256,9 +252,11 @@ TEST_CASE( "Testing compact monotone component derivative", "[CompactMonotoneCom comp.EvaluateImpl(rightEvalPts, coeffs, rightEvals); Kokkos::View contDerivs = comp.ContinuousDerivative(evalPts, coeffs); - for(unsigned int i=0; i sens ("sensitivities", 1, numPts); Kokkos::deep_copy(sens, 1.); From 3e2e704267dd82cc40c4b58b98158107fc6384ef Mon Sep 17 00:00:00 2001 From: "D. Sharp" Date: Thu, 13 Jun 2024 15:09:30 -0600 Subject: [PATCH 09/11] lint tests --- tests/Test_MapFactory.cpp | 337 +++++++++++--------- tests/Test_MonotoneComponent_compact.cpp | 388 ++++++++++++----------- 2 files changed, 390 insertions(+), 335 deletions(-) diff --git a/tests/Test_MapFactory.cpp b/tests/Test_MapFactory.cpp index 64e1bb66..3dc7c011 100644 --- a/tests/Test_MapFactory.cpp +++ b/tests/Test_MapFactory.cpp @@ -14,242 +14,255 @@ using namespace mpart; using namespace Catch; using MemorySpace = Kokkos::HostSpace; -TEST_CASE( "Testing map component factory", "[MapFactoryComponent]" ) { +TEST_CASE("Testing map component factory", "[MapFactoryComponent]") +{ - MapOptions options; options.basisType = BasisTypes::ProbabilistHermite; options.basisNorm = false; unsigned int dim = 3; unsigned int maxDegree = 5; - FixedMultiIndexSet mset(dim,maxDegree); + FixedMultiIndexSet mset(dim, maxDegree); - SECTION("AdaptiveSimpson"){ + SECTION("AdaptiveSimpson") + { options.quadType = QuadTypes::AdaptiveSimpson; std::shared_ptr> map = MapFactory::CreateComponent(mset, options); - REQUIRE(map!=nullptr); + REQUIRE(map != nullptr); unsigned int numPts = 100; - Kokkos::View pts("Points", dim, numPts); - for(unsigned int i=0; i pts("Points", dim, numPts); + for (unsigned int i = 0; i < numPts; ++i) + pts(dim - 1, i) = double(i) / double(numPts - 1); - Kokkos::View eval = map->Evaluate(pts); + Kokkos::View eval = map->Evaluate(pts); } - SECTION("ClenshawCurtis"){ + SECTION("ClenshawCurtis") + { options.quadType = QuadTypes::ClenshawCurtis; - + std::shared_ptr> map = MapFactory::CreateComponent(mset, options); - REQUIRE(map!=nullptr); + REQUIRE(map != nullptr); unsigned int numPts = 100; - Kokkos::View pts("Points", dim, numPts); - for(unsigned int i=0; i pts("Points", dim, numPts); + for (unsigned int i = 0; i < numPts; ++i) + pts(dim - 1, i) = double(i) / double(numPts - 1); - Kokkos::View eval = map->Evaluate(pts); + Kokkos::View eval = map->Evaluate(pts); } - SECTION("AdaptiveClenshawCurtis"){ + SECTION("AdaptiveClenshawCurtis") + { options.quadType = QuadTypes::AdaptiveClenshawCurtis; - + std::shared_ptr> map = MapFactory::CreateComponent(mset, options); - REQUIRE(map!=nullptr); + REQUIRE(map != nullptr); unsigned int numPts = 100; - Kokkos::View pts("Points", dim, numPts); - for(unsigned int i=0; i pts("Points", dim, numPts); + for (unsigned int i = 0; i < numPts; ++i) + pts(dim - 1, i) = double(i) / double(numPts - 1); - Kokkos::View eval = map->Evaluate(pts); + Kokkos::View eval = map->Evaluate(pts); } } +TEST_CASE("Testing map component factory with linearized basis", "[MapFactoryLinearizedComponent]") +{ -TEST_CASE( "Testing map component factory with linearized basis", "[MapFactoryLinearizedComponent]" ) { - - MapOptions options; options.basisType = BasisTypes::ProbabilistHermite; options.basisLB = -5; options.basisUB = 4; options.basisNorm = false; - - + MapOptions options2; options2.basisType = BasisTypes::ProbabilistHermite; options2.basisNorm = false; - + unsigned int dim = 1; unsigned int maxDegree = 7; - FixedMultiIndexSet mset(dim,maxDegree); + FixedMultiIndexSet mset(dim, maxDegree); - SECTION("AdaptiveSimpson"){ + SECTION("AdaptiveSimpson") + { options.quadType = QuadTypes::AdaptiveSimpson; std::shared_ptr> linearized_map = MapFactory::CreateComponent(mset, options); - + std::shared_ptr> map = MapFactory::CreateComponent(mset, options2); - REQUIRE(linearized_map!=nullptr); - REQUIRE(map!=nullptr); + REQUIRE(linearized_map != nullptr); + REQUIRE(map != nullptr); - Kokkos::View coeffs("Coefficients", map->numCoeffs); - for(unsigned int i=0; inumCoeffs; ++i) + Kokkos::View coeffs("Coefficients", map->numCoeffs); + for (unsigned int i = 0; i < map->numCoeffs; ++i) coeffs(i) = 1.0; map->SetCoeffs(coeffs); linearized_map->SetCoeffs(coeffs); unsigned int numPts = 5; - Kokkos::View pts("Points", dim, numPts); - pts(0,0) = -6; - pts(0,1) = -4.5; - pts(0,2) = 0; - pts(0,3) = 3.5; - pts(0,4) = 4.5; - - - Kokkos::View linearized_evals = linearized_map->Evaluate(pts); - Kokkos::View evals = map->Evaluate(pts); - - for(unsigned int i=0; ioptions.basisUB)){ - CHECK( std::abs(linearized_evals(0,i) - evals(0,i))>1e-13); - }else{ - CHECK( linearized_evals(0,i) == Approx(evals(0,i)).epsilon(1e-15)); + Kokkos::View pts("Points", dim, numPts); + pts(0, 0) = -6; + pts(0, 1) = -4.5; + pts(0, 2) = 0; + pts(0, 3) = 3.5; + pts(0, 4) = 4.5; + + Kokkos::View linearized_evals = linearized_map->Evaluate(pts); + Kokkos::View evals = map->Evaluate(pts); + + for (unsigned int i = 0; i < numPts; ++i) + { + if ((pts(0, i) < options.basisLB) || (pts(0, i) > options.basisUB)) + { + CHECK(std::abs(linearized_evals(0, i) - evals(0, i)) > 1e-13); + } + else + { + CHECK(linearized_evals(0, i) == Approx(evals(0, i)).epsilon(1e-15)); } } } - } -TEST_CASE( "Testing compact map component factory", "[MapFactoryCompactComponent]" ) { +TEST_CASE("Testing compact map component factory", "[MapFactoryCompactComponent]") +{ MapOptions options; options.basisType = BasisTypes::ProbabilistHermite; options.isCompact = true; options.basisNorm = false; - + unsigned int dim = 2; unsigned int maxDegree = 7; - MultiIndexSet mset_h = MultiIndexSet::CreateTotalOrder(dim,maxDegree, [](MultiIndex m){return m.HasNonzeroEnd() || m.Max() == 0;}); + MultiIndexSet mset_h = MultiIndexSet::CreateTotalOrder(dim, maxDegree, [](MultiIndex m) + { return m.HasNonzeroEnd() || m.Max() == 0; }); FixedMultiIndexSet mset = mset_h.Fix(true); - SECTION("AdaptiveSimpson"){ + SECTION("AdaptiveSimpson") + { options.quadType = QuadTypes::AdaptiveSimpson; std::shared_ptr> map = MapFactory::CreateComponent(mset, options); - REQUIRE(map!=nullptr); + REQUIRE(map != nullptr); - Kokkos::View coeffs("Coefficients", map->numCoeffs); - for(unsigned int i=0; inumCoeffs; ++i) + Kokkos::View coeffs("Coefficients", map->numCoeffs); + for (unsigned int i = 0; i < map->numCoeffs; ++i) coeffs(i) = 1.0; map->SetCoeffs(coeffs); unsigned int numPts = 5; - Kokkos::View pts("Points", dim, numPts); - pts(0,0) = 0.0; - pts(0,1) = 0.2; - pts(0,2) = 0.5; - pts(0,3) = 0.94; - pts(0,4) = 1.0; - pts(1,0) = 0.0; - pts(1,1) = 0.0; - pts(1,2) = 0.4; - pts(1,3) = 1.0; - pts(1,4) = 1.0; - - Kokkos::View evals = map->Evaluate(pts); - - for(unsigned int i=0; i= 0.); - CHECK(evals(0,i) <= 1.); + Kokkos::View pts("Points", dim, numPts); + pts(0, 0) = 0.0; + pts(0, 1) = 0.2; + pts(0, 2) = 0.5; + pts(0, 3) = 0.94; + pts(0, 4) = 1.0; + pts(1, 0) = 0.0; + pts(1, 1) = 0.0; + pts(1, 2) = 0.4; + pts(1, 3) = 1.0; + pts(1, 4) = 1.0; + + Kokkos::View evals = map->Evaluate(pts); + + for (unsigned int i = 0; i < numPts; ++i) + { + CHECK(evals(0, i) >= 0.); + CHECK(evals(0, i) <= 1.); } } } -TEST_CASE( "Testing compact map component factory, legendre basis", "[MapFactoryCompactComponent_Legendre]" ) { +TEST_CASE("Testing compact map component factory, legendre basis", "[MapFactoryCompactComponent_Legendre]") +{ MapOptions options; options.basisType = BasisTypes::Legendre; options.isCompact = true; options.basisNorm = false; - + unsigned int dim = 2; unsigned int maxDegree = 7; - MultiIndexSet mset_h = MultiIndexSet::CreateTotalOrder(dim,maxDegree); + MultiIndexSet mset_h = MultiIndexSet::CreateTotalOrder(dim, maxDegree); FixedMultiIndexSet mset = mset_h.Fix(true); - SECTION("AdaptiveClenshawCurtis"){ + SECTION("AdaptiveClenshawCurtis") + { options.quadType = QuadTypes::AdaptiveClenshawCurtis; std::shared_ptr> map = MapFactory::CreateComponent(mset, options); - REQUIRE(map!=nullptr); + REQUIRE(map != nullptr); - Kokkos::View coeffs("Coefficients", map->numCoeffs); - for(unsigned int i=0; inumCoeffs; ++i) - coeffs(i) = i*cos(0.5+i*M_PI*2/map->numCoeffs); + Kokkos::View coeffs("Coefficients", map->numCoeffs); + for (unsigned int i = 0; i < map->numCoeffs; ++i) + coeffs(i) = i * cos(0.5 + i * M_PI * 2 / map->numCoeffs); map->SetCoeffs(coeffs); unsigned int numPts = 5; - Kokkos::View pts("Points", dim, numPts); - pts(0,0) = 0.0; - pts(0,1) = 0.2; - pts(0,2) = 0.5; - pts(0,3) = 0.94; - pts(0,4) = 1.0; - pts(1,0) = 0.0; - pts(1,1) = 0.0; - pts(1,2) = 0.4; - pts(1,3) = 1.0; - pts(1,4) = 1.0; - - Kokkos::View evals = map->Evaluate(pts); - - for(unsigned int i=0; i= 0.); - CHECK(evals(0,i) <= 1.); + Kokkos::View pts("Points", dim, numPts); + pts(0, 0) = 0.0; + pts(0, 1) = 0.2; + pts(0, 2) = 0.5; + pts(0, 3) = 0.94; + pts(0, 4) = 1.0; + pts(1, 0) = 0.0; + pts(1, 1) = 0.0; + pts(1, 2) = 0.4; + pts(1, 3) = 1.0; + pts(1, 4) = 1.0; + + Kokkos::View evals = map->Evaluate(pts); + + for (unsigned int i = 0; i < numPts; ++i) + { + CHECK(evals(0, i) >= 0.); + CHECK(evals(0, i) <= 1.); } } } -TEST_CASE( "Testing multivariate expansion factory", "[MapFactoryExpansion]" ) { +TEST_CASE("Testing multivariate expansion factory", "[MapFactoryExpansion]") +{ MapOptions options; options.basisType = BasisTypes::ProbabilistHermite; - + unsigned int outDim = 5; unsigned int inDim = 3; unsigned int maxDegree = 5; - FixedMultiIndexSet mset(inDim,maxDegree); + FixedMultiIndexSet mset(inDim, maxDegree); std::shared_ptr> func = MapFactory::CreateExpansion(outDim, mset, options); - REQUIRE(func!=nullptr); + REQUIRE(func != nullptr); unsigned int numPts = 100; - Kokkos::View pts("Points", inDim, numPts); - for(unsigned int i=0; i pts("Points", inDim, numPts); + for (unsigned int i = 0; i < numPts; ++i) + pts(inDim - 1, i) = double(i) / double(numPts - 1); - Kokkos::View eval = func->Evaluate(pts); - CHECK(eval.extent(0)==outDim); - CHECK(eval.extent(1)==numPts); + Kokkos::View eval = func->Evaluate(pts); + CHECK(eval.extent(0) == outDim); + CHECK(eval.extent(1) == numPts); } - -TEST_CASE( "Testing factory method for triangular map", "[MapFactoryTriangular]" ) { +TEST_CASE("Testing factory method for triangular map", "[MapFactoryTriangular]") +{ MapOptions options; options.basisType = BasisTypes::ProbabilistHermite; - std::shared_ptr> map = MapFactory::CreateTriangular(4,3,5, options); + std::shared_ptr> map = MapFactory::CreateTriangular(4, 3, 5, options); REQUIRE(map != nullptr); } -TEST_CASE( "Testing factory method for single entry map, activeInd = 1", "[MapFactorySingleEntryMap 1]" ) { +TEST_CASE("Testing factory method for single entry map, activeInd = 1", "[MapFactorySingleEntryMap 1]") +{ MapOptions options; options.basisType = BasisTypes::ProbabilistHermite; @@ -264,7 +277,8 @@ TEST_CASE( "Testing factory method for single entry map, activeInd = 1", "[MapFa REQUIRE(map != nullptr); } -TEST_CASE( "Testing factory method for single entry map, activeInd = dim", "[MapFactorySingleEntryMap 2]" ) { +TEST_CASE("Testing factory method for single entry map, activeInd = dim", "[MapFactorySingleEntryMap 2]") +{ MapOptions options; options.basisType = BasisTypes::ProbabilistHermite; @@ -279,7 +293,8 @@ TEST_CASE( "Testing factory method for single entry map, activeInd = dim", "[Map REQUIRE(map != nullptr); } -TEST_CASE( "Testing factory method for single entry map, 1 < activeInd < dim", "[MapFactorySingleEntryMap 3]" ) { +TEST_CASE("Testing factory method for single entry map, 1 < activeInd < dim", "[MapFactorySingleEntryMap 3]") +{ MapOptions options; options.basisType = BasisTypes::ProbabilistHermite; @@ -293,83 +308,91 @@ TEST_CASE( "Testing factory method for single entry map, 1 < activeInd < dim", " REQUIRE(map != nullptr); } -TEST_CASE( "Testing factory method for Sigmoid Component", "[MapFactorySigmoidComponent]" ) { +TEST_CASE("Testing factory method for Sigmoid Component", "[MapFactorySigmoidComponent]") +{ MapOptions options; unsigned int inputDim = 7; unsigned int maxDegree = 3; unsigned int num_sigmoids = 5; - unsigned int numCenters = 2 + num_sigmoids*(num_sigmoids+1)/2; + unsigned int numCenters = 2 + num_sigmoids * (num_sigmoids + 1) / 2; options.basisType = BasisTypes::HermiteFunctions; - Kokkos::View centers("Centers", numCenters); + Kokkos::View centers("Centers", numCenters); double bound = 3.; - centers(0) = -bound; centers(1) = bound; + centers(0) = -bound; + centers(1) = bound; unsigned int center_idx = 2; - for(int j = 0; j < num_sigmoids; j++){ - for(int i = 0; i <= j; i++){ - centers(center_idx) = -bound + (2*bound)*(i+1)/(j+2); + for (int j = 0; j < num_sigmoids; j++) + { + for (int i = 0; i <= j; i++) + { + centers(center_idx) = -bound + (2 * bound) * (i + 1) / (j + 2); center_idx++; } } std::shared_ptr> func = MapFactory::CreateSigmoidComponent(inputDim, maxDegree, centers, options); REQUIRE(func != nullptr); unsigned int numPts = 100; - Kokkos::View pts("Points", inputDim, numPts); - Kokkos::MDRangePolicy, typename MemoryToExecution::Space> policy({0,0}, {inputDim, numPts}); - Kokkos::parallel_for("Fill points", policy, KOKKOS_LAMBDA(const int i, const int j){ - pts(i,j) = double(j*i)/double((inputDim)*(numPts-1)); - }); + Kokkos::View pts("Points", inputDim, numPts); + Kokkos::MDRangePolicy, typename MemoryToExecution::Space> policy({0, 0}, {inputDim, numPts}); + Kokkos::parallel_for("Fill points", policy, KOKKOS_LAMBDA(const int i, const int j) { pts(i, j) = double(j * i) / double((inputDim) * (numPts - 1)); }); Kokkos::fence(); // Checking example of Gradient StridedVector coeffs = func->Coeffs(); Kokkos::deep_copy(coeffs, 1.0); - Kokkos::View eval = func->Evaluate(pts); - CHECK(eval.extent(0)==1); - SECTION("Check Gradient") { - Kokkos::View sens ( "Sensitivities", 1, numPts); - Kokkos::RangePolicy::Space> policy_pts {0, numPts}; - Kokkos::parallel_for("fill sensitivities", policy_pts, KOKKOS_LAMBDA(const int i){ - sens(0,i) = 1.0; - }); - Kokkos::View grad = func->Gradient(pts, sens); - CHECK(grad.extent(0)==inputDim); - CHECK(grad.extent(1)==numPts); + Kokkos::View eval = func->Evaluate(pts); + CHECK(eval.extent(0) == 1); + SECTION("Check Gradient") + { + Kokkos::View sens("Sensitivities", 1, numPts); + Kokkos::RangePolicy::Space> policy_pts{0, numPts}; + Kokkos::parallel_for("fill sensitivities", policy_pts, KOKKOS_LAMBDA(const int i) { sens(0, i) = 1.0; }); + Kokkos::View grad = func->Gradient(pts, sens); + CHECK(grad.extent(0) == inputDim); + CHECK(grad.extent(1) == numPts); double fd_step = 1e-6; - for(int i = 0; i < inputDim; i++){ - Kokkos::parallel_for(policy_pts, KOKKOS_LAMBDA(const int j){ + for (int i = 0; i < inputDim; i++) + { + Kokkos::parallel_for(policy_pts, KOKKOS_LAMBDA(const int j) { if(i > 0) pts(i-1,j) -= fd_step; - pts(i,j) += fd_step; - }); + pts(i,j) += fd_step; }); Kokkos::fence(); - Kokkos::View eval2 = func->Evaluate(pts); - for(int j = 0; j < numPts; j++){ - double fd = (eval2(0,j) - eval(0,j))/(fd_step); - CHECK(grad(i,j) == Approx(fd).epsilon(20*fd_step)); + Kokkos::View eval2 = func->Evaluate(pts); + for (int j = 0; j < numPts; j++) + { + double fd = (eval2(0, j) - eval(0, j)) / (fd_step); + CHECK(grad(i, j) == Approx(fd).epsilon(20 * fd_step)); } } } - SECTION("Create Sigmoid Component from fixed msets") { + SECTION("Create Sigmoid Component from fixed msets") + { // Make some arbitrary limiter - auto limiter = [maxDegree](MultiIndex const& index){ - return index.Get(index.Length()-1) != 0 && index.Sum() == maxDegree; + auto limiter = [maxDegree](MultiIndex const &index) + { + return index.Get(index.Length() - 1) != 0 && index.Sum() == maxDegree; }; - FixedMultiIndexSet mset= MultiIndexSet::CreateTotalOrder(inputDim, maxDegree, limiter).Fix(true); + FixedMultiIndexSet mset = MultiIndexSet::CreateTotalOrder(inputDim, maxDegree, limiter).Fix(true); std::shared_ptr> map = MapFactory::CreateSigmoidComponent(mset, centers, options); REQUIRE(map != nullptr); REQUIRE(map->numCoeffs == mset.Size()); } - SECTION("Create Triangular Sigmoid Map From Components") { + SECTION("Create Triangular Sigmoid Map From Components") + { std::vector>> maps; - for(int i = 1; i <= inputDim; i++){ + for (int i = 1; i <= inputDim; i++) + { maps.push_back(MapFactory::CreateSigmoidComponent(i, 0, centers, options)); } auto map = std::make_shared>(maps); REQUIRE(map != nullptr); } - SECTION("CreateSigmoidTriangular") { + SECTION("CreateSigmoidTriangular") + { std::vector> centers_vec; unsigned int outputDim = 3; - for(int i = 0; i < outputDim; i++){ + for (int i = 0; i < outputDim; i++) + { centers_vec.push_back(centers); } std::shared_ptr> map = MapFactory::CreateSigmoidTriangular(inputDim, outputDim, 0, centers_vec, options); diff --git a/tests/Test_MonotoneComponent_compact.cpp b/tests/Test_MonotoneComponent_compact.cpp index a87cc731..acff2e30 100644 --- a/tests/Test_MonotoneComponent_compact.cpp +++ b/tests/Test_MonotoneComponent_compact.cpp @@ -15,7 +15,8 @@ using namespace mpart; using namespace Catch::Matchers; using HostSpace = Kokkos::HostSpace; -TEST_CASE( "Testing compact monotone component evaluation in 1d", "[MonotoneComponentCompact1d]" ) { +TEST_CASE("Testing compact monotone component evaluation in 1d", "[MonotoneComponentCompact1d]") +{ const double testTol = 1e-7; unsigned int dim = 1; @@ -23,22 +24,23 @@ TEST_CASE( "Testing compact monotone component evaluation in 1d", "[MonotoneComp // Create points evently space on [lb,ub] unsigned int numPts = 20; - Kokkos::View evalPts("Evaluate Points", dim, numPts); - for(unsigned int i=0; i evalPts("Evaluate Points", dim, numPts); + for (unsigned int i = 0; i < numPts; ++i) + evalPts(0, i) = (i / double(numPts - 0.5)); /* Create and evaluate an affine map - Set coefficients so that f(x) = 1.0 + x - (int_0^x exp( d f(t) ) dt)/(int_0^1 exp( d f(t) ) dt ) = x*exp(-1) + 1 */ - SECTION("Affine Map"){ + SECTION("Affine Map") + { unsigned int maxDegree = 1; // This only will be okay for compact map since dim = 1 MultiIndexSet mset = MultiIndexSet::CreateTotalOrder(dim, maxDegree); - MultivariateExpansionWorker,HostSpace> expansion(mset); + MultivariateExpansionWorker, HostSpace> expansion(mset); - Kokkos::View coeffs("Expansion coefficients", mset.Size()); + Kokkos::View coeffs("Expansion coefficients", mset.Size()); coeffs(0) = 1.0; // Constant term coeffs(1) = 1.0; // Linear term @@ -47,13 +49,14 @@ TEST_CASE( "Testing compact monotone component evaluation in 1d", "[MonotoneComp double absTol = 1e-7; AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); - MonotoneComponent,HostSpace>, Exp, AdaptiveSimpson, HostSpace, true> comp(expansion, quad); + MonotoneComponent, HostSpace>, Exp, AdaptiveSimpson, HostSpace, true> comp(expansion, quad); - Kokkos::View output("output", numPts); + Kokkos::View output("output", numPts); comp.EvaluateImpl(evalPts, coeffs, output); - for(unsigned int i=0; i 0.; CHECK(isInbounds); } @@ -64,35 +67,38 @@ TEST_CASE( "Testing compact monotone component evaluation in 1d", "[MonotoneComp - df/dt = 1.0 + t - int_0^x exp( df/dt ) dt = int_0^x exp(1+t) = exp(1+x)-exp(1) => (exp(1+x)-exp(1))/(exp(2)-exp(1)) */ - SECTION("Quadratic Map"){ + SECTION("Quadratic Map") + { unsigned int maxDegree = 2; MultiIndexSet mset = MultiIndexSet::CreateTotalOrder(dim, maxDegree); - MultivariateExpansionWorker,HostSpace> expansion(mset); + MultivariateExpansionWorker, HostSpace> expansion(mset); - Kokkos::View coeffs("Expansion coefficients", mset.Size()); - coeffs(1) = 1.0; // Linear term = x ^1 - coeffs(2) = 0.5; // Quadratic term = x^2 - 1.0 + Kokkos::View coeffs("Expansion coefficients", mset.Size()); + coeffs(1) = 1.0; // Linear term = x ^1 + coeffs(2) = 0.5; // Quadratic term = x^2 - 1.0 coeffs(0) = 1.0 + coeffs(2); // Constant term = x^0 unsigned int maxSub = 30; double relTol = 1e-7; double absTol = 1e-7; - AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol,QuadError::First); + AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); - MonotoneComponent,HostSpace>, Exp, AdaptiveSimpson, HostSpace, true> comp(expansion, quad); + MonotoneComponent, HostSpace>, Exp, AdaptiveSimpson, HostSpace, true> comp(expansion, quad); - Kokkos::View output("Output", numPts); + Kokkos::View output("Output", numPts); comp.EvaluateImpl(evalPts, coeffs, output); - for(unsigned int i=0; i evalPts("Evaluate Points", dim, numPts); - for(unsigned int i=0; i evalPts("Evaluate Points", dim, numPts); + for (unsigned int i = 0; i < numPts; ++i) + evalPts(0, i) = (i / double(numPts - 1)); /* Create and evaluate an affine map - Set coefficients so that f(x) = 1.0 + x - ( f(0) + int_0^x exp( d f(t) ) dt ) / ( f(0) + int_0^1 exp( d f(t) ) dt )= (1 + x * exp(1))/(1 + exp(1)) */ - SECTION("Affine Map"){ + SECTION("Affine Map") + { unsigned int maxDegree = 1; MultiIndexSet mset = MultiIndexSet::CreateTotalOrder(dim, maxDegree); - MultivariateExpansionWorker,HostSpace> expansion(mset); + MultivariateExpansionWorker, HostSpace> expansion(mset); - Kokkos::View coeffs("Expansion coefficients", mset.Size()); + Kokkos::View coeffs("Expansion coefficients", mset.Size()); coeffs(0) = 1.0; // Constant term coeffs(1) = 1.0; // Linear term @@ -125,15 +132,16 @@ TEST_CASE( "Testing bracket-based inversion of compact monotone component", "[Co MonotoneComponent, HostSpace, true> comp(expansion, quad); - Kokkos::View ys("ys", numPts); + Kokkos::View ys("ys", numPts); comp.EvaluateImpl(evalPts, coeffs, ys); - Kokkos::View testInverse("Test output", numPts); - for(int i = 0; i < 100; i++) + Kokkos::View testInverse("Test output", numPts); + for (int i = 0; i < 100; i++) comp.InverseImpl(evalPts, ys, coeffs, testInverse); - for(unsigned int i=0; i,HostSpace> expansion(mset); + MultivariateExpansionWorker, HostSpace> expansion(mset); - Kokkos::View coeffs("Expansion coefficients", mset.Size()); - coeffs(1) = 1.0; // Linear term = x ^1 - coeffs(2) = 0.5; // Quadratic term = x^2 - 1.0 + Kokkos::View coeffs("Expansion coefficients", mset.Size()); + coeffs(1) = 1.0; // Linear term = x ^1 + coeffs(2) = 0.5; // Quadratic term = x^2 - 1.0 coeffs(0) = 1.0 + coeffs(2); // Constant term = x^0 unsigned int maxSub = 30; double relTol = 1e-7; double absTol = 1e-7; - AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol,QuadError::First); + AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); MonotoneComponent, HostSpace, true> comp(expansion, quad); - Kokkos::View ys("ys",numPts); - comp.EvaluateImpl(evalPts, coeffs,ys); + Kokkos::View ys("ys", numPts); + comp.EvaluateImpl(evalPts, coeffs, ys); - Kokkos::View testInverse("inverse", numPts); + Kokkos::View testInverse("inverse", numPts); comp.InverseImpl(evalPts, ys, coeffs, testInverse); - for(unsigned int i=0; i x("Evaluate Points", dim, 1); - x(0,0) = 0.5; + Kokkos::View x("Evaluate Points", dim, 1); + x(0, 0) = 0.5; unsigned int maxDegree = 2; MultiIndexSet mset = MultiIndexSet::CreateTotalOrder(dim, maxDegree); - MultivariateExpansionWorker,HostSpace> expansion(mset); + MultivariateExpansionWorker, HostSpace> expansion(mset); - Kokkos::View coeffs("Expansion coefficients", mset.Size()); - coeffs(1) = 1.0; // Linear term = x ^1 - coeffs(2) = 0.5; // Quadratic term = x^2 - 1.0 + Kokkos::View coeffs("Expansion coefficients", mset.Size()); + coeffs(1) = 1.0; // Linear term = x ^1 + coeffs(2) = 0.5; // Quadratic term = x^2 - 1.0 coeffs(0) = 1.0 + coeffs(2); // Constant term = x^0 unsigned int maxSub = 30; double relTol = 1e-7; double absTol = 1e-7; - AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol,QuadError::First); + AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); MonotoneComponent, HostSpace, true> comp(expansion, quad); - Kokkos::View ys("ys", numPts); + Kokkos::View ys("ys", numPts); comp.EvaluateImpl(evalPts, coeffs, ys); - Kokkos::View testInverse("inverse", numPts); - comp.InverseImpl(x, ys, coeffs,testInverse); + Kokkos::View testInverse("inverse", numPts); + comp.InverseImpl(x, ys, coeffs, testInverse); - for(unsigned int i=0; i evalPts("Evaluate Points", dim, numPts); - for(unsigned int i=0; i evalPts("Evaluate Points", dim, numPts); + for (unsigned int i = 0; i < numPts; ++i) + { + evalPts(0, i) = (i / double(numPts - 1)) * (ub - lb) + lb; + evalPts(1, i) = evalPts(0, i); } - Kokkos::View rightEvalPts("Finite difference points", dim, numPts); - for(unsigned int i=0; i rightEvalPts("Finite difference points", dim, numPts); + for (unsigned int i = 0; i < numPts; ++i) + { + rightEvalPts(0, i) = evalPts(0, i); + rightEvalPts(1, i) = evalPts(1, i) + fdStep; } unsigned int maxDegree = 4; MultiIndexSet mset = MultiIndexSet::CreateTotalOrder(dim, maxDegree); - MultivariateExpansionWorker,HostSpace> expansion(mset); + MultivariateExpansionWorker, HostSpace> expansion(mset); unsigned int numTerms = mset.Size(); unsigned int maxSub = 30; double relTol = 1e-7; double absTol = 1e-7; - AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol,QuadError::First); + AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); MonotoneComponent, HostSpace, true> comp(expansion, quad); // Create some arbitrary coefficients - Kokkos::View coeffs("Expansion coefficients", mset.Size()); - for(unsigned int i=0; i coeffs("Expansion coefficients", mset.Size()); + for (unsigned int i = 0; i < coeffs.extent(0); ++i) + coeffs(i) = 0.1 * std::cos(2 * i + 0.5); - Kokkos::View evals("evals",numPts); + Kokkos::View evals("evals", numPts); comp.EvaluateImpl(evalPts, coeffs, evals); - Kokkos::View rightEvals("revals", numPts); + Kokkos::View rightEvals("revals", numPts); comp.EvaluateImpl(rightEvalPts, coeffs, rightEvals); - Kokkos::View contDerivs = comp.ContinuousDerivative(evalPts, coeffs); - - SECTION("Continuous derivatives") { - for(unsigned int i=0; i contDerivs = comp.ContinuousDerivative(evalPts, coeffs); + + SECTION("Continuous derivatives") + { + for (unsigned int i = 0; i < numPts; ++i) + { + double fdDeriv = (rightEvals(i) - evals(i)) / fdStep; + CHECK_THAT(contDerivs(i), WithinRel(fdDeriv, testTol)); } } - SECTION("Coefficient Jacobian"){ + SECTION("Coefficient Jacobian") + { - Kokkos::View evals2("FD Evals", numPts); - Kokkos::View jac("Jacobian", numTerms, numPts); + Kokkos::View evals2("FD Evals", numPts); + Kokkos::View jac("Jacobian", numTerms, numPts); comp.CoeffJacobian(evalPts, coeffs, evals2, jac); - for(unsigned int i=0; i derivs("Derivatives", numPts); - Kokkos::View derivs2("Derivatives2", numPts); + Kokkos::View derivs("Derivatives", numPts); + Kokkos::View derivs2("Derivatives2", numPts); - Kokkos::View jac("Jacobian", numTerms,numPts); + Kokkos::View jac("Jacobian", numTerms, numPts); comp.ContinuousMixedJacobian(evalPts, coeffs, jac); derivs = comp.ContinuousDerivative(evalPts, coeffs); // Perturb the coefficients and recompute - Kokkos::View coeffs2("Coefficients2", numTerms); + Kokkos::View coeffs2("Coefficients2", numTerms); Kokkos::deep_copy(coeffs2, coeffs); - for(unsigned int j=0; j evals("Evaluations", numPts); - Kokkos::View evals2("Evaluations 2", numPts); + Kokkos::View evals("Evaluations", numPts); + Kokkos::View evals2("Evaluations 2", numPts); - Kokkos::View jac("Jacobian", dim, numPts); + Kokkos::View jac("Jacobian", dim, numPts); comp.InputJacobian(evalPts, coeffs, evals, jac); - Kokkos::View evalPts2("Points2", evalPts.extent(0), evalPts.extent(1)); + Kokkos::View evalPts2("Points2", evalPts.extent(0), evalPts.extent(1)); Kokkos::deep_copy(evalPts2, evalPts); - for(unsigned int j=0; j evals("Evaluations", 1, numPts); - - Kokkos::View sens("Jacobian", dim+1, numPts); - REQUIRE_THROWS_AS(comp.GradientImpl(evalPts, sens, evals), std::invalid_argument); + Kokkos::View evals("Evaluations", 1, numPts); + Kokkos::View sens("Jacobian", dim + 1, numPts); + REQUIRE_THROWS_AS(comp.GradientImpl(evalPts, sens, evals), std::invalid_argument); } } - -TEST_CASE( "Compact least squares test", "[CompactMonotoneComponentRegression]" ) { +TEST_CASE("Compact least squares test", "[CompactMonotoneComponentRegression]") +{ unsigned int numPts = 100; - Kokkos::View pts("Training Points", 1,numPts); - for(unsigned int i=0; i fvals("Training Values", numPts); - for(unsigned int i=0; i pts("Training Points", 1, numPts); + for (unsigned int i = 0; i < numPts; ++i) + pts(0, i) = i / (numPts - 1.0); + Kokkos::View fvals("Training Values", numPts); + for (unsigned int i = 0; i < numPts; ++i) + fvals(i) = (pts(0, i) * pts(0, i) + pts(0, i)) / 2; // Bijection on [0,1] // Don't need limiter for compact in one dimension MultiIndexSet mset = MultiIndexSet::CreateTotalOrder(1, 6); - MultivariateExpansionWorker,HostSpace> expansion(mset); + MultivariateExpansionWorker, HostSpace> expansion(mset); unsigned int maxSub = 30; double relTol = 1e-3; @@ -385,14 +409,13 @@ TEST_CASE( "Compact least squares test", "[CompactMonotoneComponentRegression]" MonotoneComponent, HostSpace, true> comp(expansion, quad); unsigned int numTerms = mset.Size(); - Kokkos::View coeffs("Coefficients", numTerms); - Kokkos::View jac("Gradient", numTerms,numPts); - Kokkos::View preds("Predictions", numPts); - + Kokkos::View coeffs("Coefficients", numTerms); + Kokkos::View jac("Gradient", numTerms, numPts); + Kokkos::View preds("Predictions", numPts); double objective; - Eigen::Map> jacMat(&jac(0,0), numTerms,numPts); + Eigen::Map> jacMat(&jac(0, 0), numTerms, numPts); Eigen::Map predVec(&preds(0), numPts); Eigen::Map obsVec(&fvals(0), numPts); @@ -400,40 +423,40 @@ TEST_CASE( "Compact least squares test", "[CompactMonotoneComponentRegression]" Eigen::VectorXd objGrad; - for(unsigned int optIt=0; optIt<5; ++optIt){ + for (unsigned int optIt = 0; optIt < 5; ++optIt) + { comp.CoeffJacobian(pts, coeffs, preds, jac); - objGrad = predVec-obsVec; + objGrad = predVec - obsVec; - objective = 0.5*objGrad.squaredNorm(); + objective = 0.5 * objGrad.squaredNorm(); coeffVec -= jacMat.transpose().colPivHouseholderQr().solve(objGrad); } - CHECK(objective<1e-3); - + CHECK(objective < 1e-3); } - TEST_CASE("Testing CompactMonotoneComponent CoeffGrad and LogDeterminantCoeffGrad", "[CompactMonotoneComponent_CoeffGrad]") { - //const double testTol = 1e-4; + // const double testTol = 1e-4; unsigned int dim = 2; // Create points evently spaced on [lb,ub] unsigned int numPts = 20; - //double lb = -0.5; - //double ub = 0.5; - - Kokkos::View evalPts("Evaluate Points", dim, numPts); - for(unsigned int i=0; i evalPts("Evaluate Points", dim, numPts); + for (unsigned int i = 0; i < numPts; ++i) + { + evalPts(0, i) = i / double(numPts + 2); + evalPts(1, i) = i / double(numPts); } unsigned int maxDegree = 3; MultiIndexSet mset = MultiIndexSet::CreateTotalOrder(dim, maxDegree); - MultivariateExpansionWorker,HostSpace> expansion(mset); + MultivariateExpansionWorker, HostSpace> expansion(mset); unsigned int maxSub = 20; double relTol = 1e-7; @@ -442,66 +465,75 @@ TEST_CASE("Testing CompactMonotoneComponent CoeffGrad and LogDeterminantCoeffGra MonotoneComponent, HostSpace, true> comp(expansion, quad); - Kokkos::View coeffs("Expansion coefficients", mset.Size()); - for(unsigned int i=0; i coeffs("Expansion coefficients", mset.Size()); + for (unsigned int i = 0; i < coeffs.extent(0); ++i) + coeffs(i) = 1. + 0.1 * std::cos(2 * i + 0.5); comp.SetCoeffs(coeffs); - SECTION("CoeffGrad") { - Kokkos::View sens ("sensitivities", 1, numPts); + SECTION("CoeffGrad") + { + Kokkos::View sens("sensitivities", 1, numPts); Kokkos::deep_copy(sens, 1.); - Kokkos::View evals = comp.Evaluate(evalPts); - Kokkos::View evals2; - Kokkos::View grads = comp.CoeffGrad(evalPts, sens); - REQUIRE(grads.extent(0)==comp.numCoeffs); - REQUIRE(grads.extent(1)==numPts); + Kokkos::View evals = comp.Evaluate(evalPts); + Kokkos::View evals2; + Kokkos::View grads = comp.CoeffGrad(evalPts, sens); + REQUIRE(grads.extent(0) == comp.numCoeffs); + REQUIRE(grads.extent(1) == numPts); // Compare with finite difference derivatives const double fdstep = 1e-5; - for(unsigned int i=0; i logDets = comp.LogDeterminant(evalPts); - Kokkos::View logDets2; - Kokkos::View grads = comp.LogDeterminantCoeffGrad(evalPts); - REQUIRE(grads.extent(0)==comp.numCoeffs); - REQUIRE(grads.extent(1)==numPts); + Kokkos::View logDets = comp.LogDeterminant(evalPts); + Kokkos::View logDets2; + Kokkos::View grads = comp.LogDeterminantCoeffGrad(evalPts); + REQUIRE(grads.extent(0) == comp.numCoeffs); + REQUIRE(grads.extent(1) == numPts); // Compare with finite difference derivatives const double fdstep = 1e-5; - for(unsigned int i=0; i Date: Thu, 20 Jun 2024 14:40:32 -0600 Subject: [PATCH 10/11] Fix LogDeterminantInputGrad --- MParT/MonotoneComponent.h | 18 +++--- tests/Test_MonotoneComponent_compact.cpp | 73 ++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 7 deletions(-) diff --git a/MParT/MonotoneComponent.h b/MParT/MonotoneComponent.h index 7800443f..3db3da06 100644 --- a/MParT/MonotoneComponent.h +++ b/MParT/MonotoneComponent.h @@ -849,7 +849,7 @@ class MonotoneComponent : public ConditionalMapBase checkMixedJacobianInput("ContinuousMixedJacobian", jacobian.extent(0), jacobian.extent(1), numTerms, numPts); // Ask the expansion how much memory it would like for it's one-point cache - quad_.SetDim(numTerms+1); + if constexpr(isCompact) quad_.SetDim(numTerms+1); const unsigned int workspaceSize = quad_.WorkspaceSize(); const unsigned int cacheSize = expansion_.CacheSize(); @@ -891,7 +891,6 @@ class MonotoneComponent : public ConditionalMapBase MonotoneIntegrand integrand_denom(cache.data(), expansion_, pt, 1., coeffs, DerivativeFlags::Parameters, nugget_); quad_.Integrate(workspace.data(), integrand_denom, 0, 1, integral_denom.data()); - expansion_.FillCache2(cache.data(), pt, 0., DerivativeFlags::Parameters); numer_diag_deriv = PosFuncType::Evaluate(df); denom_eval = integral_denom(0); denom_eval_sq = denom_eval*denom_eval; @@ -925,12 +924,13 @@ class MonotoneComponent : public ConditionalMapBase checkMixedJacobianInput("ContinuousMixedInputJacobian", jacobian.extent(0), jacobian.extent(1), dim, numPts); - // Ask the expansion how much memory it would like for its one-point cache + // Ask the expansion how much memory it would like for it's one-point cache + if constexpr(isCompact) quad_.SetDim(dim_+1); const unsigned int workspaceSize = quad_.WorkspaceSize(); - const unsigned int cacheSize = expansion_.CacheSize() + isCompact*(workspaceSize + dim_ + 1); + const unsigned int cacheSize = expansion_.CacheSize(); // Create a policy with enough scratch memory to cache the polynomial evaluations - auto cacheBytes = Kokkos::View::shmem_size(cacheSize); + auto cacheBytes = Kokkos::View::shmem_size(cacheSize + isCompact*(workspaceSize + dim_ + 1)); auto functor = KOKKOS_CLASS_LAMBDA (typename Kokkos::TeamPolicy::member_type team_member) { @@ -963,13 +963,15 @@ class MonotoneComponent : public ConditionalMapBase integral_denom = Kokkos::View(team_member.thread_scratch(1), dim_+1); workspace = Kokkos::View(team_member.thread_scratch(1), workspaceSize); - expansion_.FillCache2(cache.data(), pt, 1., DerivativeFlags::Input); + MonotoneIntegrand integrand_denom(cache.data(), expansion_, pt, 1., coeffs, DerivativeFlags::Input, nugget_); + quad_.Integrate(workspace.data(), integrand_denom, 0, 1, integral_denom.data()); + numer_diag_deriv = PosFuncType::Evaluate(df); denom_eval = integral_denom(0); denom_eval_sq = denom_eval*denom_eval; } - for(unsigned int i=0; i jacView(i) = numer_mixed_grad; } } + if constexpr(isCompact) jacView(dim_-1) = jacView(dim_-1)*dgdf/denom_eval; + } }; diff --git a/tests/Test_MonotoneComponent_compact.cpp b/tests/Test_MonotoneComponent_compact.cpp index acff2e30..f360fb61 100644 --- a/tests/Test_MonotoneComponent_compact.cpp +++ b/tests/Test_MonotoneComponent_compact.cpp @@ -385,6 +385,79 @@ TEST_CASE("Testing compact monotone component derivative", "[CompactMonotoneComp } } +TEST_CASE("Compact component input gradients", "[CompactInputGrad]") { + + // const double testTol = 1e-4; + unsigned int dim = 2; + + // Create points evently spaced on [lb,ub] + unsigned int numPts = 20; + double fd_step = 1e-7; + + Kokkos::View evalPts("Evaluate Points", dim, numPts); + for (unsigned int i = 0; i < numPts; ++i) + { + evalPts(0, i) = i / double(numPts + 2); + evalPts(1, i) = i / double(numPts + 1); + } + + unsigned int maxDegree = 3; + MultiIndexSet mset = MultiIndexSet::CreateTotalOrder(dim, maxDegree); + MultivariateExpansionWorker, HostSpace> expansion(mset); + + unsigned int maxSub = 20; + double relTol = 1e-7; + double absTol = 1e-7; + AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); + + MonotoneComponent, HostSpace, true> comp(expansion, quad); + + Kokkos::View coeffs("Expansion coefficients", mset.Size()); + for (unsigned int i = 0; i < coeffs.extent(0); ++i) + coeffs(i) = 1. + 0.1 * std::cos(2 * i + 0.5); + + comp.SetCoeffs(coeffs); + + + SECTION("Gradient") { + Kokkos::View evals = comp.Evaluate(evalPts); + Kokkos::View evals_fd("Finite Difference Eval space", 1, numPts); + Kokkos::View sens("sensitivities", 1, numPts); + double sens_constant = 2.; + Kokkos::deep_copy(sens, sens_constant); + Kokkos::View grads = comp.Gradient(evalPts, sens); + REQUIRE(grads.extent(0) == comp.inputDim); + REQUIRE(grads.extent(1) == numPts); + for(int i = 0; i < dim; i++) { + for(int j = 0; j < numPts; j++) + evalPts(i,j) += fd_step; + comp.EvaluateImpl(evalPts, evals_fd); + for(int j = 0; j < numPts; j++) { + double fd_grad = (evals_fd(0, j) - evals(0,j))/fd_step; + CHECK_THAT(grads(i,j), WithinRel(sens_constant*fd_grad, 1e-3) || WithinAbs(sens_constant*fd_grad, 1e-3)); + evalPts(i,j) -= fd_step; + } + } + } + + SECTION("LogDeterminantInputGrad") { + Kokkos::View logdets = comp.LogDeterminant(evalPts); + Kokkos::View logdets_fd("Finite Difference LogDeterminant space", numPts); + Kokkos::View grads = comp.LogDeterminantInputGrad(evalPts); + REQUIRE(grads.extent(0) == comp.inputDim); + REQUIRE(grads.extent(1) == numPts); + for(int i = 0; i < dim; i++) { + for(int j = 0; j < numPts; j++) evalPts(i,j) += fd_step; + comp.LogDeterminantImpl(evalPts, logdets_fd); + for(int j = 0; j < numPts; j++) { + double fd_grad = (logdets_fd(j) - logdets(j))/fd_step; + CHECK_THAT(grads(i,j), WithinRel(fd_grad, 1e-3) || WithinAbs(fd_grad, 1e-3)); + evalPts(i,j) -= fd_step; + } + } + } +} + TEST_CASE("Compact least squares test", "[CompactMonotoneComponentRegression]") { From bbc6169630f583ae9106f604321ba3ed5f8fde04 Mon Sep 17 00:00:00 2001 From: "D. Sharp" Date: Thu, 20 Jun 2024 14:44:59 -0600 Subject: [PATCH 11/11] Fix Affine tests --- tests/Test_MonotoneComponent_compact.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Test_MonotoneComponent_compact.cpp b/tests/Test_MonotoneComponent_compact.cpp index f360fb61..114039c9 100644 --- a/tests/Test_MonotoneComponent_compact.cpp +++ b/tests/Test_MonotoneComponent_compact.cpp @@ -56,8 +56,8 @@ TEST_CASE("Testing compact monotone component evaluation in 1d", "[MonotoneCompo for (unsigned int i = 0; i < numPts; ++i) { - CHECK_THAT(output(i), WithinRel(1 + exp(-1) * evalPts(0, i), testTol)); - bool isInbounds = output(i) < 1. && output(i) > 0.; + CHECK_THAT(output(i), WithinRel(evalPts(0, i), testTol)); + bool isInbounds = output(i) <= 1. && output(i) >= 0.; CHECK(isInbounds); } }