Skip to content

Commit

Permalink
Merge pull request #165 from MeasureTransport/mparno/issue97
Browse files Browse the repository at this point in the history
Added handling of other quadrature options.
  • Loading branch information
rubiop authored Jul 22, 2022
2 parents a245442 + 5bac464 commit ff71166
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 7 deletions.
102 changes: 102 additions & 0 deletions src/MapFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,108 @@ std::shared_ptr<ConditionalMapBase<MemorySpace>> mpart::MapFactory::CreateCompon
output->Coeffs() = Kokkos::View<double*,MemorySpace>("Component Coefficients", mset.Size());
return output;
}

}else if(opts.quadType==QuadTypes::ClenshawCurtis){

ClenshawCurtisQuadrature<MemorySpace> quad(opts.quadPts, 1);

if(opts.basisType==BasisTypes::ProbabilistHermite){

MultivariateExpansionWorker<ProbabilistHermite,MemorySpace> expansion(mset);
std::shared_ptr<ConditionalMapBase<MemorySpace>> output;

switch(opts.posFuncType) {
case PosFuncTypes::SoftPlus:
output = std::make_shared<MonotoneComponent<decltype(expansion), SoftPlus, decltype(quad), MemorySpace>>(mset, quad, opts.contDeriv); break;
case PosFuncTypes::Exp:
output = std::make_shared<MonotoneComponent<decltype(expansion), Exp, decltype(quad), MemorySpace>>(mset, quad, opts.contDeriv); break;
}

output->SetCoeffs(Kokkos::View<double*,MemorySpace>("Component Coefficients", mset.Size()));
return output;

}else if(opts.basisType==BasisTypes::PhysicistHermite){

MultivariateExpansionWorker<PhysicistHermite, MemorySpace> expansion(mset);
std::shared_ptr<ConditionalMapBase<MemorySpace>> output;

switch(opts.posFuncType) {
case PosFuncTypes::SoftPlus:
output = std::make_shared<MonotoneComponent<decltype(expansion), SoftPlus, decltype(quad), MemorySpace>>(mset, quad, opts.contDeriv); break;
case PosFuncTypes::Exp:
output = std::make_shared<MonotoneComponent<decltype(expansion), Exp, decltype(quad), MemorySpace>>(mset, quad, opts.contDeriv); break;
}

output->SetCoeffs(Kokkos::View<double*,MemorySpace>("Component Coefficients", mset.Size()));
return output;

}else if(opts.basisType==BasisTypes::HermiteFunctions){

MultivariateExpansionWorker<HermiteFunction, MemorySpace> expansion(mset);
std::shared_ptr<ConditionalMapBase<MemorySpace>> output;

switch(opts.posFuncType) {
case PosFuncTypes::SoftPlus:
output = std::make_shared<MonotoneComponent<decltype(expansion), SoftPlus, decltype(quad), MemorySpace>>(mset, quad, opts.contDeriv);
case PosFuncTypes::Exp:
output = std::make_shared<MonotoneComponent<decltype(expansion), Exp, decltype(quad), MemorySpace>>(mset, quad, opts.contDeriv);
}

output->Coeffs() = Kokkos::View<double*,MemorySpace>("Component Coefficients", mset.Size());
return output;
}

}else if(opts.quadType==QuadTypes::AdaptiveClenshawCurtis){

unsigned int level = std::log2(opts.quadPts-2);
AdaptiveClenshawCurtis<MemorySpace> quad(level, opts.quadMaxSub, 1, nullptr, opts.quadAbsTol, opts.quadRelTol, QuadError::First, opts.quadMinSub);

if(opts.basisType==BasisTypes::ProbabilistHermite){

MultivariateExpansionWorker<ProbabilistHermite,MemorySpace> expansion(mset);
std::shared_ptr<ConditionalMapBase<MemorySpace>> output;

switch(opts.posFuncType) {
case PosFuncTypes::SoftPlus:
output = std::make_shared<MonotoneComponent<decltype(expansion), SoftPlus, decltype(quad), MemorySpace>>(mset, quad, opts.contDeriv); break;
case PosFuncTypes::Exp:
output = std::make_shared<MonotoneComponent<decltype(expansion), Exp, decltype(quad), MemorySpace>>(mset, quad, opts.contDeriv); break;
}

output->SetCoeffs(Kokkos::View<double*,MemorySpace>("Component Coefficients", mset.Size()));
return output;

}else if(opts.basisType==BasisTypes::PhysicistHermite){

MultivariateExpansionWorker<PhysicistHermite, MemorySpace> expansion(mset);
std::shared_ptr<ConditionalMapBase<MemorySpace>> output;

switch(opts.posFuncType) {
case PosFuncTypes::SoftPlus:
output = std::make_shared<MonotoneComponent<decltype(expansion), SoftPlus, decltype(quad), MemorySpace>>(mset, quad, opts.contDeriv); break;
case PosFuncTypes::Exp:
output = std::make_shared<MonotoneComponent<decltype(expansion), Exp, decltype(quad), MemorySpace>>(mset, quad, opts.contDeriv); break;
}

output->SetCoeffs(Kokkos::View<double*,MemorySpace>("Component Coefficients", mset.Size()));
return output;

}else if(opts.basisType==BasisTypes::HermiteFunctions){

MultivariateExpansionWorker<HermiteFunction, MemorySpace> expansion(mset);
std::shared_ptr<ConditionalMapBase<MemorySpace>> output;

switch(opts.posFuncType) {
case PosFuncTypes::SoftPlus:
output = std::make_shared<MonotoneComponent<decltype(expansion), SoftPlus, decltype(quad), MemorySpace>>(mset, quad, opts.contDeriv);
case PosFuncTypes::Exp:
output = std::make_shared<MonotoneComponent<decltype(expansion), Exp, decltype(quad), MemorySpace>>(mset, quad, opts.contDeriv);
}

output->Coeffs() = Kokkos::View<double*,MemorySpace>("Component Coefficients", mset.Size());
return output;
}

}


