[ 
https://issues.apache.org/jira/browse/NUMBERS-167?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17706930#comment-17706930
 ] 

Gilles Sadowski commented on NUMBERS-167:
-----------------------------------------

In the use case which I'm mentioning, the pre-computed value is use in a loop 
that iterates at most 5 times (hard-coded). So the "LogGamma" value would be 
needlessly evaluated at most 4 times (or once, if the code path doesn't use it).
Given that you
{quote}did not see a simple implementation
{quote}
and
{quote}decided it was non-trivial.
{quote}
my feeling is that the complexity of the API envisioned in the previous 
discussion doesn't seem worth it...

Also, the "for" loop is within this function:
{code}
    /** [...]
     * This function returns an approximation of the inverse cumulative
     * distribution function for the chi-square distribution. That is, given p
     * and nu it computes the quantile x such that Pr{X2 ≤ x} = p, where X2 
is
     * a random variable from the chi-square distribution with nu degrees of
     * freedom.                                 
     *
     * NaN is returned if p < 0 or p > 1. Zero and positive infinity is 
returned
     * when p is equal to 0 and 1, respectively, or when p is too close to these
     * values for a more accurate evaluation.
     *                                                                          
                                                                                
                        
     * This is a straight-forward implementation of the Fortran algorithm AS91
     * (D.J. Best & D.E. Roberts, The percentage points of the Chi2
     * distribution, Applied Statistics 24, 385, 1975), with some modifications
     * to handle extreme values of p better.
     *                                                                          
                                                                                
                        
     * The accuracy is essentially determined by the accuracy of the lnGamma()
     * and incompleteGammaP() functions used to compute the cumulative
     * distribution.
     *
     * @param p
     *            probability (in the range 0 to 1)
     * @param nu
     *            number of degrees of freedom
     * @return lower tail quantile
     */
    public static double chiSquareCdfInv(double p, double nu) {
    // ...
    }                                                                           
                                                            
{code}


> RegularizedGamma.P with precomputed LogGamma value
> --------------------------------------------------
>
>                 Key: NUMBERS-167
>                 URL: https://issues.apache.org/jira/browse/NUMBERS-167
>             Project: Commons Numbers
>          Issue Type: Wish
>          Components: gamma
>            Reporter: Gilles Sadowski
>            Priority: Minor
>             Fix For: 1.2
>
>         Attachments: pr_106.patch
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> We have
> {code:java}
> double v = RegularizedGamma.P.value(a, x);
> {code}
> where method {{value}} internally calls {{LogGamma.value(a)}}.
> There is a use-case for
> {code:java}
> double logGammaA = LogGamma.value(a);
> double v = RegularizedGamma.P.value(a, x, logGammaA);
> {code}
> for when the user varies {{x}} but not {{a}}.
> Method name TBD:  Another overload of {{value}} may be confusing (?).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to