Subject: Re: [boost] [math distributions] where to check for validity of distribution variables?
From: Thijs van den Berg (thijs_at_[hidden])
Date: 2008-11-22 09:48:21
John Maddock wrote:
> Thijs van den Berg wrote:
>>>>>> What do you think? We might turn "having valid parameters" into a
>>>>>> property of *all*
>>>>>> distribution. As an alternative, we might add a non member
>>>>>> function bool valid<distributionType...
>>>>>> but that wouldn't allow for caching validation in e.g. a
>>>> Sounds fine to me.
>>> thats great! What's your opinion on the fact that you can only set
>>> parameter in the constructor?
>>> E.g. the normal distribution does a parameter check in the
>>> and those parameters
>>> can't change after that.
> That's what the existing distributions do. In fact we could omit most
> of the subsequent parameter checking code if we could figure out
> whether the error handlers will throw or not on error (in fact we
> *can* get this information at compile time and make the subsequent
> checks a no-op if we know that the constructor would have thrown on
> error... we just ran out of time on that refinement).
I don't understand this, it has to do with my lack of knowledge on
this... If you ensure that the parameters get checked in the
constructor, why would that check *not* throw an error when needed?
Compile time might be tricky depending on the complicity of the
parameter validation code, but simple range check on the parameters
could be done compile time. What mechanism are your thinking about
regarding compile checking, e.g. that scale>0?
>>> I'll work out the parameter idea in the Laplace distribution code...
> OK good.
I got a bit of Laplace code to share!
I still need to test the numerical results, but I compiles without
errors/warnings, and it throws errors when parameters are invalid.
Do I need to put the code somewhere? I've attached it to this mail...
I have 3 idea's in the code I'd like to discuss.
* a public member function "check_parameters" in the distribution class
* a public member function operator() that allows run-time changing of
dist parameters. I know that's a big change... I myself could use
something like this. E.g. I have some code that calibrates a stochastic
model based on time series data & stores the estimated distribution
parameters in a file. Another program will read the distribution
parameters from that file, crate distributions objects, and do
probability calculations with that. I can only do that when I can set
the distribution parameters *runtime*.
* no more checking for distribution parameters in the non-member
functions. Checking is only done when the distribution parameters get
set or get changed. But as said before, I have no good grasp on the
subtle issues with that. You said "if we could figure out whether the
error handlers will throw or not", implying that there are complexities
At the moment, I just have the code. It you think the code is ok, then
how would I go about with documentation & testing? Do you have some
structure in place for that? I've seen quite some code in the
sandbox/math, ...concept etc...
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk