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

Gilles commented on MATH-1370:
------------------------------

Do you agree that the method {{probability}} defined as follows:
{noformat}
double probability(final T x) {
    final Double p = massPoints.get(x);
    return p == null ? 0 : p.doubleValue();
}
{noformat}
is a slight improvement over your version (only 1 lookup)?


> Increase efficiency of EnumeratedDistribution#probability
> ---------------------------------------------------------
>
>                 Key: MATH-1370
>                 URL: https://issues.apache.org/jira/browse/MATH-1370
>             Project: Commons Math
>          Issue Type: Improvement
>            Reporter: Ryan Gaffney
>            Priority: Minor
>              Labels: patch, performance
>         Attachments: enum-distribution-perf-patch
>
>
> There are lots of other low hanging fruit in the distribution package but 
> unfortunately this is the only one I got to that day.
> In the EnumeratedDistribution case, the probability() method is currently 
> O(N) where N denotes number of random variables, even though the random 
> variables are fixed / known. This change makes probability() O(1). The 
> unlikely worst case scenario now consumes slightly more than 2x the memory, 
> but I do not think this would be an issue in the vast majority of cases.
> Original PR (incorrectly against master) 
> [here|https://github.com/apache/commons-math/pull/34].



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to