⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exampleset.java.old

📁 著名的开源仿真软件yale
💻 OLD
📖 第 1 页 / 共 3 页
字号:
    /** Appends an AttributeReference to the list of attribute references. */    public void appendAttributeReference(AttributeReference ref) { 	performance = null;	shouldRecalculateInformationGain = true;	attributeReferences.add(ref); 	mapReferences();    }    /** Appends all AttributeReference in l to the list of attribute references. */    public void appendAttributeReferences(List l) {	performance = null;	shouldRecalculateInformationGain = true;	attributeReferences.addAll(l);	mapReferences();    }    /** Clears all AttributeReferences. */    public void clearAttributeReferences() {	performance = null;	shouldRecalculateInformationGain = true;	attributeReferences.clear();	mapReferences();    }    /** Removes the i-th AttributeReference. */    public AttributeReference removeAttributeReference(int i) {	performance = null;	shouldRecalculateInformationGain = true;	AttributeReference ar = (AttributeReference)attributeReferences.remove(i);	mapReferences();	return ar;    }    /** Removes all attribute references from the example table that are unused. */    public void removeUnusedAttributes() {	ListIterator i = attributeReferences.listIterator();	while (i.hasNext()) {	    AttributeReference ar = (AttributeReference)i.next();	    if (!ar.isUsed()) i.remove();	}	mapReferences();	shouldRecalculateInformationGain = true;    }    /** Removes the attribute reference referencing attribute. */    public void removeAttribute(Attribute attribute) {	ListIterator i = attributeReferences.listIterator();	while (i.hasNext()) {	    AttributeReference ar = (AttributeReference)i.next();	    if (ar.getAttribute().equals(attribute)) {		i.remove();		break;	    }	}	mapReferences();    }    /** Returns the Attribute referenced to by the i-th AttribtueReference. */    public Attribute getAttribute(int i) {	return getAttributeReference(i).getAttribute();    }    /** Returns the attribute with the given name. */    public Attribute getAttribute(String name) {	return getAttributeReference(mapName(name)).getAttribute();    }    /** Returns true if and only if the i-th Attribute reference is used. */    public boolean isAttributeUsed(int i) {	return getAttributeReference(i).isUsed();    }    /** Sets the used-flag of the i-th AttributeReference to u. */    public void setAttributeUsed(int i, boolean u) {	performance = null;	getAttributeReference(i).setUsed(u);    }    /** Sets all AttribtueReferences to used. */    public void setAllAttributesUsed() {	performance = null;	for (int i = 0; i < getNumberOfAttributes(); i++) 	    setAttributeUsed(i, true);    }    /** inverts the used flag of all AttribtueReferences. */    public boolean invertAttributeUsed(int i) {	performance = null;	return getAttributeReference(i).invertUsed();    }    /** Returns the number of attributes (used and unused). */    public int getNumberOfAttributes() {	return attributeReferences.size();    }    public int getNumberOfUsedAttributes() {	int n = 0;	for (int i = 0; i < getNumberOfAttributes(); i++)	    if (isAttributeUsed(i)) n++;	return n;        }    /** Returns a list of used attributes. */    public List getUsedAttributes() {	List l = new ArrayList();	for (int i = 0; i < getNumberOfAttributes(); i++) {	    if (isAttributeUsed(i))		l.add(getAttribute(i));	}	return l;    }    /** Returns the label attribute. */    public Attribute getLabel() {	return label;    }    /** Sets the label attribute. */    public void setLabel(Attribute label) {	if (label != null) {	    LogService.logMessage("ExampleSet.setLabel(): Overwriting old label!",				  LogService.WARNING);	}	this.label = label;    }    /** Returns the predicted label attribute. */    public Attribute getPredictedLabel() {	return predictedLabel;    }    /** Sets the predicted label attribute. */    public Attribute getWeight() {	return weight;    }    /** Returns the cluster attribute. */    public Attribute getCluster() {	return cluster;    }    /** Creates a new attribute in the ExampleTable that is used as the      *  predicted label attribute for this ExampleSet. The old      *  attribute is overwritten! */    public void createPredictedLabel() throws OperatorException {	if (label == null) {	    throw new FatalException("Cannot create predicted label (no label used). If you want to label unlabelled data, use a <label> tag in the attribute description file with sourcecol=\"none\"!");	}	predictedLabel = new Attribute(label, "prediction");	exampleTable.addAttribute(predictedLabel);    }    /** Creates a new attribute in the ExampleTable that is used as the      *  cluster attribute for this ExampleSet. The old      *  attribute is overwritten! */    public void createClusterAttribute() {	if (cluster != null) {	    LogService.logMessage("ExampleSet.createClusterAttribute(): Overwriting old cluster attribute!",				  LogService.WARNING);	}	cluster = new Attribute(Attribute.createName("cluster"), 				Ontology.CLUSTER,				Ontology.SINGLE_VALUE,				Attribute.UNDEFINED_BLOCK_NR,				null);	exampleTable.addAttribute(cluster);    }    /** Creates a new attribute in the ExampleTable that is used as the      *  weight attribute for this ExampleSet. Weights are initialized with 0!     *  The old attribute is overwritten! */    public void createWeightAttribute() {	if (weight != null) {	    LogService.logMessage("ExampleSet.createWeightAttribute(): Overwriting old weight attribute!",				  LogService.WARNING);	}	weight = new Attribute(Attribute.createName("weight"), 			       Ontology.REAL,			       Ontology.SINGLE_VALUE,			       Attribute.UNDEFINED_BLOCK_NR,			       null);	exampleTable.addAttribute(weight);    }    // --------------------------------------------------------------------------------    /** Sets the smallest value for the information gain, that appears among all attributes.     */    public void setSmallestInformationGain(double smallest) {	smallestInformationGain = smallest;	shouldRecalculateInformationGain = false;    }    /** Returns the smallest value for the information gain, that appears among all attributes.     */    public double getSmallestInformationGain() {	return smallestInformationGain;    }    /** Sets the information gain for the attribute with the given index.     */    public void setInformationGain(int index, double value) {	getAttributeReference(index).setInformationGain(value);    }    /** Returns the information gain for the attribute with the given index.     */    public double getInformationGain(int index) {	return getAttributeReference(index).getInformationGain();    }    /** Returns true if information gain must be updated (e.g. because attribute references have changed.) */    public boolean shouldRecalculateInformationGain() {	return shouldRecalculateInformationGain;    }    // --------------------------------------------------------------------------------    /** Sets the performance criterion to <tt>null</tt>, so that it has to be recalculated. */    public void updatePerformance() { performance = null; }    /** Returns the performance. May be null if not yet evaluated. */    public PerformanceVector getPerformance() { return performance; }    /** Sets the performance of this example set. */    public void setPerformance(PerformanceVector performance) { 	this.performance = performance;     }    // --------------------------------------------------------------------------------    /** Returns an iterator for all selected attributes and the selected subset (if any). */    public ExampleReader getExampleReader() {	ExampleReader reader = null;	if (topPartition() != null) {	    reader = new MultiSplitReader(exampleTable.getDataReader(),					  this);	} else {	    reader = new SelectionExampleReader(exampleTable.getDataReader(),						this);	}	return reader;    }    /** Returns an int-array of length getNumberOfUsedAttributes() which maps     *  all used attributes to their true index. */    protected Attribute[] getSelection() {	Attribute[] selection = new Attribute[getNumberOfUsedAttributes()];	int j = 0;	for (int i = 0; i < getNumberOfAttributes(); i++) {	    AttributeReference a = getAttributeReference(i);	    if (a.isUsed()) {		selection[j++] = a.getAttribute();	    }	}	return selection;    }        // --------------------------------------------------------------------------------    /** Split the example set internally into n equal partitions. For use with selectMultiSplit.      *  Uses the global random. Future calls to setMultiSplit will split only the selected     *  partitions (stack like). Remember to call cancelMultiSplit() after use! */    public void setMultiSplit(int n) {	setMultiSplit(n, RandomGenerator.getGlobalRandomGenerator());    }    /** Like setMultiSplit(int), but uses random for splitting. */    public void setMultiSplit(int n, RandomGenerator random) {	partition = new Partition(partition, 				  n, 				  exampleTable.getSize(), 				  true,				  random);    }    /** Splits the example set into two partitions of size <i>ratio</i> and <i>1-ratio</i>. */    public void split(double ratio, RandomGenerator random) {	partition = new Partition(partition, 				  new double[]{ratio, 1-ratio}, 				  exampleTable.getSize(), 				  true,				  random);    }    /** Splits the example set into two partitions of size <i>ratio</i> and <i>1-ratio</i>. */    public void split(double ratio) {	partition = new Partition(partition, 				  new double[]{ratio, 1-ratio}, 				  exampleTable.getSize(), 				  true,				  RandomGenerator.getGlobalRandomGenerator());    }    /** Splits the example set into two partitions. The first set will contain <i>first</i> examples     *  while the second will contain the rest. The sets are not shuffeled, i.e. if the ExampleSet set      *  was created by concatenating a training and test set files they can be seperated by calling     *  this method. */    public void splitOnePoint(int first) {	double firstRatio = ((double)first)/((double)exampleTable.getSize());	partition = new Partition(partition, 				  new double[]{firstRatio, 1-firstRatio}, 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -