Simple training and testing issue using libsvm C++ in Eclipse -
i trying execute simple xor output prediction using libsvm c++ in eclipse. code have written. output value should predicting a+1
have error cannot solve:
expected expression before ')' token.
this line error:
#define malloc(type,n) (type *)malloc((n)*sizeof(type))"
what doing wrong?
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <errno.h> #include "libsvm.h" #include "main.h" #define malloc(type,n) (type *)malloc((n)*sizeof(type)) // struct svm_node *x = (struct svm_node *) malloc((n+1)*sizeof(struct svm_node)); struct svm_parameter param; // set parse_command_line struct svm_problem prob; // set read_problem struct svm_model *model; struct svm_node *x_space; struct svm_node ** x; struct svm_node *testnode; void makemodel2(void) // int main(int argc, char **argv) { //char input_file_name[1024]; //char model_file_name[1024]; //const char *error_msg; param.svm_type = c_svc; param.kernel_type = rbf; param.degree = 3; param.gamma = 0.5; param.coef0 = 0; param.nu = 0.5; param.cache_size = 100; param.c = 1; param.eps = 1e-3; param.p = 0.1; param.shrinking = 1; param.probability = 0; param.nr_weight = 0; param.weight_label = null; param.weight = null; // --- problem definition --- prob.l = 4; //x values matrix of xor values double matrix[prob.l][2]; matrix[0][0] = 1; matrix[0][1] = 1; matrix[1][0] = 1; matrix[1][1] = 0; matrix[2][0] = 0; matrix[2][1] = 1; matrix[3][0] = 0; matrix[3][1] = 0; //this part have trouble understanding struct svm_node** x = (struct svm_node * *)malloc((prob.l)*sizeof(struct svm_node *)); // svm_node** x = malloc(svm_node*,prob.l); // (x *)malloc((prob.l)*sizeof(prob.l)) // x = malloc(x,prob.l); //trying assign matrix svm_node training examples (int row = 0;row <prob.l; row++){ x_space = malloc(x_space,3); // svm_node* x_space = malloc(svm_node,3); // x_space = malloc(x_space,3); // struct svm_node *x_space = (struct svm_node *) malloc((3)*sizeof(struct svm_node)); (int col = 0;col < 2;col++){ x_space[col].index = col; x_space[col].value = matrix[row][col]; } //each row of properties should terminated -1 according readme x_space[2].index = -1; x[row] = x_space; } prob.x = x; //yvalues prob.y = (double *)malloc((prob.l)*sizeof(double)); // prob.y = malloc(double,prob.l); // prob.y = malloc(prob.y,prob.l); prob.y[0] = -1; prob.y[1] = 1; prob.y[2] = 1; prob.y[3] = -1; // --- train model--- model = svm_train(&prob,¶m); // svm_model *model = svm_train(&prob,¶m); // --- test model --- struct svm_node *testnode = (struct svm_node *) malloc((3)*sizeof(struct svm_node)); // svm_node* testnode = malloc(svm_node,3); // testnode = malloc(testnode,3); // testnode = malloc(testnode,3); testnode[0].index = 0; testnode[0].value = 1; testnode[1].index = 1; testnode[1].value = 0; testnode[2].index = -1; //this works correctly: retval[0] = svm_predict(model,testnode); // double retval = svm_predict(model,testnode); //printf("retval: %f\n",retval); svm_destroy_param(¶m); free(prob.y); free(prob.x); free(x_space); //return 0; }
Comments
Post a Comment