00001 // Predictor.h 00002 00003 #ifndef PREDICTOR_H 00004 #define PREDICTOR_H 00005 00006 #include <stdint.h> 00007 #include <sstream> 00008 #include <ostream> 00009 #include <string> 00010 00011 namespace Yosokumo 00012 { 00013 00014 /** 00015 * A column of values, an independent variable. Other terminology that is 00016 * sometimes used: An attribute or an input. These are the primary 00017 * characteristics of a <code>Predictor</code>: 00018 * <ul> 00019 * <li>a name - unsigned positive integer 00020 * <li>a status - active or inactive 00021 * <li>a type - categorical or continuous 00022 * <li>a level - nominal, ordinal, interval, ratio 00023 * </ul> 00024 * 00025 * @author Roger House 00026 * @version 0.9 00027 */ 00028 class Predictor 00029 { 00030 public: 00031 00032 /** 00033 * Provides a logical delete facility. The default value is 00034 * <code>ACTIVE</code>. 00035 */ 00036 enum Status 00037 { 00038 /** 00039 * the predictor is active, i.e., it should be considered when 00040 * constructing the model. 00041 */ 00042 ACTIVE, 00043 /** 00044 * the predictor is inactive, i.e., it should not be considered when 00045 * constructing the model. 00046 */ 00047 INACTIVE 00048 }; 00049 00050 00051 /** 00052 * Describes the quality of the predictor and determines the statistical 00053 * operations that can be performed on the feature. The default value 00054 * is <code>CONTINUOUS</code>. 00055 */ 00056 enum Type 00057 { 00058 /** 00059 * the feature takes on discrete values. 00060 */ 00061 CATEGORICAL, 00062 /** 00063 * the feature may take any real value. 00064 */ 00065 CONTINUOUS 00066 }; 00067 00068 /** 00069 * Indicates the level of measurement for the feature. The default value 00070 * is <code>RATIO</code>. 00071 */ 00072 enum Level 00073 { 00074 /** 00075 * the values are names or labels for certain characteristics, 00076 * without any implied order among them. 00077 */ 00078 NOMINAL, 00079 /** 00080 * the feature takes values that represent the rank order of the 00081 * specimen, but the distance between the values is not meaningful. 00082 */ 00083 ORDINAL, 00084 /** 00085 * the predictor values can be ranked and have a standard unit of 00086 * measurement, but the zero value is arbitrary. 00087 */ 00088 INTERVAL, 00089 /** 00090 * The values taken by the predictor have a standard unit of 00091 * measurement, are rankable, and the zero value is non-arbitrary. 00092 */ 00093 RATIO 00094 }; 00095 00096 private: 00097 00098 int64_t name; 00099 Status status; 00100 Type type; 00101 Level level; 00102 00103 public: 00104 00105 // Constructors, destructor, operator== 00106 00107 /** 00108 * Default constructor - initializes a newly created <code>Predictor</code> 00109 * object with default attributes. 00110 * <ul> 00111 * <li>name 1 00112 * <li>status ACTIVE 00113 * <li>type CONTINUOUS 00114 * <li>level RATIO 00115 * </ul> 00116 */ 00117 Predictor(); 00118 00119 /** 00120 * Initializes a newly created <code>Predictor</code> object with default 00121 * attributes. 00122 * <ul> 00123 * <li>status ACTIVE 00124 * <li>type CONTINUOUS 00125 * <li>level RATIO 00126 * </ul> 00127 * 00128 * @param name the name of the predictor. 00129 */ 00130 Predictor(int64_t name); 00131 00132 /** 00133 * Initializes a newly created <code>Predictor</code> object with attributes 00134 * specified by the input parameters. 00135 * 00136 * @param name the name of the predictor. 00137 * @param status the status of the predictor. 00138 * @param type the type of the predictor. 00139 * @param level the level of the predictor. 00140 */ 00141 Predictor 00142 ( 00143 int64_t name, 00144 Status status, 00145 Type type, 00146 Level level 00147 ); 00148 00149 /** 00150 * Copy constructor - initializes a newly created <code>Predictor</code> 00151 * object with a copy of another <code>Predictor</code> object. 00152 * 00153 * @param rhs the <code>Predictor</code> to make a copy of. 00154 */ 00155 Predictor(const Predictor &rhs); 00156 00157 00158 /** 00159 * Destructor - destroy a <code>Predictor</code> object. 00160 */ 00161 virtual ~Predictor(); 00162 00163 /** 00164 * Assignment operator - assign one <code>Predictor</code> to another. 00165 * 00166 * @param rhs the righthand side of the assignment. 00167 * 00168 * @return a reference to <code>this</code> Predictor. 00169 */ 00170 Predictor& operator=(const Predictor& rhs); 00171 00172 private: 00173 00174 /** 00175 * Initializes a <code>Predictor</code> object with attributes 00176 * specified by the input parameters. 00177 * 00178 * @param name the name of the predictor. 00179 * @param status the status of the predictor. 00180 * @param type the type of the predictor. 00181 * @param level the level of the predictor. 00182 */ 00183 void initPredictor 00184 ( 00185 int64_t name, 00186 Status status, 00187 Type type, 00188 Level level 00189 ); 00190 00191 public: 00192 00193 // Equality operators 00194 00195 /** 00196 * Equality operator - compare two <code>Predictors</code> for equality. 00197 * 00198 * @param rhs the righthand side of the equality. 00199 * 00200 * @return <code>true</code> if and only if <code>this</code> 00201 * <code>Predictors</code> and the righthand side 00202 * <code>Predictors</code> are identically equal. 00203 */ 00204 bool operator==(const Predictor &rhs) const; 00205 00206 /** 00207 * Inequality operator - compare two <code>Predictors</code> for inequality. 00208 * 00209 * @param rhs the righthand side of the inequality. 00210 * 00211 * @return <code>true</code> if and only if <code>this</code> 00212 * <code>Predictors</code> and the righthand side 00213 * <code>Predictors</code> are not identically equal. 00214 */ 00215 bool operator!=(const Predictor &rhs) const; 00216 00217 // Setters and getters 00218 00219 /** 00220 * Set the predictor name. 00221 * 00222 * @param name the name to assign to this predictor. This is the 00223 * unique identification of the predictor. It must be positive. 00224 */ 00225 void setPredictorName(int64_t name); 00226 00227 /** 00228 * Return the predictor name. 00229 * 00230 * @return the name of this predictor, which is the unique 00231 * identification of the predictor. 00232 */ 00233 int64_t getPredictorName() const; 00234 00235 00236 /** 00237 * Set the predictor status. 00238 * 00239 * @param s the status to assign to this predictor. 00240 */ 00241 void setStatus(Status s); 00242 00243 /** 00244 * Return the predictor status. 00245 * 00246 * @return the status of this predictor. 00247 */ 00248 Status getStatus() const; 00249 00250 00251 /** 00252 * Set the predictor type. 00253 * 00254 * @param t the type to assign to this predictor. 00255 */ 00256 void setType(Type t); 00257 00258 /** 00259 * Return the predictor type. 00260 * 00261 * @return the type of this predictor. 00262 */ 00263 Type getType() const; 00264 00265 00266 /** 00267 * Set the predictor level. 00268 * 00269 * @param L the level to assign to this predictor. 00270 */ 00271 void setLevel(Level L); 00272 00273 /** 00274 * Return the predictor level. 00275 * 00276 * @return the level of this predictor. 00277 */ 00278 Level getLevel() const; 00279 00280 00281 // Utility 00282 00283 /** 00284 * Return a string representation of this <code>Predictor</code>. 00285 * 00286 * @return the string representation of this <code>Predictor</code>. 00287 */ 00288 std::string toString(); 00289 00290 00291 }; // end class Predictor 00292 00293 00294 /** Output stream insertion operator. 00295 * 00296 * @param os the output stream. 00297 * @param p the <code>Predictor</code> to insert in the stream. 00298 * 00299 * @return the output stream. 00300 */ 00301 std::ostream &operator<<(std::ostream &os, Predictor &p); 00302 00303 00304 /** String stream insertion operator. 00305 * 00306 * @param s the string stream. 00307 * @param p the <code>Predictor</code> to insert in the stream. 00308 * 00309 * @return the string stream. 00310 */ 00311 std::stringstream &operator<<(std::stringstream &s, Predictor &p); 00312 00313 } // end namespace Yosokumo 00314 00315 #endif // PREDICTOR_H 00316 00317 // end Predictor.h