Expand Down
47 changes: 40 additions & 7 deletions tests/Test_MapFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,55 @@ using MemorySpace = Kokkos::HostSpace;

TEST_CASE( "Testing map component factory", "[MapFactoryComponent]" ) {


MapOptions options;
options.basisType = BasisTypes::ProbabilistHermite;

unsigned int dim = 3;
unsigned int maxDegree = 5;
FixedMultiIndexSet<MemorySpace> mset(dim,maxDegree);

std::shared_ptr<ConditionalMapBase<MemorySpace>> map = MapFactory::CreateComponent<MemorySpace>(mset, options);
REQUIRE(map!=nullptr);
SECTION("AdaptiveSimpson"){
options.quadType = QuadTypes::AdaptiveSimpson;

unsigned int numPts = 100;
Kokkos::View<double**,MemorySpace> pts("Points", dim, numPts);
for(unsigned int i=0; i<numPts; ++i)
pts(dim-1,i) = double(i)/double(numPts-1);
std::shared_ptr<ConditionalMapBase<MemorySpace>> map = MapFactory::CreateComponent<MemorySpace>(mset, options);
REQUIRE(map!=nullptr);

unsigned int numPts = 100;
Kokkos::View<double**,MemorySpace> pts("Points", dim, numPts);
for(unsigned int i=0; i<numPts; ++i)
pts(dim-1,i) = double(i)/double(numPts-1);

Kokkos::View<double**, MemorySpace> eval = map->Evaluate(pts);
}

SECTION("ClenshawCurtis"){
options.quadType = QuadTypes::ClenshawCurtis;

std::shared_ptr<ConditionalMapBase<MemorySpace>> map = MapFactory::CreateComponent<MemorySpace>(mset, options);
REQUIRE(map!=nullptr);

unsigned int numPts = 100;
Kokkos::View<double**,MemorySpace> pts("Points", dim, numPts);
for(unsigned int i=0; i<numPts; ++i)
pts(dim-1,i) = double(i)/double(numPts-1);

Kokkos::View<double**, MemorySpace> eval = map->Evaluate(pts);
}

SECTION("AdaptiveClenshawCurtis"){
options.quadType = QuadTypes::AdaptiveClenshawCurtis;

std::shared_ptr<ConditionalMapBase<MemorySpace>> map = MapFactory::CreateComponent<MemorySpace>(mset, options);
REQUIRE(map!=nullptr);

unsigned int numPts = 100;
Kokkos::View<double**,MemorySpace> pts("Points", dim, numPts);
for(unsigned int i=0; i<numPts; ++i)
pts(dim-1,i) = double(i)/double(numPts-1);

Kokkos::View<double**, MemorySpace> eval = map->Evaluate(pts);
Kokkos::View<double**, MemorySpace> eval = map->Evaluate(pts);
}
}


Expand Down

0 comments on commit ff71166

Please sign in to comment.