MCPcopy Create free account
hub / github.com/bgrimstad/splinter / testApproximation

Function testApproximation

test/testingutilities.cpp:892–919  ·  view source on GitHub ↗

Must use std::function because a capturing alpha cannot be converted to a function pointer

Source from the content-addressed store, hash-verified

890
891// Must use std::function because a capturing alpha cannot be converted to a function pointer
892void testApproximation(std::vector<TestFunction *> funcs,
893 std::function<Function *(const DataTable &table)> approx_gen_func,
894 TestType type, size_t numSamplePoints, size_t numEvalPoints,
895 double one_eps, double two_eps, double inf_eps)
896{
897 for(auto &exact : funcs) {
898
899 auto dim = exact->getNumVariables();
900 CHECK(dim > 0);
901 if(dim > 0) {
902 auto samplePoints = linspace(dim, -5, 5, std::pow(numSamplePoints, 1.0/dim));
903 auto evalPoints = linspace(dim, -4.95, 4.95, std::pow(numEvalPoints, 1.0/dim));
904
905 DataTable table = sample(exact, samplePoints);
906
907 Function *approx = approx_gen_func(table);
908
909 INFO("Function: " << exact->getFunctionStr());
910 INFO("Approximant: " << approx->getDescription());
911
912 DenseMatrix errorNorms = getErrorNorms(exact, approx, evalPoints);
913
914 checkNorm(errorNorms, type, evalPoints.size(), one_eps, two_eps, inf_eps);
915
916 delete approx;
917 }
918 }
919}
920
921DenseMatrix centralDifference(const Function &approx, const DenseVector &x)
922{

Callers

nothing calls this directly

Calls 6

sampleFunction · 0.85
getErrorNormsFunction · 0.85
checkNormFunction · 0.85
getFunctionStrMethod · 0.80
getDescriptionMethod · 0.80
linspaceFunction · 0.70

Tested by

no test coverage detected