/** * Compute the number of all possible conditions that could appear in a rule of a given data. For * nominal attributes, it's the number of values that could appear; for numeric attributes, it's * the number of values * 2, i.e. <= and >= are counted as different possible conditions. * * @return number of all conditions of the data */ public double numAllConditions() { double total = 0; for (int i = 0; i < Attributes.getInputNumAttributes(); i++) { Attribute att = Attributes.getInputAttribute(i); if (att.getType() == Attribute.NOMINAL) total += (double) att.getNumNominalValues(); else total += 2.0 * (double) numDistinctValues(i); } return total; }
/** * Compute the number of all possible conditions that could appear in a rule of a given data. For * nominal attributes, it's the number of values that could appear; for numeric attributes, it's * the number of values * 2, i.e. <= and >= are counted as different possible conditions. * * @param attIndex the attribute' index * @return number of all conditions of the data */ public double numAllConditions(int attIndex) { Attribute att = Attributes.getInputAttribute(attIndex); if (att.getType() == Attribute.NOMINAL) return (double) att.getNumNominalValues(); else return 2.0 * (double) numDistinctValues(attIndex); }
/** 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(); Attribute at; // store attribute inputs and of the header for (int j = 0; j < Attributes.getInputNumAttributes(); j++) { at = Attributes.getInputAttribute(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 MyAttribute(attributeName, j)); MyAttribute att = (MyAttribute) 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 MyAttribute(attributeName, j)); MyAttribute att = (MyAttribute) 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 MyAttribute(attributeName, attributeValues, j)); MyAttribute att = (MyAttribute) attributes.elementAt(j); att.activate(); } } } // for // store outputs of the header at = Attributes.getOutputAttribute(0); attributeName = at.getName(); int j = Attributes.getNumAttributes() - 1; // check if it is real if (at.getType() == 2) { float min = (float) at.getMinAttribute(); float max = (float) at.getMinAttribute(); attributes.addElement(new MyAttribute(attributeName, j)); MyAttribute att = (MyAttribute) 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 MyAttribute(attributeName, j)); MyAttribute att = (MyAttribute) 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 MyAttribute(attributeName, attributeValues, j)); MyAttribute att = (MyAttribute) attributes.elementAt(j); att.activate(); } } // set the index of the output class classIndex = Attributes.getNumAttributes() - 1; }