lojix/learning/src/main/com/thesett/aima/learning/decisiontree/prototype/ProtoDTLearningMethod.java
private OrdinalAttribute getMajorityClassification(String property, Iterable<State> examples)
        throws LearningFailureException
    {
        /*log.fine("private OrdinalAttribute getMajorityClassification(String property, Collection<State> examples): called");*/
        /*log.fine("property = " + property);*/

        // Flag used to indicate that the map to hold the value counts in has been initialized.
        Map<OrdinalAttribute, Integer> countMap = null;

        // Used to hold the biggest count found so far.
        int biggestCount = 0;

        // Used to hold the value with the biggest count found so far.
        OrdinalAttribute biggestAttribute = null;

        // Loop over all the examples counting the number of occurences of each possible classification by the
        // named property.
        for (State example : examples)
        {
            OrdinalAttribute nextAttribute = (OrdinalAttribute) example.getProperty(property);
            /*log.fine("nextAttribute = " + nextAttribute);*/

            // If this is the first attribute then find out how many possible values it can take on.
            if (countMap == null)
            {
                // A check has already been performed at the start of the learning method to ensure that the output
                // property only takes on a finite number of values.
                countMap = new HashMap<OrdinalAttribute, Integer>();
            }

            int count;

            // Increment the count for the number of occurences of this classification.
            if (!countMap.containsKey(nextAttribute))
            {
                count = 1;
                countMap.put(nextAttribute, count);
            }
            else
            {
                count = countMap.get(nextAttribute);
                countMap.put(nextAttribute, count++);
            }

            // Compare it to the biggest score found so far to see if it is bigger.
            if (count > biggestCount)
            {
                // Update the biggest score.
                biggestCount = count;

                // Update the value of the majority classification.
                biggestAttribute = nextAttribute;
            }
        }

        // Return the majority classification found.
        return biggestAttribute;
    }
private OrdinalAttribute getMajorityClassification(String property, Iterable<State> examples)
        throws LearningFailureException
    {
        /*log.fine("private OrdinalAttribute getMajorityClassification(String property, Collection<State> examples): called");*/
        /*log.fine("property = " + property);*/

        // Flag used to indicate that the map to hold the value counts in has been initialized.
        Map<OrdinalAttribute, Integer> countMap = null;

        // Used to hold the biggest count found so far.
        int biggestCount = 0;

        // Used to hold the value with the biggest count found so far.
        OrdinalAttribute biggestAttribute = null;

        // Loop over all the examples counting the number of occurences of each possible classification by the
        // named property.
        for (State example : examples)
        {
            OrdinalAttribute nextAttribute = (OrdinalAttribute) example.getProperty(property);
            /*log.fine("nextAttribute = " + nextAttribute);*/

            // If this is the first attribute then find out how many possible values it can take on.
            if (countMap == null)
            {
                // A check has already been performed at the start of the learning method to ensure that the output
                // property only takes on a finite number of values.
                countMap = new HashMap<OrdinalAttribute, Integer>();
            }

            int count;

            // Increment the count for the number of occurences of this classification.
            if (!countMap.containsKey(nextAttribute))
            {
                count = 1;
                countMap.put(nextAttribute, count);
            }
            else
            {
                count = countMap.get(nextAttribute);
                countMap.put(nextAttribute, count++);
            }

            // Compare it to the biggest score found so far to see if it is bigger.
            if (count > biggestCount)
            {
                // Update the biggest score.
                biggestCount = count;

                // Update the value of the majority classification.
                biggestAttribute = nextAttribute;
            }
        }

        // Return the majority classification found.
        return biggestAttribute;
    }
private OrdinalAttribute getMajorityClassification ( String property , Iterable < State > examples ) throws LearningFailureException { /*log.fine("private OrdinalAttribute getMajorityClassification(String property, Collection<State> examples): called");*/ /*log.fine("property = " + property);*/ // Flag used to indicate that the map to hold the value counts in has been initialized. Map < OrdinalAttribute , Integer > countMap = null ; // Used to hold the biggest count found so far. int biggestCount = 0 ; // Used to hold the value with the biggest count found so far. OrdinalAttribute biggestAttribute = null ; // Loop over all the examples counting the number of occurences of each possible classification by the // named property. for ( State example : examples ) { OrdinalAttribute nextAttribute = ( OrdinalAttribute ) example . getProperty ( property ) ; /*log.fine("nextAttribute = " + nextAttribute);*/ // If this is the first attribute then find out how many possible values it can take on. if ( countMap == null ) { // A check has already been performed at the start of the learning method to ensure that the output // property only takes on a finite number of values. countMap = new HashMap < OrdinalAttribute , Integer > ( ) ; } int count ; // Increment the count for the number of occurences of this classification. if ( ! countMap . containsKey ( nextAttribute ) ) { count = 1 ; countMap . put ( nextAttribute , count ) ; } else { count = countMap . get ( nextAttribute ) ; countMap . put ( nextAttribute , count ++ ) ; } // Compare it to the biggest score found so far to see if it is bigger. if ( count > biggestCount ) { // Update the biggest score. biggestCount = count ; // Update the value of the majority classification. biggestAttribute = nextAttribute ; } } // Return the majority classification found. return biggestAttribute ; }
This helper method works out how the majority of the specified examples are classified by the named property. The
property should always be the goal property that the algorithm is learning and must always take on a finite
number of different values.

@param  property The name of the property to find the majority classification for.
@param  examples A collection of state objects to count over in order to find the majority classification for the
named property.

@return The value of the majority classification for the named property or null if the example collection was
empty so no majority could be found.

@throws LearningFailureException If the number of possible value that the specified property can take on is not
finite.
This helper method works out how the majority of the specified examples are classified by the named property . The property should always be the goal property that the algorithm is learning and must always take on a finite number of different values .