@Override boolean evaluate(Instance inst, int lhsAttIndex, String rhsOperand, double numericOperand, Pattern regexPattern, boolean rhsIsAttribute, int rhsAttIndex) { if (rhsIsAttribute) { if (inst.isMissing(lhsAttIndex) || inst.isMissing(rhsAttIndex)) { return false; } return (inst.value(lhsAttIndex) < inst.value(rhsAttIndex)); } if (inst.isMissing(lhsAttIndex)) { return false; } return (inst.value(lhsAttIndex) < numericOperand); } },
/** * LabelCardinality - return the label cardinality of dataset D of L labels. */ public static final double labelCardinality(Instances D, int L) { double sum = 0.0; double numInstances = (double)D.numInstances(); for(int i = 0; i < D.numInstances(); i++) { for(int j = 0; j < L; j++) { if (!D.instance(i).isMissing(j)) { sum += D.instance(i).value(j); } } } return (double)sum/ numInstances; }
/** * Updates the minimum and maximum values for all the attributes * based on a new instance. * * @param instance the new instance */ private void updateMinMax(Instance instance) { for (int j = 0;j < m_Train.numAttributes(); j++) { if ((m_Train.attribute(j).isNumeric()) && (!instance.isMissing(j))) { if (Double.isNaN(m_MinArray[j])) { m_MinArray[j] = instance.value(j); m_MaxArray[j] = instance.value(j); } else { if (instance.value(j) < m_MinArray[j]) { m_MinArray[j] = instance.value(j); } else { if (instance.value(j) > m_MaxArray[j]) { m_MaxArray[j] = instance.value(j); } } } } } }
@Override public Instance output() { Instance outInst = m_delegate.output(); if (m_hasStringAtts && outInst != null) { for (int i = 0; i < outInst.dataset().numAttributes(); i++) { if (outInst.dataset().attribute(i).isString() && !outInst.isMissing(i)) { String val = outInst.stringValue(i); outInst.attribute(i).setStringValue(val); outInst.setValue(i, 0); } } } return outInst; }
/** * Updates the minimum and maximum values for all the attributes based on a * new instance. * * @param instance the new instance */ private void updateMinMax(Instance instance) { for (int j = 0; j < m_instances.numAttributes(); j++) { if (!instance.isMissing(j)) { if (Double.isNaN(m_Min[j])) { m_Min[j] = instance.value(j); m_Max[j] = instance.value(j); } else if (instance.value(j) < m_Min[j]) { m_Min[j] = instance.value(j); } else if (instance.value(j) > m_Max[j]) { m_Max[j] = instance.value(j); } } } }
/** * Removes all instances with missing values for a particular attribute from * the dataset. * * @param attIndex the attribute's index (index starts with 0) */ // @ requires 0 <= attIndex && attIndex < numAttributes(); public void deleteWithMissing(int attIndex) { ArrayList<Instance> newInstances = new ArrayList<Instance>(numInstances()); for (int i = 0; i < numInstances(); i++) { if (!instance(i).isMissing(attIndex)) { newInstances.add(instance(i)); } } m_Instances = newInstances; }
/** * checks whether the value at the given position is missing * * @param rowIndex the row index * @param columnIndex the column index * @return true if the value at the position is missing */ public boolean isMissingAt(int rowIndex, int columnIndex) { boolean result; result = false; if ((rowIndex >= 0) && (rowIndex < getRowCount()) && (columnIndex > 0) && (columnIndex < getColumnCount())) { result = (m_Data.instance(rowIndex).isMissing(columnIndex - 1)); } return result; }
/** * LabelCardinality - return the label cardinality of dataset D of L labels. */ public static final double labelCardinality(Instances D, int L) { double sum = 0.0; double numInstances = (double)D.numInstances(); for(int i = 0; i < D.numInstances(); i++) { for(int j = 0; j < L; j++) { if (!D.instance(i).isMissing(j)) { sum += D.instance(i).value(j); } } } return (double)sum/ numInstances; }
/** * Checks if the given instance is compatible with this dataset. Only looks at * the size of the instance and the ranges of the values for nominal and * string attributes. * * @param instance the instance to check * @return true if the instance is compatible with the dataset */ public/* @pure@ */boolean checkInstance(Instance instance) { if (instance.numAttributes() != numAttributes()) { return false; } for (int i = 0; i < numAttributes(); i++) { if (instance.isMissing(i)) { continue; } else if (attribute(i).isNominal() || attribute(i).isString()) { if (instance.value(i) != (int) instance.value(i)) { return false; } else if ((instance.value(i) < 0) || (instance.value(i) > attribute(i).numValues() - 1)) { return false; } } } return true; }
@Override boolean evaluate(Instance inst, int lhsAttIndex, String rhsOperand, double numericOperand, Pattern regexPattern, boolean rhsIsAttribute, int rhsAttIndex) { if (rhsIsAttribute) { if (inst.isMissing(lhsAttIndex) || inst.isMissing(rhsAttIndex)) { return false; } return (inst.value(lhsAttIndex) <= inst.value(rhsAttIndex)); } if (inst.isMissing(lhsAttIndex)) { return false; } return (inst.value(lhsAttIndex) <= numericOperand); } },
/** * Updates the minimum and maximum values for all the attributes based on a * new instance. * * @param instance the new instance */ private void updateMinMax(Instance instance) { for (int j = 0; j < m_instances.numAttributes(); j++) { if (!instance.isMissing(j)) { if (Double.isNaN(m_Min[j])) { m_Min[j] = instance.value(j); m_Max[j] = instance.value(j); } else if (instance.value(j) < m_Min[j]) { m_Min[j] = instance.value(j); } else if (instance.value(j) > m_Max[j]) { m_Max[j] = instance.value(j); } } } }
/** * Removes all instances with missing values for a particular attribute from * the dataset. * * @param attIndex the attribute's index (index starts with 0) */ // @ requires 0 <= attIndex && attIndex < numAttributes(); public void deleteWithMissing(int attIndex) { ArrayList<Instance> newInstances = new ArrayList<Instance>(numInstances()); for (int i = 0; i < numInstances(); i++) { if (!instance(i).isMissing(attIndex)) { newInstances.add(instance(i)); } } m_Instances = newInstances; }
/** * checks whether the value at the given position is missing * * @param rowIndex the row index * @param columnIndex the column index * @return true if the value at the position is missing */ public boolean isMissingAt(int rowIndex, int columnIndex) { boolean result; result = false; if ((rowIndex >= 0) && (rowIndex < getRowCount()) && (columnIndex > 0) && (columnIndex < getColumnCount())) { result = (m_Data.instance(rowIndex).isMissing(columnIndex - 1)); } return result; }
/** * Calculates the distribution, in the dataset, of the indexed nominal * attribute values. It also counts the actual number of training instances * that contributed (those with non-missing values) to calculate the * distribution. */ private void generateAttrDistribution() { m_Distribution = new int[m_TrainSet.attribute(m_AttrIndex).numValues()]; int i; Instance train; for (i = 0; i < m_NumInstances; i++) { train = m_TrainSet.instance(i); if (!train.isMissing(m_AttrIndex)) { m_TotalCount++; m_Distribution[(int) train.value(m_AttrIndex)]++; } } }
/** * Checks if the given instance is compatible with this dataset. Only looks at * the size of the instance and the ranges of the values for nominal and * string attributes. * * @param instance the instance to check * @return true if the instance is compatible with the dataset */ public/* @pure@ */boolean checkInstance(Instance instance) { if (instance.numAttributes() != numAttributes()) { return false; } for (int i = 0; i < numAttributes(); i++) { if (instance.isMissing(i)) { continue; } else if (attribute(i).isNominal() || attribute(i).isString()) { if (instance.value(i) != (int) instance.value(i)) { return false; } else if ((instance.value(i) < 0) || (instance.value(i) > attribute(i).numValues() - 1)) { return false; } } } return true; }
@Override boolean evaluate(Instance inst, int lhsAttIndex, String rhsOperand, double numericOperand, Pattern regexPattern, boolean rhsIsAttribute, int rhsAttIndex) { if (rhsIsAttribute) { if (inst.isMissing(lhsAttIndex) || inst.isMissing(rhsAttIndex)) { return false; } return (inst.value(lhsAttIndex) <= inst.value(rhsAttIndex)); } if (inst.isMissing(lhsAttIndex)) { return false; } return (inst.value(lhsAttIndex) <= numericOperand); } },
/** * checks whether the value at the given position is missing * * @param rowIndex the row index * @param columnIndex the column index * @return true if the value at the position is missing */ public boolean isMissingAt(int rowIndex, int columnIndex) { boolean result; result = false; if ((rowIndex >= 0) && (rowIndex < getRowCount()) && isAttribute(columnIndex)) { result = (m_Data.instance(rowIndex).isMissing(getAttributeIndex(columnIndex))); } return result; }