From: Sunsern C. <sch...@us...> - 2009-06-08 23:41:12
|
Update of /cvsroot/jboost/jboost/src/jboost/examples In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv11232/src/jboost/examples Modified Files: Tag: jboost-2_0 AttributeDescription.java Example.java ExampleDescription.java ExampleSet.java LabelDescription.java TextDescription.java WeightDescription.java Log Message: jboost 2.0 Index: LabelDescription.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/examples/LabelDescription.java,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.4.1 diff -C2 -d -r1.1.1.1 -r1.1.1.1.4.1 *** LabelDescription.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- LabelDescription.java 8 Jun 2009 23:40:49 -0000 1.1.1.1.4.1 *************** *** 12,32 **** */ public class LabelDescription extends FiniteDescription { ! LabelDescription(String name, Configuration c, List okValues) throws ClassNotFoundException { ! super(name,c,okValues); ! attributeClass = Class.forName("jboost.examples.LabelDescription"); ! multiLabel = c.getBool("multiLabel", false); ! } ! private boolean multiLabel; ! public boolean isMultiLabel() { ! return multiLabel; ! } ! public String toString() { ! return super.toString() + " multiLabel: " + multiLabel; ! } ! /* public String toString(Attribute attr) throws Exception { String retval=new String(); --- 12,32 ---- */ public class LabelDescription extends FiniteDescription { ! LabelDescription(String name, Configuration c, List okValues) throws ClassNotFoundException { ! super(name,c,okValues); ! attributeClass = Class.forName("jboost.examples.LabelDescription"); ! multiLabel = c.getBool("multiLabel", false); ! } ! private boolean multiLabel; ! public boolean isMultiLabel() { ! return multiLabel; ! } ! public String toString() { ! return super.toString() + " multiLabel: " + multiLabel; ! } ! /* public String toString(Attribute attr) throws Exception { String retval=new String(); *************** *** 46,81 **** return(retval); } ! */ ! /** Reads a MultiFinite attribute ! * Note that it is currently based on String but should use StringBuffer ! * Also note that right now it can only deal with one value. ! */ ! public Attribute str2Att(String string) throws BadAttException { ! if(string == null) return new Label(null); ! StringTokenizer st = new StringTokenizer(string); ! if (!multiLabel && (st.countTokens() != 1)) ! throw new BadAttException((st.countTokens() == 0 ! ? "Zero" ! : "Multiple") ! + " labels found when expecting single label: "+string); ! String s; ! boolean v[] = new boolean[getNoOfValues()]; ! while(st.hasMoreElements()) { ! s = st.nextToken(); ! if(!caseSignificant) ! s = s.toLowerCase(); ! if(!punctuationSignificant) ! s = StringOp.removePunctuation(s); ! if(map.containsKey(s)) ! v[((Integer) map.get(s)).intValue()] = true; ! else if(map.containsKey("*")) ! v[((Integer) map.get("*")).intValue()] = true; ! else ! throw(new BadAttException("Unknown label: "+s ! +" when not allowed.")); } - return new Label(v); - } } --- 46,81 ---- return(retval); } ! */ ! /** Reads a MultiFinite attribute ! * Note that it is currently based on String but should use StringBuffer ! * Also note that right now it can only deal with one value. ! */ ! public Attribute str2Att(String string) throws BadAttException { ! if(string == null) return new Label(null); ! StringTokenizer st = new StringTokenizer(string); ! if (!multiLabel && (st.countTokens() != 1)) ! throw new BadAttException((st.countTokens() == 0 ! ? "Zero" ! : "Multiple") ! + " labels found when expecting single label: "+string); ! String s; ! boolean v[] = new boolean[getNoOfValues()]; ! while(st.hasMoreElements()) { ! s = st.nextToken(); ! if(!caseSignificant) ! s = s.toLowerCase(); ! if(!punctuationSignificant) ! s = StringOp.removePunctuation(s); ! if(map.containsKey(s)) ! v[((Integer) map.get(s)).intValue()] = true; ! else if(map.containsKey("*")) ! v[((Integer) map.get("*")).intValue()] = true; ! else ! throw(new BadAttException("Unknown label: "+s ! +" when not allowed.")); ! } ! return new Label(v); } } Index: Example.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/examples/Example.java,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -C2 -d -r1.2 -r1.2.2.1 *** Example.java 11 Sep 2008 21:25:45 -0000 1.2 --- Example.java 8 Jun 2009 23:40:49 -0000 1.2.2.1 *************** *** 13,20 **** /** a textual comment */ protected String m_comment; /** a pointer to the exampleDescription */ protected ExampleDescription m_exampleDescription; - /** * Default ctor --- 13,21 ---- /** a textual comment */ protected String m_comment; + /** INDEX */ + protected int m_index; /** a pointer to the exampleDescription */ protected ExampleDescription m_exampleDescription; /** * Default ctor *************** *** 23,30 **** * @param ed */ ! public Example(Attribute[] attArray, Label label, double weight, ExampleDescription ed) { m_instance = new Instance(attArray); m_label=label; m_weight= weight; m_exampleDescription = ed; } --- 24,32 ---- * @param ed */ ! public Example(Attribute[] attArray, int index, Label label, double weight, ExampleDescription ed) { m_instance = new Instance(attArray); m_label=label; m_weight= weight; + m_index = index; m_exampleDescription = ed; } *************** *** 36,40 **** */ public Example(Attribute[] attArray, Label label) { ! this(attArray,label, 1.0, null); } --- 38,42 ---- */ public Example(Attribute[] attArray, Label label) { ! this(attArray,- 1, label, 1.0, null); } *************** *** 62,66 **** } ! /** * Get the weight of this example --- 64,83 ---- } ! /** ! * Get the INDEX of this example ! * @return INDEX ! */ ! public int getIndex() { ! return m_index; ! } ! ! /** ! * Set the INDEX of this example ! * @param INDEX ! */ ! public void setIndex(int index) { ! m_index= index; ! } ! /** * Get the weight of this example Index: TextDescription.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/examples/TextDescription.java,v retrieving revision 1.2 retrieving revision 1.2.4.1 diff -C2 -d -r1.2 -r1.2.4.1 *** TextDescription.java 16 Feb 2008 00:02:19 -0000 1.2 --- TextDescription.java 8 Jun 2009 23:40:49 -0000 1.2.4.1 *************** *** 19,44 **** */ public class TextDescription extends AttributeDescription { ! TextDescription(String name, Configuration c) throws ClassNotFoundException { ! attributeName = name; ! attributeClass = Class.forName("jboost.examples.SetAttribute"); ! // get configuration parameters ! crucial=c.getBool("crucial",false); ! ignoreAttribute=c.getBool("ignoreAttribute",false); ! caseSignificant=c.getBool("caseSignificant",false); ! existence=c.getBool("existence",false); ! ngramsize=c.getInt("ngramsize",1); ! ngramtype = c.getString("ngramtype", "full").toLowerCase(); ! if (ngramsize < 1) // these should probably be SpecFileExceptions ! throw new RuntimeException("Illegal ngramsize received for attribute " ! + name); ! if (!(ngramtype.equals("fixed") || ! ngramtype.equals("full") || ! ngramtype.equals("sparse"))) ! throw new RuntimeException("Illegal ngram type for attribute " ! + name); ! } ! /** Reads a text attribute. Main method, str2Att, converts text to an arrya of integers. The integers reflect the order in which the word appeared in --- 19,44 ---- */ public class TextDescription extends AttributeDescription { ! TextDescription(String name, Configuration c) throws ClassNotFoundException { ! attributeName = name; ! attributeClass = Class.forName("jboost.examples.SetAttribute"); ! // get configuration parameters ! crucial=c.getBool("crucial",false); ! ignoreAttribute=c.getBool("ignoreAttribute",false); ! caseSignificant=c.getBool("caseSignificant",false); ! existence=c.getBool("existence",false); ! ngramsize=c.getInt("ngramsize",1); ! ngramtype = c.getString("ngramtype", "full").toLowerCase(); ! if (ngramsize < 1) // these should probably be SpecFileExceptions ! throw new RuntimeException("Illegal ngramsize received for attribute " ! + name); ! if (!(ngramtype.equals("fixed") || ! ngramtype.equals("full") || ! ngramtype.equals("sparse"))) ! throw new RuntimeException("Illegal ngram type for attribute " ! + name); ! } ! /** Reads a text attribute. Main method, str2Att, converts text to an arrya of integers. The integers reflect the order in which the word appeared in *************** *** 67,234 **** wordList - the unique least that appeared int this document, int order. ! */ ! public Attribute str2Att(String string) throws BadAttException { ! try{if(string == null) return new SetAttribute(null,this);} ! catch(RepeatedElementException e){ ! throw new RuntimeException ! ("TextDescription.str2Att: got a RepeatedElementException " ! +"on a null set !!"); ! } ! string=string.trim(); ! if(string.length()==0) { ! try { return(new SetAttribute(new int[0])); } ! catch(RepeatedElementException e) { ! throw new RuntimeException ! ("RepeatedElementException in TextDescription.str2Att"); ! } ! } ! WordTable wt = WordTable.globalTable; ! // going over words int string and mapping each to an int ! HashMap locMap = new HashMap(); ! // locMap - maps every word that appeared in local document to an ! // object cotaining the number of times the word appeared int ! // current document. ! int numLocWords = 0; // Number of words seen so far int text ! String word; // word to process next ! ArrayList wordList = new ArrayList(); ! // the unique "words" that appeared in this document, where a ! // word may actually be an ngram ! Enumeration st; ! if (ngramtype.equals("sparse")) ! st = new SparseNgram(string, ngramsize); ! else if (ngramtype.equals("full")) ! st = new FullNgram(string, ngramsize); ! else // fixed ngram ! st = new FixedNgram(string, ngramsize); ! try { ! String[] wordArr = string.split(" "); ! //while ( st.hasMoreElements()) { ! for (int i=0; i<wordArr.length; i++) { ! //word = (String) st.nextElement(); ! word = wordArr[i]; ! // if(Monitor.logLevel>3) Monitor.log("DIAG TextAttReader.str2Att: word=" +word); ! if (wt.frozen && !wt.map.containsKey(word)) ! continue; ! if (locMap.containsKey(word)) { // word appeared in curr text ! ((LocWord)locMap.get(word)).inc(); } ! else { // word not in curr text ! locMap.put(word, new LocWord()); ! if (!wt.frozen && !wt.map.containsKey(word)) { // string is nowhere ! if(Monitor.logLevel>30) ! Monitor.log("adding to wordTable word:"+word ! +", token="+wt.size); ! wt.map.put(word, new GloWord(wt.size)); //put new key ! wt.words.add(word); ! wt.size++; ! } ! wordList.add(word); ! numLocWords++; } ! ((GloWord)wt.map.get(word)).inc(); ! } } ! catch (Exception e) { ! if(Monitor.logLevel>3) Monitor.log(e.getMessage()+e); ! throw new BadAttException("Error reading: "+string,0,0); } - int[] wordTokenArr = new int[numLocWords]; - for (int i=0; i<numLocWords; i++) - wordTokenArr[i] =((GloWord)wt.map.get(wordList.get(i))).getToken(); ! Attribute setAttribute = null; ! try{setAttribute = new SetAttribute(wordTokenArr,this);} ! catch(Exception e) { ! e.printStackTrace(); ! if(Monitor.logLevel>3) ! Monitor.log(e.getMessage()+e); ! throw new BadAttException("Error reading: "+string+"\n"+e,0,0); } - return setAttribute; - } ! private int ngramsize; ! private String ngramtype; ! public String getAttributeValue(int i) { ! return (String)WordTable.globalTable.words.get(i); ! } ! public String toString() { ! String retval=new String(attributeName); ! retval+=" "+attributeClass.getName(); ! retval+=" crucial: "+crucial; ! retval+=" ignoreAttribute: "+ignoreAttribute; ! retval+=" caseSignificant: "+caseSignificant; ! retval+=" existence: "+existence; ! retval+=" ngramsize: "+ngramsize; ! retval+=" ngramtype: "+ngramtype; ! return(retval); ! } ! ! public String toString(Attribute attr) { ! if(attr.isDefined()==false) return("UNDEFINED"); ! String retval=new String(); ! int[] tok=((SetAttribute)attr).getList(); ! // This should be improved when the reader is integrated. ! if(tok==null) return(null); ! ! int lineLength=0; ! for(int i=0; i<tok.length; i++) { ! String s=(String) getAttributeValue(tok[i]); ! if(s.startsWith("1 ")) // if this is a simple one word token ! // then remove the prefix ! s=s.substring(2); ! retval += s; ! if(i<tok.length-1) retval+=","; ! lineLength += s.length()+1; ! if(lineLength > 80) { ! lineLength=0; ! retval+="\n"; ! } } - - return(retval); - } ! static public void setTokenSet(String[] t) { ! if (WordTable.globalTable.size > 0) ! throw new RuntimeException("attempted to call TextDescription." ! +"setTokenSet with a nonempty hash " ! +"table"); ! for (int i = 0; i < t.length; i++) { ! if (WordTable.globalTable.map.containsKey(t[i])) ! throw new IllegalArgumentException("tokens passed to " ! +"TextDescription.setTokenSet must all be unique"); ! WordTable.globalTable.map.put(t[i], new GloWord(i)); ! WordTable.globalTable.words.add(t[i]); } ! WordTable.globalTable.size = t.length; ! WordTable.globalTable.frozen = true; ! } ! } /** contains the global token of a word and number of times it appeared in all documents ! */ class GloWord extends LocWord{ ! private int token; ! public GloWord() {this.token=0;} ! public GloWord(int token) {this.token = token;} ! public int getToken() {return token;} } /** contains the number of times a word appeared in current document*/ class LocWord implements Serializable{ ! int numApp; // number of times word appeared ! public LocWord() {this.numApp = 1;} ! public void inc() {numApp++;} ! public int getNumApp() {return numApp;} } ! ! --- 67,234 ---- wordList - the unique least that appeared int this document, int order. ! */ ! public Attribute str2Att(String string) throws BadAttException { ! try{if(string == null) return new SetAttribute(null,this);} ! catch(RepeatedElementException e){ ! throw new RuntimeException ! ("TextDescription.str2Att: got a RepeatedElementException " ! +"on a null set !!"); ! } ! string=string.trim(); ! if(string.length()==0) { ! try { return(new SetAttribute(new int[0])); } ! catch(RepeatedElementException e) { ! throw new RuntimeException ! ("RepeatedElementException in TextDescription.str2Att"); ! } ! } ! WordTable wt = WordTable.globalTable; ! // going over words int string and mapping each to an int ! HashMap locMap = new HashMap(); ! // locMap - maps every word that appeared in local document to an ! // object cotaining the number of times the word appeared int ! // current document. ! int numLocWords = 0; // Number of words seen so far int text ! String word; // word to process next ! ArrayList wordList = new ArrayList(); ! // the unique "words" that appeared in this document, where a ! // word may actually be an ngram ! Enumeration st; ! if (ngramtype.equals("sparse")) ! st = new SparseNgram(string, ngramsize); ! else if (ngramtype.equals("full")) ! st = new FullNgram(string, ngramsize); ! else // fixed ngram ! st = new FixedNgram(string, ngramsize); ! try { ! String[] wordArr = string.split(" "); ! //while ( st.hasMoreElements()) { ! for (int i=0; i<wordArr.length; i++) { ! //word = (String) st.nextElement(); ! word = wordArr[i]; ! // if(Monitor.logLevel>3) Monitor.log("DIAG TextAttReader.str2Att: word=" +word); ! if (wt.frozen && !wt.map.containsKey(word)) ! continue; ! if (locMap.containsKey(word)) { // word appeared in curr text ! ((LocWord)locMap.get(word)).inc(); ! } ! else { // word not in curr text ! locMap.put(word, new LocWord()); ! if (!wt.frozen && !wt.map.containsKey(word)) { // string is nowhere ! if(Monitor.logLevel>30) ! Monitor.log("adding to wordTable word:"+word ! +", token="+wt.size); ! wt.map.put(word, new GloWord(wt.size)); //put new key ! wt.words.add(word); ! wt.size++; ! } ! wordList.add(word); ! numLocWords++; ! } ! ((GloWord)wt.map.get(word)).inc(); ! } } ! catch (Exception e) { ! if(Monitor.logLevel>3) Monitor.log(e.getMessage()+e); ! throw new BadAttException("Error reading: "+string,0,0); } ! int[] wordTokenArr = new int[numLocWords]; ! for (int i=0; i<numLocWords; i++) ! wordTokenArr[i] =((GloWord)wt.map.get(wordList.get(i))).getToken(); ! ! Attribute setAttribute = null; ! try{setAttribute = new SetAttribute(wordTokenArr,this);} ! catch(Exception e) { ! e.printStackTrace(); ! if(Monitor.logLevel>3) ! Monitor.log(e.getMessage()+e); ! throw new BadAttException("Error reading: "+string+"\n"+e,0,0); ! } ! return setAttribute; } ! ! private int ngramsize; ! private String ngramtype; ! ! public String getAttributeValue(int i) { ! return (String)WordTable.globalTable.words.get(i); } ! public String toString() { ! String retval=new String(attributeName); ! retval+=" "+attributeClass.getName(); ! retval+=" crucial: "+crucial; ! retval+=" ignoreAttribute: "+ignoreAttribute; ! retval+=" caseSignificant: "+caseSignificant; ! retval+=" existence: "+existence; ! retval+=" ngramsize: "+ngramsize; ! retval+=" ngramtype: "+ngramtype; ! return(retval); } ! public String toString(Attribute attr) { ! if(attr.isDefined()==false) return("UNDEFINED"); ! String retval=new String(); ! int[] tok=((SetAttribute)attr).getList(); ! // This should be improved when the reader is integrated. ! if(tok==null) return(null); ! int lineLength=0; ! for(int i=0; i<tok.length; i++) { ! String s=(String) getAttributeValue(tok[i]); ! if(s.startsWith("1 ")) // if this is a simple one word token ! // then remove the prefix ! s=s.substring(2); ! retval += s; ! if(i<tok.length-1) retval+=","; ! lineLength += s.length()+1; ! if(lineLength > 80) { ! lineLength=0; ! retval+="\n"; ! } ! } ! return(retval); } ! static public void setTokenSet(String[] t) { ! if (WordTable.globalTable.size > 0) ! throw new RuntimeException("attempted to call TextDescription." ! +"setTokenSet with a nonempty hash " ! +"table"); ! for (int i = 0; i < t.length; i++) { ! if (WordTable.globalTable.map.containsKey(t[i])) ! throw new IllegalArgumentException("tokens passed to " ! +"TextDescription.setTokenSet must all be unique"); ! WordTable.globalTable.map.put(t[i], new GloWord(i)); ! WordTable.globalTable.words.add(t[i]); ! } ! WordTable.globalTable.size = t.length; ! WordTable.globalTable.frozen = true; } ! } /** contains the global token of a word and number of times it appeared in all documents ! */ class GloWord extends LocWord{ ! private int token; ! public GloWord() {this.token=0;} ! public GloWord(int token) {this.token = token;} ! public int getToken() {return token;} } /** contains the number of times a word appeared in current document*/ class LocWord implements Serializable{ ! int numApp; // number of times word appeared ! public LocWord() {this.numApp = 1;} ! public void inc() {numApp++;} ! public int getNumApp() {return numApp;} } ! ! Index: AttributeDescription.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/examples/AttributeDescription.java,v retrieving revision 1.3 retrieving revision 1.3.4.1 diff -C2 -d -r1.3 -r1.3.4.1 *** AttributeDescription.java 23 Oct 2007 22:44:54 -0000 1.3 --- AttributeDescription.java 8 Jun 2009 23:40:49 -0000 1.3.4.1 *************** *** 33,37 **** if (name.equals(DataStream.LABELS_ATTR)) retval=new LabelDescription(name,options,okValues); else if (name.equals(DataStream.WEIGHT_ATTR)) retval= new WeightDescription(name, options); ! //else if (name.equals(DataStream.ID_ATTR)) retval= new IdDescription(name, options); else if(type.equals("number")) retval=new NumberDescription(name,options); else if(type.equals("string")) retval=new StringDescription(name,options); --- 33,37 ---- if (name.equals(DataStream.LABELS_ATTR)) retval=new LabelDescription(name,options,okValues); else if (name.equals(DataStream.WEIGHT_ATTR)) retval= new WeightDescription(name, options); ! else if (name.equals(DataStream.INDEX_ATTR)) retval= new IndexDescription(name, options); else if(type.equals("number")) retval=new NumberDescription(name,options); else if(type.equals("string")) retval=new StringDescription(name,options); Index: ExampleSet.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/examples/ExampleSet.java,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -C2 -d -r1.4 -r1.4.2.1 *** ExampleSet.java 3 Jan 2009 05:13:32 -0000 1.4 --- ExampleSet.java 8 Jun 2009 23:40:49 -0000 1.4.2.1 *************** *** 19,24 **** * The content of the ExampleSet */ private Example[] exampleSet; - public final String IndexName="INDEX"; // Indicates that a field is just an index, use to track individual examples in the log files. - private int indexLocation=-1; // The number of the attribute that stores the index. /** --- 19,22 ---- *************** *** 61,73 **** isBinary = (noOfLabels==2 && !multiLabel); - // Find out if there is an attribute whose name is IndexName. This attribute is used to relate examples in different datasets. - for(int i=0; i<exampleDescription.getNoOfAttributes(); i++) { - String name = exampleDescription.getAttributeDescription(i).getAttributeName(); - if(name.equals(IndexName)) { - indexLocation=i; - break; - } - //System.out.printf("ExampleSet.indexLocation=%d%n", indexLocation); - } } --- 59,62 ---- *************** *** 222,226 **** Predictor base) { - if (base != null) { if (curIter == lastIter) --- 211,214 ---- *************** *** 235,242 **** } - for (int i = 0; i < exampleSet.length; i++) prediction[i] = ! combined.predict(exampleSet[i].getInstance(),curIter); lastIter = curIter; --- 223,230 ---- } for (int i = 0; i < exampleSet.length; i++) prediction[i] = ! //combined.predict(exampleSet[i].getInstance(),curIter); ! combined.predict(exampleSet[i].getInstance()); lastIter = curIter; *************** *** 291,295 **** /** check if there is an attribute whose name is "INDEX" **/ public boolean hasIndex() { ! return indexLocation>-1; } --- 279,283 ---- /** check if there is an attribute whose name is "INDEX" **/ public boolean hasIndex() { ! return exampleDescription.getIndexDescription() != null; } *************** *** 298,302 **** double[] indexes = new double[exampleSet.length]; for(int i=0; i<indexes.length; i++) { ! indexes[i]=((RealAttribute) exampleSet[i].getAttribute(indexLocation)).getValue(); } return indexes; --- 286,290 ---- double[] indexes = new double[exampleSet.length]; for(int i=0; i<indexes.length; i++) { ! indexes[i]=(double) exampleSet[i].getIndex(); } return indexes; Index: ExampleDescription.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/examples/ExampleDescription.java,v retrieving revision 1.2 retrieving revision 1.2.4.1 diff -C2 -d -r1.2 -r1.2.4.1 *** ExampleDescription.java 2 Oct 2007 20:34:56 -0000 1.2 --- ExampleDescription.java 8 Jun 2009 23:40:49 -0000 1.2.4.1 *************** *** 11,21 **** /** 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 */ --- 11,24 ---- /** An AttributeDescription for the labels */ ! private LabelDescription m_label; /** An AttributeDescription for the example weights */ ! private WeightDescription m_weight; ! ! /** An AttributeDescription for INDEX */ ! private IndexDescription m_index; /** a description of each attribute */ ! private Vector m_attribute; /** the index of the example attribute that contains the label */ *************** *** 25,44 **** 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; } --- 28,64 ---- private int m_weightIndex; + /** the index of the example attribute that contains INDEX */ + private int m_indexIndex; + /** Flag for using private sampling weights */ private boolean m_useSamplingWeights; /** * Defaul constructor */ public ExampleDescription() { ! m_attribute=new Vector(); ! m_label= null; ! m_weight= null; ! m_index= null; m_useSamplingWeights= false; m_labelIndex= -1; m_weightIndex= -1; + m_indexIndex= -1; + } + + /** + * Sets the index description. + */ + public void setIndex(AttributeDescription ad) { + m_index=(IndexDescription) ad; + } + + /** + * Sets the index description. + */ + public void setIndex(AttributeDescription ad, int index) { + m_index=(IndexDescription) ad; + m_indexIndex= index; } *************** *** 47,51 **** */ public void setLabel(AttributeDescription ad) { ! label=(LabelDescription) ad; } --- 67,71 ---- */ public void setLabel(AttributeDescription ad) { ! m_label=(LabelDescription) ad; } *************** *** 54,58 **** */ public void setLabel(AttributeDescription ad, int index) { ! label=(LabelDescription) ad; m_labelIndex= index; } --- 74,78 ---- */ public void setLabel(AttributeDescription ad, int index) { ! m_label=(LabelDescription) ad; m_labelIndex= index; } *************** *** 72,80 **** } /** * Assign the weight description */ public void setWeight(AttributeDescription weightDescription) { ! weight= (WeightDescription) weightDescription; } --- 92,108 ---- } + /** + * Return the index of the INDEX + */ + public int getIndexIndex() { + return m_indexIndex; + } + + /** * Assign the weight description */ public void setWeight(AttributeDescription weightDescription) { ! m_weight= (WeightDescription) weightDescription; } *************** *** 83,87 **** */ public void setWeight(AttributeDescription weightDescription, int index) { ! weight= (WeightDescription) weightDescription; m_weightIndex= index; } --- 111,115 ---- */ public void setWeight(AttributeDescription weightDescription, int index) { ! m_weight= (WeightDescription) weightDescription; m_weightIndex= index; } *************** *** 91,97 **** */ public WeightDescription getWeightDescription() { ! return weight; } /** * If true, then the examples with this description will contain --- 119,134 ---- */ public WeightDescription getWeightDescription() { ! return m_weight; } + + /** + * Return the Index Description + */ + public IndexDescription getIndexDescription() { + return m_index; + } + + /** * If true, then the examples with this description will contain *************** *** 113,117 **** /** Add an attribute description. */ public void addAttribute(AttributeDescription ad) { ! attribute.add(ad); } --- 150,154 ---- /** Add an attribute description. */ public void addAttribute(AttributeDescription ad) { ! m_attribute.add(ad); } *************** *** 124,132 **** 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); --- 161,169 ---- Label l= e.getLabel(); Instance ins= e.getInstance(); ! retval += m_label.toString(l); int i=0; int s=ins.getSize(); for(i=0; i < s; i++) { ! retval += ((AttributeDescription) m_attribute.get(i)).toString(e.getAttribute(i)); } return(retval); *************** *** 137,154 **** 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); --- 174,191 ---- public String toString() { String retval=new String(); ! for(int i=0; i<m_attribute.size(); i++) ! retval += (AttributeDescription) m_attribute.get(i) + "\n"; ! retval += m_label + "\n"; return(retval); } public LabelDescription getLabelDescription() { ! return(m_label); } public AttributeDescription[] getAttributes() { ! AttributeDescription[] retval=new AttributeDescription[m_attribute.size()]; for(int i=0;i<retval.length;i++) { ! retval[i]=(AttributeDescription)m_attribute.get(i); } return(retval); *************** *** 160,168 **** */ public int getNoOfAttributes() { ! return attribute.size(); } public AttributeDescription getAttributeDescription(int i) { ! return (AttributeDescription) attribute.get(i); } --- 197,205 ---- */ public int getNoOfAttributes() { ! return m_attribute.size(); } public AttributeDescription getAttributeDescription(int i) { ! return (AttributeDescription) m_attribute.get(i); } Index: WeightDescription.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/examples/WeightDescription.java,v retrieving revision 1.2 retrieving revision 1.2.4.1 diff -C2 -d -r1.2 -r1.2.4.1 *** WeightDescription.java 2 Oct 2007 20:34:56 -0000 1.2 --- WeightDescription.java 8 Jun 2009 23:40:49 -0000 1.2.4.1 *************** *** 9,13 **** public class WeightDescription extends NumberDescription { ! public static final double MAX_WEIGHT = 1; WeightDescription(String name, Configuration config) --- 9,13 ---- public class WeightDescription extends NumberDescription { ! public static final double MAX_WEIGHT = 1; WeightDescription(String name, Configuration config) *************** *** 40,47 **** --- 40,49 ---- throw new BadAttException("The weight: " + weight + " is less than 0",0,0); } + /* if (att > MAX_WEIGHT) { att= MAX_WEIGHT; throw new BadAttException("The weight: " + weight + " is larger than MAX_WEIGHT=" + MAX_WEIGHT,0,0); } + */ } } |