Пример #1
0
 /// <summary>
 /// Handle a model.
 /// </summary>
 /// <param name="xmlin">Where to read the model from.</param>
 /// <param name="model">Where to load the model into.</param>
 private void HandleModel(ReadXML xmlin, svm_model model)
 {
     while (xmlin.ReadToTag())
     {
         if (xmlin.IsIt(SVMNetworkPersistor.TAG_TYPE_SVM, true))
         {
             int i = EngineArray.FindStringInArray(
                 SVMNetworkPersistor.svm_type_table, xmlin.ReadTextToTag());
             model.param.svm_type = i;
         }
         else if (xmlin.IsIt(SVMNetworkPersistor.TAG_DEGREE, true))
         {
             model.param.degree = int.Parse(xmlin.ReadTextToTag());
         }
         else if (xmlin.IsIt(SVMNetworkPersistor.TAG_GAMMA, true))
         {
             model.param.gamma = double.Parse(xmlin.ReadTextToTag());
         }
         else if (xmlin.IsIt(SVMNetworkPersistor.TAG_COEF0, true))
         {
             model.param.coef0 = double.Parse(xmlin.ReadTextToTag());
         }
         else if (xmlin.IsIt(SVMNetworkPersistor.TAG_NUMCLASS, true))
         {
             model.nr_class = int.Parse(xmlin.ReadTextToTag());
         }
         else if (xmlin.IsIt(SVMNetworkPersistor.TAG_TOTALSV, true))
         {
             model.l = int.Parse(xmlin.ReadTextToTag());
         }
         else if (xmlin.IsIt(SVMNetworkPersistor.TAG_RHO, true))
         {
             int n = model.nr_class * (model.nr_class - 1) / 2;
             model.rho = new double[n];
             String[] st = xmlin.ReadTextToTag().Split(',');
             for (int i = 0; i < n; i++)
             {
                 model.rho[i] = double.Parse(st[i]);
             }
         }
         else if (xmlin.IsIt(SVMNetworkPersistor.TAG_LABEL, true))
         {
             int n = model.nr_class;
             model.label = new int[n];
             String[] st = xmlin.ReadTextToTag().Split(',');
             for (int i = 0; i < n; i++)
             {
                 model.label[i] = int.Parse(st[i]);
             }
         }
         else if (xmlin.IsIt(SVMNetworkPersistor.TAG_PROB_A, true))
         {
             int n = model.nr_class * (model.nr_class - 1) / 2;
             model.probA = new double[n];
             String[] st = xmlin.ReadTextToTag().Split(',');
             for (int i = 0; i < n; i++)
             {
                 model.probA[i] = Double.Parse(st[i]);
             }
         }
         else if (xmlin.IsIt(SVMNetworkPersistor.TAG_PROB_B, true))
         {
             int n = model.nr_class * (model.nr_class - 1) / 2;
             model.probB = new double[n];
             String[] st = xmlin.ReadTextToTag().Split(',');
             for (int i = 0; i < n; i++)
             {
                 model.probB[i] = Double.Parse(st[i]);
             }
         }
         else if (xmlin.IsIt(SVMNetworkPersistor.TAG_NSV, true))
         {
             int n = model.nr_class;
             model.nSV = new int[n];
             String[] st = xmlin.ReadTextToTag().Split(',');
             for (int i = 0; i < n; i++)
             {
                 model.nSV[i] = int.Parse(st[i]);
             }
         }
         else if (xmlin.IsIt(SVMNetworkPersistor.TAG_TYPE_KERNEL, true))
         {
             int i = EngineArray.FindStringInArray(
                 SVMNetworkPersistor.kernel_type_table, xmlin
                 .ReadTextToTag());
             model.param.kernel_type = i;
         }
         else if (xmlin.IsIt(SVMNetworkPersistor.TAG_DATA, true))
         {
             HandleData(xmlin, model);
         }
         else if (xmlin.IsIt(SVMNetworkPersistor.TAG_MODEL, false))
         {
             break;
         }
     }
 }