21 using namespace KKMLL;
27 featureNumsAllocatedSize (0),
38 featureNumsAllocatedSize (0),
42 kkuint16* otherFeatureNums = _featureNumList.featureNums;
43 kkuint16 otherNumOfFeatures = _featureNumList.numOfFeatures;
44 AllocateArraySize (_featureNumList.numOfFeatures + 1);
45 for (
kkuint16 x = 0; x < otherNumOfFeatures; x++)
53 featureNums (featureNumList.featureNums),
54 featureNumsAllocatedSize (featureNumList.featureNumsAllocatedSize),
55 maxFeatureNum (featureNumList.maxFeatureNum),
56 numOfFeatures (featureNumList.numOfFeatures)
59 featureNumList.featureNums = NULL;
60 featureNumList.featureNumsAllocatedSize = 0;
61 featureNumList.maxFeatureNum = 0;
62 featureNumList.numOfFeatures = 0;
70 featureNumsAllocatedSize (0),
71 maxFeatureNum (_maxFeatureNum),
74 AllocateArraySize (_maxFeatureNum + 1);
81 featureNumsAllocatedSize (0),
87 AllocateArraySize (10);
94 featureNumsAllocatedSize (0),
103 AllocateArraySize ((kkuint16)listOfSelectedFeatures.size ());
104 for (kkuint32 x = 0; x < listOfSelectedFeatures.size (); x++)
105 AddFeature (listOfSelectedFeatures[x]);
116 featureNumsAllocatedSize (0),
130 delete [] featureNums;
139 memoryConsumedEstimated +=
sizeof (
kkuint16) * featureNumsAllocatedSize;
141 return memoryConsumedEstimated;
149 if (featureNumsAllocatedSize >= size)
158 featureNumsAllocatedSize = size;
169 for (x = 0; x < numOfFeatures; ++x)
170 newFeatureNums[x] = featureNums[x];
172 for (x = numOfFeatures; x < size; ++x)
173 newFeatureNums[x] = 0;
175 delete [] featureNums;
176 featureNums = newFeatureNums;
177 newFeatureNums = NULL;
178 featureNumsAllocatedSize = size;
191 bitStr
.Set (featureNums[x]
);
199 for (
kkint32 x = 0; x < numOfFeatures; x++)
200 newList[x] = featureNums[x];
220 for (x = 0; x < featureNumsAllocatedSize; x++)
234 kkint32 indexToDel = numOfFeatures - 1;
236 while ((indexToDel >= 0) && (featureNums[indexToDel] > featureNum))
241 if (featureNums[indexToDel] == featureNum)
245 for (x = indexToDel; x < (numOfFeatures - 1); x++)
246 featureNums[x] = featureNums[x + 1];
250 featureNums[numOfFeatures] = 0;
261 featureNumsAllocatedSize = 10;
264 if (numOfFeatures >= featureNumsAllocatedSize)
267 kkint32 newFeatureNumsAllocatedSize = numOfFeatures + 10;
271 for (x = 0; x < numOfFeatures; ++x)
272 newFeatureNums[x] = featureNums[x];
274 while (x < newFeatureNumsAllocatedSize)
276 newFeatureNums[x] = 0;
280 delete [] featureNums;
281 featureNums = newFeatureNums;
282 featureNumsAllocatedSize = newFeatureNumsAllocatedSize;
285 if (numOfFeatures == 0)
287 featureNums[0] = featureNum;
294 if (featureNums[x] < featureNum)
297 featureNums[numOfFeatures] = featureNum;
303 while ((x >= 0) && (featureNums[x] > featureNum))
305 featureNums[x + 1] = featureNums[x];
306 featureNums[x] = featureNum;
314 if (featureNum > maxFeatureNum)
315 maxFeatureNum = featureNum;
333 for (
kkuint16 fn = 0; fn <= maxFeatureNum; ++fn)
335 if (attributeTypes[fn] != AttributeType::Ignore)
336 features.AddFeature (fn);
351 for (
kkuint16 x = 0; x <= maxFeatureNum; ++x)
367 bool isSubSet =
true;
386 while ((x < numOfFeatures) && (!found))
388 found = (_featureNum == featureNums[x]);
407 if (_idx >= numOfFeatures)
410 errMsg <<
"FeatureNumList::operator[] ***ERROR*** Invalid Index[" << _idx <<
"] requested.";
411 cerr << endl << errMsg << endl << endl;
416 return featureNums[_idx];
424 KKStr featureNumStr
(numOfFeatures * 6
);
426 if (numOfFeatures <= 0)
427 return featureNumStr;
431 while (nextIdx < numOfFeatures)
433 kkint32 startOfGroup = nextIdx;
436 while ((endOfGroup < (numOfFeatures - 1)) &&
437 (featureNums[endOfGroup] == (featureNums[endOfGroup + 1] - 1))
443 if ((endOfGroup - startOfGroup) < 3)
446 for (x = startOfGroup; x <= endOfGroup; x++)
449 featureNumStr <<
",";
450 featureNumStr << featureNums[x];
456 featureNumStr <<
",";
457 featureNumStr << featureNums[startOfGroup] <<
"-" << featureNums[endOfGroup];
460 nextIdx = endOfGroup + 1;
463 return featureNumStr;
509 results->push_back (n);
517 if ((startNum > endNum) || (startNum < 0) || (endNum >
uint16_max))
523 for (kkuint16 z = startNum; z <= endNum; ++z)
524 results->push_back (z);
535 sort (results->begin (), results->end ());
553 featureNumsAllocatedSize = 0;
561 AllocateArraySize (maxFeatureNum + 1);
568 sort(list->begin (), list->end ());
569 maxFeatureNum = list->back ();
570 AllocateArraySize ((kkuint16)list->size ());
571 for (
auto idx: *list)
618 while (t && (!cancelFlag))
637 if (expectedNumOfFeatures != numOfFeatures)
639 log.Level (-1) << endl
640 <<
"FeatureNumList::ReadXML ***ERROR*** expectedNumOfFeatures[" << expectedNumOfFeatures <<
"] not equal numOfFeatures[" << numOfFeatures <<
"]" << endl
655 featureNums =
new kkuint16[numOfFeatures];
656 featureNumsAllocatedSize = numOfFeatures;
658 for (
kkint32 x = 0; x < numOfFeatures; ++x)
659 featureNums[x] = _features.featureNums[x];
671 featureNums = _features.featureNums;
672 numOfFeatures = _features.numOfFeatures;
673 maxFeatureNum = _features.maxFeatureNum;
674 featureNumsAllocatedSize = _features.featureNumsAllocatedSize;
676 _features.featureNums = NULL;
677 _features.numOfFeatures = 0;
678 _features.maxFeatureNum = 0;
679 _features.featureNumsAllocatedSize = 0;
702 if (featureNums[x] < _features.featureNums[x])
705 else if (featureNums[x] > _features.featureNums[x])
711 if (x < numOfFeatures)
714 else if (x < _features.numOfFeatures)
725 if (numOfFeatures != _features.numOfFeatures)
761 ostream& operator<< ( ostream& os,
770 ostream& operator<< ( ostream& os,
788 kkuint16 mfn = Max (maxFeatureNum, rightSide.MaxFeatureNum ());
789 kkuint16 bestCaseNof = Min (numOfFeatures, rightSide.NumOfFeatures ());
791 result.AllocateArraySize (bestCaseNof);
796 while ((l < numOfFeatures) && (r < rightSide.numOfFeatures))
798 if (featureNums[l] < rightSide.featureNums[r])
801 else if (featureNums[l] > rightSide.featureNums[r])
829 for (l = 0; l < numOfFeatures; l++)
846 for (
kkuint16 x = 0; x < rightNumOfFeatures; ++x)
900 while ((l < numOfFeatures) && (r < rightSide.numOfFeatures))
902 if (featureNums[l] < rightSide.featureNums[r])
908 else if (featureNums[l] > rightSide.featureNums[r])
935 if (numToKeep > numOfFeatures)
939 <<
"FeatureNumList::RandomlySelectFeatures *** ERROR ***" << endl
941 <<
"NumToKeep[" << numToKeep <<
"] Is greater than NumOfFeatures[" << numOfFeatures <<
"]" << endl
944 numToKeep = numOfFeatures;
953 for (x = 0; x < numOfFeatures; x++)
954 selectedFeatures[x] = featureNums[x];
958 for (x = 0; x < numToKeep; x++)
961 z = selectedFeatures[x];
962 selectedFeatures[x] = selectedFeatures[y];
963 selectedFeatures[y] = z;
967 for (x = 0; x < numToKeep; x++)
970 delete [] selectedFeatures;
972 return randomlySelectedFeatures;
983 while (fni < numOfFeatures)
985 while (x < featureNums[fni])
993 while (x < maxFeatureNum)
KKStr(kkint32 size)
Creates a KKStr object that pre-allocates space for 'size' characters.
XmlTag(const KKStr &_name, TagTypes _tagType)
bool EqualIgnoreCase(const char *s2) const
FeatureNumListPtr RandomlySelectFeatures(kkint32 numToKeep) const
Generates a new FeatureNumList object that will select at random 'numToKeep' features from this insta...
void TrimWhiteSpace(const char *_whiteSpace=" ")
After this call all leading and trailing whitespace will be trimmed from tokens.
FeatureNumList operator+(kkuint16 rightSide) const
Returns new FeatureNumList that is a union of this instance and 'rightSide'.
kkuint32 NumOfFields() const
FeatureNumList operator+(const FeatureNumList &rightSide) const
Returns new FeatureNumList that is a union of this instance and 'rightSide'.
kkint32 LRand48()
A implementations of the Unix version of rand48 returning a 32 bit integer.
bool Test(kkuint16 _featureNum) const
Indicates whether feature '_featureNum' is selected.
Keeps track of selected features.
FeatureNumList(FileDescPtr _fileDesc)
KKStr GetNextToken(const char *delStr="\n\t\r ")
Extract next Token from string, tokens will be separated by delimiter characters. ...
KKMLL::AttributeType Type(kkint32 fieldNum) const
KKStr HexStr() const
Returns a Hex-String representation.
void ReSet()
Set all bits to '0'.
unsigned __int16 kkuint16
16 bit unsigned integer.
FeatureNumList & operator=(const FeatureNumListPtr _features)
bool InList(kkuint16 featureNum) const
returns true if '_featureNum' is one of the selected features.
XmlContent * XmlContentPtr
KKStr ToHexString() const
const AttributeTypeVector & AttributeVector() const
void ParseToString(const KKStr &_str, bool &_valid)
Will select the features specified in "featureListStr".
FeatureNumList & operator+=(kkuint16 featureNum)
Returns this FeatureNumList that is a union of this instance and 'rightSide'.
FeatureNumList(const BitString &bitString)
Constructs a 'FeatureNumList' instance using the set bits in 'bitString' to indicate which features a...
unsigned __int32 kkuint32
FeatureNumList(const FeatureNumList &featureNumList)
Copy constructor.
kkuint16 * CreateFeatureNumArray() const
Allocates a array of kkint32's that is a copy of FeatureNums. The caller will own the array and is re...
FeatureNumList operator-(const FeatureNumList &rightSide) const
Allows you to manage very long bit strings.
FeatureNumList(FeatureNumList &&featureNumList)
Move constructor.
void AddAtribute(const KKStr &attributeName, kkint32 attributeValue)
FeatureNumList Complement() const
Perform a complement of selected features. That is if a feature is selected turn it off and if it is ...
kkuint16 operator[](kkint32 idx) const
Returns back the selected feature.
KKStrParser(const KKStr &_str)
kkint32 AttributeValueInt32(const KKStr &attributeName) const
bool IsSubSet(const FeatureNumList &z)
Returns true if 'z' is a subset of this instance.
FeatureNumList * FeatureNumListPtr
void UnSet()
Turns off all features so that no feature is selected.
void AddAtribute(const KKStr &attributeName, const KKStr &attributeValue)
kkint32 MaxFeatureNum() const
void ToBitString(BitString &bitStr) const
kkint32 NumOfFeatures() const
void AddFeature(kkuint16 featureNum)
Adds 'featureNum' to the list of selected features. If it is already selected nothing happens...
void UnSet(kkuint16 featureNum)
Turns off specified feature 'featureNum'; if 'featureNum' is not turned on then nothing happens; same...
kkuint32 BitLen() const
Returns the length of the bit-string.
XmlTag const * XmlTagConstPtr
Manages the reading and writing of objects in a simple XML format. For a class to be supported by Xml...
KKStr SubStrPart(kkint32 firstChar, kkint32 lastChar) const
returns a SubString consisting of all characters starting at index 'firstChar' and ending at 'lastInd...
void SetAllFeatures(FileDescPtr fileDesc)
Selects all features except those flagged as 'IgnoreAttribute' in the associated FileDesc.
KKStr ToHexString(FileDescPtr fileDesc) const
Uses 'fileDesc' to determine length of hex string.
bool operator>(const FeatureNumList &_features) const
Indicates if the Left FeatureNumList instances is greater than the right one.
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of 'std::string' strings.
void ListOfSetBits16(VectorUint16 &setBits) const
kkint32 LocateCharacter(char ch) const
Returns index of 1st occurrence of 'ch' otherwise -1.
kkint32 Compare(const FeatureNumList &_features) const
Compare with another featureNumList returning -1, 0, and 1 indicating less_than, equal, or greater_than.
FeatureNumList operator-(kkuint16 rightSide) const
void Set(kkuint32 bitNum)
Set the bit indicated by 'bitNum' to '1'.
FeatureNumList & operator=(const FeatureNumList &_features)
static FeatureNumList AllFeatures(FileDescPtr fileDesc)
Create a FeatureNumList object where all features are selected, except ones that are flagged as Ignor...
FeatureNumList(kkuint32 _maxFeatureNum)
std::ostream &__cdecl operator<<(std::ostream &os, const KKStr &str)
KKStr ToString() const
Returns comma delimited list of all features selected; will make use of range specification.
kkint32 NumSelFeatures() const
bool AllFeaturesSelected(FileDescPtr fileDesc) const
Returns true if all features are selected.
FeatureNumList(const KKStr &_featureListStr, bool &_valid)
Constructs a 'FeatureNumList' instance from a string that contains a list of selected features...
FeatureNumList * FeatureNumListPtr
void WriteXML(std::ostream &o)
FeatureNumList operator*(const FeatureNumList &rightSide) const
Returns new instance that is the intersection of features.
bool operator==(const FeatureNumList &_features) const
Indicates if the two FeatureNumLiost instances have the same features selected.
KKStrPtr const Content() const
Used for logging messages.
void EncodeProblem(const struct svm_paramater ¶m, struct svm_problem &prob_in, struct svm_problem &prob_out)
void ReadXML(XmlStream &s, XmlTagConstPtr tag, VolConstBool &cancelFlag, RunLog &log)
BitString(kkuint32 _bitLen)
Construct a bit string of length _binLen with all bits set to '0'.
Class that manages the extraction of tokens from a String without being destructive to the original s...
virtual XmlTokenPtr GetNextToken(VolConstBool &cancelFlag, RunLog &log)
KKException(const KKStr &_exceptionStr)
std::vector< kkuint16 > VectorUint16
Vector of unsigned 16 bit integers.
FeatureNumList & operator+=(const FeatureNumList &rightSide)
Returns this FeatureNumList that is a union of this instance and 'rightSide'.
KKStr SubStrPart(kkint32 firstChar) const
returns a SubString consisting of all characters starting at index 'firstChar' until the end of the s...
kkint32 MemoryConsumedEstimated() const
bool operator<(const FeatureNumList &_features) const
Indicates if the Left FeatureNumList instances is less than the right one.
#define XmlFactoryMacro(NameOfClass)
void WriteXML(const KKStr &varName, std::ostream &o) const
const kkuint16 * FeatureNums() const
FeatureNumList & operator=(FeatureNumList &&_features)
FeatureNumList & operator-=(kkuint16 rightSide)
volatile const bool VolConstBool