/** *@details A static method that will return a instance of 'FeatureNumList' that will have all non 'Ignore' features * in '_fileDesc' selected. */ FeatureNumList FeatureNumList::AllFeatures (FileDescConstPtr _fileDesc) { IntType maxFeatureNum = (IntType)(_fileDesc->NumOfFields () - 1); FeatureNumList features (maxFeatureNum); const AttributeTypeVector& attributeTypes = _fileDesc->AttributeVector (); for (IntType fn = 0; fn <= maxFeatureNum; ++fn) { if (attributeTypes[fn] != AttributeType::Ignore) features.AddFeature (fn); } return features; } /* AllFeatures */
FeatureVectorListPtr FeatureFileIO::LoadFile (const KKStr& _fileName, FileDescConstPtr _fileDesc, MLClassList& _classes, istream& _in, OptionUInt32 _maxCount, // Maximum # images to load. VolConstBool& _cancelFlag, bool& _changesMade, KKStr& _errorMessage, RunLog& _log ) { _errorMessage = "Driver '" + DriverName () + "' does not implemenet 'LoadFile' method."; _log.Level (10) << endl << "FeatureFileIO::LoadFile ***ERROR*** " << _errorMessage << endl << " _fileName : " << _fileName << endl << " _fileDesc : " << _fileDesc->NumOfFields () << endl << " _classes : " << _classes.ToCommaDelimitedStr () << endl << " _in.flags : " << _in.flags () << endl << " _maxCount : " << _maxCount << endl << " _cancelFlag : " << _cancelFlag << endl << " _changesMade: " << _changesMade << endl << endl; _errorMessage = "ROBERTS read functionality not implemented."; return NULL; }
/** *@details Using 'fileDesc' as the guide as to how many features there are and which ones are to * be ignored will set all features that are not 'Ignore' to on. */ void FeatureNumList::SetAllFeatures (FileDescConstPtr fileDesc) { for (IntType x = 0; x <= maxFeatureNum; ++x) { if (fileDesc->Type (x) != AttributeType::Ignore) AddFeature (IntType (x)); } return; } /* SetAllFeatures */
FeatureNumList::FeatureNumList (FileDescConstPtr _fileDesc): featureNums (NULL), featureNumsAllocatedSize (0), maxFeatureNum (0), numOfFeatures (0) { if (_fileDesc) maxFeatureNum = (IntType)(_fileDesc->NumOfFields () - 1); AllocateArraySize ((IntType)10); }
KKStr FeatureNumList::ToHexString (FileDescConstPtr fileDesc) const { BitString bs (fileDesc->NumOfFields ()); ToBitString (bs); return bs.HexStr (); } /* ToHexString */
bool FeatureNumList::AllFeaturesSelected (FileDescConstPtr fileDesc) const { if (numOfFeatures >= (kkint32)fileDesc->NumOfFields ()) return true; return false; } /* AllFeaturesSelected */
/** *@brief Constructs a Feature Encoder object. *@param[in] _param *@param[in] _fileDesc *@param[in] _log A log file stream. All important events will be output to this stream */ FeatureEncoder2::FeatureEncoder2 (const ModelParam& _param, FileDescConstPtr _fileDesc ): attributeVector (_fileDesc->AttributeVector ()), cardinalityDest (NULL), cardinalityVector (_fileDesc->CardinalityVector ()), codedNumOfFeatures (0), destFeatureNums (NULL), destWhatToDo (NULL), encodedFileDesc (NULL), encodingMethod (ModelParam::EncodingMethodType::NoEncoding), fileDesc (_fileDesc), numOfFeatures (0), srcFeatureNums (NULL), param (_param) { FeatureNumListConstPtr selectedFeatures = param.SelectedFeatures (); numOfFeatures = param.SelectedFeatures ()->NumOfFeatures (); encodingMethod = param.EncodingMethod (); srcFeatureNums = new kkuint16 [numOfFeatures]; cardinalityDest = new kkint32 [numOfFeatures]; destFeatureNums = new kkint32 [numOfFeatures]; destWhatToDo = new FeWhatToDo[numOfFeatures]; VectorKKStr destFieldNames; kkint32 x; for (x = 0; x < numOfFeatures; x++) { kkuint16 srcFeatureNum = (*selectedFeatures)[x]; srcFeatureNums [x] = srcFeatureNum; destFeatureNums [x] = codedNumOfFeatures; cardinalityDest [x] = 1; destWhatToDo [x] = FeWhatToDo::FeAsIs; Attribute srcAttribute = (fileDesc->Attributes ())[srcFeatureNum]; switch (encodingMethod) { case ModelParam::EncodingMethodType::Binary: if ((attributeVector[srcFeatureNum] == AttributeType::Nominal) || (attributeVector[srcFeatureNum] == AttributeType::Symbolic) ) { destWhatToDo [x] = FeWhatToDo::FeBinary; cardinalityDest [x] = cardinalityVector[srcFeatureNums [x]]; codedNumOfFeatures += cardinalityDest[x]; for (kkint32 zed = 0; zed < cardinalityDest[x]; zed++) { KKStr fieldName = srcAttribute.Name () + "_" + srcAttribute.GetNominalValue (zed); destFieldNames.push_back (fieldName); } } else { codedNumOfFeatures++; destWhatToDo [x] = FeWhatToDo::FeAsIs; destFieldNames.push_back (srcAttribute.Name ()); } break; case ModelParam::EncodingMethodType::Scaled: codedNumOfFeatures++; if ((attributeVector[srcFeatureNums[x]] == AttributeType::Nominal) || (attributeVector[srcFeatureNums[x]] == AttributeType::Symbolic) ) destWhatToDo [x] = FeWhatToDo::FeScale; else destWhatToDo [x] = FeWhatToDo::FeAsIs; destFieldNames.push_back (srcAttribute.Name ()); break; case ModelParam::EncodingMethodType::NoEncoding: default: codedNumOfFeatures++; destWhatToDo [x] = FeWhatToDo::FeAsIs; destFieldNames.push_back (srcAttribute.Name ()); break; } } encodedFileDesc = FileDesc::NewContinuousDataOnly (destFieldNames); }