0
$\begingroup$

I have a $q$-dimensional grid, known at run, not compile-time, that has $50$ points in each direction and hence $50^3$ combinations that I would like to first build and then call a function with each point as its single argument, to store the output in a data structure that has a pointer to the argument.

Is there a good way to implement this in C++ by using perhaps a library that is optimised to handle such tasks? Ideally with good bindings to Eigen but I can hack that together myself if need be. More formally:

My problem is now to populate the vector of grid points with each lambda ranging from $0.95$ to $1$ in steps of $0.001$ so that I have a model of the Cartesian coordinate system $[0.95,1] \times [0.95,1] \times[0.95,1] \in \mathbb{R}^{3}$.

My first attempt at a solution would be this:

class grid_point{
grid_point(int q){

lambda = VectorXf::Zeros(q);
}

private:
VectorXd lambda;
float likelihood;
}

And then instantiate vector<grid_point> my_grid(num_steps); where num_steps = pow(50,3). I suppose this question here is similar but it implements a bunch of nested for loops. I am wondering if there are packages that implement this natively possibly as part of the STL or in some custom package that people on this site are using. Performing grid search must be a well-trodden path in many disciplines.

I may be able to use the library <algorithm> but to me this feels like I am reinventing the wheel as I am sure there must be more efficient ways to

  1. generate all tuples that span my model of $\mathbb{R} ^{3}$
  2. and then call a function with a single parameter on it to write its output into grid_point.

Many thanks, All!

Seems like this question is not getting much interest. But here is an update on what can be done:

My current sense is to build it from scratch as above and somehow try to find use of this methodology here enter link description here.

$\endgroup$
  • $\begingroup$ What does "traverse" mean in your context? Is all you want to do "read each element once"? $\endgroup$ – Wolfgang Bangerth Apr 17 at 22:01
  • $\begingroup$ Hi @WolfgangBangerth thank you for your interest! I have clarified your question in my edited version. Please let me know if there are more ways to make it clearer! $\endgroup$ – Hirek Apr 18 at 11:24
  • $\begingroup$ You have less than a million point, which makes your problem quite small. You don’t need a package, certainly not an optimized one, you can just do it yourself. $\endgroup$ – Kirill Apr 19 at 18:09
1
$\begingroup$

I would second the opinion expressed in the context. For that small problem and limited usage, you don't need a library. Generation of a structured grid and retrieving points can be coded up in at most several screens of code.

However, I would point out for you ViennaGrid library, which can be used and actually provides STL iterators. In addition, the documentation for ViennaGrid also contains some discussion on the alternatives (both for structured and unstructured meshes).

Anyway, even a small ViennaGrid library would be an overkill for this task, in my opinion.

$\endgroup$
  • $\begingroup$ Thanks so much @AntonMenshov ! $\endgroup$ – Hirek May 10 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.