/**
 *@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 */
Пример #2
0
/**
  *@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);
}