📄 tertius.java
字号:
/** * Get the value of classIndex. * * @return Value of classIndex. */ public int getClassIndex() { return m_classIndex; } /** * Set the value of classIndex. * * @param v Value to assign to classIndex. */ public void setClassIndex(int v) { m_classIndex = v; } /** * Returns the tip text for this property. * * @return Tip text for this property suitable for * displaying in the explorer/experimenter GUI. */ public String hornClausesTipText() { return "Find rules with a single conclusion literal only."; } /** * Get the value of hornClauses. * * @return Value of hornClauses. */ public boolean getHornClauses() { return m_horn; } /** * Set the value of hornClauses. * * @param v Value to assign to hornClauses. */ public void setHornClauses(boolean v) { m_horn = v; } /** * Returns the tip text for this property. * * @return Tip text for this property suitable for * displaying in the explorer/experimenter GUI. */ public String equivalentTipText() { return "Keep equivalent rules. " + "A rule r2 is equivalent to a rule r1 if the body of r2 is the " + "negation of the head of r1, and the head of r2 is the " + "negation of the body of r1."; } /** * Get the value of equivalent. * * @return Value of equivalent. */ public boolean disabled_getEquivalent() { return !m_equivalent; } /** * Set the value of equivalent. * * @param v Value to assign to equivalent. */ public void disabled_setEquivalent(boolean v) { m_equivalent = !v; } /** * Returns the tip text for this property. * * @return Tip text for this property suitable for * displaying in the explorer/experimenter GUI. */ public String sameClauseTipText() { return "Keep rules corresponding to the same clauses. " + "If set to false, only the rule with the best confirmation " + "value and rules with a lower number of counter-instances " + "will be kept."; } /** * Get the value of sameClause. * * @return Value of sameClause. */ public boolean disabled_getSameClause() { return !m_sameClause; } /** * Set the value of sameClause. * * @param v Value to assign to sameClause. */ public void disabled_setSameClause(boolean v) { m_sameClause = !v; } /** * Returns the tip text for this property. * * @return Tip text for this property suitable for * displaying in the explorer/experimenter GUI. */ public String subsumptionTipText() { return "Keep subsumed rules. " + "If set to false, subsumed rules will only be kept if they " + "have a better confirmation or a lower number of counter-instances."; } /** * Get the value of subsumption. * * @return Value of subsumption. */ public boolean disabled_getSubsumption() { return !m_subsumption; } /** * Set the value of subsumption. * * @param v Value to assign to subsumption. */ public void disabled_setSubsumption(boolean v) { m_subsumption = !v; } /** * Returns the tip text for this property. * * @return Tip text for this property suitable for * displaying in the explorer/experimenter GUI. */ public String missingValuesTipText() { return "Set the way to handle missing values. " + "Missing values can be set to match any value, or never match values " + "or to be significant and possibly appear in rules."; } /** * Get the value of missingValues. * * @return Value of missingValues. */ public SelectedTag getMissingValues() { return new SelectedTag(m_missing, TAGS_MISSING); } /** * Set the value of missingValues. * * @param v Value to assign to missingValues. */ public void setMissingValues(SelectedTag v) { if (v.getTags() == TAGS_MISSING) { m_missing = v.getSelectedTag().getID(); } } /** * Returns the tip text for this property. * * @return Tip text for this property suitable for * displaying in the explorer/experimenter GUI. */ public String rocAnalysisTipText() { return "Return TP-rate and FP-rate for each rule found."; } /** * Get the value of rocAnalysis. * * @return Value of rocAnalysis. */ public boolean getRocAnalysis() { return m_roc; } /** * Set the value of rocAnalysis. * * @param v Value to assign to rocAnalysis. */ public void setRocAnalysis(boolean v) { m_roc = v; } /** * Returns the tip text for this property. * * @return Tip text for this property suitable for * displaying in the explorer/experimenter GUI. */ public String partFileTipText() { return "Set file containing the parts of the individual " + "for individual-based learning."; } /** * Get the value of partFile. * * @return Value of partFile. */ public File disabled_getPartFile() { return new File(m_partsString); } /** * Set the value of partFile. * * @param v Value to assign to partFile. * @throws Exception if file cannot be opened */ public void disabled_setPartFile(File v) throws Exception { m_partsString = v.getAbsolutePath(); if (m_partsString.length() != 0) { Reader reader; try { reader = new BufferedReader(new FileReader(m_partsString)); } catch (Exception e) { throw new Exception("Can't open file " + e.getMessage() + "."); } m_parts = new Instances(reader); } } /** * Returns the tip text for this property. * * @return Tip text for this property suitable for * displaying in the explorer/experimenter GUI. */ public String valuesOutputTipText() { return "Give visual feedback during the search. " + "The current best and worst values can be output either to stdout or to a separate window."; } /** * Get the value of valuesOutput. * * @return Value of valuesOutput. */ public SelectedTag getValuesOutput() { return new SelectedTag(m_printValues, TAGS_VALUES); } /** * Set the value of valuesOutput. * * @param v Value to assign to valuesOutput. */ public void setValuesOutput(SelectedTag v) { if (v.getTags() == TAGS_VALUES) { m_printValues = v.getSelectedTag().getID(); } } /** * Build the predicate corresponding to an attribute. * * @param instances The instances this predicates comes from. * @param attr The attribute this predicate corresponds to. * @param isClass Saying if the attribute is the class attribute. * @return The corresponding Predicate. * @throws Exception if the predicate could not be build * (the attribute is numeric). */ private Predicate buildPredicate(Instances instances, Attribute attr, boolean isClass) throws Exception { Predicate predicate; /* The result. */ Literal lit; Literal negation; boolean missingValues; /* Missing values for this attribute ? */ boolean individual = (m_parts != null); /* Individual-based learning ? */ int type = (instances == m_parts) ? IndividualLiteral.PART_PROPERTY : IndividualLiteral.INDIVIDUAL_PROPERTY; /* Type of property. */ if (attr.isNumeric()) { throw new Exception("Can't handle numeric attributes!"); } missingValues = instances.attributeStats(attr.index()).missingCount > 0; /* Build predicate. */ if (individual) { predicate = new Predicate(instances.relationName() + "." + attr.name(), attr.index(), isClass); } else { predicate = new Predicate(attr.name(), attr.index(), isClass); } if (attr.numValues() == 2 && (!missingValues || m_missing == EXPLICIT)) { /* Case of two values. * If there are missing values, this case is treated like other cases. */ if (individual) { lit = new IndividualLiteral(predicate, attr.value(0), 0, Literal.POS, m_missing, type); negation = new IndividualLiteral(predicate, attr.value(1), 1, Literal.POS, m_missing, type); } else { lit = new AttributeValueLiteral(predicate, attr.value(0), 0, Literal.POS, m_missing); negation = new AttributeValueLiteral(predicate, attr.value(1), 1, Literal.POS, m_missing); } lit.setNegation(negation); negation.setNegation(lit); predicate.addLiteral(lit); } else { /* Case of several values. */ for (int i = 0; i < attr.numValues(); i++) { if (individual) { lit = new IndividualLiteral(predicate, attr.value(i), i, Literal.POS, m_missing, type); } else { lit = new AttributeValueLiteral(predicate, attr.value(i), i, Literal.POS, m_missing); } if (m_negation != NONE) { if (individual) { negation = new IndividualLiteral(predicate, attr.value(i), i, Literal.NEG, m_missing, type); } else { negation = new AttributeValueLiteral(predicate, attr.value(i), i, Literal.NEG, m_missing); } lit.setNegation(negation); negation.setNegation(lit); } predicate.addLiteral(lit); } /* One more value if missing is significant. */ if (missingValues && m_missing == SIGNIFICANT) { if (individual) { lit = new IndividualLiteral(predicate, "?", -1, Literal.POS, m_missing, type); } else { lit = new AttributeValueLiteral(predicate, "?", -1, Literal.POS, m_missing); } if (m_negation != NONE) { if (individual) { negation = new IndividualLiteral(predicate, "?", -1, Literal.NEG, m_missing, type); } else { negation = new AttributeValueLiteral(predicate, "?", -1, Literal.NEG, m_missing); } lit.setNegation(negation); negation.setNegation(lit); } predicate.addLiteral(lit); } } return predicate; } /** * Build the predicates to use in the rules. * * @throws If the predicates could not be built * (numeric attribute). */ private ArrayList buildPredicates() throws Exception { ArrayList predicates = new ArrayList(); /* The result. */ Predicate predicate; Attribute attr; Enumeration attributes = m_instances.enumerateAttributes(); boolean individual = (m_parts != null); /* Individual-based learning ? */ /* Attributes. */ while (attributes.hasMoreElements()) { attr = (Attribute) attributes.nextElement(); /* Identifiers do not appear in rules in individual-based learning. */ if (!(individual && attr.name().equals("id"))) { predicate = buildPredicate(m_instances, attr, false); predicates.add(predicate); } } /* Class attribute. */ attr = m_instances.classAttribute(); /* Identifiers do not appear in rules. */ if (!(individual && attr.name().equals("id"))) { predicate = buildPredicate(m_instances, attr, true); predicates.add(predicate); } /* Attributes of the parts in individual-based learning. */ if (individual) { attributes = m_parts.enumerateAttributes(); while (attributes.hasMoreElements()) { attr = (Attribute) attributes.nextElement(); /* Identifiers do not appear in rules. */ if (!attr.name().equals("id")) { predicate = buildPredicate(m_parts, attr, false); predicates.add(predicate); } } } return predicates; } /** * Count the number of distinct confirmation values in the results. * * @return Number of confirmation values in the results. */ private int numValuesInResult() { int result = 0; SimpleLinkedList.LinkedListIterator iter = m_results.iterator(); Rule current; Rule next; if (!iter.hasNext()) { return result; } else { current = (Rule) iter.next(); while (iter.hasNext()) { next = (Rule) iter.next(); if (current.getConfirmation() > next.getConfirmation()) { result++; } current = next; } return result + 1; } } /** * Test if it is worth refining a rule. * * @param rule The rule to consider. * @return True if the rule can be refined, false otherwise. */ private boolean canRefine(Rule rule) { if (rule.isEmpty()) { return true; } if (m_best != 0) { if (numValuesInResult() < m_best) { return true; } Rule worstResult = (Rule) m_results.getLast(); if (rule.getOptimistic() >= worstResult.getConfirmation()) { return true; } return false; } else { return true; } } /** * Test if it is worth calculating the optimistic estimate of a rule. * * @param rule The rule to consider. * @return True if the optimistic estimate can be calculated, false otherwise. */ private boolean canCalculateOptimistic(Rule rule) { if (rule.hasTrueBody() || rule.hasFalseHead()) { return false; } if (!rule.overFrequencyThreshold(m_frequencyThreshold)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -