/** * Constructor. * * @param data Dataset * @param batchSize Batch size * @param truncateLength Maximum sequence length * @param relationalAttributeIndex Relational attribute index */ public RelationalDataSetIterator( Instances data, int batchSize, int truncateLength, int relationalAttributeIndex) { this.data = data; this.batchSize = batchSize; this.cursor = 0; this.truncateLength = truncateLength; this.relationalAttributeIndex = relationalAttributeIndex; this.numFeatures = data.attribute(relationalAttributeIndex).relation().numAttributes(); }
/** * sets up the structure */ protected void locate() { int i; m_Attributes = new BitSet(m_AllowedIndices.length); m_Locators = new ArrayList<AttributeLocator>(); for (i = 0; i < m_AllowedIndices.length; i++) { if (m_Data.attribute(m_AllowedIndices[i]).type() == Attribute.RELATIONAL) m_Locators.add(new AttributeLocator(m_Data.attribute(m_AllowedIndices[i]).relation(), getType())); else m_Locators.add(null); m_Attributes.set(i, m_Data.attribute(m_AllowedIndices[i]).type() == getType()); } }
/** * sets up the structure */ protected void locate() { int i; m_Attributes = new BitSet(m_AllowedIndices.length); m_Locators = new ArrayList<AttributeLocator>(); for (i = 0; i < m_AllowedIndices.length; i++) { if (m_Data.attribute(m_AllowedIndices[i]).type() == Attribute.RELATIONAL) m_Locators.add(new AttributeLocator(m_Data.attribute(m_AllowedIndices[i]).relation(), getType())); else m_Locators.add(null); m_Attributes.set(i, m_Data.attribute(m_AllowedIndices[i]).type() == getType()); } }
text.append(prefix).append(i).append(" ").append(Utils.quote(att.value((int) value))); } else if (att.isRelationValued()) { // Output relational value regardless text.append(prefix).append(i).append(" ").append(Utils.quote(att.relation((int) value).stringWithoutHeader())); } else if (value != 0) { // Only output other attribute types if value != 0 if (att.isNominal()) {
/** * Returns the relational value of a relational attribute. * * @param att the attribute * @return the corresponding relation as an Instances object, null if missing * @throws IllegalArgumentException if the attribute is not a relation-valued * attribute * @throws UnassignedDatasetException if the instance doesn't belong to a * dataset. */ @Override public final/* @pure@ */Instances relationalValue(Attribute att) { int attIndex = att.index(); if (att.isRelationValued()) { if (isMissing(attIndex)) { return null; } return att.relation((int) value(attIndex)); } else { throw new IllegalArgumentException("Attribute isn't relation-valued!"); } }
/** * Returns the relational value of a relational attribute. * * @param att the attribute * @return the corresponding relation as an Instances object, null if missing * @throws IllegalArgumentException if the attribute is not a relation-valued * attribute * @throws UnassignedDatasetException if the instance doesn't belong to a * dataset. */ @Override public final/* @pure@ */Instances relationalValue(Attribute att) { int attIndex = att.index(); if (att.isRelationValued()) { if (isMissing(attIndex)) { return null; } return att.relation((int) value(attIndex)); } else { throw new IllegalArgumentException("Attribute isn't relation-valued!"); } }
/** * returns the underlying instances at the given position * * @param rowIndex the row index * @param columnIndex the column index * @return the corresponding instances */ protected Instances getInstancesAt(int rowIndex, int columnIndex) { Instances result; DataSortedTableModel model; double value; model = (DataSortedTableModel) getModel(); value = model.getInstancesValueAt(rowIndex, columnIndex); result = model.getInstances().attribute(columnIndex - 1) .relation((int) value); return result; }
/** * returns the underlying instances at the given position * * @param rowIndex the row index * @param columnIndex the column index * @return the corresponding instances */ protected Instances getInstancesAt(int rowIndex, int columnIndex) { Instances result; DataSortedTableModel model; double value; model = (DataSortedTableModel) getModel(); value = model.getInstancesValueAt(rowIndex, columnIndex); result = model.getInstances().attribute(columnIndex - 1) .relation((int) value); return result; }
/** * returns the underlying instances at the given position * * @param rowIndex the row index * @param columnIndex the column index * @return the corresponding instances */ protected Instances getInstancesAt(int rowIndex, int columnIndex) { Instances result; ArffSortedTableModel model; double value; model = (ArffSortedTableModel) getModel(); value = model.getInstancesValueAt(rowIndex, columnIndex); result = model.getInstances().attribute(model.getAttributeIndex(columnIndex)) .relation((int) value); return result; }
/** * returns the underlying instances at the given position * * @param rowIndex the row index * @param columnIndex the column index * @return the corresponding instances */ protected Instances getInstancesAt(int rowIndex, int columnIndex) { Instances result; ArffSortedTableModel model; double value; model = (ArffSortedTableModel) getModel(); value = model.getInstancesValueAt(rowIndex, columnIndex); result = model.getInstances().attribute(model.getAttributeIndex(columnIndex)) .relation((int) value); return result; }
/** * Create a copy of the structure. If the data has string or relational * attributes, theses are replaced by empty copies. Other attributes are left * unmodified, but the underlying list structure holding references to the attributes * is shallow-copied, so that other Instances objects with a reference to this list are not affected. * * @return a copy of the instance structure. */ public Instances stringFreeStructure() { ArrayList<Attribute> newAtts = new ArrayList<Attribute>(); for (Attribute att : m_Attributes) { if (att.type() == Attribute.STRING) { newAtts.add(new Attribute(att.name(), (List<String>) null, att.index())); } else if (att.type() == Attribute.RELATIONAL) { newAtts.add(new Attribute(att.name(), new Instances(att.relation(), 0), att.index())); } } if (newAtts.size() == 0) { return new Instances(this, 0); } ArrayList<Attribute> atts = Utils.cast(m_Attributes.clone()); for (Attribute att : newAtts) { atts.set(att.index(), att); } Instances result = new Instances(this, 0); result.m_Attributes = atts; return result; }
/** * Create a copy of the structure. If the data has string or relational * attributes, theses are replaced by empty copies. Other attributes are left * unmodified, but the underlying list structure holding references to the attributes * is shallow-copied, so that other Instances objects with a reference to this list are not affected. * * @return a copy of the instance structure. */ public Instances stringFreeStructure() { ArrayList<Attribute> newAtts = new ArrayList<Attribute>(); for (Attribute att : m_Attributes) { if (att.type() == Attribute.STRING) { newAtts.add(new Attribute(att.name(), (List<String>) null, att.index())); } else if (att.type() == Attribute.RELATIONAL) { newAtts.add(new Attribute(att.name(), new Instances(att.relation(), 0), att.index())); } } if (newAtts.size() == 0) { return new Instances(this, 0); } ArrayList<Attribute> atts = Utils.cast(m_Attributes.clone()); for (Attribute att : newAtts) { atts.set(att.index(), att); } Instances result = new Instances(this, 0); result.m_Attributes = atts; return result; }
Instances rel = new Instances(data.attribute(index).relation(), 0); for (int n = 0; n < getNumInstancesRelational(); n++) { Instance inst = new DenseInstance(rel.numAttributes());
/** * Returns the value of a nominal, string, date, or relational attribute for * the instance as a string. * * @param att the attribute * @return the value as a string * @throws IllegalArgumentException if the attribute is not a nominal, string, * date, or relation-valued attribute. * @throws UnassignedDatasetException if the instance doesn't belong to a * dataset. */ @Override public final/* @pure@ */String stringValue(Attribute att) { int attIndex = att.index(); if (isMissing(attIndex)) { return "?"; } switch (att.type()) { case Attribute.NOMINAL: case Attribute.STRING: return att.value((int) value(attIndex)); case Attribute.DATE: return att.formatDate(value(attIndex)); case Attribute.RELATIONAL: return att.relation((int) value(attIndex)).stringWithoutHeader(); default: throw new IllegalArgumentException( "Attribute isn't nominal, string or date!"); } }
Instances rel = new Instances(data.attribute(index).relation(), 0); for (int n = 0; n < getNumInstancesRelational(); n++) { Instance inst = new DenseInstance(rel.numAttributes());
/** * Returns the value of a nominal, string, date, or relational attribute for * the instance as a string. * * @param att the attribute * @return the value as a string * @throws IllegalArgumentException if the attribute is not a nominal, string, * date, or relation-valued attribute. * @throws UnassignedDatasetException if the instance doesn't belong to a * dataset. */ @Override public final/* @pure@ */String stringValue(Attribute att) { int attIndex = att.index(); if (isMissing(attIndex)) { return "?"; } switch (att.type()) { case Attribute.NOMINAL: case Attribute.STRING: return att.value((int) value(attIndex)); case Attribute.DATE: return att.formatDate(value(attIndex)); case Attribute.RELATIONAL: return att.relation((int) value(attIndex)).stringWithoutHeader(); default: throw new IllegalArgumentException( "Attribute isn't nominal, string or date!"); } }
Instances tempData = instanceInfo.attribute(1).relation() .stringFreeStructure(); ArrayList<Attribute> atts = new ArrayList<Attribute>(tempData.numAttributes()); m_BagStringAtts = new StringLocator(instanceInfo.attribute(1).relation() .stringFreeStructure()); m_BagRelAtts = new RelationalLocator(instanceInfo.attribute(1).relation() .stringFreeStructure());
train.deleteWithMissingClass(); int numAttributes = train.attribute(1).relation().numAttributes(); m_Center = new double[numAttributes];
/** * performs a typical test */ public void testTypical() { Instances icopy = new Instances(m_Instances); Instances result = useFilter(); // # of instances int count = 0; for (int i = 0; i < result.numInstances(); i++) count += result.instance(i).relationalValue(1).numInstances(); assertEquals(icopy.numInstances(), count); // # of attributes count = result.numAttributes() + result.attribute(1).relation().numAttributes() - 1; assertEquals(icopy.numAttributes(), count); }
/** * performs a typical test */ public void testTypical() { Instances icopy = new Instances(m_Instances); Instances result = useFilter(); // # of instances int count = 0; for (int i = 0; i < icopy.numInstances(); i++) count += icopy.instance(i).relationalValue(1).numInstances(); assertEquals(result.numInstances(), count); // # of attributes count = icopy.numAttributes() + icopy.attribute(1).relation().numAttributes() - 1; assertEquals(result.numAttributes(), count); }