Hello.

> Here is one.  The goal is to provide an over-dispersed exponential
> distribution which is defined as an exponential distribution with a prior
> distribution on the lambda parameter.
> 
> /**
>  * Sample from an exponential distribution whose parameter is distributed
> according
>  * to a Gamma distribution.
>  */
> public class UncertainExponentialDistribution extends
> ExponentialDistribution {
>     private Gamma prior;
> 
>     public UncertainExponentialDistribution(double alpha, double beta) {
>         prior = new Gamma(alpha, beta);
>     }
> 
>     public double getLambda() {
>         return prior.next();
>     }
> }
> 
> Doing this with an immutable super class is a royal pain in the ass.  Doing
> this with setters on lambda isn't sooo bad, but it really obscures the real
> point which is that the over-dispersed exponential distribution is *exactly*
> an exponential distribution but lambda varies.  The implementation above
> says exactly that.
> 
> So what about the layer below?  The exponential can be defined as a
> specialized Gamma which benefits from the same sort of idiom (yes I know
> that this distribution can be implemented as -lambda * log(1-rand()), but we
> are talking principles here, not specifics).
> 
> public class ExponentialDistribution extends AbstractDistribution {
>     private double lambda;
> 
>     private Gamma wrapped;
> 
>     public ExponentialDistribution() {
>     }
> 
>     public ExponentialDistribution(double lambda) {
>         this.lambda = lambda;
>         wrapped = new Gamma(1, 1 / lambda) {
>             @Override
>             public double getAlpha() {
>                 return 1;
>             }
> 
>             @Override
>             public double getBeta() {
>                 return 1 / getLambda();
>             }
>         };
>     }
> 
>     public double next() {
>         return wrapped.next();
>     }
> 
>     /**
>      * Default implementation of this getter just returns the value we
> know.  Sub-classes
>      * might over-ride this for special effects.
>      * @return
>      */
>     public double getLambda() {
>         return lambda;
>     }
> }
> 
> Again, we have clarity of expression.  The phrase "gamma distribution with
> alpha = 1 and beta = 1/lambda" is just what is in the code here.  You
> *could* do this with setters, but at considerable loss of clarity and no
> gain in efficiency.

I must say that I don't understand the example.
Is it based on anything in CM?  I don't see a method "next()" anywhere...
You say that it can't be done with an immutable super-class but nothing is
mutable in the above (or is it precisely "next()" that is altering the
content of the undefined "Gamma" class?).
I don't understand why the "wrapped" variable has an overridden "getAlpha()"
since it actually returns 1 and it is the first parameter passed to the
constructor (which is what the accessor in the base class is supposed to
return).
All of this is quite unclear to me, so that I can't even judge what
functionality would be useful (and how it could perhaps be achieved in some
other way). Maybe it would make more sense if I could run a working example.

Sorry,
Gilles

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to