⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 checkkernel.java

📁 代码是一个分类器的实现,其中使用了部分weka的源代码。可以将项目导入eclipse运行
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    m_ClasspathProblems = false;    println("--> Checking for interfaces");    canTakeOptions();    boolean weightedInstancesHandler = weightedInstancesHandler()[0];    boolean multiInstanceHandler = multiInstanceHandler()[0];    println("--> Kernel tests");    testsPerClassType(Attribute.NOMINAL,    weightedInstancesHandler, multiInstanceHandler);    testsPerClassType(Attribute.NUMERIC,    weightedInstancesHandler, multiInstanceHandler);    testsPerClassType(Attribute.DATE,       weightedInstancesHandler, multiInstanceHandler);    testsPerClassType(Attribute.STRING,     weightedInstancesHandler, multiInstanceHandler);    testsPerClassType(Attribute.RELATIONAL, weightedInstancesHandler, multiInstanceHandler);  }    /**   * Set the lernel to test.    *   * @param value the kernel to use.   */  public void setKernel(Kernel value) {    m_Kernel = value;  }    /**   * Get the kernel being tested   *   * @return the kernel being tested   */  public Kernel getKernel() {    return m_Kernel;  }    /**   * Run a battery of tests for a given class attribute type   *   * @param classType true if the class attribute should be numeric   * @param weighted true if the kernel says it handles weights   * @param multiInstance true if the kernel is a multi-instance kernel   */  protected void testsPerClassType(int classType,                                    boolean weighted,                                   boolean multiInstance) {        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      PRel = false;    if (PNom || PNum || PStr || PDat || PRel) {      if (weighted)        instanceWeights(PNom, PNum, PStr, PDat, PRel, multiInstance, classType);            if (classType == Attribute.NOMINAL)        canHandleNClasses(PNom, PNum, PStr, PDat, PRel, multiInstance, 4);      if (!multiInstance) {	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];      if (handleMissingPredictors)        canHandleMissing(PNom, PNum, PStr, PDat, PRel, multiInstance, classType, true, false, 100);            boolean handleMissingClass = canHandleMissing(PNom, PNum, PStr, PDat, PRel,           multiInstance, classType,           false, true, 20)[0];      if (handleMissingClass)        canHandleMissing(PNom, PNum, PStr, PDat, PRel, multiInstance, classType, false, true, 100);            correctBuildInitialisation(PNom, PNum, PStr, PDat, PRel, multiInstance, classType);      datasetIntegrity(PNom, PNum, PStr, PDat, PRel, multiInstance, classType,          handleMissingPredictors, handleMissingClass);    }  }    /**   * Checks whether the scheme can take command line options.   *   * @return index 0 is true if the kernel can take options   */  protected boolean[] canTakeOptions() {        boolean[] result = new boolean[2];        print("options...");    if (m_Kernel instanceof OptionHandler) {      println("yes");      if (m_Debug) {        println("\n=== Full report ===");        Enumeration enu = ((OptionHandler)m_Kernel).listOptions();        while (enu.hasMoreElements()) {          Option option = (Option) enu.nextElement();          print(option.synopsis() + "\n"               + option.description() + "\n");        }        println("\n");      }      result[0] = true;    }    else {      println("no");      result[0] = false;    }        return result;  }    /**   * Checks whether the scheme says it can handle instance weights.   *   * @return true if the kernel handles instance weights   */  protected boolean[] weightedInstancesHandler() {        boolean[] result = new boolean[2];        print("weighted instances kernel...");    if (m_Kernel instanceof WeightedInstancesHandler) {      println("yes");      result[0] = true;    }    else {      println("no");      result[0] = false;    }        return result;  }    /**   * Checks whether the scheme handles multi-instance data.   *    * @return true if the kernel handles multi-instance data   */  protected boolean[] multiInstanceHandler() {    boolean[] result = new boolean[2];        print("multi-instance kernel...");    if (m_Kernel instanceof MultiInstanceCapabilitiesHandler) {      println("yes");      result[0] = true;    }    else {      println("no");      result[0] = false;    }        return result;  }    /**   * Checks basic prediction of the scheme, for simple non-troublesome   * datasets.   *   * @param nominalPredictor if true use nominal predictor attributes   * @param numericPredictor if true use numeric predictor attributes   * @param stringPredictor if true use string predictor attributes   * @param datePredictor if true use date predictor attributes   * @param relationalPredictor if true use relational predictor attributes   * @param multiInstance whether multi-instance is needed   * @param classType the class type (NOMINAL, NUMERIC, etc.)   * @return index 0 is true if the test was passed, index 1 is true if test    *         was acceptable   */  protected boolean[] canPredict(      boolean nominalPredictor,      boolean numericPredictor,       boolean stringPredictor,       boolean datePredictor,      boolean relationalPredictor,      boolean multiInstance,      int classType) {        print("basic predict");    printAttributeSummary(        nominalPredictor, numericPredictor, stringPredictor, datePredictor, relationalPredictor, multiInstance, classType);    print("...");    FastVector accepts = new FastVector();    accepts.addElement("unary");    accepts.addElement("binary");    accepts.addElement("nominal");    accepts.addElement("numeric");    accepts.addElement("string");    accepts.addElement("date");    accepts.addElement("relational");    accepts.addElement("multi-instance");    accepts.addElement("not in classpath");    int numTrain = getNumInstances(), numClasses = 2, missingLevel = 0;    boolean predictorMissing = false, classMissing = false;        return runBasicTest(nominalPredictor, numericPredictor, stringPredictor,         datePredictor, relationalPredictor,         multiInstance,        classType,         missingLevel, predictorMissing, classMissing,        numTrain, numClasses,         accepts);  }    /**   * Checks whether nominal schemes can handle more than two classes.   * If a scheme is only designed for two-class problems it should   * throw an appropriate exception for multi-class problems.   *   * @param nominalPredictor if true use nominal predictor attributes   * @param numericPredictor if true use numeric predictor attributes   * @param stringPredictor if true use string predictor attributes   * @param datePredictor if true use date predictor attributes   * @param relationalPredictor if true use relational predictor attributes   * @param multiInstance whether multi-instance is needed   * @param numClasses the number of classes to test   * @return index 0 is true if the test was passed, index 1 is true if test    *         was acceptable   */  protected boolean[] canHandleNClasses(      boolean nominalPredictor,      boolean numericPredictor,       boolean stringPredictor,       boolean datePredictor,      boolean relationalPredictor,      boolean multiInstance,      int numClasses) {        print("more than two class problems");    printAttributeSummary(        nominalPredictor, numericPredictor, stringPredictor, datePredictor, relationalPredictor, multiInstance, Attribute.NOMINAL);    print("...");    FastVector accepts = new FastVector();    accepts.addElement("number");    accepts.addElement("class");    int numTrain = getNumInstances(), missingLevel = 0;    boolean predictorMissing = false, classMissing = false;        return runBasicTest(nominalPredictor, numericPredictor, stringPredictor,                         datePredictor, relationalPredictor,                         multiInstance,                        Attribute.NOMINAL,                        missingLevel, predictorMissing, classMissing,                        numTrain, numClasses,                         accepts);  }    /**   * Checks whether the scheme can handle class attributes as Nth attribute.   *   * @param nominalPredictor if true use nominal predictor attributes   * @param numericPredictor if true use numeric predictor attributes   * @param stringPredictor if true use string predictor attributes   * @param datePredictor if true use date predictor attributes   * @param relationalPredictor if true use relational predictor attributes   * @param multiInstance whether multi-instance is needed   * @param classType the class type (NUMERIC, NOMINAL, etc.)   * @param classIndex the index of the class attribute (0-based, -1 means last attribute)   * @return index 0 is true if the test was passed, index 1 is true if test    *         was acceptable   * @see TestInstances#CLASS_IS_LAST   */  protected boolean[] canHandleClassAsNthAttribute(      boolean nominalPredictor,      boolean numericPredictor,       boolean stringPredictor,       boolean datePredictor,      boolean relationalPredictor,      boolean multiInstance,      int classType,      int classIndex) {        if (classIndex == TestInstances.CLASS_IS_LAST)      print("class attribute as last attribute");    else      print("class attribute as " + (classIndex + 1) + ". attribute");    printAttributeSummary(        nominalPredictor, numericPredictor, stringPredictor, datePredictor, relationalPredictor, multiInstance, classType);    print("...");    FastVector accepts = new FastVector();    int numTrain = getNumInstances(), numClasses = 2, missingLevel = 0;    boolean predictorMissing = false, classMissing = false;        return runBasicTest(nominalPredictor, numericPredictor, stringPredictor,                         datePredictor, relationalPredictor,                         multiInstance,                        classType,                        classIndex,                        missingLevel, predictorMissing, classMissing,                        numTrain, numClasses,                         accepts);  }    /**   * Checks whether the scheme can handle zero training instances.   *   * @param nominalPredictor if true use nominal predictor attributes   * @param numericPredictor if true use numeric predictor attributes   * @param stringPredictor if true use string predictor attributes   * @param datePredictor if true use date predictor attributes   * @param relationalPredictor if true use relational predictor attributes   * @param multiInstance whether multi-instance is needed   * @param classType the class type (NUMERIC, NOMINAL, etc.)   * @return index 0 is true if the test was passed, index 1 is true if test    *         was acceptable   */  protected boolean[] canHandleZeroTraining(      boolean nominalPredictor,      boolean numericPredictor,       boolean stringPredictor,       boolean datePredictor,      boolean relationalPredictor,      boolean multiInstance,      int classType) {        print("handle zero training instances");    printAttributeSummary(        nominalPredictor, numericPredictor, stringPredictor, datePredictor, relationalPredictor, multiInstance, classType);    print("...");    FastVector accepts = new FastVector();    accepts.addElement("train");    accepts.addElement("value");    int numTrain = 0, numClasses = 2, missingLevel = 0;    boolean predictorMissing = false, classMissing = false;        return runBasicTest(              nominalPredictor, numericPredictor, stringPredictor,               datePredictor, relationalPredictor,               multiInstance,              classType,               missingLevel, predictorMissing, classMissing,              numTrain, numClasses,               accepts);  }    /**   * Checks whether the scheme correctly initialises models when    * buildKernel is called. This test calls buildKernel with   * one training dataset. buildKernel is then called on a training    * set with different structure, and then again with the original training    * set. If the equals method of the KernelEvaluation class returns    * false, this is noted as incorrect build initialisation.   *   * @param nominalPredictor if true use nominal predictor attributes   * @param numericPredictor if true use numeric predictor attributes   * @param stringPredictor if true use string predictor attributes   * @param datePredictor if true use date predictor attributes   * @param relationalPredictor if true use relational predictor attributes   * @param multiInstance whether multi-instance is needed   * @param classType the class type (NUMERIC, NOMINAL, etc.)   * @return index 0 is true if the test was passed

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -