📄 exampledescription.java
字号:
package jboost.examples;import java.util.Vector;/** * A description of the fields in a single example * @author Yoav Freund * @version $Header: /cvsroot/jboost/jboost/src/jboost/examples/ExampleDescription.java,v 1.2 2007/10/02 20:34:56 aarvey Exp $ */public class ExampleDescription { /** An AttributeDescription for the labels */ private LabelDescription label; /** An AttributeDescription for the example weights */ private WeightDescription weight; /** a description of each attribute */ private Vector attribute; /** the index of the example attribute that contains the label */ private int m_labelIndex; /** the index of the example attribute that contains the weight */ private int m_weightIndex; /** Flag for using private sampling weights */ private boolean m_useSamplingWeights; /** * Defaul constructor */ public ExampleDescription() { attribute=new Vector(); label= null; weight= null; m_useSamplingWeights= false; m_labelIndex= -1; m_weightIndex= -1; } /** * Sets the label description. */ public void setLabel(AttributeDescription ad) { label=(LabelDescription) ad; } /** * Sets the label description. */ public void setLabel(AttributeDescription ad, int index) { label=(LabelDescription) ad; m_labelIndex= index; } /** * Return the index of the label attribute */ public int getLabelIndex() { return m_labelIndex; } /** * Return the index of the weight attribute */ public int getWeightIndex() { return m_weightIndex; } /** * Assign the weight description */ public void setWeight(AttributeDescription weightDescription) { weight= (WeightDescription) weightDescription; } /** * Assign the weight description */ public void setWeight(AttributeDescription weightDescription, int index) { weight= (WeightDescription) weightDescription; m_weightIndex= index; } /** * Return the WeightDescription */ public WeightDescription getWeightDescription() { return weight; } /** * If true, then the examples with this description will contain * an attribute that measures the example's sampling probability. * @param flag */ public void setSamplingWeightsFlag(boolean flag) { m_useSamplingWeights= flag; } /** * Return the flag value * @param flag */ public boolean getSamplingWeightsFlag() { return m_useSamplingWeights; } /** Add an attribute description. */ public void addAttribute(AttributeDescription ad) { attribute.add(ad); } /** Converts an Example to a string * this function is here since the way in which examples * are stored needs to use the example description to * reproduce something interpretable. */ public String toString(Example e) throws Exception { String retval= new String(); Label l= e.getLabel(); Instance ins= e.getInstance(); retval += label.toString(l); int i=0; int s=ins.getSize(); for(i=0; i < s; i++) { retval += ((AttributeDescription) attribute.get(i)).toString(e.getAttribute(i)); } return(retval); } /** Converts the ExampleDescription into a String * the output is in the same format as a spec file. */ public String toString() { String retval=new String(); for(int i=0; i<attribute.size(); i++) retval += (AttributeDescription) attribute.get(i) + "\n"; retval += label + "\n"; return(retval); } public LabelDescription getLabelDescription() { return(label); } public AttributeDescription[] getAttributes() { AttributeDescription[] retval=new AttributeDescription[attribute.size()]; for(int i=0;i<retval.length;i++) { retval[i]=(AttributeDescription)attribute.get(i); } return(retval); } /** * Return the number of attributes plus the Label and the example weight, if present * @return count */ public int getNoOfAttributes() { return attribute.size(); } public AttributeDescription getAttributeDescription(int i) { return (AttributeDescription) attribute.get(i); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -