Boost logo

Boost Users :

Subject: Re: [Boost-users] Declare statistical distribution array: boost/math/distributions
From: Marco Guazzone (marco.guazzone_at_[hidden])
Date: 2009-05-19 15:50:02


On Tue, May 19, 2009 at 8:52 PM, Alex Tsoi <tsoi.teen_at_[hidden]> wrote:
> 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<gamma_distribution<double>*> mydist10_2(10);
mydist10_2[0] = new gamma_distribution<double>(1.2);
mydist10_2[1] = new gamma_distribution<double>(1.3);
//...

or (maybe better):
std::vector< boost::shared_ptr< gamma_distribution<double> > > mydist10_3(10):
mydist10_3[0] = boost::shared_ptr< gamma_distribution<double> >(new
gamma_distribution<double>(1.2));
mydist10_3[1] = boost::shared_ptr< gamma_distribution<double> >(new
gamma_distribution<double>(1.3));
//...

Cheers,

-- Marco

> Thanks a lot for any comment or suggestion.
>
> Alex-
>
>
>
> --
> Lam C. Tsoi (Alex)
> Medical University of South Carolina
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net