28 using namespace KKMLL;
56 _log.Level (20) <<
"FeatureFileIOSparse::GetFileDesc FileName[" << _fileName <<
"]." << endl;
81 while ((!eol) && (!eof))
95 kkint32 featureNum = atoi (featureNumStr.Str ());
97 if (featureNum > featureNumMax)
98 featureNumMax = featureNum;
100 if (featureNum < featureNumMin)
101 featureNumMin = featureNum;
111 for (
kkint32 fieldNum = featureNumMin; fieldNum <= featureNumMax; fieldNum++)
113 bool alreadyExists =
false;
131 KKStr& _errorMessage,
135 _log.Level (20) <<
"FeatureFileIOSparse::LoadFile FileName[" << _fileName <<
"]" << endl;
147 kkint32 maxFeatureNum = minFeatureNum + numOfFeatures - 1;
154 while ((!eof) && (!_cancelFlag) && ((kkint32)examples->size () < _maxCount))
158 GetToken (_in,
" \t", className, eof, eol);
168 if (className.SubStrPart (0, 1) ==
"//")
171 while ((!eol) && (!eof))
172 GetToken (_in,
" \t", className, eof, eol);
176 MLClassPtr mlClass = _classes.GetMLClassPtr (className);
178 FeatureVectorPtr example =
new FeatureVector (numOfFeatures);
179 example->MLClass (mlClass);
181 KKStr exampleName = rootName +
"_" + StrFormatInt (lineCount,
"ZZZZZZ0");
182 example->ExampleFileName (exampleName);
185 GetToken (_in,
" \t", field, eof, eol);
186 while ((!eol) && (!eof))
188 KKStr featureNumStr = field.ExtractToken (
":");
189 kkint32 featureNum = atoi (featureNumStr.Str ());
191 if ((featureNum < minFeatureNum) || (featureNum > maxFeatureNum))
194 <<
"FeatureFileIOSparse::LoadFile FeatureNum[" << featureNumStr <<
"] out of range." << endl
195 <<
" FileName[" << _fileName <<
"] LineNum[" << lineCount <<
"]." << endl
197 _errorMessage <<
"FeatureNum[" << featureNumStr <<
"] is out of range.";
198 delete example; example = NULL;
199 delete examples; examples = NULL;
203 featureNum = featureNum - minFeatureNum;
205 float value = (
float)atof (field.Str ());
206 example->AddFeatureData (featureNum, value);
207 GetToken (_in,
" \t", field, eof, eol);
210 examples->PushOnBack (example);
222 const KKStr& _fileName,
228 KKStr& _errorMessage,
232 _log.Level (20) <<
"FeatureFileIOSparse::SaveFile FileName[" << _fileName <<
"]." << endl;
233 FeatureVectorPtr example = NULL;
236 _numExamplesWritten = 0;
243 for (idx = 0; (idx < _data.QueueSize ()) && (!_cancelFlag); idx++)
245 example = _data.IdxToPtr (idx);
253 if (value != (
float)0.0)
254 _out <<
" " << (featureNum + minFeatureNum) <<
":" << example->FeatureData (featureNum);
257 _numExamplesWritten++;
void GetToken(std::istream &_in, const char *_delimiters, KKStr &_token, bool &_eof, bool &_eol)
Will retrieve the next token from the input stream.
virtual void SaveFile(FeatureVectorList &_data, const KKStr &_fileName, FeatureNumListConst &_selFeatures, ostream &_out, kkuint32 &_numExamplesWritten, VolConstBool &_cancelFlag, bool &_successful, KKStr &_errorMessage, RunLog &_log)
Provides a detailed description of the attributes of a dataset.
virtual FileDescPtr GetFileDesc(const KKStr &_fileName, istream &_in, MLClassListPtr _classList, kkint32 &_estSize, KKStr &_errorMessage, RunLog &_log)
kkuint32 NumOfFields() const
void AddAAttribute(const KKB::KKStr &_name, KKMLL::AttributeType _type, bool &alreadyExists)
float FeatureData(kkint32 featureNum) const
KKStr ExtractToken(const char *delStr="\n\t\r ")
const FileDescPtr FileDesc() const
kkint32 SparseMinFeatureNum() const
FeatureNumList const FeatureNumListConst
bool operator==(const char *rtStr) const
void SparseMinFeatureNum(kkint32 _sparseMinFeatureNum)
unsigned __int32 kkuint32
FeatureVectorList(FileDescPtr _fileDesc, bool _owner)
Will create a new empty list of FeatureVector's.
Container class for FeatureVector derived objects.
virtual FeatureVectorListPtr LoadFile(const KKStr &_fileName, const FileDescPtr _fileDesc, MLClassList &_classes, istream &_in, kkint32 _maxCount, VolConstBool &_cancelFlag, bool &_changesMade, KKStr &_errorMessage, RunLog &_log)
kkuint16 operator[](kkint32 idx) const
Returns back the selected feature.
KKStr operator+(const char *left, const KKStr &right)
kkint32 NumOfFeatures() const
Base class for all FeatureFileIO classes.
KKStr SubStrPart(kkint32 firstChar, kkint32 lastChar) const
returns a SubString consisting of all characters starting at index 'firstChar' and ending at 'lastInd...
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of 'std::string' strings.
KKStr StrFormatInt(kkint32 val, const char *mask)
std::ostream &__cdecl operator<<(std::ostream &os, const KKStr &str)
Used for logging messages.
void EncodeProblem(const struct svm_paramater ¶m, struct svm_problem &prob_in, struct svm_problem &prob_out)
MLClassList * MLClassListPtr
virtual MLClassPtr GetMLClassPtr(const KKStr &_name)
return pointer to instance with '_name'; if none exists, create one and add to list.
const KKStr & ClassName() const
Name of class that this example is assigned to.
Supports the reading and writing of Sparse feature files similar to the ones libSVM use...
Maintains a list of MLClass instances.
FeatureFileIO(const KKStr &_driverName, bool _canRead, bool _canWrite)
KKStr osGetRootName(const KKStr &fullFileName)
volatile const bool VolConstBool