Declare statistical distribution array: boost/math/distributions
Hi all, I am trying to write a MCMC algorithm by using boost's math distribution library, what I want to do is to first declare an array of length 10 of gamma distribution, and then run a for loop to declare each gamma distribution's parameters. However, boost does not allow me to declare the gamma distribution array without having defining the parameter in advance: gamma_distribution<double> mydist10[10]; error: no appropriate default constructor available. because the library requires to know the parameter of the gamma distribution in advance. Do you guys have any idea to overcome this ? Thanks a lot for any comment or suggestion. Alex- -- Lam C. Tsoi (Alex) Medical University of South Carolina
On Tue, May 19, 2009 at 8:52 PM, Alex Tsoi
Hi all,
I am trying to write a MCMC algorithm by using boost's math distribution library, what I want to do is to first declare an array of length 10 of gamma distribution, and then run a for loop to declare each gamma distribution's parameters. However, boost does not allow me to declare the gamma distribution array without having defining the parameter in advance:
gamma_distribution<double> mydist10[10];
error: no appropriate default constructor available.
because the library requires to know the parameter of the gamma distribution in advance.
Do you guys have any idea to overcome this ?
Use a gamma_distribution<double>* as contained element.
For instance:
gamma_distribution<double>*. mydist10_1[10]:
mydist10_1[0] = new gamma_distribution<double>(1.2);
mydist10_1[1] = new gamma_distribution<double>(1.3);
//...
or:
std::vector
Thanks a lot for any comment or suggestion.
Alex-
-- Lam C. Tsoi (Alex) Medical University of South Carolina
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
I am trying to write a MCMC algorithm by using boost's math distribution library, what I want to do is to first declare an array of length 10 of gamma distribution, and then run a for loop to declare each gamma distribution's parameters. However, boost does not allow me to declare the gamma distribution array without having defining the parameter in advance:
gamma_distribution<double> mydist10[10];
error: no appropriate default constructor available.
because the library requires to know the parameter of the gamma distribution in advance.
Do you guys have any idea to overcome this ?
Thanks a lot for any comment or suggestion.
There is an ugly workaround: boost::math::gamma_distribution<> a[2] = { boost::math::gamma_distribution<>(0), boost::math::gamma_distribution<>(0), }; and then assignment works via: a[0] = boost::math::gamma_distribution<>(par1, par2); etc. HTH, John.
On Thu, May 21, 2009 at 12:01 PM, John Maddock
I am trying to write a MCMC algorithm by using boost's math distribution library, what I want to do is to first declare an array of length 10 of gamma distribution, and then run a for loop to declare each gamma distribution's parameters. However, boost does not allow me to declare the gamma distribution array without having defining the parameter in advance:
gamma_distribution<double> mydist10[10];
error: no appropriate default constructor available.
because the library requires to know the parameter of the gamma distribution in advance.
Do you guys have any idea to overcome this ?
Thanks a lot for any comment or suggestion.
There is an ugly workaround:
boost::math::gamma_distribution<> a[2] = { boost::math::gamma_distribution<>(0), boost::math::gamma_distribution<>(0), };
and then assignment works via:
a[0] = boost::math::gamma_distribution<>(par1, par2);
Yes but I think there 2 disadvantages: 1. If you declare an array of N elements you have to explicity create N Gamma(0,1) distirbutions: gamma_distribution a[N] = { gamma_distribution(0), /* #1 *./ ... gamma_distribution(0) /* #N *./ }; 2. The program "wastes time" to create N Gamma(0,1) elements that are eventually replaced (by copy-assignement) by other Gamma distribution objects. I prefer the pointer solution, but this is only my modest opinion :) -- Marco
etc.
HTH, John. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Alex Tsoi
-
John Maddock
-
Marco Guazzone