/** * Delete last added parent from parent set and update internals (specifically the cardinality of the parent set) * * @param _Instances used for updating the internals */ public void deleteLastParent(Instances _Instances) { m_nNrOfParents--; m_nCardinalityOfParents = m_nCardinalityOfParents / _Instances.attribute(m_nParents[m_nNrOfParents]).numValues(); } // DeleteLastParent
/** * GetKs - return [K_1,K_2,...,K_L] where each Y_j \in {1,...,K_j}. * @param D a dataset */ private static int[] getKs(Instances D) { int L = D.classIndex(); int K[] = new int[L]; for(int k = 0; k < L; k++) { K[k] = D.attribute(k).numValues(); } return K; }
/** * IsMT - see if dataset D is multi-dimensional (else only multi-label) * @param D data * @return true iff D is multi-dimensional only (else false) */ public static boolean isMT(Instances D) { int L = D.classIndex(); for(int j = 0; j < L; j++) { if (D.attribute(j).isNominal()) { if (D.attribute(j).numValues() > 2) { return true; } } else { System.err.println("wtf?"); } } return false; }
protected void buildInternal(MultiLabelInstances mlData) throws Exception { Instances transformedData; transformation = new LabelPowersetTransformation(); debug("Transforming the training set."); transformedData = transformation.transformInstances(mlData); //debug("Transformed training set: \n + transformedData.toString()); // check for unary class debug("Building single-label classifier."); if (transformedData.attribute(transformedData.numAttributes() - 1).numValues() > 1) { baseClassifier.buildClassifier(transformedData); } }
/** * Adds more colours to the colour list */ private void extendColourMap() { if (m_plotInstances.attribute(m_cIndex).isNominal()) { for (int i = m_colorList.size(); i < m_plotInstances.attribute(m_cIndex) .numValues(); i++) { Color pc = m_DefaultColors[i % 10]; int ija = i / 10; ija *= 2; for (int j = 0; j < ija; j++) { pc = pc.brighter(); } if (m_backgroundColor != null) { pc = Plot2D.checkAgainstBackground(pc, m_backgroundColor); } m_colorList.add(pc); } } }
/** * Gives a string representation of the test, starting from the comparison * symbol. * * @return a string representing the test */ private String testComparisonString() { Attribute att = m_Dataset.attribute(m_AttIndex); if (att.isNumeric()) { return ((m_Not ? ">= " : "< ") + Utils.doubleToString(m_Split, 3)); } else { if (att.numValues() != 2) { return ((m_Not ? "!= " : "= ") + att.value((int) m_Split)); } else { return ("= " + (m_Not ? att.value((int) m_Split == 0 ? 1 : 0) : att .value((int) m_Split))); } } }
/** * generates a consequence of length 1 for a class association rule. * * @param instances the instances under consideration * @return FastVector with consequences of length 1 */ public static ArrayList<Object> singleConsequence(Instances instances) { ItemSet consequence; ArrayList<Object> consequences = new ArrayList<Object>(); for (int j = 0; j < (instances.classAttribute()).numValues(); j++) { consequence = new ItemSet(instances.numInstances()); int[] consequenceItems = new int[instances.numAttributes()]; consequence.setItem(consequenceItems); for (int k = 0; k < instances.numAttributes(); k++) { consequence.setItemAt(-1, k); } consequence.setItemAt(j, instances.classIndex()); consequences.add(consequence); } return consequences; }
@Override public List<String> getPredictionLabels() { if (m_modelHeader == null) { return null; } if (m_modelHeader.classAttribute().isNominal()) { if (m_predictionLabels == null) { m_predictionLabels = new ArrayList<String>(); for (int i = 0; i < m_modelHeader.classAttribute().numValues(); i++) { m_predictionLabels.add(m_modelHeader.classAttribute().value(i)); } } } return m_predictionLabels; }
/** * Constructor. * * @param att the attribute that backs this item. * @param valueIndex the index of the value for this item. * @throws Exception if the backing attribute is not binary or unary. */ public BinaryItem(Attribute att, int valueIndex) throws Exception { super(att, valueIndex); if (att.isNumeric() || (att.isNominal() && att.numValues() > 2)) { throw new Exception("BinaryItem must be constructed using a nominal attribute" + " with at most 2 values!"); } }
/** * IsMT - see if dataset D is multi-target (else only multi-label) * @param D data * @return true iff D is multi-target only (else false) */ public static boolean isMT(Instances D) { int L = D.classIndex(); for(int j = 0; j < L; j++) { if (D.attribute(j).isNominal()) { // Classification if (D.attribute(j).numValues() > 2) { // Multi-class return true; } } else { // Regression? System.err.println("[Warning] Found a non-nominal class -- not sure how this happened?"); } } return false; }
/** * Test merging all labels. */ public void testMergeAll() { ((MergeInfrequentNominalValues)m_Filter).setMinimumFrequency(100); ((MergeInfrequentNominalValues)m_Filter).setInvertSelection(true); Instances result = useFilter(); // Number of attributes and instances shouldn't change assertEquals(m_Instances.numAttributes(), result.numAttributes()); assertEquals(m_Instances.numInstances(), result.numInstances()); assertEquals(1, result.attribute(1).numValues()); assertEquals(1, result.attribute(4).numValues()); }
/** * GetKs - return [K_1,K_2,...,K_L] where each Y_j \in {1,...,K_j}. * In the multi-label case, K[j] = 2 for all j = 1,...,L. * @param D a dataset * @return an array of the number of values that each label can take */ private static int[] getKs(Instances D) { int L = D.classIndex(); int K[] = new int[L]; for(int k = 0; k < L; k++) { K[k] = D.attribute(k).numValues(); } return K; }
/** * New probability estimators for an iteration */ private void new_estimators() { for (int i = 0; i < m_num_clusters; i++) { for (int j = 0; j < m_num_attribs; j++) { if (m_theInstances.attribute(j).isNominal()) { m_modelPrev[i][j] = m_model[i][j]; m_model[i][j] = new DiscreteEstimator(m_theInstances.attribute(j) .numValues(), true); } else { m_modelNormalPrev[i][j][0] = m_modelNormal[i][j][0]; m_modelNormalPrev[i][j][1] = m_modelNormal[i][j][1]; m_modelNormalPrev[i][j][2] = m_modelNormal[i][j][2]; m_modelNormal[i][j][0] = m_modelNormal[i][j][1] = m_modelNormal[i][j][2] = 0.0; } } } }
/** * change the name of a node * * @param nTargetNode index of the node to set name for * @param sName new name to assign */ public void setNodeName(int nTargetNode, String sName) { // update undo stack if (m_bNeedsUndoAction) { addUndoAction(new RenameAction(nTargetNode, getNodeName(nTargetNode), sName)); } Attribute att = m_Instances.attribute(nTargetNode); int nCardinality = att.numValues(); ArrayList<String> values = new ArrayList<String>(nCardinality); for (int iValue = 0; iValue < nCardinality; iValue++) { values.add(att.value(iValue)); } replaceAtt(nTargetNode, sName, values); } // setNodeName
/** * Delete last added parent from parent set and update internals (specifically the cardinality of the parent set) * * @param _Instances used for updating the internals */ public void deleteLastParent(Instances _Instances) { m_nNrOfParents--; m_nCardinalityOfParents = m_nCardinalityOfParents / _Instances.attribute(m_nParents[m_nNrOfParents]).numValues(); } // DeleteLastParent
/** * Converts a {@link weka.core.Attribute} object to an amidst {@link Attribute} and add it to the current list of attributes. * @param attrWeka a {@link weka.core.Attribute} object. * @param attrList a {@code List} of {@link Attributes}. */ private static void convertAttribute(weka.core.Attribute attrWeka, List<Attribute> attrList){ StateSpaceType stateSpaceTypeAtt; if(attrWeka.isNominal()){ String[] vals = new String[attrWeka.numValues()]; for (int i=0; i<attrWeka.numValues(); i++) { vals[i] = attrWeka.value(i); } stateSpaceTypeAtt = new FiniteStateSpace(attrWeka.numValues()); }else{ stateSpaceTypeAtt = new RealStateSpace(); } Attribute att = new Attribute(attrWeka.index(),attrWeka.name(), stateSpaceTypeAtt); attrList.add(att); } }
/** * Constructor. * * @param att the attribute that backs this item. * @param valueIndex the index of the value for this item. * @throws Exception if the backing attribute is not binary or unary. */ public BinaryItem(Attribute att, int valueIndex) throws Exception { super(att, valueIndex); if (att.isNumeric() || (att.isNominal() && att.numValues() > 2)) { throw new Exception("BinaryItem must be constructed using a nominal attribute" + " with at most 2 values!"); } }
/** * IsMT - see if dataset D is multi-target (else only multi-label) * @param D data * @return true iff D is multi-target only (else false) */ public static boolean isMT(Instances D) { int L = D.classIndex(); for(int j = 0; j < L; j++) { if (D.attribute(j).isNominal()) { // Classification if (D.attribute(j).numValues() > 2) { // Multi-class return true; } } else { // Regression? System.err.println("[Warning] Found a non-nominal class -- not sure how this happened?"); } } return false; }