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 .