/** Creates the total selector's set for get all the possible rules */ private Complejo hazSelectores(Dataset train) { Complejo almacenSelectores; int nClases = train.getnclases(); almacenSelectores = new Complejo(nClases); // Aqui voy a almacenar los selectores (numVariable,operador,valor) Attribute[] atributos = null; int num_atributos, type; Vector nominalValues; atributos = Attributes.getAttributes(); num_atributos = Attributes.getNumAttributes(); Selector s; for (int i = 0; i < train.getnentradas(); i++) { type = atributos[i].getType(); switch (type) { case 0: // NOMINAL nominalValues = atributos[i].getNominalValuesList(); // System.out.print("{"); for (int j = 0; j < nominalValues.size(); j++) { // System.out.print ((String)nominalValues.elementAt(j)+" "); s = new Selector(i, 0, (String) nominalValues.elementAt(j), true); // [atr,op,valor] // incluimos tb los valores en double para facilitar algunas funciones s.setValor((double) j); almacenSelectores.addSelector(s); // s.print(); } // System.out.println("}"); break; } // System.out.println(num_atributos); } return almacenSelectores; }
/** * Returns the attribute that has the name. * * @param name The name of the attribute. */ public final Attribute getAttribute(String name) { for (int i = 0; i < attributes.size(); i++) if (((Attribute) attributes.elementAt(i)).name().equalsIgnoreCase(name)) return (Attribute) attributes.elementAt(i); return null; }
/** * Checks if a node is legitimate. A node is illegitimate if its hamming distance to a pruned node * is 1 (this is, the node is a child of a previously pruned node). * * @param f node to check its legitimacy * @return true if the node is legitimate, false otherwise. */ private boolean legitimate(boolean f[]) { boolean feas = true; for (int i = 0; i < pruned.size() && feas; i++) { if (hamming(pruned.elementAt(i), f) == 1) feas = false; } return feas; }
/** * Function to remove all the attributes with missing value in the given attribute. * * @param attIndex The index of the attribute. */ public final void deleteWithMissing(int attIndex) { Vector newItemsets = new Vector(numItemsets()); for (int i = 0; i < numItemsets(); i++) if (!itemset(i).isMissing(attIndex)) newItemsets.addElement(itemset(i)); itemsets = newItemsets; }
/** Function to stores header of a data file. */ private void readHeader() { String attributeName; Vector attributeValues; int i; name = Attributes.getRelationName(); // Create vectors to hold information temporarily. attributes = new Vector(); keel.Dataset.Attribute at; // store attribute,inputs and outputs of the header for (int j = 0; j < Attributes.getNumAttributes(); j++) { at = Attributes.getAttribute(j); attributeName = at.getName(); // check if it is real if (at.getType() == 2) { float min = (float) at.getMinAttribute(); float max = (float) at.getMinAttribute(); attributes.addElement(new Attribute(attributeName, j)); Attribute att = (Attribute) attributes.elementAt(j); att.setRange(min, max); att.activate(); } else { if (at.getType() == 1) // check if it is integer { int min = (int) at.getMinAttribute(); int max = (int) at.getMinAttribute(); attributes.addElement(new Attribute(attributeName, j)); Attribute att = (Attribute) attributes.elementAt(j); att.setRange(min, max); att.activate(); } else // it is nominal { attributeValues = new Vector(); for (int k = 0; k < at.getNumNominalValues(); k++) { attributeValues.addElement(at.getNominalValue(k)); } attributes.addElement(new Attribute(attributeName, attributeValues, j)); Attribute att = (Attribute) attributes.elementAt(j); att.activate(); } } } // for // set the index of the output class classIndex = Attributes.getNumAttributes() - 1; }
/** * Function to swap two itemsets. * * @param i The first itemset. * @param j The second itemset. */ private void swap(int i, int j) { Object help = itemsets.elementAt(i); itemsets.insertElementAt(itemsets.elementAt(j), i); itemsets.removeElementAt(i + 1); itemsets.insertElementAt(help, j); itemsets.removeElementAt(j + 1); }
/** * Enumerates all the attributes. * * @return An enumeration that contains all the attributes. */ public Enumeration enumerateAttributes() { Vector help = new Vector(attributes.size() - 1); for (int i = 0; i < attributes.size(); i++) if (i != classIndex) help.addElement(attributes.elementAt(i)); return help.elements(); }
/** Recursive method for ABB */ private void abb(boolean feat[]) { boolean[] child; double measure; threshold = data.measureIEP(feat); for (int i = 0; i < cardinalidadCto(feat); i++) { child = removeOne(feat, i); measure = data.measureIEP(child); if (legitimate(child) && measure < threshold) { if (measure < data.measureIEP(features)) { // we keep the best found in 'features' System.arraycopy(child, 0, features, 0, child.length); } abb(child); } else { // we prune this node pruned.add(child); } } }
/** Returns the last itemset. */ public final Itemset lastItemset() { return (Itemset) itemsets.lastElement(); }
/** * Returns the itemset at the given position. * * @param index The index of the itemset. */ public final Itemset itemset(int index) { return (Itemset) itemsets.elementAt(index); }
/** * Enumerates all the itemsets. * * @return An enumeration that contains all the itemsets. */ public final Enumeration enumerateItemsets() { return itemsets.elements(); }
/** * Function to remove an itemset at the given position. * * @param index The index of the itemset to be deleted. */ public final void delete(int index) { itemsets.removeElementAt(index); }
/** Returns the number of itemsets. */ public final int numItemsets() { return itemsets.size(); }
/** Returns the number of attributes. */ public final int numAttributes() { return attributes.size(); }
/** * Returns the attribute that has the index. * * @param index The index of the attribute. */ public final Attribute getAttribute(int index) { return (Attribute) attributes.elementAt(index); }
/** * Function to add one itemset. * * @param itemset The itemset to add to the dataset. */ public final void addItemset(Itemset itemset) { Itemset newItemset = (Itemset) itemset.copy(); newItemset.setDataset(this); itemsets.addElement(newItemset); }