示例#1
0
void  ModelParamUsfCasCor::ReadXML (XmlStream&      s,
                                    XmlTagConstPtr  tag,
                                    VolConstBool&   cancelFlag,
                                    RunLog&         log
                                   )
{
  XmlTokenPtr  t = s.GetNextToken (cancelFlag, log);
  while  (t  &&  (!cancelFlag))
  {
    t = ReadXMLModelParamToken (t);
    if  ((t != NULL)  &&  (t->TokenType () == XmlToken::TokenTypes::tokElement))
    {
      XmlElementPtr e = dynamic_cast<XmlElementPtr> (t);
      const KKStr&  varName = e->VarName ();

      if  (varName.EqualIgnoreCase ("in_limit"))
        in_limit =  dynamic_cast<XmlElementInt32Ptr> (e)->Value ();

      else if  (varName.EqualIgnoreCase ("number_of_rounds"))
        number_of_rounds =  dynamic_cast<XmlElementInt32Ptr> (e)->Value ();

      else if  (varName.EqualIgnoreCase ("number_of_trials"))
        number_of_trials =  dynamic_cast<XmlElementInt32Ptr> (e)->Value ();

      else if  (varName.EqualIgnoreCase ("random_seed"))
        random_seed =  dynamic_cast<XmlElementInt64Ptr> (e)->Value ();

      else if  (varName.EqualIgnoreCase ("useCache"))
        useCache =  dynamic_cast<XmlElementBoolPtr> (e)->Value ();

      else
      {
        log.Level (-1) << endl
          << "ModelParamUsfCasCor::ReadXM   ***ERROR***   Unexpected Element: " << e->NameTag ()->ToString () << endl
          << endl;
      }
    }
    delete  t;
    t = s.GetNextToken (cancelFlag, log);
  }
  delete  t;
  t = NULL;

  bool  validFormat = false;
}  /* ReadXML */
示例#2
0
void  FeatureEncoder::ReadXML (XmlStream&      s,
                               XmlTagConstPtr  tag,
                               VolConstBool&   cancelFlag,
                               RunLog&         log
                              )
{
  XmlTokenPtr t = s.GetNextToken (cancelFlag,  log);
  while  (t  &&  (!cancelFlag))
  {
    if  (t->TokenType () == XmlToken::TokenTypes::tokElement)
    {
      XmlElementPtr e = dynamic_cast<XmlElementPtr> (t);
      if  (e)
      {
        KKStr varName = e->VarName ();

        if  (varName.EqualIgnoreCase ("CodedNumOfFeatures"))
          codedNumOfFeatures= e->ToInt32 ();

        else if  (varName.EqualIgnoreCase ("C_Param"))
          c_Param = e->ToDouble ();

        else if  (varName.EqualIgnoreCase ("NumEncodedFeatures"))
          numEncodedFeatures = e->ToInt32 ();

        else if  (varName.EqualIgnoreCase ("NumOfFeatures"))
          numOfFeatures = e->ToInt32 ();

        else if  (varName.EqualIgnoreCase ("xSpaceNeededPerExample"))
          xSpaceNeededPerExample = e->ToInt32 ();

        else if  (typeid (*e) == typeid (XmlElementArrayInt32))
        {
          XmlElementArrayInt32Ptr xmlArray = dynamic_cast<XmlElementArrayInt32Ptr> (e);
          kkuint32 count = xmlArray->Count ();
          if  (count != numOfFeatures)
          {
            log.Level (-1) << endl
              << "FeatureEncoder::ReadXML   ***ERROR***  Variable[" << varName << "]  Invalid Length[" << count << "]  Expected[" << numOfFeatures << "]" << endl
              << endl;
          }
          else
          {
            if  (varName.EqualIgnoreCase ("CardinalityDest"))
            {
              delete  cardinalityDest;
              cardinalityDest = xmlArray->TakeOwnership ();
            }

            else if  (varName.EqualIgnoreCase ("DestFeatureNums"))
            {
              delete  destFeatureNums;
              destFeatureNums = xmlArray->TakeOwnership ();
            }

            else if  (varName.EqualIgnoreCase ("SrcFeatureNums"))
            {
              delete  srcFeatureNums;
              srcFeatureNums = xmlArray->TakeOwnership ();
            }
          }
        }

        else if  (varName.EqualIgnoreCase ("Class1"))
          class1 = MLClass::CreateNewMLClass (e->ToKKStr (), -1);

        else if  (varName.EqualIgnoreCase ("Class2"))
          class2 = MLClass::CreateNewMLClass (e->ToKKStr (), -1);

        else if  (varName.EqualIgnoreCase ("FileDesc")  &&  (typeid (*e) == typeid (XmlElementFileDesc)))
          fileDesc = dynamic_cast<XmlElementFileDescPtr> (e)->Value ();

        else if  (varName.EqualIgnoreCase ("DestFileDesc")  &&  (typeid (*e) == typeid (XmlElementFileDesc)))
          destFileDesc = dynamic_cast<XmlElementFileDescPtr> (e)->Value ();

        else if  (varName.EqualIgnoreCase ("DestWhatToDo")  &&  (typeid (*e) == typeid (XmlElementVectorInt32)))
        {
          XmlElementVectorInt32Ptr  xmlVect = dynamic_cast<XmlElementVectorInt32Ptr> (e);
          if  (xmlVect  &&  xmlVect->Value ())
          {
            const VectorInt32&  v = *(xmlVect->Value ());
            if  (v.size () != numOfFeatures)
            {
              log.Level (-1) << endl
                << "FeatureEncoder::ReadXML   ***ERROR***   Variable[" << varName << "]  Invalid Size[" << v.size () << "]  Expected[" << numOfFeatures << "]." << endl
                << endl;
            }
            else
            {
              delete  destWhatToDo;
              destWhatToDo = new FeWhatToDo[v.size ()];
              for  (kkuint32 x = 0;  x < v.size ();  ++x)
                destWhatToDo[x] = (FeWhatToDo)v[x];
            }
          }
        }

        else if  (varName.EqualIgnoreCase ("EncodingMethod"))
          encodingMethod = EncodingMethodFromStr (e->ToKKStr ());

        else
        {
          log.Level (-1) << "XmlElementTrainingClassList   ***ERROR***   Un-expected Section Element[" << e->SectionName () << "]" << endl;
        }
      }
    }

    delete  t;
    t = s.GetNextToken (cancelFlag, log);
  }
  delete  t;
  t = NULL;
}  /* ReadXML */
示例#3
0
void  ModelUsfCasCor::ReadXML (XmlStream&      s,
                               XmlTagConstPtr  tag,
                               VolConstBool&   cancelFlag,
                               RunLog&         log
                              )
{
  delete  usfCasCorClassifier;
  usfCasCorClassifier = NULL;

  XmlTokenPtr  t = s.GetNextToken (cancelFlag, log);
  while  (t  &&  (!cancelFlag))
  {
    t = ReadXMLModelToken (t, log);
    if  (t)
    {
      if  (t->VarName ().EqualIgnoreCase ("UsfCasCorClassifier")  &&  (typeid (*t) == typeid(XmlElementUsfCasCor)))
      {
        delete usfCasCorClassifier;
        usfCasCorClassifier = dynamic_cast<XmlElementUsfCasCorPtr>(t)->TakeOwnership ();
      }
      else
      {
        KKStr  errMsg (128);
        errMsg << "ModelUsfCasCor::ReadXML   ***ERROR***   Unexpected Element: Section: " << t->SectionName () << " VarName:" << t->VarName ();
        log.Level (-1) << endl << errMsg << endl << endl;
        AddErrorMsg (errMsg, 0);
      }
    }
    delete  t;
    t = s.GetNextToken (cancelFlag, log);
  }

  delete  t;
  t = NULL;

  if  (!cancelFlag)
  {
    if  (!param)
      param = dynamic_cast<ModelParamUsfCasCorPtr> (Model::param);

    if  (Model::param == NULL)
    {
      KKStr errMsg (128);
      errMsg << "ModelUsfCasCor::ReadXML  ***ERROR***  Base class 'Model' does not have 'param' defined.";
      AddErrorMsg (errMsg, 0);
      log.Level (-1) << endl << errMsg << endl << endl;
    }

    else if  (typeid (*Model::param) != typeid(ModelParamUsfCasCor))
    {
      KKStr errMsg (128);
      errMsg << "ModelUsfCasCor::ReadXML  ***ERROR***  Base class 'Model' param parameter is of the wrong type;  found: " << Model::param->ModelParamTypeStr ();
      AddErrorMsg (errMsg, 0);
      log.Level (-1) << endl << errMsg << endl << endl;
    }

    else
    {
      param = dynamic_cast<ModelParamUsfCasCorPtr> (Model::param);
    }

    ReadXMLModelPost (log);
  }
}  /* ReadXML */