From: Aaron A. <aa...@us...> - 2007-10-23 22:44:58
|
Update of /cvsroot/jboost/jboost/src/jboost/examples In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv4508 Modified Files: AttributeDescription.java Added Files: IdDescription.java IntegerAttribute.java IntegerDescription.java Log Message: The beginnings of integer fields (shrink datasize by half) and ID attribute Index: AttributeDescription.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/examples/AttributeDescription.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AttributeDescription.java 2 Oct 2007 20:34:56 -0000 1.2 --- AttributeDescription.java 23 Oct 2007 22:44:54 -0000 1.3 *************** *** 33,36 **** --- 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); --- NEW FILE: IdDescription.java --- package jboost.examples; import jboost.controller.Configuration; import jboost.tokenizer.BadAttException; /** * The description for a private weight of each example. */ public class IdDescription extends IntegerDescription { public static final int MAX_ID = Integer.MAX_VALUE; IdDescription(String name, Configuration config, int default_val) throws ClassNotFoundException { super(name,config); } /** * Reads an id * If no value is specified, default to 1 * If the value is negative, return 0 as the weight. * If the value is greater than 1, return 1. * @param weight the string representation of the weight * @return Attribute the RealAttribute corresponding to the weight */ public Attribute str2Att(String id) throws BadAttException { double att = 1.0; // initialized because try complains otherwise. if (id != null) { id= id.trim(); if (id.length() != 0) { try { att= Double.parseDouble(id); } catch (NumberFormatException nfe) { throw new BadAttException(id + " is not a float",0,0); } if (att < 0) { att= 0; throw new BadAttException("The id: " + id + " is less than 0",0,0); } if (att > MAX_ID) { throw new BadAttException("The id: " + id + " is larger than MAX_ID=" + MAX_ID,0,0); } } } return new RealAttribute (att); } } --- NEW FILE: IntegerDescription.java --- package jboost.examples; import jboost.controller.Configuration; import jboost.tokenizer.BadAttException; /** * the description for number attributes. */ class IntegerDescription extends AttributeDescription { IntegerDescription(String name, Configuration c) throws ClassNotFoundException { attributeName = name; attributeClass = Class.forName("jboost.examples.IntegerAttribute"); // Need to make a SAFE version of configuration, which implements an error() function, which // can return and error message. crucial=c.getBool("crucial",false); ignoreAttribute=c.getBool("ignoreAttribute",false); existence=c.getBool("existence",false); existence=c.getBool("order",true); } /** checks format of string in datafile and converts to float * * If the attribute is missing it creates a new * real attribute, that is not defined. */ public Attribute str2Att(String string) throws BadAttException { if(string == null) return(new RealAttribute()); string=string.trim(); if(string.length()==0) return(new RealAttribute()); double att = 0.; // initialized because try complains otherwise. try { att = Double.parseDouble(string); } catch (NumberFormatException e) { System.err.println(string + " is not a float."); throw new BadAttException(string+" is not a float",0,0); } return new RealAttribute (att); } public String toString() { String retval=new String(attributeName); retval+=" "+attributeClass.getName(); retval+=" crucial: "+crucial; retval+=" ignoreAttribute: "+ignoreAttribute; retval+=" existence: "+existence; retval+=" order: "+order; return(retval); } public String toString(Attribute attr) { String retval=new String(); if(attr==null) return("undefined"); retval+=((RealAttribute)attr).toString(); return(retval); } } --- NEW FILE: IntegerAttribute.java --- package jboost.examples; /** Represents a single real valued attribute */ public class IntegerAttribute extends Attribute { private int value; public IntegerAttribute(int value) {this.value=value; setDefined();} public IntegerAttribute() {defined=false;} public int getValue() {return value;} public String toString() { return this.isDefined() ? String.valueOf(value) : "undefined"; } } |