Невозможно преобразовать аргумент 1 из cli :: interior_ptr 'в' svm_model ** ' - PullRequest
0 голосов
/ 11 июля 2020

Я пытаюсь написать классификацию программ с помощью svm в windows форме gui c ++. Но это превратилось в ошибку, и я не знаю, как ее решить. Вот программа, вызывающая ошибку:

         predict(input, output);
         svm_free_and_destroy_model(&model);
         free(x);
         free(row);
         fclose(input);
         fclose(output);

Ошибка говорит:

Ошибка 25, ошибка C2664: 'void svm_free_and_destroy_model (svm_model **)': невозможно преобразовать аргумент 1 из 'cli :: interior_ptr 'to' svm_model ** '

Вот полная программа:

 static int(*info)(const char *fmt, ...) = &printf;

     struct svm_node *x;
     int max_nr_attr = 64;

     struct svm_model* model;
     int predict_probability = 0;

     static char *row;
     static int max_line_len;

     static char* readline(FILE *input)
     {
         int len;

         if (fgets(row, max_line_len, input) == NULL)
             return NULL;

         while (strrchr(row, '\n') == NULL)
         {
             max_line_len *= 2;
             row = (char *)realloc(row, max_line_len);
             len = (int)strlen(row);
             if (fgets(row + len, max_line_len - len, input) == NULL)
                 break;
         }
         return row;
     }

     void exit_input_error(int line_num)
     {
         fprintf(stderr, "Wrong input format at line %d\n", line_num);
         exit(1);
     }

     void predict(FILE *input, FILE *output) //svm predict
     {

         int correct = 0;
         int total = 0;
         double error = 0;
         double sump = 0, sumt = 0, sumpp = 0, sumtt = 0, sumpt = 0;

         int svm_type = svm_get_svm_type(model);
         int nr_class = svm_get_nr_class(model);
         double *prob_estimates = NULL;
         int j;

         if (predict_probability)
         {
             if (svm_type == NU_SVR || svm_type == EPSILON_SVR)
                 info("Prob. model for test data: target value = predicted value + z,\nz: Laplace distribution e^(-|z|/sigma)/(2sigma),sigma=%g\n", svm_get_svr_probability(model));
             else
             {
                 int *labels = (int *)malloc(nr_class*sizeof(int));
                 svm_get_labels(model, labels);
                 prob_estimates = (double *)malloc(nr_class*sizeof(double));
                 fprintf(output, "labels");
                 for (j = 0; j < nr_class; j++) {
                     fprintf(output, " %d", labels[j]);
                 }
                 fprintf(output, "\n");
                 free(labels);
             }
         }

         max_line_len = 1024;
         row = (char *)malloc(max_line_len*sizeof(char));
         while (readline(input) != NULL)
         {
             int i = 0;
             double target_label, predict_label;
             char *idx, *val, *label, *endptr;
             int inst_max_index = -1; // strtol gives 0 if wrong format, and precomputed kernel has <index> start from 0

             label = strtok(baris, " \t\n");
             //if (label == NULL) // empty line
             //exit_input_error(total + 1);

             target_label = strtod(label, &endptr);
             //if (endptr == label || *endptr != '\0')
             //exit_input_error(total + 1);

             while (1)
             {
                 if (i >= max_nr_attr - 1)  // need one more for index = -1
                 {
                     max_nr_attr *= 2;
                     x = (struct svm_node *) realloc(x, max_nr_attr*sizeof(struct svm_node));
                 }

                 idx = strtok(NULL, ":");
                 val = strtok(NULL, " \t");

                 if (val == NULL)
                     break;
                 errno = 0;
                 x[i].index = (int)strtol(idx, &endptr, 10);
                 //if (endptr == idx || errno != 0 || *endptr != '\0' || x[i].index <= inst_max_index)
                 //exit_input_error(total + 1);
                 //else
                 inst_max_index = x[i].index;

                 errno = 0;
                 x[i].value = strtod(val, &endptr);
                 //if (endptr == val || errno != 0 || (*endptr != '\0' && !isspace(*endptr)))
                 //exit_input_error(total + 1);

                 ++i;
             }
             x[i].index = -1;

             if (predict_probability && (svm_type == C_SVC || svm_type == NU_SVC))
             {
                 predict_label = svm_predict_probability(model, x, prob_estimates);
                 fprintf(output, "%g", predict_label);
                 for (j = 0; j < nr_class; j++)
                     fprintf(output, " %g", prob_estimates[j]);
                 fprintf(output, "\n");
             }
             else
             {
                 predict_label = svm_predict(model, x);
                 classification_s = predict_label;
                 fprintf(output, "%.17g\n", predict_label);
             }

             if (predict_label == target_label)
                 ++correct;
             error += (predict_label - target_label)*(predict_label - target_label);
             sump += predict_label;
             sumt += target_label;
             sumpp += predict_label*predict_label;
             sumtt += target_label*target_label;
             sumpt += predict_label*target_label;
             ++total;
         }
         if (svm_type == NU_SVR || svm_type == EPSILON_SVR)
         {
             info("Mean squared error = %g (regression)\n", error / total);
             info("Squared correlation coefficient = %g (regression)\n",
                 ((total*sumpt - sump*sumt)*(total*sumpt - sump*sumt)) /
                 ((total*sumpp - sump*sump)*(total*sumtt - sumt*sumt))
                 );
         }
         else
             info("Accuracy = %g%% (%d/%d) (classification)\n",
             (double)correct / total * 100, correct, total);
         if (predict_probability)
             free(prob_estimates);
     }

     private: System::Void button10_Click(System::Object^  sender, System::EventArgs^  e) {

         FILE *input, *output;
         int i;

         input = fopen("data-testing.txt", "r");
         if (input == NULL)
         {
             //fprintf(stderr, "can't open input file %s\n", argv[i]);
             exit(1);
         }

         output = fopen("output.txt", "w");
         if (output == NULL)
         {
             //fprintf(stderr, "can't open output file %s\n", argv[i + 2]);
             exit(1);
         }

         if ((model = svm_load_model("datatraining.model")) == 0)
         {
             //fprintf(stderr, "can't open model file %s\n", argv[i + 1]);
             exit(1);
         }

         x = (struct svm_node *) malloc(max_nr_attr*sizeof(struct svm_node));
         if (predict_probability)
         {
             if (svm_check_probability_model(model) == 0)
             {
                 fprintf(stderr, "Model does not support probabiliy estimates\n");
                 exit(1);
             }
         }
         else
         {
             if (svm_check_probability_model(model) != 0)
                 info("Model supports probability estimates, but disabled in prediction.\n");
         }

         predict(input, output);
         svm_free_and_destroy_model(&model);
         free(x);
         free(baris);
         fclose(input);
         fclose(output);

         if (classification_s == 1)
             textBox3->Text += "Middle " +  Environment::NewLine;
         else if (classification_s == 2)
             textBox3->Text += "Big " + Environment::NewLine;
         else
             textBox3->Text += "Small " + Environment::NewLine;

А вот svm_free_and_destroy_model в svm.h:

   void svm_free_and_destroy_model(svm_model** model_ptr_ptr)
{
     if(model_ptr_ptr != NULL && *model_ptr_ptr != NULL)
    {
            svm_free_model_content(*model_ptr_ptr);
            free(*model_ptr_ptr);
             *model_ptr_ptr = NULL;
     }
 }

И я не разобрался с указателем в этом случае и не знаю, как получить к нему доступ. Пожалуйста, помогите мне решить эту проблему. Мне это действительно нужно для моего последнего экзамена. Большое спасибо

...