From: Paul T. <p.t...@ca...> - 2006-06-30 07:20:09
|
Phil, There's boost::multi_array, which is templated by the number of dimensions. Construction with different numbers of cells in each dimension, and iterating over the cells are helped using boost::array This allows one to write _dimension-independent code_ . This would seem to be more flexible than matrices of matrices or vectors of vectors of vectors... Perhaps this would be a good base for the spasm discrete grid stuff. I'm not actually working with discrete grids, so this never progressed beyond looking at the multi-dimensional array iteration. Hope it helps. Paul Thompson. #include "boost/multi_array.hpp" #include <cassert> #include <cmath> ... //construction of multi-dimensional array, const int numdims = 4; const int cells_per_dim = 20; typedef double valuetype; typedef boost::multi_array<valuetype, numdims> array_type; boost::array<array_type::index, numdims> shape; shape[0] = 10; shape[1] = 11; shape[2] = 12; shape[3] = 14; //size of the dimensions //construct the multi-dim array (10 x 11 x 12 x 14 4 dimensional array !) array_type A(shape); boost::array<array_type::index,numdims> idx; idx[0] = 5; idx[1] = 6; idx[2] = 7; idx[3] = 8; //set the (5,6,7,8) entry in the matrix: A(idx) = 0.0; The boost::array idx can be used to iterate over the matrix: void iterate_multidimarray_do_something_func( int numdims, int cells_per_dim, array_type &A, void (*do_something_func)(boost::array<array_type::index,numdims>, array_type &) ) { boost::array<array_type::index,numdims> idx; //reset idx to zeros for (int dim = 0; dim < numdims; dim++) { idx[dim] = 0; } bool done = false; //this loop considers idx as a base:cells_per_dim number, where idx[i] is a digit // and counts from 00000 to the maximum... Calling do_something_func on the whole grid. while(!done) { do_something_func(idx,A); // increment the first dimension every time. idx[numdims-1]++; // check all other dimensions for overflow, propagate the carry. for (int dim = numdims-1; dim >= 0 ; dim--) { // overflow this dimension, 'carry' over to the next dimension. if (idx[dim] >= cells_per_dim) { idx[dim] = 0; idx[dim-1]++; } // if the final dimension is past the final cell number, finish if (idx[0] >= cells_per_dim) { done = true; break; } } } return; } -----Original Message----- From: Phil [mailto:sa...@un...] Sent: Friday, 30 June 2006 3:26 PM To: Ben Upcroft Cc: Bertrand Douillard; Lee Ling (Sharon) Ong; Matt Ridley; 'Paul Thompson'; Suresh Kumar; Tim Bailey; Tobias Kaupp; Alex Makarenko; Ryan Cross Subject: Re: Fwd: Spasm 2.0 Hi Ben, This sounds like a good plan. I have managed to get some grid based Bayesian stuff working to some extent. In the coming weeks I hope to start refining it a little and moving it into a more spasm like structure. I am a little unfamiliar with the template structure that spasm is using so I'll have to some more learning on that side. What changed will be made if we move away from templates to an inference model? also, to enable me to do some calculations, I have added the following line to my /ulapack/matrix_types.hpp to enable me to use 4 Dimensional matrices. Is there an obvious and better way of doing this so I do not have to change uLapack? typedef ublas::matrix<ublas::matrix<double, ublas::column_major>, ublas::column_major> Matrix4d; Cheers Phil Ben Upcroft wrote: > Has everyone signed up to the mailing list? If you didn't get the > message below and wish to get similar messages, please sign up. > > Ben > > ---------- Forwarded Message ---------- > > Subject: Spasm 2.0 > Date: Friday 30 June 2006 10:08 > From: Matthew Ridley <mr...@me...> > To: spa...@li... > Cc: Ben Upcroft <b.u...@ca...> > > I wanted to kick off some discussion with regards to what we want > spasm 2.0 to look like. > > some of my thoughts are: > > - Remove Particles from PDF, i.e. create a Sample/WeightedSample class > and associated utilities. > - Make conversion between PDF types use global functions, this means > that these are independent of class definitions. > - spasm-filters to use inheritance instead of templates for various > PDF types. > > - spasm-gl for rending PDF's in OpenGL ? > > Ben: is everyone on the list yet ? > > Matt > -- > > ------------------------------------------------------- > > |