lojix/learning/src/main/com/thesett/aima/learning/AbstractLearningMethod.java
protected void initialize() throws LearningFailureException
    {
        // Check that at least one training example has been set.
        if (inputExamples.isEmpty())
        {
            throw new LearningFailureException("No training examples to learn from.", null);
        }

        // Check if an output property set to override the default was not set.
        if (!outputPropertiesSet)
        {
            // Set the 'goal' property as the default.
            addGoalProperty("goal");
        }

        // Check if an input property set to override the default was not set.
        if (!inputPropertiesSet)
        {
            // Extract all properties from the first example in the training data set as the input property set,
            // automatically excluding any properties which are in the output set.
            State example = inputExamples.iterator().next();
            Set<String> allProperties = example.getComponentType().getAllPropertyNames();

            inputProperties = new HashSet<String>(allProperties);
            inputProperties.removeAll(outputProperties);

            inputPropertiesSet = true;
        }

        // Check all the training examples have all the required input and output properties.
        for (State example : inputExamples)
        {
            Set<String> properties = example.getComponentType().getAllPropertyNames();

            String errorMessage = "";

            for (String inputProperty : inputProperties)
            {
                if (!properties.contains(inputProperty))
                {
                    errorMessage +=
                        "The training example, " + example + " does not contain the specified input property, " +
                        inputProperty + "\n";
                }
            }

            for (String outputProperty : outputProperties)
            {
                if (!properties.contains(outputProperty))
                {
                    errorMessage +=
                        "The training example, " + example + " does not contain the specified output property, " +
                        outputProperty + "\n";
                }
            }

            if (!"".equals(errorMessage))
            {
                throw new LearningFailureException(errorMessage, null);
            }
        }
    }
protected void initialize() throws LearningFailureException
    {
        // Check that at least one training example has been set.
        if (inputExamples.isEmpty())
        {
            throw new LearningFailureException("No training examples to learn from.", null);
        }

        // Check if an output property set to override the default was not set.
        if (!outputPropertiesSet)
        {
            // Set the 'goal' property as the default.
            addGoalProperty("goal");
        }

        // Check if an input property set to override the default was not set.
        if (!inputPropertiesSet)
        {
            // Extract all properties from the first example in the training data set as the input property set,
            // automatically excluding any properties which are in the output set.
            State example = inputExamples.iterator().next();
            Set<String> allProperties = example.getComponentType().getAllPropertyNames();

            inputProperties = new HashSet<String>(allProperties);
            inputProperties.removeAll(outputProperties);

            inputPropertiesSet = true;
        }

        // Check all the training examples have all the required input and output properties.
        for (State example : inputExamples)
        {
            Set<String> properties = example.getComponentType().getAllPropertyNames();

            String errorMessage = "";

            for (String inputProperty : inputProperties)
            {
                if (!properties.contains(inputProperty))
                {
                    errorMessage +=
                        "The training example, " + example + " does not contain the specified input property, " +
                        inputProperty + "\n";
                }
            }

            for (String outputProperty : outputProperties)
            {
                if (!properties.contains(outputProperty))
                {
                    errorMessage +=
                        "The training example, " + example + " does not contain the specified output property, " +
                        outputProperty + "\n";
                }
            }

            if (!"".equals(errorMessage))
            {
                throw new LearningFailureException(errorMessage, null);
            }
        }
    }
This should be called at the start of the learn method to initialize the input and output property sets.

@throws LearningFailureException If the set of training data and input and output properties are malformed.
Either because the training data set is empty or because there are input or
output properties that are not found in the training data set.