commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phil Steitz (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (MATH-1007) Add mode function to StatUtils class
Date Tue, 16 Jul 2013 01:05:47 GMT

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

Phil Steitz commented on MATH-1007:
-----------------------------------

I think it is best to return a double[].  Here is what I propose as method signature / contract:

{code}
/**
     * Returns the sample mode(s).  The mode is the most frequently occurring
     * value in the sample. If there is a unique value with maximum frequency,
     * this value is returned in the first element of the output array. Otherwise,
     * the returned array contains the maximum frequency elements in increasing
     * order.  For example, if {@code sample} is {0, 12, 5, 6, 0, 13, 5, 17},
     * the returned array will have length two, with 0 in the first element and
     * 5 in the second.
     *
     * <p>NaN values are ignored when computing the mode - i.e., NaNs will never
     * appear in the output array.  If the sample includes only NaNs or has
     * length 0, an empty array is returned.</p>
     *
     * @param sample input data
     * @return array of maximum frequency elements sorted in ascending order.
     */
    public static double[] mode(final double[] sample)

{code}
                
> Add mode function to StatUtils class
> ------------------------------------
>
>                 Key: MATH-1007
>                 URL: https://issues.apache.org/jira/browse/MATH-1007
>             Project: Commons Math
>          Issue Type: New Feature
>            Reporter: Sebb
>
> It might be useful to have a StatUtils function to get the mode.
> However, this may be tricky as it does not easily fit in with the current StatUtils design.
> The mode can have multiple elements, but all the other methods only return a single value.
> There are at least two options for converting an array to a single value:
> - arbitrarily (or randomly) pick one
> - throw an Exception if there is more than one mode
> Or maybe StatUtils should return a double array.
> StatUtils also uses nested classes for all but the difference and normalize methods.
However the standard interfaces and classes don't support returning arrays.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message