From: Phil S. <sa...@gm...> - 2006-07-03 01:39:26
|
Thanks Paul, I'm sure if I read i a few times i'll get my head around it. Thanks for writing it out clearly. Would the iterating be a lot faster using this method? so far, the way I was doing it was not as fast as I had hoped. Cheers Phil Sammons Today's Topics: > > 1. Re: Spasm 2.0, discrete grids (Paul Thompson) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Fri, 30 Jun 2006 17:20:01 +1000 > From: "Paul Thompson" <p.t...@ca...> > Subject: Re: [Spasm-devel] Spasm 2.0, discrete grids > To: <spa...@li...> > Message-ID: <200...@tr...> > Content-Type: text/plain; charset="us-ascii" > > 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 > > -- > > > > ------------------------------------------------------- > > > > > > > > > > > ------------------------------ > > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job > easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > > > ------------------------------ > > _______________________________________________ > Spasm-devel mailing list > Spa...@li... > https://lists.sourceforge.net/lists/listinfo/spasm-devel > > > End of Spasm-devel Digest, Vol 2, Issue 1 > ***************************************** > |