Package weka.associations.tertius

Examples of weka.associations.tertius.Rule


   */
  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;
View Full Code Here


    }
    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;
View Full Code Here

    }
    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;
View Full Code Here

    }
    if (m_best != 0) {
      if (numValuesInResult() < m_best) {
  return true;
      }
      Rule worstResult = (Rule) m_results.getLast();
      if (rule.getConfirmation() >= worstResult.getConfirmation()) {
  return true;
      }
      return false;   
    } else {
      return true;
View Full Code Here

   * Subsumption tests are performed and the rule may not be added. <p>
   * Previous results may also be removed because of sumption.
   */
  private void addResult(Rule rule) {

    Rule current;
    boolean added = false;

    /* Iterate the list until we find the right place. */
    SimpleLinkedList.LinkedListIterator iter = m_results.iterator();
    while (iter.hasNext()) {
      current = (Rule) iter.next();
      if (Rule.confirmationThenObservedComparator.compare(current, rule) > 0) {
  iter.addBefore(rule);
  added = true;
  break;
      }
      /* Subsumption tests to see if the rule can be added. */
      if ((m_subsumption || m_sameClause || m_equivalent)
    && current.subsumes(rule)) {
  if (current.numLiterals() == rule.numLiterals()) {
    if (current.equivalentTo(rule)) {
      /* Equivalent rules. */
      if (m_equivalent) {
        return;
      }
    } else {
      /* Same clauses. */
      if (m_sameClause
    && Rule.confirmationComparator.compare(current, rule) < 0) {
        return;
      }
    }
  } else {
    /* Subsumption. */
    if (m_subsumption
        && Rule.observedComparator.compare(current, rule) <= 0) { 
      return;
    }
  }
      }
    }

    if (added == false) {
      /* The rule must be added in the end of the results. */
      m_results.add(rule);
    }

    /* Iterate the results with a lower confirmation
     *  to see if some of them must be removed. */
    SimpleLinkedList.LinkedListInverseIterator inverse
      = m_results.inverseIterator();
    while (inverse.hasPrevious()) {
      current = (Rule) inverse.previous();
      if (Rule.confirmationThenObservedComparator.compare(current, rule) < 0) {
  break;
      }
      if (current != rule && rule.subsumes(current)) {
  if (current.numLiterals() == rule.numLiterals()) {
    if (!current.equivalentTo(rule)) {
      /* Same clauses. */
      if (m_sameClause
    && Rule.confirmationComparator.compare(current, rule) > 0) {
        inverse.remove();
      }
    }
  } else {
    /* Subsumption. */
    if (m_subsumption
        && Rule.observedComparator.compare(rule, current) <= 0) { 
      inverse.remove();
    }
  } 
      }
    }

    /* Remove the rules with the worst confirmation value
     * if there are too many results. */
    if (m_best != 0 && numValuesInResult() > m_best) {
      Rule worstRule = (Rule) m_results.getLast();
      inverse = m_results.inverseIterator();
      while (inverse.hasPrevious()) {
  current = (Rule) inverse.previous();
  if (Rule.confirmationComparator.compare(current, worstRule) < 0) {
    break;
View Full Code Here

   * refinement.
   */
  public void search() {

    SimpleLinkedList nodes = new SimpleLinkedList(); /* The agenda. */
    Rule currentNode;
    SimpleLinkedList children;
    SimpleLinkedList.LinkedListIterator iter;
    Rule child;
    boolean negBody = (m_negation == BODY || m_negation == ALL);
    boolean negHead = (m_negation == HEAD || m_negation == ALL);

    /* Start with the empty rule. */
      nodes.add(new Rule(m_repeat, m_numLiterals, negBody, negHead,
       m_classification, m_horn));
   
    /* Print the current values. */
    printValues();

    /* Explore the rules in the agenda. */
    while (m_status != STOP && !nodes.isEmpty()) {
      currentNode = (Rule) nodes.removeFirst();
      if (canRefine(currentNode)) {
  children = currentNode.refine(m_predicates);
  iter = children.iterator();
  /* Calculate the optimistic estimate of the children and
   * consider them for adding to the agenda and to the results. */
  while (iter.hasNext()) {
    m_hypotheses++;
    child = (Rule) iter.next();
    child.upDate(m_instances);
    if (canCalculateOptimistic(child)) {
      child.calculateOptimistic();
      if (canExplore(child)) {
        m_explored++;
        if (canStoreInNodes(child)) {
        } else {
    iter.remove();
        }
        if (canCalculateConfirmation(child)) {
    child.calculateConfirmation();
    if (canStoreInResults(child)) {
      addResult(child);
    }   
        }
      } else {
View Full Code Here

    System.out.print("0.000000 0.000000 - 0.000000 0.000000");
  } else { //m_printValues == WINDOW
    m_valuesText.setText("0.000000 0.000000 - 0.000000 0.000000");
  }
      } else {
  Rule best = (Rule) m_results.getFirst();
  Rule worst = (Rule) m_results.getLast();
  String values = best.valuesToString() + " - " + worst.valuesToString();
  if (m_printValues == OUT) {
    System.out.print("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
         + "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
    System.out.print(values);
  } else { //m_printValues == WINDOW
View Full Code Here

    int i = 0;

    text.append("\nTertius\n=======\n\n");

    while (iter.hasNext()) {
      Rule current = (Rule) iter.next();
      text.append(Utils.doubleToString((double) i + 1,
               (int) (Math.log(size)
                / Math.log(10) + 1),
               0)
      + ". ");
      text.append("/* ");
      if (m_roc) {
  text.append(current.rocToString());
      } else {
  text.append(current.valuesToString());
      }
      text.append(" */ ");
      text.append(current.toString());
      text.append("\n");
      i++;
    }
    text.append("\nNumber of hypotheses considered: " + m_hypotheses);
View Full Code Here

    }
    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;
View Full Code Here

    }
    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;
View Full Code Here

TOP

Related Classes of weka.associations.tertius.Rule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.