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

📄 exampleset.java.old

📁 著名的开源仿真软件yale
💻 OLD
📖 第 1 页 / 共 3 页
字号:
				  exampleTable.getSize(), 				  true,				  RandomGenerator.getGlobalRandomGenerator());    }    /** Removes the top partition from the split stack.      */    public void cancelSplit() {	popPartition();    }    /** Returns the number of subsets in the partition.     */    public int getPartitionSize() {	return partition.numPartitions();    }    /** ExampleReaders created in the future will only show elements (non-elements)     *  of the partition <code>index</code> if <code>select</code> is <code>true</code>     *  (<code>false</code>).     *  A preceding call to <code>setMultiSplit(int)</code> is mandatory.     */    public void selectMultiSplit(int index, boolean select) {	topPartition().selectMultiSplit(index, select);    }    /** Like <tt>selectMultiSplit(index, true)</tt>.      */    public void selectMultiSplit(int index) {	topPartition().selectMultiSplit(index, true);    }    /** ExampleReaders created in the future will show elements of partition <code>i</code>     *  if and only if <code>mask[i]=true</code>.     *  A preceding call to <code>setMultiSplit(int)</code> is mandatory.     */    public void selectMultiSplit(boolean[] mask) {	topPartition().selectMultiSplit(mask);    }    protected Partition topPartition() { 	return partition;     }    private Partition popPartition() { 	partition = partition.pop();	return partition;    }    /** Teilt das Example Set in eine neue Partition, bei der die Beispiele der Untermengen die gleiche Auspr&auml;gung      *  des Attributes mit dem gegebenen Index haben. Es gibt danach also so viele Untermenge wie Auspr&auml;gungen, abz&uuml;glich     *  der Untermengen, die leer sind (da die eigentlich vorhandene Auspr&auml;gung nun nicht mehr vorhanden ist). <br>     *  Funktioniert nur bei nominalen Attributen.     */    public int splitByAttribute(Attribute attribute) {	int offset = 0;	if (Ontology.ATTRIBUTE_VALUE_TYPE.isA(attribute.getValueType(), Ontology.NOMINAL)) {	    offset = Attribute.FIRST_CLASS_INDEX;	} else if (Ontology.ATTRIBUTE_VALUE_TYPE.isA(attribute.getValueType(), Ontology.INTEGER)) {	    offset = 0;	} else {	    throw new RuntimeException("ExampleSet can only be splitted by a nominal or integer attribute. You have tried to split the example set by '" + attribute + "'.");	}	int[] elements = new int[getSize()];	ExampleReader reader = getExampleReader();	int i = 0;	int maxNumber = 0;	// array bestimmen mit indizes fuer die verschiedenen Partitionen fuer die Attributwerte	while (reader.hasNext()) {	    Example example = reader.next();	    int value = (int)example.getValue(attribute) - offset;	    maxNumber = Math.max(maxNumber, value);	    elements[i++] = value;	}	// neue partition erzeugen 	partition = new Partition(partition, 				  elements,				  exampleTable.getSize(),				  maxNumber+1);	// anzahl der Partitionen zurueckschicken	return maxNumber+1;    }    /** Teilt das Example Set in eine neue Partition mit zwei Untermengen. Die Beispiele der Untermengen haben als      *  Auspr&auml;gung Werte kleiner gleich dem Schwellenwert und Werte gr&ouml;&szlig;er dem Schwellenwert. <br>     *  Kann daher nur bei numerischen Attributen angewendet werden.     */    public int splitByAttribute(Attribute attribute, double threshold) {	if (!Ontology.ATTRIBUTE_VALUE_TYPE.isA(attribute.getValueType(), Ontology.NUMERICAL)) {	    throw new RuntimeException("ExampleSet can only be splitted by a non nominal attribute at threshold '" + threshold + "'. You have tried to split the example set by '" + attribute + "'.");	}	int[] elements = new int[getSize()];	ExampleReader reader = getExampleReader();	int i = 0; 	// array bestimmen mit indizes fuer die verschiedenen Partitionen fuer die Attributwerte	while (reader.hasNext()) {	    Example example = reader.next();	    if (example.getValue(attribute) <= threshold) 		elements[i++] = 0;	    else elements[i++] = 1;	}	// neue partition erzeugen 	partition = new Partition(partition, 				  elements,				  exampleTable.getSize(),				  2);	// anzahl der Partitionen zurueckschicken	return 2;     }    // --------------------------------------------------------------------------------    /** Returns all attributes which are compatible with <tt>a</tt> (more     *  specific) with respect to their <tt>used</tt> flag. For each value series block     *  the start index is used. If no compatible attributes are found, returns null. */    public Attribute[] getCompatibleAttributes(Attribute a) {	List indices = new LinkedList();	for (int i = 0; i < getNumberOfAttributes(); i++) {	    Attribute a1 = getAttribute(i);	    // check for compatibility...	    if ((isAttributeUsed(i)) && (a1.compatible(a))) {		// ...and add attribute index if ok		indices.add(a1);		// skip the rest of the block if value series		if (a1.isSeries()) {		    i = getBlockEndIndex(i);		}	    }	}	if (indices.size() == 0) return null;	// convert to int array	Attribute[] result = new Attribute[indices.size()];	int j = 0;	ListIterator i = indices.listIterator();	while (i.hasNext())	    result[j++] = (Attribute)i.next();	return result;    }    public Attribute[] getRandomCompatibleAttributes(Attribute[] expectedInputAttributes) {	Attribute [] arguments = new Attribute [expectedInputAttributes.length];	for (int j = 0 ; j < expectedInputAttributes.length ; j++){	    Attribute attribute = expectedInputAttributes[j];	    Attribute[] compatibleAttributes = getCompatibleAttributes(attribute);	    arguments[j] = 		compatibleAttributes[RandomGenerator.getGlobalRandomGenerator().nextInt(compatibleAttributes.length)];	}	return arguments;    }    /** Sets the number of argument combinations for each feature generator and returns     *  the sum of combinations.      */    public int setArgumentCombinations(List generators) {	int combinationSum = 0;	ListIterator i = generators.listIterator();	while (i.hasNext()) {	    FeatureGenerator g = (FeatureGenerator)i.next();	    int c = numberOfApplicableArgumentCombinations(g);	    combinationSum += c;	    if (c > 0) {		g.setArgumentCombinations(c);	    }	}	return combinationSum;    }    public boolean isApplicable(FeatureGenerator generator) {	return numberOfApplicableArgumentCombinations(generator) > 0;    }    /** Returns the number of possible attribute combinations for this generator.     */    public int numberOfApplicableArgumentCombinations(FeatureGenerator generator) {	Attribute[] input = generator.getInputAttributes();	int numberOfCombinations = 1;	for (int i = 0; i < input.length; i++) {	    Attribute[] ca = getCompatibleAttributes(input[i]);	    if (ca == null) return 0;	    numberOfCombinations *= ca.length;	}	return numberOfCombinations;    }    /** Returns the last attribute index belonging to the block starting     *  at startindex. */    public int getBlockEndIndex(int startindex) {	int blockNr = getAttribute(startindex).getBlockNr();	for (int i = startindex+1; i < getNumberOfAttributes(); i++)	    if (getAttribute(i).getBlockNr() != blockNr) return i-1;	return getNumberOfAttributes()-1;    }    // --------------------------------------------------------------------------------    public boolean isValid() {	return getNumberOfUsedAttributes() > 0;    }    // --------------------------------------------------------------------------------    public String toString() {        StringBuffer str = new StringBuffer("ExampleSet: ");        str.append(getSize() + " examples; " + 	    (partition != null ? partition.toString() : "no partition"));	str.append(";\n       attributes = {\n");	if (getNumberOfAttributes() >= 1000) {                             // RK/2002/04/23: TMP	    str.append(" ...\n");                                          // RK/2002/04/23: TMP	} else {                                                           // RK/2002/04/23: TMP	    for (int i = 0; i < getNumberOfAttributes(); i++) {		Attribute att = getAttribute(i);		str.append((i == 0 ? "" : ",\n") +			   "         " + att.toString() + (isAttributeUsed(i) ? "<on>" : "<off>"));		if (Ontology.ATTRIBUTE_BLOCK_TYPE.isA(att.getBlockType(), Ontology.VALUE_SERIES_START)) {		    int end = getBlockEndIndex(i);		    str.append(",..., "+(end-i-1)+" attributes,...");		    i = end-1;		}	    }	}                                                                   // RK/2002/04/23: TMP	str.append("\n       }; "+getNumberOfUsedAttributes()+"/" + getNumberOfAttributes() + " used");	str.append("\n       label = " +getLabel());	if (getPredictedLabel() != null)	    str.append("\n       predicted label = " + getPredictedLabel());	if (getWeight() != null)	    str.append("\n       weight = " + getWeight());        return str.toString();    }    public String selectionString() {	String str = "[";	for (int i = 0; i < getNumberOfAttributes(); i++) {	    str += isAttributeUsed(i) ? "x" : "-";	}	return str+"]";	    }    private String toHTML() {	StringBuffer buffer = new StringBuffer("<html>");	buffer.append("<b>Number of examples:</b> "+getSize()+"<br>");	buffer.append("<b>Number of attributes:</b> "+getNumberOfUsedAttributes()+"<br>");	buffer.append("<ol>");	Iterator i = getUsedAttributes().iterator();	int j = 0;	while (i.hasNext()) {	    buffer.append("<li>"+i.next()+"</li>");	    j++;	    if (j > 100) {		buffer.append("<li>...</li>");		break;	    }	}	buffer.append("</ol>");	if (getLabel() != null) buffer.append("<b>Label:</b> "+getLabel()+"<br>");	if (getPredictedLabel() != null) buffer.append("<b>Predicition:</b> "+getPredictedLabel()+"<br>");	if (getWeight() != null) buffer.append("<b>Weight:</b> "+getWeight()+"<br>");	buffer.append("</html>");	return buffer.toString();    }    public Component getVisualisationComponent() {	JLabel label = new JLabel(toHTML());	label.setFont(label.getFont().deriveFont(java.awt.Font.PLAIN));	return label;    }    /** Returns true, if all AttributeReferences are equal. */    public boolean equals(ExampleSet es) {	if (es.getNumberOfAttributes() != this.getNumberOfAttributes()) return false;	for (int i = 0; i < this.getNumberOfAttributes(); i++) {	    if (!es.getAttributeReference(i).equals(this.getAttributeReference(i))) return false;	}	return true;    }    /** Returns true if exampleSet contains the same AttributReferences. Their used-flags need not be equal.     */    public boolean equalAttributeReferences(ExampleSet es) {	if (es.getNumberOfAttributes() != this.getNumberOfAttributes()) return false;	for (int i = 0; i < this.getNumberOfAttributes(); i++) {	    if (es.getAttributeReference(i).getAttribute().getIndex() != this.getAttributeReference(i).getAttribute().getIndex()) return false;	}	return true;    }}

⌨️ 快捷键说明

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