Example #1
0
 /**
  * It checks if the complex covers a given example
  *
  * @param m The example
  * @return boolean True if it covers the example. False in other case
  */
 public boolean covered(Instance m) {
   boolean cubierto = true;
   double[] ejemplo = m.getMuest();
   for (int i = 0; i < this.size() && cubierto; i++) {
     Selector s = this.getSelector(i);
     switch (s.getOperator()) {
       case 0: // equal operator
         double[] valor = s.getValues();
         cubierto = false;
         for (int j = 0; (j < valor.length) && (!cubierto); j++) {
           cubierto = (ejemplo[s.getAttribute()] == valor[j]);
         }
         break;
       case 1: // distinct operator
         cubierto = ejemplo[s.getAttribute()] != s.getValue();
         break;
       case 2: // lower or equal
         cubierto = ejemplo[s.getAttribute()] <= s.getValue();
         break;
       case 3: // higher
         cubierto = ejemplo[s.getAttribute()] > s.getValue();
         break;
     }
   }
   return cubierto;
 }
Example #2
0
  /**
   * Prints as a String the complex content (List->Attribute)
   *
   * @return a String the complex content
   */
  public String printString(int[] numValues) {

    String cad = "";
    for (int x = 0; x < compl.size(); x++) {
      Selector s = (Selector) compl.get(x);
      // cad += "Atr" + s.getAtributo() + " ";
      double[] values = s.getValues();
      String[] nValues = s.getNValues();
      // si para un atributo aparecen todos sus valores, la condicion es true
      // no imprimimos condicion
      if (values.length < numValues[s.getAttribute()]) {

        if ((x < (compl.size())) && (x > 0)) {
          cad += " AND ";
        }
        cad += attributeNames[s.getAttribute()] + " ";

        switch (s.getOperator()) {
          case 0:
            if (values.length > 1) cad += "in";
            else cad += "=";
            break;
          case 1:
            cad += "<>";
            break;
          case 2:
            cad += "<=";
            break;
          case 3:
            cad += ">";
            break;
        }

        if (Attributes.getInputAttribute(s.getAttribute()).getType() == Attribute.NOMINAL) {
          if (nValues.length > 1) {
            cad += " [" + nValues[0];
            for (int i = 1; i < nValues.length - 1; i++) {
              cad += " , " + nValues[i];
            }
            cad += " , " + nValues[nValues.length - 1] + "] ";
          } else {
            cad += " " + nValues[0] + "";
          }
        } else {
          if (values.length > 1) {
            cad += " [" + values[0];
            for (int i = 1; i < values.length - 1; i++) {
              cad += " , " + values[i];
            }
            cad += " , " + values[values.length - 1] + "]";
          } else {
            cad += " " + values[0] + "";
          }
        }
      }
    }
    return cad;
  }
Example #3
0
 /**
  * It prints on a string the content of the complex
  *
  * @return String a string with the content of the complex
  */
 public String printString() {
   String cad = "";
   for (int x = 0; x < compl.size(); x++) {
     Selector s = (Selector) compl.get(x);
     cad += nombreAtributos[s.getAttribute()] + " ";
     switch (s.getOperator()) {
       case 0:
         cad += "=";
         break;
       case 1:
         cad += "<>";
         break;
       case 2:
         cad += "<=";
         break;
       case 3:
         cad += ">";
         break;
     }
     double[] valores = s.getValues();
     if (valores.length > 1) {
       cad += " " + valores[0];
       for (int i = 1; i < valores.length - 1; i++) {
         cad += " ^ " + valores[i];
       }
       cad += " ^ " + valores[valores.length - 1] + "";
     } else {
       cad += " " + valores[0] + "";
     }
     if (x < compl.size() - 1) {
       cad += " AND ";
     }
   }
   return cad;
 }
Example #4
0
 /** It prints the complex content */
 public void print() {
   for (int x = 0; x < compl.size(); x++) {
     Selector s = (Selector) compl.get(x);
     System.out.print("(" + nombreAtributos[s.getAttribute()] + " ");
     switch (s.getOperator()) {
       case 0:
         System.out.print("=");
         break;
       case 1:
         System.out.print("<>");
         break;
       case 2:
         System.out.print("<=");
         break;
       default:
         System.out.print(">");
     }
     double[] valores = s.getValues();
     if (valores.length > 1) {
       System.out.print(" " + valores[0]);
       for (int i = 1; i < valores.length - 1; i++) {
         System.out.print(" ^ " + valores[i]);
       }
       System.out.print(" ^ " + valores[valores.length - 1] + ")");
     } else {
       System.out.print(" " + valores[0] + ")");
     }
     if (x < compl.size() - 1) {
       System.out.print(" AND ");
     }
   }
 }
