/** * Produces a shallow copy of this attribute. * * @return a copy of this attribute with the same index */ // @ also ensures \result instanceof Attribute; @Override public/* @ pure non_null @ */Object copy() { return copy(m_Name); }
/** * Produces a shallow copy of this attribute. * * @return a copy of this attribute with the same index */ // @ also ensures \result instanceof Attribute; @Override public/* @ pure non_null @ */Object copy() { return copy(m_Name); }
/** * Get this derived field as an Attribute. * * @return an Attribute for this derived field. */ @Override public Attribute getFieldAsAttribute() { return m_expression.getOutputDef().copy(m_fieldName); }
/** * Get this derived field as an Attribute. * * @return an Attribute for this derived field. */ @Override public Attribute getFieldAsAttribute() { return m_expression.getOutputDef().copy(m_fieldName); }
public static Attribute copy(Attribute original, int newIndex) { Attribute copy = original.copy(original.name()); copy.setIndex(newIndex); return copy; } }
public GroupFeature(List<FeatureExtractor> features) { this.features = ImmutableList.copyOf(features); ImmutableList.Builder<Attribute> result = ImmutableList.builder(); for (FeatureExtractor fe: this.features) { for (Attribute att: fe.attributes()) { result.add((Attribute)att.copy()); } } _attributes = result.build(); _instances = new Instances("FOO", newArrayList(_attributes), 0); result = ImmutableList.builder(); for (int i = 0; i < _instances.numAttributes(); i++) { result.add(_instances.attribute(i)); } _attributes = result.build(); }
/** * Renames the value of a nominal (or string) attribute value. This change * only affects this dataset. * * @param att the attribute's index (index starts with 0) * @param val the value's index (index starts with 0) * @param name the new name */ public void renameAttributeValue(int att, int val, String name) { Attribute newAtt = (Attribute) attribute(att).copy(); ArrayList<Attribute> newVec = new ArrayList<Attribute>(numAttributes()); newAtt.setValue(val, name); for (Attribute attr : m_Attributes) { if (attr.index() == att) { newVec.add(newAtt); } else { newVec.add(attr); } } m_Attributes = newVec; }
/** * Renames the value of a nominal (or string) attribute value. This change * only affects this dataset. * * @param att the attribute's index (index starts with 0) * @param val the value's index (index starts with 0) * @param name the new name */ public void renameAttributeValue(int att, int val, String name) { Attribute newAtt = (Attribute) attribute(att).copy(); ArrayList<Attribute> newVec = new ArrayList<Attribute>(numAttributes()); newAtt.setValue(val, name); for (Attribute attr : m_Attributes) { if (attr.index() == att) { newVec.add(newAtt); } else { newVec.add(attr); } } m_Attributes = newVec; }
/** * Sets up the structure for the plot instances. */ @Override protected void determineFormat() { int numClusters; ArrayList<Attribute> hv; Attribute predictedCluster; ArrayList<String> clustVals; int i; numClusters = m_Evaluation.getNumClusters(); hv = new ArrayList<Attribute>(); clustVals = new ArrayList<String>(); for (i = 0; i < numClusters; i++) { clustVals.add("cluster" + /* (i+1) */i); } predictedCluster = new Attribute("Cluster", clustVals); for (i = 0; i < m_Instances.numAttributes(); i++) { hv.add((Attribute) m_Instances.attribute(i).copy()); } hv.add(predictedCluster); m_PlotInstances = new Instances(m_Instances.relationName() + "_clustered", hv, m_Instances.numInstances()); }
/** * Sets up the structure for the plot instances. */ @Override protected void determineFormat() { int numClusters; ArrayList<Attribute> hv; Attribute predictedCluster; ArrayList<String> clustVals; int i; numClusters = m_Evaluation.getNumClusters(); hv = new ArrayList<Attribute>(); clustVals = new ArrayList<String>(); for (i = 0; i < numClusters; i++) { clustVals.add("cluster" + /* (i+1) */i); } predictedCluster = new Attribute("Cluster", clustVals); for (i = 0; i < m_Instances.numAttributes(); i++) { hv.add((Attribute) m_Instances.attribute(i).copy()); } hv.add(predictedCluster); m_PlotInstances = new Instances(m_Instances.relationName() + "_clustered", hv, m_Instances.numInstances()); }
/** * Sets the weight of an attribute. This change only affects this dataset. * * @param att the attribute's index (index starts with 0) * @param weight the new weight */ public void setAttributeWeight(int att, double weight) { Attribute existingAtt = attribute(att); if (existingAtt.weight() == weight) { return; } Attribute newAtt = (Attribute)existingAtt.copy(); newAtt.setWeight(weight); ArrayList<Attribute> newVec = new ArrayList<Attribute>(numAttributes()); HashMap<String, Integer> newMap = new HashMap<String, Integer>((int)(numAttributes() / 0.75)); for (Attribute attr : m_Attributes) { if (attr.index() == att) { newVec.add(newAtt); newMap.put(newAtt.name(), att); } else { newVec.add(attr); newMap.put(attr.name(), attr.index()); } } m_Attributes = newVec; m_NamesToAttributeIndices = newMap; }
/** * Set up the header for the PC->original space dataset * * @return the output format * @throws Exception if something goes wrong */ private Instances setOutputFormatOriginal() throws Exception { ArrayList<Attribute> attributes = new ArrayList<Attribute>(); for (int i = 0; i < m_numAttribs; i++) { String att = m_trainInstances.attribute(i).name(); attributes.add(new Attribute(att)); } if (m_hasClass) { attributes.add((Attribute) m_trainHeader.classAttribute().copy()); } Instances outputFormat = new Instances(m_trainHeader.relationName() + "->PC->original space", attributes, 0); // set the class to be the last attribute if necessary if (m_hasClass) { outputFormat.setClassIndex(outputFormat.numAttributes() - 1); } return outputFormat; }
/** * Set the output format. Changes the format of the specified date attribute. */ private void setOutputFormat() { // Create new attributes ArrayList<Attribute> newAtts = new ArrayList<Attribute>(getInputFormat() .numAttributes()); for (int j = 0; j < getInputFormat().numAttributes(); j++) { Attribute att = getInputFormat().attribute(j); if (j == m_AttIndex.getIndex()) { Attribute a = new Attribute(att.name(), getDateFormat().toPattern()); a.setWeight(att.weight()); newAtts.add(a); } else { newAtts.add((Attribute) att.copy()); } } // Create new header Instances newData = new Instances(getInputFormat().relationName(), newAtts, 0); newData.setClassIndex(getInputFormat().classIndex()); m_OutputAttribute = newData.attribute(m_AttIndex.getIndex()); setOutputFormat(newData); }
/** * Set the output format. Changes the format of the specified date attribute. */ private void setOutputFormat() { // Create new attributes ArrayList<Attribute> newAtts = new ArrayList<Attribute>(getInputFormat() .numAttributes()); for (int j = 0; j < getInputFormat().numAttributes(); j++) { Attribute att = getInputFormat().attribute(j); if (j == m_AttIndex.getIndex()) { Attribute a = new Attribute(att.name(), getDateFormat().toPattern()); a.setWeight(att.weight()); newAtts.add(a); } else { newAtts.add((Attribute) att.copy()); } } // Create new header Instances newData = new Instances(getInputFormat().relationName(), newAtts, 0); newData.setClassIndex(getInputFormat().classIndex()); m_OutputAttribute = newData.attribute(m_AttIndex.getIndex()); setOutputFormat(newData); }
/** * SwitchAttributes - Move label attributes from End to Beginning of attribute space (MULAN format to MEKA format). * Note: can use e.g.: java weka.filters.unsupervised.attribute.Reorder -i thyroid.arff -R 30-last,1-29" */ public static final Instances switchAttributes(Instances D, int L) { int d = D.numAttributes(); for(int j = 0; j < L; j++) { D.insertAttributeAt(D.attribute(d-1).copy(D.attribute(d-1).name()+"-"),0); for(int i = 0; i < D.numInstances(); i++) { D.instance(i).setValue(0,D.instance(i).value(d)); } D.deleteAttributeAt(d); } return D; }
/** * mulan2meka - Move label attributes from the End to the Beginning of attribute space (MULAN format to MEKA format). * Note: can use e.g.: java weka.filters.unsupervised.attribute.Reorder -i thyroid.arff -R 30-last,1-29" * See also: F.reorderLabels(D,s) */ public static final Instances mulan2meka(Instances D, int L) { int d = D.numAttributes(); for(int j = 0; j < L; j++) { D.insertAttributeAt(D.attribute(d-1).copy(D.attribute(d-1).name()+"-"),0); for(int i = 0; i < D.numInstances(); i++) { D.instance(i).setValue(0,D.instance(i).value(d)); } D.deleteAttributeAt(d); } return D; }
/** * mulan2meka - Move label attributes from the End to the Beginning of attribute space (MULAN format to MEKA format). * Note: can use e.g.: java weka.filters.unsupervised.attribute.Reorder -i thyroid.arff -R 30-last,1-29" * See also: F.reorderLabels(D,s) */ public static final Instances mulan2meka(Instances D, int L) { int d = D.numAttributes(); for(int j = 0; j < L; j++) { D.insertAttributeAt(D.attribute(d-1).copy(D.attribute(d-1).name()+"-"),0); for(int i = 0; i < D.numInstances(); i++) { D.instance(i).setValue(0,D.instance(i).value(d)); } D.deleteAttributeAt(d); } return D; }
/** * SwitchAttributes - Move L label attributes from the beginning to end of attribute space of an Instances. * Necessary because MULAN assumes label attributes are at the end, not the beginning. * (the extra time for this process is not counted in the running-time analysis of published work). */ public static final Instances switchAttributes(Instances instances, int L) { for(int j = 0; j < L; j++) { //instances.insertAttributeAt(new Attribute(instances.attribute(0).name()+"-"),instances.numAttributes()); instances.insertAttributeAt(instances.attribute(0).copy(instances.attribute(0).name()+"-"),instances.numAttributes()); for(int i = 0; i < instances.numInstances(); i++) { instances.instance(i).setValue(instances.numAttributes()-1,instances.instance(i).value(0)); } instances.deleteAttributeAt(0); } return instances; }
/** * meka2mulan - Move L label attributes from the beginning to end of attribute space of an Instances. * Necessary because MULAN assumes label attributes are at the end, not the beginning. * (the extra time for this process is not counted in the running-time analysis of published work). */ public static final Instances meka2mulan(Instances D, int L) { for(int j = 0; j < L; j++) { //D.insertAttributeAt(new Attribute(D.attribute(0).name()+"-"),D.numAttributes()); D.insertAttributeAt(D.attribute(0).copy(D.attribute(0).name()+"-"),D.numAttributes()); for(int i = 0; i < D.numInstances(); i++) { D.instance(i).setValue(D.numAttributes()-1,D.instance(i).value(0)); } D.deleteAttributeAt(0); } return D; }
/** * meka2mulan - Move L label attributes from the beginning to end of attribute space of an Instances. * Necessary because MULAN assumes label attributes are at the end, not the beginning. * (the extra time for this process is not counted in the running-time analysis of published work). */ public static final Instances meka2mulan(Instances D, int L) { for(int j = 0; j < L; j++) { //D.insertAttributeAt(new Attribute(D.attribute(0).name()+"-"),D.numAttributes()); D.insertAttributeAt(D.attribute(0).copy(D.attribute(0).name()+"-"),D.numAttributes()); for(int i = 0; i < D.numInstances(); i++) { D.instance(i).setValue(D.numAttributes()-1,D.instance(i).value(0)); } D.deleteAttributeAt(0); } return D; }