Sparse Grids Example 11: Unstructured data.
Sparse grid approximation (or surrogates) can be constructed from a set of points not necessarily aligned to the points on the grid, using a least-squares fit.
#endif
cout << "\n---------------------------------------------------------------------------------------------------\n";
cout << std::scientific; cout.precision(4);
cout << "Example 11: construction using unstructured data\n\n";
int const num_inputs = 2;
int const num_test_points = 1000;
std::vector<double> test_points(num_test_points * num_inputs);
std::minstd_rand park_miller(42);
std::uniform_real_distribution<double> domain(-1.0, 1.0);
for(auto &t : test_points) t = domain(park_miller);
std::function<void(double const x[], double y[], size_t)> model)->
double{
std::vector<double> grid_result;
double err = 0.0;
for(int i=0; i<num_test_points; i++){
double model_result;
model(&test_points[i*num_inputs], &model_result, 0);
err = std::max(err, std::abs(grid_result[i] - model_result));
}
return err;
};
auto model = [](double const x[], double y[], size_t)->
void{ y[0] = std::exp(-x[0]*x[0] -x[1]-x[1]); };
int const num_data_points = 2000;
std::vector<double> data_input(num_inputs * num_data_points);
std::vector<double> data_output(num_data_points);
for(auto &d : data_input) d = domain(park_miller);
for(int i=0; i<num_data_points; i++) model(&data_input[i * num_inputs], &data_output[i], 0);
cout << "Skipping example 11, BLAS, CUDA, or MAGMA acceleration required.\n";
return;
}
cout << "Using construction from unstructured (random) data\n";
cout << " approximatino error = " << get_error(grid, model) << "\n\n";
#ifndef __TASMANIAN_DOXYGEN_SKIP
The master-class that represents an instance of a Tasmanian sparse grid.
Definition: TasmanianSparseGrid.hpp:293
static bool isAccelerationAvailable(TypeAcceleration acc)
Returns whether a specific mode can be enabled.
void evaluateBatch(std::vector< FloatType > const &x, std::vector< FloatType > &y) const
Computes the value of the interpolant (or point-wise approximation) for a batch of points.
void enableAcceleration(TypeAcceleration acc)
Change the current acceleration mode to the one specified.
@ rule_clenshawcurtis
Classic nested rule using Chebyshev nodes with very low Lebesgue constant.
Definition: tsgEnumerates.hpp:289
@ accel_cpu_blas
Default (if available), uses both BLAS and LAPACK libraries.
Definition: tsgEnumerates.hpp:555
@ accel_gpu_magma
Same the CUDA option but uses the UTK MAGMA library for the linear algebra operations.
Definition: tsgEnumerates.hpp:563
@ accel_gpu_cuda
Similar to the cuBLAS option but also uses a set of Tasmanian custom GPU kernels.
Definition: tsgEnumerates.hpp:561
@ type_level
Ignoring the polynomial space, use rules with index .
Definition: tsgEnumerates.hpp:209
void loadUnstructuredDataL2(double const data_points[], int num_data, double const model_values[], double tolerance, TasmanianSparseGrid &grid)
Construct a sparse grid surrogate using a least-squares fit.
Definition: tsgLoadUnstructuredPoints.hpp:282
TasmanianSparseGrid makeGlobalGrid(int dimensions, int outputs, int depth, TypeDepth type, TypeOneDRule rule, std::vector< int > const &anisotropic_weights=std::vector< int >(), double alpha=0.0, double beta=0.0, const char *custom_filename=nullptr, std::vector< int > const &level_limits=std::vector< int >())
Factory method, creates a new grid and calls TasmanianSparseGrid::makeGlobalGrid().
Definition: TasmanianSparseGrid.hpp:2272