Example #5
0
  /**
   * Prints on the standard output the content of this complex object. (List -> Attribute operator
   * value)
   */
  public void print(int nominal) {
    for (int x = 0; x < compl.size(); x++) {
      Selector s = (Selector) compl.get(x);

      double[] values = s.getValues();
      String[] nValues = s.getNValues();

      // System.out.print("(Atr" + s.getAtributo() + " ");
      System.out.print("(" + attributeNames[s.getAttribute()] + " ");

      switch (s.getOperator()) {
        case 0:
          if (values.length > 1 /*|| valoresN.length>1*/) System.out.print("in");
          else System.out.print("=");
          break;
        case 1:
          System.out.print("<>");
          break;
        case 2:
          System.out.print("<=");
          break;
        default:
          System.out.print(">");
      }

      if (nominal == 0) { // el atributo es nominal
        if (nValues.length > 1) {
          System.out.print(" " + nValues[0]);
          for (int i = 1; i < nValues.length - 1; i++) {
            System.out.print(" " + nValues[i]);
          }
          System.out.print(" " + nValues[nValues.length - 1] + ")");
        } else {
          System.out.print(" " + nValues[0] + ")");
        }
      } else {
        if (values.length > 1) {
          System.out.print(" [" + values[0]);
          for (int i = 1; i < values.length - 1; i++) {
            System.out.print(" " + values[i]);
          }
          System.out.print(" " + values[values.length - 1] + "])");
        } else {
          System.out.print(" " + values[0] + ")");
        }
      }

      if (x < compl.size() - 1) {
        System.out.print(" AND ");
      }
      // System.out.print(" -- "+heuristica+" -- ");
      System.out.println();
    }
  }
Example #6
0
 /**
  * Check if the complex gets the given data
  *
  * @param m Muestra The example
  * @return boolean True if gets the example
  */
 public boolean isCovered(Sample m) {
   boolean cubierto = true;
   double[] sample = m.getSample();
   for (int i = 0; i < this.size() && cubierto; i++) { // recorremos los selectores del complejo
     Selector s = this.getSelector(i);
     switch (s.getOperator()) {
       case 0: // se trata del igual
         double[] valor = s.getValues();
         cubierto = false;
         // ahora cada selector solo guarda el minimo y maximo
         // para cuando se trata de una excepcion
         if (valor.length == 1) {
           if (sample[s.getAttribute()] == valor[0]) cubierto = true;
         }
         // ahora ya sabemos que valor solo va a tener 2 componentes
         else {
           if ((sample[s.getAttribute()] >= valor[0]) && (sample[s.getAttribute()] <= valor[1]))
             cubierto = true;
         }
         break;
       case 1: // se trata del distinto
         cubierto = sample[s.getAttribute()] != s.getZeroValue();
         break;
       case 2: // menor o igual
         cubierto = sample[s.getAttribute()] <= s.getZeroValue();
         break;
       case 3: // mayor
         cubierto = sample[s.getAttribute()] > s.getZeroValue();
         break;
     }
   }
   return cubierto;
 }
Example #7
0
 /**
  * Remove the selectors from the list of the selectors that have the parameter attribute o
  *
  * @param attribute the attribute
  */
 public void removeSelectorAttribute(int attribute) {
   Selector s;
   int atrib;
   for (int i = 0; i < compl.size(); i++) {
     s = (Selector) compl.get(i);
     atrib = s.getAttribute();
     if (atrib == attribute) {
       compl.remove(s);
       /*CUIDADO!!!hay q volver al indice anterior pq se ha eliminado un elemento!!*/
       i = i - 1;
     }
   }
 }
Example #8
0
  /**
   * It copies the complex
   *
   * @return A new cloned complex
   */
  public Complex copyRule() {
    int i;

    Complex c = new Complex(nclass);
    for (i = 0; i < compl.size(); i++) {
      Selector aux = (Selector) compl.get(i);
      Selector s = new Selector(aux.getAttribute(), aux.getOperator(), aux.getValue());
      c.addSelector(s);
    }
    c.distrib = this.getDistribution();
    c.setClass(clas);

    return c;
  }
Example #9
0
  /**
   * Checks if the rule gets the parameter instance
   *
   * @param instance the instance
   * @return boolean True if the rule gets the instance
   */
  public boolean instanceCoveredByRule(Instance instance) {
    boolean bCovered = true;
    double cadena;
    for (int i = 0; i < this.size() && bCovered; i++) {
      Selector s = this.getSelector(i);
      switch (s.getOperator()) {
        case 0: // se trata del igual
          double[] valor = s.getValues();
          bCovered = false;
          for (int j = 0; (j < valor.length) && (!bCovered); j++) {
            cadena = instance.getInputRealValues(s.getAttribute());

            if (cadena == valor[j]) bCovered = true;
            else bCovered = false;
            /*int numInputAttributes  = Attributes.getInputNumAttributes();
            int numOutputAttributes = Attributes.getOutputNumAttributes();
            int numUndefinedAttributes = Attributes.getNumAttributes();*/
          }
          break;
      }
    }
    return bCovered;
  }