/** * configures the CheckClassifier instance used throughout the tests * * @return the fully configured CheckClassifier instance used for testing */ protected CheckClassifier getTester() { CheckClassifier result; result = new CheckClassifier(); result.setSilent(true); result.setClassifier(m_Classifier); result.setNumInstances(20); result.setDebug(DEBUG); result.setPostProcessor(getPostProcessor()); return result; }
boolean PNom = canPredict(true, false, false, false, false, multiInstance, classType)[0]; boolean PNum = canPredict(false, true, false, false, false, multiInstance, classType)[0]; boolean PStr = canPredict(false, false, true, false, false, multiInstance, classType)[0]; boolean PDat = canPredict(false, false, false, true, false, multiInstance, classType)[0]; boolean PRel; if (!multiInstance) { PRel = canPredict(false, false, false, false, true, multiInstance, classType)[0]; } else { instanceWeights(PNom, PNum, PStr, PDat, PRel, multiInstance, classType); canHandleOnlyClass(PNom, PNum, PStr, PDat, PRel, classType); canHandleNClasses(PNom, PNum, PStr, PDat, PRel, multiInstance, 4); canHandleClassAsNthAttribute(PNom, PNum, PStr, PDat, PRel, multiInstance, classType, 0); canHandleClassAsNthAttribute(PNom, PNum, PStr, PDat, PRel, multiInstance, classType, 1); canHandleZeroTraining(PNom, PNum, PStr, PDat, PRel, multiInstance, classType); boolean handleMissingPredictors = canHandleMissing(PNom, PNum, PStr, PDat, PRel, multiInstance, classType, true, false, 20)[0];
public void doTests() { if (getClassifier() == null) { println("\n=== No classifier set ==="); return; println("\n=== Check on Classifier: " + getClassifier().getClass().getName() + " ===\n"); println("--> Checking for interfaces"); canTakeOptions(); boolean updateableClassifier = updateableClassifier()[0]; boolean weightedInstancesHandler = weightedInstancesHandler()[0]; boolean multiInstanceHandler = multiInstanceHandler()[0]; println("--> Classifier tests"); declaresSerialVersionUID(); testToString(); testsPerClassType(Attribute.NOMINAL, updateableClassifier, weightedInstancesHandler, multiInstanceHandler); testsPerClassType(Attribute.NUMERIC, updateableClassifier, weightedInstancesHandler, multiInstanceHandler); testsPerClassType(Attribute.DATE, updateableClassifier, weightedInstancesHandler, multiInstanceHandler); testsPerClassType(Attribute.STRING, updateableClassifier, weightedInstancesHandler, multiInstanceHandler); testsPerClassType(Attribute.RELATIONAL, updateableClassifier, weightedInstancesHandler, multiInstanceHandler);
/** * Test method for this class * * @param args the commandline parameters */ public static void main(String[] args) { runCheck(new CheckClassifier(), args); } }
/** * checks whether the classifier can handle the given percentage of missing * class labels * * @param type the class type * @param percent the percentage of missing class labels * @param allowFail if true a fail statement may be executed * @return true if the classifier can handle it */ protected boolean checkMissingClass(int type, int percent, boolean allowFail) { boolean[] result; result = m_Tester.canHandleMissing(m_NominalPredictors[type], m_NumericPredictors[type], m_StringPredictors[type], m_DatePredictors[type], m_RelationalPredictors[type], m_multiInstanceHandler, type, false, true, percent); if (allowFail) { if (!result[0] && !result[1]) { fail("Error handling " + percent + "% missing class labels (" + getClassTypeString(type) + " class)!"); } } return result[0]; }
/** * tests whether the scheme declares a serialVersionUID. */ public void testSerialVersionUID() { boolean[] result; result = m_Tester.declaresSerialVersionUID(); if (!result[0]) { fail("Doesn't declare serialVersionUID!"); } }
/** * tests whether classifier handles N classes * * @see CheckClassifier#canHandleNClasses(boolean, boolean, boolean, boolean, * boolean, boolean, int) * @see CheckClassifier#testsPerClassType(int, boolean, boolean, boolean) * @see #m_NClasses */ public void testNClasses() { boolean[] result; if (!canPredict(Attribute.NOMINAL)) { return; } result = m_Tester.canHandleNClasses(m_NominalPredictors[Attribute.NOMINAL], m_NumericPredictors[Attribute.NOMINAL], m_StringPredictors[Attribute.NOMINAL], m_DatePredictors[Attribute.NOMINAL], m_RelationalPredictors[Attribute.NOMINAL], m_multiInstanceHandler, m_NClasses); if (!result[0] && !result[1]) { fail("Error handling " + m_NClasses + " classes!"); } }
/** * tests whether classifier handles data containing only a class attribute * * @see CheckClassifier#canHandleOnlyClass(boolean, boolean, boolean, boolean, * boolean, int) * @see CheckClassifier#testsPerClassType(int, boolean, boolean, boolean) */ public void testOnlyClass() { boolean[] result; int i; for (i = FIRST_CLASSTYPE; i <= LAST_CLASSTYPE; i++) { // does the classifier support this type of class at all? if (!canPredict(i)) { continue; } result = m_Tester.canHandleOnlyClass(m_NominalPredictors[i], m_NumericPredictors[i], m_StringPredictors[i], m_DatePredictors[i], m_RelationalPredictors[i], i); if (!result[0] && !result[1]) { fail("Error handling data containing only the class!"); } } }
/** * tests whether the classifier can handle zero training instances * * @see CheckClassifier#canHandleZeroTraining(boolean, boolean, boolean, * boolean, boolean, boolean, int) * @see CheckClassifier#testsPerClassType(int, boolean, boolean, boolean) */ public void testZeroTraining() { boolean[] result; int i; for (i = FIRST_CLASSTYPE; i <= LAST_CLASSTYPE; i++) { // does the classifier support this type of class at all? if (!canPredict(i)) { continue; } result = m_Tester.canHandleZeroTraining(m_NominalPredictors[i], m_NumericPredictors[i], m_StringPredictors[i], m_DatePredictors[i], m_RelationalPredictors[i], m_multiInstanceHandler, i); if (!result[0] && !result[1]) { fail("Error handling zero training instances (" + getClassTypeString(i) + " class)!"); } } }
/** * tests whether the classifier alters the training set during training. * * @see CheckClassifier#datasetIntegrity(boolean, boolean, boolean, boolean, * boolean, boolean, int, boolean, boolean) * @see CheckClassifier#testsPerClassType(int, boolean, boolean, boolean) */ public void testDatasetIntegrity() { boolean[] result; int i; for (i = FIRST_CLASSTYPE; i <= LAST_CLASSTYPE; i++) { // does the classifier support this type of class at all? if (!canPredict(i)) { continue; } result = m_Tester.datasetIntegrity(m_NominalPredictors[i], m_NumericPredictors[i], m_StringPredictors[i], m_DatePredictors[i], m_RelationalPredictors[i], m_multiInstanceHandler, i, m_handleMissingPredictors[i], m_handleMissingClass[i]); if (!result[0] && !result[1]) { fail("Training set is altered during training (" + getClassTypeString(i) + " class)!"); } } }
/** * tests whether the classifier correctly initializes in the buildClassifier * method * * @see CheckClassifier#correctBuildInitialisation(boolean, boolean, boolean, * boolean, boolean, boolean, int) * @see CheckClassifier#testsPerClassType(int, boolean, boolean, boolean) */ public void testBuildInitialization() { boolean[] result; int i; for (i = FIRST_CLASSTYPE; i <= LAST_CLASSTYPE; i++) { // does the classifier support this type of class at all? if (!canPredict(i)) { continue; } result = m_Tester.correctBuildInitialisation(m_NominalPredictors[i], m_NumericPredictors[i], m_StringPredictors[i], m_DatePredictors[i], m_RelationalPredictors[i], m_multiInstanceHandler, i); if (!result[0] && !result[1]) { fail("Incorrect build initialization (" + getClassTypeString(i) + " class)!"); } } }
/** * checks whether the classifier can handle the class attribute at a given * position (0-based index, -1 means last). * * @param type the class type * @param position the position of the class attribute (0-based, -1 means * last) * @return true if the classifier can handle it */ protected boolean checkClassAsNthAttribute(int type, int position) { boolean[] result; String indexStr; result = m_Tester.canHandleClassAsNthAttribute(m_NominalPredictors[type], m_NumericPredictors[type], m_StringPredictors[type], m_DatePredictors[type], m_RelationalPredictors[type], m_multiInstanceHandler, type, position); if (position == -1) { indexStr = "last"; } else { indexStr = (position + 1) + "."; } if (!result[0] && !result[1]) { fail("Error handling class as " + indexStr + " attribute (" + getClassTypeString(type) + " class)!"); } return result[0]; }
result = m_Tester.canPredict(nom, num, str, dat, rel, m_multiInstanceHandler, i); if (nom) {
/** * Test method for this class * * @param args the commandline parameters */ public static void main(String[] args) { runCheck(new CheckClassifier(), args); } }
/** * checks whether the classifier can handle the given percentage of missing * predictors * * @param type the class type * @param percent the percentage of missing predictors * @param allowFail if true a fail statement may be executed * @return true if the classifier can handle it */ protected boolean checkMissingPredictors(int type, int percent, boolean allowFail) { boolean[] result; result = m_Tester.canHandleMissing(m_NominalPredictors[type], m_NumericPredictors[type], m_StringPredictors[type], m_DatePredictors[type], m_RelationalPredictors[type], m_multiInstanceHandler, type, true, false, percent); if (allowFail) { if (!result[0] && !result[1]) { fail("Error handling " + percent + "% missing predictors (" + getClassTypeString(type) + " class)!"); } } return result[0]; }
/** * tests whether the scheme declares a serialVersionUID. */ public void testSerialVersionUID() { boolean[] result; result = m_Tester.declaresSerialVersionUID(); if (!result[0]) { fail("Doesn't declare serialVersionUID!"); } }
/** * tests whether classifier handles N classes * * @see CheckClassifier#canHandleNClasses(boolean, boolean, boolean, boolean, * boolean, boolean, int) * @see CheckClassifier#testsPerClassType(int, boolean, boolean, boolean) * @see #m_NClasses */ public void testNClasses() { boolean[] result; if (!canPredict(Attribute.NOMINAL)) { return; } result = m_Tester.canHandleNClasses(m_NominalPredictors[Attribute.NOMINAL], m_NumericPredictors[Attribute.NOMINAL], m_StringPredictors[Attribute.NOMINAL], m_DatePredictors[Attribute.NOMINAL], m_RelationalPredictors[Attribute.NOMINAL], m_multiInstanceHandler, m_NClasses); if (!result[0] && !result[1]) { fail("Error handling " + m_NClasses + " classes!"); } }
/** * tests whether classifier handles data containing only a class attribute * * @see CheckClassifier#canHandleOnlyClass(boolean, boolean, boolean, boolean, * boolean, int) * @see CheckClassifier#testsPerClassType(int, boolean, boolean, boolean) */ public void testOnlyClass() { boolean[] result; int i; for (i = FIRST_CLASSTYPE; i <= LAST_CLASSTYPE; i++) { // does the classifier support this type of class at all? if (!canPredict(i)) { continue; } result = m_Tester.canHandleOnlyClass(m_NominalPredictors[i], m_NumericPredictors[i], m_StringPredictors[i], m_DatePredictors[i], m_RelationalPredictors[i], i); if (!result[0] && !result[1]) { fail("Error handling data containing only the class!"); } } }
/** * tests whether the classifier can handle zero training instances * * @see CheckClassifier#canHandleZeroTraining(boolean, boolean, boolean, * boolean, boolean, boolean, int) * @see CheckClassifier#testsPerClassType(int, boolean, boolean, boolean) */ public void testZeroTraining() { boolean[] result; int i; for (i = FIRST_CLASSTYPE; i <= LAST_CLASSTYPE; i++) { // does the classifier support this type of class at all? if (!canPredict(i)) { continue; } result = m_Tester.canHandleZeroTraining(m_NominalPredictors[i], m_NumericPredictors[i], m_StringPredictors[i], m_DatePredictors[i], m_RelationalPredictors[i], m_multiInstanceHandler, i); if (!result[0] && !result[1]) { fail("Error handling zero training instances (" + getClassTypeString(i) + " class)!"); } } }
/** * tests whether the classifier alters the training set during training. * * @see CheckClassifier#datasetIntegrity(boolean, boolean, boolean, boolean, * boolean, boolean, int, boolean, boolean) * @see CheckClassifier#testsPerClassType(int, boolean, boolean, boolean) */ public void testDatasetIntegrity() { boolean[] result; int i; for (i = FIRST_CLASSTYPE; i <= LAST_CLASSTYPE; i++) { // does the classifier support this type of class at all? if (!canPredict(i)) { continue; } result = m_Tester.datasetIntegrity(m_NominalPredictors[i], m_NumericPredictors[i], m_StringPredictors[i], m_DatePredictors[i], m_RelationalPredictors[i], m_multiInstanceHandler, i, m_handleMissingPredictors[i], m_handleMissingClass[i]); if (!result[0] && !result[1]) { fail("Training set is altered during training (" + getClassTypeString(i) + " class)!"); } } }