@Override public void insertAttributeAt(Attribute arg0, int arg1) { super.insertAttributeAt(arg0, arg1); }
@Override public void undo() { try { m_Instances.insertAttributeAt(m_att, m_nTargetNode); SerializedObject so = new SerializedObject(m_CPT); m_Distributions[m_nTargetNode] = (Estimator[]) so.getObject(); for (int iChild = 0; iChild < m_children.size(); iChild++) { int nChild = m_children.get(iChild); m_Instances.insertAttributeAt(m_att, m_nTargetNode); so = new SerializedObject(m_childAtts[iChild]); m_Distributions[nChild] = (Estimator[]) so.getObject(); } } catch (Exception e) { e.printStackTrace(); } } // undo
@Override public void undo() { try { m_Instances.insertAttributeAt(m_att, m_nTargetNode); SerializedObject so = new SerializedObject(m_CPT); m_Distributions[m_nTargetNode] = (Estimator[]) so.getObject(); for (int iChild = 0; iChild < m_children.size(); iChild++) { int nChild = m_children.get(iChild); m_Instances.insertAttributeAt(m_att, m_nTargetNode); so = new SerializedObject(m_childAtts[iChild]); m_Distributions[nChild] = (Estimator[]) so.getObject(); } } catch (Exception e) { e.printStackTrace(); } } // undo
/** * replace attribute with specified name and values * * @param nTargetNode index of node the replace specification for * @param sName new name of the node * @param values array of values of the node */ void replaceAtt(int nTargetNode, String sName, ArrayList<String> values) { Attribute newAtt = new Attribute(sName, values); if (m_Instances.classIndex() == nTargetNode) { m_Instances.setClassIndex(-1); /* * m_Instances.insertAttributeAt(newAtt, nTargetNode); * m_Instances.deleteAttributeAt(nTargetNode + 1); * m_Instances.setClassIndex(nTargetNode); */ m_Instances.deleteAttributeAt(nTargetNode); m_Instances.insertAttributeAt(newAtt, nTargetNode); m_Instances.setClassIndex(nTargetNode); } else { /* * m_Instances.insertAttributeAt(newAtt, nTargetNode); * m_Instances.deleteAttributeAt(nTargetNode + 1); */ m_Instances.deleteAttributeAt(nTargetNode); m_Instances.insertAttributeAt(newAtt, nTargetNode); } } // replaceAtt
/** * InsertZintoD - Insert data Z[][] to Instances D (e.g., as labels). * NOTE: Assumes binary labels! * @see #addZtoD(Instances, double[][], int) */ private static Instances insertZintoD(Instances D, double Z[][]) { int L = Z[0].length; // add attributes for(int j = 0; j < L; j++) { D.insertAttributeAt(new Attribute("c"+j,Arrays.asList(new String[]{"0","1"})),j); } // add values Z[0]...Z[N] to D // (note that if D.numInstances() < Z.length, only some are added) for(int j = 0; j < L; j++) { for(int i = 0; i < D.numInstances(); i++) { D.instance(i).setValue(j,Z[i][j] > 0.5 ? 1.0 : 0.0); } } D.setClassIndex(L); return D; }
/** * InsertZintoD - Insert data Z[][] to Instances D (e.g., as labels). * NOTE: Assumes binary labels! * @see #addZtoD(Instances, double[][], int) */ private static Instances insertZintoD(Instances D, double Z[][]) { int L = Z[0].length; // add attributes for(int j = 0; j < L; j++) { D.insertAttributeAt(new Attribute("c"+j,Arrays.asList(new String[]{"0","1"})),j); } // add values Z[0]...Z[N] to D // (note that if D.numInstances() < Z.length, only some are added) for(int j = 0; j < L; j++) { for(int i = 0; i < D.numInstances(); i++) { D.instance(i).setValue(j,Z[i][j] > 0.5 ? 1.0 : 0.0); } } D.setClassIndex(L); return D; }
private Instances enterDurations(Instances data, List<Integer> durs) { // System.out.println("discretizing durations..."); // now discretize and set target attributes (= pause durations) // for that, first train discretizer GmmDiscretizer discr = GmmDiscretizer.trainDiscretizer(durs, 6, true); // used to store the collected values ArrayList<String> targetVals = new ArrayList<String>(); for (int mappedDur : discr.getPossibleValues()) { targetVals.add(mappedDur + "ms"); } // FastVector attributeDeclarations = data.; // attribute declaration finished data.insertAttributeAt(new Attribute("target", targetVals), data.numAttributes()); for (int i = 0; i < durs.size(); i++) { Instance currInst = data.instance(i); int dur = durs.get(i); // System.out.println(" mapping " + dur + " to " + discr.discretize(dur) + " - bi:" + // data.instance(i).value(data.attribute("breakindex"))); currInst.setValue(data.numAttributes() - 1, discr.discretize(dur) + "ms"); } // Make the last attribute be the class data.setClassIndex(data.numAttributes() - 1); return data; }
/** * AddZtoD - Add attribute space Z[N][H] (N rows of H columns) to Instances D, which should have N rows also. * @param D dataset (of N instances) * @param Z attribute space (of N rows, H columns) * @param L column to add Z from in D */ private static Instances addZtoD(Instances D, double Z[][], int L) { int H = Z[0].length; int N = D.numInstances(); // add attributes for(int a = 0; a < H; a++) { D.insertAttributeAt(new Attribute("A"+a),L+a); } // add values Z[0]...Z[N] to D for(int a = 0; a < H; a++) { for(int i = 0; i < N; i++) { D.instance(i).setValue(L+a,Z[i][a]); } } D.setClassIndex(L); return D; }
/** * AddZtoD - Add attribute space Z[N][H] (N rows of H columns) to Instances D, which should have N rows also. * @param D dataset (of N instances) * @param Z attribute space (of N rows, H columns) * @param L column to add Z from in D */ private static Instances addZtoD(Instances D, double Z[][], int L) { int H = Z[0].length; int N = D.numInstances(); // add attributes for(int a = 0; a < H; a++) { D.insertAttributeAt(new Attribute("A"+a),L+a); } // add values Z[0]...Z[N] to D for(int a = 0; a < H; a++) { for(int i = 0; i < N; i++) { D.instance(i).setValue(L+a,Z[i][a]); } } D.setClassIndex(L); return D; }
protected Instances convert(Instances D, int j, int k) { int L = D.classIndex(); D = new Instances(D); D.insertAttributeAt(classAttribute,0); D.setClassIndex(0); for(int i = 0; i < D.numInstances(); i++) { String c = (String)((int)Math.round(D.instance(i).value(j+1))+""+(int)Math.round(D.instance(i).value(k+1))); D.instance(i).setClassValue(c); } for (int i = 0; i < L; i++) D.deleteAttributeAt(1); m_InstancesTemplate = new Instances(D,0); return D; }
protected Instances convert(Instances D, int j, int k) { int L = D.classIndex(); D = new Instances(D); D.insertAttributeAt(classAttribute,0); D.setClassIndex(0); for(int i = 0; i < D.numInstances(); i++) { String c = (String)((int)Math.round(D.instance(i).value(j+1))+""+(int)Math.round(D.instance(i).value(k+1))); D.instance(i).setClassValue(c); } for (int i = 0; i < L; i++) D.deleteAttributeAt(1); m_InstancesTemplate = new Instances(D,0); return D; }
protected Instances convert(Instances D, int j, int k) { int L = D.classIndex(); D = new Instances(D); D.insertAttributeAt(classAttribute,0); D.setClassIndex(0); for(int i = 0; i < D.numInstances(); i++) { String c = (String)((int)Math.round(D.instance(i).value(j+1))+""+(int)Math.round(D.instance(i).value(k+1))); D.instance(i).setClassValue(c); } for (int i = 0; i < L; i++) D.deleteAttributeAt(1); m_InstancesTemplate = new Instances(D,0); return D; }
public Instances transformInstances(MultiLabelInstances mlData) throws Exception { labelIndices = mlData.getLabelIndices(); numOfLabels = mlData.getNumLabels(); Instances data = mlData.getDataSet(); Instances transformed = new Instances(mlData.getDataSet(), 0); // delete all labels transformed = RemoveAllLabels.transformInstances(transformed, labelIndices); // add single label attribute ArrayList<String> classValues = new ArrayList<String>(numOfLabels); for (int x = 0; x < numOfLabels; x++) { classValues.add("Class" + (x + 1)); } Attribute newClass = new Attribute("Class", classValues); transformed.insertAttributeAt(newClass, transformed.numAttributes()); transformed.setClassIndex(transformed.numAttributes() - 1); for (int instanceIndex = 0; instanceIndex < data.numInstances(); instanceIndex++) { //System.out.println(data.instance(instanceIndex).toString()); List<Instance> result = transformInstance(data.instance(instanceIndex)); for (Instance instance : result) { //System.out.println(instance.toString()); transformed.add(instance); //System.out.println(transformed.instance(transformed.numInstances()-1)); } } return transformed; }
/** * Sets the format of the input instances. * * @param instanceInfo an Instances object containing the input instance * structure (any instances contained in the object are ignored - * only the structure is required). * @return true if the outputFormat may be collected immediately * @throws Exception if the format couldn't be set successfully */ @Override public boolean setInputFormat(Instances instanceInfo) throws Exception { Instances outputFormat; Attribute newAttribute; super.setInputFormat(instanceInfo); m_Counter = -1; m_Index.setUpper(instanceInfo.numAttributes()); outputFormat = new Instances(instanceInfo, 0); newAttribute = new Attribute(m_Name); if ((m_Index.getIndex() < 0) || (m_Index.getIndex() > getInputFormat().numAttributes())) { throw new IllegalArgumentException("Index out of range"); } outputFormat.insertAttributeAt(newAttribute, m_Index.getIndex()); setOutputFormat(outputFormat); return true; }
/** * 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; }