本文整理了Java中weka.core.Instances.insertAttributeAt()
方法的一些代码示例,展示了Instances.insertAttributeAt()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Instances.insertAttributeAt()
方法的具体详情如下:
包路径:weka.core.Instances
类名称:Instances
方法名:insertAttributeAt
[英]Inserts an attribute at the given position (0 to numAttributes()) and sets all values to be missing. Shallow copies the attribute before it is inserted. Existing attribute objects at and after the insertion point are also copied so that their indices can be incremented. Creates a fresh list to hold the old and new attribute objects.
[中]在给定位置(0到numAttributes())插入属性,并将所有值设置为缺失。浅层在插入属性之前复制该属性。插入点处和之后的现有属性对象也会被复制,以便可以增加其索引。创建新列表以保存旧属性对象和新属性对象。
代码示例来源:origin: com.googlecode.obvious/obviousx-weka
@Override
public void insertAttributeAt(Attribute arg0, int arg1) {
super.insertAttributeAt(arg0, arg1);
}
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
@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
代码示例来源:origin: Waikato/weka-trunk
@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
代码示例来源:origin: Waikato/weka-trunk
/**
* 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
代码示例来源:origin: net.sf.meka/meka
/**
* 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;
}
代码示例来源:origin: Waikato/meka
/**
* 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;
}
代码示例来源:origin: de.dfki.mary/marytts-builder
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;
}
代码示例来源:origin: Waikato/meka
/**
* 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;
}
代码示例来源:origin: net.sf.meka/meka
/**
* 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;
}
代码示例来源:origin: net.sf.meka/meka
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;
}
代码示例来源:origin: nz.ac.waikato.cms.weka/meka
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;
}
代码示例来源:origin: Waikato/meka
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;
}
代码示例来源:origin: net.sf.meka.thirdparty/mulan
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;
}
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
/**
* 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;
}
代码示例来源:origin: nz.ac.waikato.cms.weka/meka
/**
* 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;
}
代码示例来源:origin: net.sf.meka/meka
/**
* 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;
}
代码示例来源:origin: Waikato/meka
/**
* 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;
}
代码示例来源:origin: nz.ac.waikato.cms.weka/meka
/**
* 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;
}
代码示例来源:origin: Waikato/meka
/**
* 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;
}
代码示例来源:origin: net.sf.meka/meka
/**
* 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;
}
内容来源于网络,如有侵权,请联系作者删除!