示例#1
0
int main(int argc, char*argv[]) {
    int i;
    srand( (unsigned)time( NULL ) );
    char *infilename=new char[50];
    char *outname=new char[50];
    for(i=1; i<argc; i++) {
        if(argv[i][0] != '-') break;
        if(++i>=argc)
            exit_with_help();
        switch(argv[i-1][1]) {
        case 'g':
            strcpy(infilename,argv[i]);
            break;
        case 'l':
            strcpy(outname,argv[i]);
            break;
        case 'f':
            type=atoi(argv[i]);
            break;
        case 'i':
            iterationnum=atoi(argv[i]);
            break;
        default:
            exit_with_help();
        }
    }
    Graph g(infilename);
    int *partid=new int[g.sizenode()];
    for(int i=0; i<g.sizenode(); i++)
        partid[i]=-1;
    autopart p(g,partid,type,iterationnum);
    ofstream outfile(".pid");
    for(int i=0; i<g.sizenode(); i++)
        outfile<<partid[i]<<endl;
}
示例#2
0
int main(int argc, char **argv)
{
	FILE *input, *output;
	int i;

	// parse options
	for(i=1;i<argc;i++)
	{
		if(argv[i][0] != '-') break;
		++i;
		switch(argv[i-1][1])
		{
//			case 'b':
//				flag_predict_probability = atoi(argv[i]);
//				break;
			case 'o':
				output_option = atoi(argv[i]);
				break;
			case 'q':
				info = &print_null;
				i--;
				break;
			default:
				fprintf(stderr,"unknown option: -%c\n", argv[i-1][1]);
				exit_with_help();
				break;
		}
	}
	if(i>=argc)
		exit_with_help();

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

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

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

	x = (struct feature_node *) malloc(max_nr_attr*sizeof(struct feature_node));
	do_predict(input, output);
	free_and_destroy_model(&model_);
	free(line);
	free(x);
	fclose(input);
	fclose(output);
	return 0;
}
int main (int argc, char *argv[]){
	std::string node_id="0", subscribe_topic_name="/camera/image", train_file="Samples";
	int debug_mode = 0 ;
	int time_functions=0;
	// parse options
	for(int i=1;i<argc;i++) {
		if(argv[i][0] != '-') {
			break;
		}
		
		if (++i>=argc) {
			exit_with_help();
		}
		switch(argv[i-1][1])
		{
			case 'd':
				debug_mode = atoi(argv[i]);
				break;
			case 'i':
				node_id = std::string(argv[i]);
				break;
			case 's':
				subscribe_topic_name = std::string(argv[i]);
				break;
			case 't':
				time_functions = atoi(argv[i]);
				break;
			case 'f':
				train_file= std::string(argv[i]);
				break;
            // case 'n':
            //     do_not_usek
			default:
				fprintf(stderr, "Unknown option: -%c\n", argv[i-1][1]);
				exit_with_help();
		}
	}
	std::string node_name, publisher_topic_name;
	node_name = std::string("interpreter_lane_detector_") + node_id;
	publisher_topic_name = std::string("/interpreter/lane_detector/") + node_id;
	
	ros::init(argc, argv, node_name.c_str());
	//ros::NodeHandle nh;

	LaneDetector lane_detector(publisher_topic_name, subscribe_topic_name, time_functions,debug_mode,train_file);
	
	ros::spin();
return 0;
}
int main(int argc, char **argv)
{
    FILE *input, *output;
    int i;
    
    // parse options
    for(i=1;i<argc;i++)
    {
        if(argv[i][0] != '-') break;
        ++i;
        switch(argv[i-1][1])
        {
            case 'q':
                info = &print_null;
                i--;
                break;
            default:
                fprintf(stderr,"Unknown option: -%c\n", argv[i-1][1]);
                exit_with_help();
        }
    }

    
    if(i>=argc-2)
        exit_with_help();

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

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

    
    printf("Predicting..\n");

    predictLLSVM(argv[i], argv[i+1]);

    fclose(input);
    fclose(output);
    return 0;
}
示例#5
0
void mexFunction( int nlhs, mxArray *plhs[],
		int nrhs, const mxArray *prhs[] )
{	
	/* Transform the input Matrix to libsvm format */
	if(nrhs == 3)
	{
		char filename[256];
		if(!mxIsDouble(prhs[1]) || !mxIsDouble(prhs[2]))
		{
			mexPrintf("Error: label vector and instance matrix must be double\n");			
			return;
		}
		
		mxGetString(prhs[0], filename, mxGetN(prhs[0])+1);		

		if(mxIsSparse(prhs[2]))
			libsvmwrite(filename, prhs[1], prhs[2]);
		else
		{
			mexPrintf("Instance_matrix must be sparse\n");			
			return;
		}
	}
	else
	{
		exit_with_help();		
		return;
	}
}
示例#6
0
int main(int argc, char* argv[])
{
  Exampler test;
  int i;
  
  // parse options -- no option so far
  for(i=1;i<argc;i++) 
    {
      if(argv[i][0] != '-') break;
      ++i;
      switch(argv[i-1][1])
	{
	default:
	  fprintf(stderr,"unknown option\n");
	}
    }
  
  // determine filenames
  if(i>=(argc - 2))
    exit_with_help();
  
  std::cout << "Loading Test Data" << std::endl;
  test.libsvm_load_data(argv[i], false);
  
  std::cout << "\nLoading Model" << std::endl;
  char* model_file = argv[i+1];
  Machine* svm_load = load_model(model_file);
  
  char* pred_file = argv[i+2];
  testing(svm_load, test, pred_file);
  
  delete svm_load;
  return 0;		
}
示例#7
0
int main(int argc, char* argv[])
{
  
  Exampler train;
  int i, mode = 0;
  double C = 1, verb = 10, tau = 0.0001;
  
  // parse options
  for(i=1;i<argc;i++) 
    {
      if(argv[i][0] != '-') break;
      ++i;
      switch(argv[i-1][1])
	{
	case 'c':
	  C = atof(argv[i]);
	  break;
	case 't':
	  tau = atof(argv[i]);
	  break;				
	case 'm':
	  mode = atoi(argv[i]);            
	  break;
	case 'v':
	  verb = atof(argv[i]);            
	  break;	
	default:
	  fprintf(stderr,"unknown option\n");
	}
    }
  
  // determine filenames
  if(i>=(argc - 1))
    exit_with_help();
  std::cout << "Loading Train Data " << std::endl;
  train.libsvm_load_data(argv[i], false);
  char* save_file = argv[i+1];
  
  // CREATE		
  int step = (int) ((double) train.nb_ex / (100 / verb));
  std::cout << "\n--> Building with C = "<< C << std::endl;
  if (mode)
    std::cout << "    BATCH Learning" << std::endl;
  else
    std::cout << "    ONLINE Learning" << std::endl;
  
  Machine* svm = create_larank();
  
  svm->C = C;
  svm->tau = tau;
  
  training(svm, train, step, mode);
  save_model(svm, save_file);
  
  delete svm;
  return 0;		
}
示例#8
0
// Input : parameters(input-mapping, motor-subsystem, and wheelbase), data_x, num_simulation_step
// Output : vs(linear velocity), omegas(angular velocity),
//          us_joystick(joystick command), qs(wheel speed left, right),
//          us_motor(motor input), fs(friction of each motor)
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ){

	if(nrhs != 3 || nlhs != 6)
	{
		exit_with_help();
		return;
	}

    mexPrintf("Using C code to make 5 seconds simulation\n");
	predict_phys(plhs, prhs);

	return;
}
示例#9
0
Datum pgm_svm_train(PG_FUNCTION_ARGS){

    PGM_Matriz_Double *matrix = (PGM_Matriz_Double*)PG_GETARG_POINTER(0);
    PGM_Vetor_Double *vector = (PGM_Vetor_Double*)PG_GETARG_POINTER(1);

    struct svm_parameter *param = (struct svm_parameter*) pgm_malloc (sizeof(struct svm_parameter));
    struct svm_problem* prob;
    //Cross Validation
    int cross_validation = 0,
        n_fold = PG_GETARG_INT32(14);

    if (n_fold < 2 && n_fold != 0) exit_with_help();
    else if( n_fold >= 2){
        cross_validation = 1;
        elog(ERROR,"CROSS VALIDATION NÃO IMPLEMENTADO");
    }

    //Mount Parameter Struct
    param->svm_type = PG_GETARG_INT32(2);
	param->kernel_type= PG_GETARG_INT32(3);
	param->degree= PG_GETARG_INT32(4);
	param->gamma= PG_GETARG_FLOAT8(5);
	param->coef0= PG_GETARG_FLOAT8(6);
	param->cache_size= PG_GETARG_FLOAT8(7);
	param->eps= PG_GETARG_FLOAT8(8);
	param->C= PG_GETARG_FLOAT8(9);
	param->nr_weight = 0;
	param->weight_label = NULL;
	param->weight = NULL;
	param->nu= PG_GETARG_FLOAT8(10);
	param->p= PG_GETARG_FLOAT8(11);
	param->shrinking= PG_GETARG_INT32(12);
	param->probability= PG_GETARG_INT32(13);

	prob = PGM_Matriz_Double2svm_problem(matrix,vector,param);

	if (cross_validation){
        do_cross_validation(prob,param,n_fold);
        elog(ERROR,"CROSS VALIDATION NÃO IMPLEMENTADO"); // Pergunta ao Filipe sobre isso!
        PG_RETURN_VOID();
	}else{

        MemoryContext contextoAnterior = MemoryContextSwitchTo( CurTransactionContext );
        struct svm_model *model = svm_train(prob,param);
        MemoryContextSwitchTo( contextoAnterior );
        PG_RETURN_POINTER(model);
	}
}
ObstacleDetector::ObstacleDetector(int argc, char *argv[], ros::NodeHandle &node_handle):nh(node_handle) {

	topic_name = std::string("interpreter/obstacleMap/0");
	sub_topic_name = std::string("/scan");
    min_dist = 0;
	max_dist = 400;
	debug = 0;
	for(int i=1;i<argc;i++)
	{
		if(argv[i][0] != '-') {
			break;
		}

		if (++i>=argc) {
		}
		switch(argv[i-1][1])
		{
			case 'd':
				debug = atoi(argv[i]);
				break;
			case 's':
				sub_topic_name = std::string(argv[i]);
				break;
            case 'p':
                topic_name = std::string(argv[i]);
                break;
            case 'l':
                max_dist = atoi(argv[i]);
                break;
            case 'm':
                min_dist = atoi(argv[i]);
                break;
			default:
				fprintf(stderr, "Unknown option: -%c\n", argv[i-1][1]);
				exit_with_help();
		}
	}

    it = new image_transport::ImageTransport(nh);
    sub = nh.subscribe(sub_topic_name.c_str(), 2, &ObstacleDetector::scanCallback,this);
    img = cv::Mat(MAP_MAX,MAP_MAX,CV_8UC1,cvScalarAll(0));
    pub = it->advertise(topic_name.c_str(), 10);

}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])  
{  
    if(nrhs == 2)  
    {  
        char filename[256];  
        int *result;  
          
        mxGetString(prhs[0], filename, mxGetN(prhs[0])+1);  
          
        plhs[0] = mxCreateNumericMatrix(1, 1, mxINT8_CLASS, 0);  
          
        result = mxGetPr(plhs[0]);  
        *result = savemodel(filename, prhs[1]);  
    }  
    else  
    {  
        exit_with_help();         
        return;  
    }  
} 
示例#12
0
void mexFunction( int nlhs, mxArray *plhs[],
		 int nrhs, const mxArray *prhs[] )
{
	struct svm_model *model;
	info = &mexPrintf;

	if(nlhs > 2 || nrhs != 2)
	{
		exit_with_help();
		fake_answer(nlhs, plhs);
		return;
	}

	if(!mxIsDouble(prhs[0])) {
		mexPrintf("Error: label vector and instance matrix must be double\n");
		fake_answer(nlhs, plhs);
		return;
	}

    uint64_t *address = (uint64_t *)mxGetPr(prhs[1]);
    model = (struct svm_model *)(*address);
        
//     struct timeval start,stop;
//     gettimeofday(&start,NULL);

    predict(nlhs, plhs, prhs, model);

//     gettimeofday(&stop,NULL);
//     mexPrintf("%lu\n",stop.tv_usec - start.tv_usec);
    
    plhs[1] = mxCreateDoubleMatrix(1, model->nr_class, mxREAL);
    double *ptr = mxGetPr(plhs[1]);
    for(int i = 0; i < model->nr_class; i++)
			ptr[i] = model->label[i];

	return;
}
示例#13
0
void mexFunction( int nlhs, mxArray *plhs[],
		int nrhs, const mxArray *prhs[] )
{
	if(nrhs == 1)
	{
		char filename[256];

		mxGetString(prhs[0], filename, mxGetN(prhs[0]) + 1);

		if(filename == NULL)
		{
			mexPrintf("Error: filename is NULL\n");
			return;
		}

		read_problem(filename, plhs);
	}
	else
	{
		exit_with_help();
		fake_answer(plhs);
		return;
	}
}
示例#14
0
void mexFunction( int nlhs, mxArray *plhs[],
		 int nrhs, const mxArray *prhs[] )
{
	int prob_estimate_flag = 0;
	struct svm_model *model;

	if(nrhs > 4 || nrhs < 3)
	{
		exit_with_help();
		fake_answer(plhs);
		return;
	}

	if(!mxIsDouble(prhs[0]) || !mxIsDouble(prhs[1])) {
		mexPrintf("Error: label vector and instance matrix must be double\n");
		fake_answer(plhs);
		return;
	}

	if(mxIsStruct(prhs[2]))
	{
		const char *error_msg;

		// parse options
		if(nrhs==4)
		{
			int i, argc = 1;
			char cmd[CMD_LEN], *argv[CMD_LEN/2];

			// put options in argv[]
			mxGetString(prhs[3], cmd,  mxGetN(prhs[3]) + 1);
			if((argv[argc] = strtok(cmd, " ")) != NULL)
				while((argv[++argc] = strtok(NULL, " ")) != NULL)
					;

			for(i=1;i<argc;i++)
			{
				if(argv[i][0] != '-') break;
				if(++i>=argc)
				{
					exit_with_help();
					fake_answer(plhs);
					return;
				}
				switch(argv[i-1][1])
				{
					case 'b':
						prob_estimate_flag = atoi(argv[i]);
						break;
					default:
						mexPrintf("Unknown option: -%c\n", argv[i-1][1]);
						exit_with_help();
						fake_answer(plhs);
						return;
				}
			}
		}

		model = matlab_matrix_to_model(prhs[2], &error_msg);
		if (model == NULL)
		{
			mexPrintf("Error: can't read model: %s\n", error_msg);
			fake_answer(plhs);
			return;
		}

		if(prob_estimate_flag)
		{
			if(svm_check_probability_model(model)==0)
			{
				mexPrintf("Model does not support probabiliy estimates\n");
				fake_answer(plhs);
				svm_destroy_model(model);
				return;
			}
		}
		else
		{
			if(svm_check_probability_model(model)!=0)
				printf("Model supports probability estimates, but disabled in predicton.\n");
		}

		predict(plhs, prhs, model, prob_estimate_flag);
		// destroy model
		svm_destroy_model(model);
	}
	else
	{
		mexPrintf("model file should be a struct array\n");
		fake_answer(plhs);
	}

	return;
}
示例#15
0
void mexFunction( int nlhs, mxArray *plhs[],
		int nrhs, const mxArray *prhs[] )
{
	int prob_estimate_flag = 0;
	struct model *model_;
	char cmd[CMD_LEN];
	col_format_flag = 0;

	if(nrhs > 5 || nrhs < 3)
	{
		exit_with_help();
		fake_answer(plhs);
		return;
	}
	if(nrhs == 5)
	{
		mxGetString(prhs[4], cmd, mxGetN(prhs[4])+1);
		if(strcmp(cmd, "col") == 0)
		{			
			col_format_flag = 1;
		}
	}

	if(!mxIsDouble(prhs[0]) || !mxIsDouble(prhs[1])) {
		mexPrintf("Error: label vector and instance matrix must be double\n");
		fake_answer(plhs);
		return;
	}

	if(mxIsStruct(prhs[2]))
	{
		const char *error_msg;

		// parse options
		if(nrhs>=4)
		{
			int i, argc = 1;
			char *argv[CMD_LEN/2];

			// put options in argv[]
			mxGetString(prhs[3], cmd,  mxGetN(prhs[3]) + 1);
			if((argv[argc] = strtok(cmd, " ")) != NULL)
				while((argv[++argc] = strtok(NULL, " ")) != NULL)
					;

			for(i=1;i<argc;i++)
			{
				if(argv[i][0] != '-') break;
				if(++i>=argc)
				{
					exit_with_help();
					fake_answer(plhs);
					return;
				}
				switch(argv[i-1][1])
				{
					case 'b':
						prob_estimate_flag = atoi(argv[i]);
						break;
					default:
						mexPrintf("unknown option\n");
						exit_with_help();
						fake_answer(plhs);
						return;
				}
			}
		}

		model_ = Malloc(struct model, 1);
		error_msg = matlab_matrix_to_model(model_, prhs[2]);
		if(error_msg)
		{
			mexPrintf("Error: can't read model: %s\n", error_msg);
			free_and_destroy_model(&model_);
			fake_answer(plhs);
			return;
		}

		if(prob_estimate_flag)
		{
			if(!check_probability_model(model_))
			{
				mexPrintf("probability output is only supported for logistic regression\n");
				prob_estimate_flag=0;
			}
		}

		if(mxIsSparse(prhs[1]))
			do_predict(plhs, prhs, model_, prob_estimate_flag);
		else
		{
			mexPrintf("Testing_instance_matrix must be sparse; "
				"use sparse(Testing_instance_matrix) first\n");
			fake_answer(plhs);
		}

		// destroy model_
		free_and_destroy_model(&model_);
	}
	else
	{
示例#16
0
void parse_command_line(int argc, char **argv, char *input_file_name, char *model_file_name)
{
	int i;
	void (*print_func)(const char*) = NULL;	// default printing to stdout

	// default values
	param.svm_type = C_SVC;
	param.kernel_type = RBF;
	param.degree = 3;
	param.gamma = 0;	// 1/num_features
	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;
	cross_validation = 0;

	// parse options
	for(i=1;i<argc;i++)
	{
		if(argv[i][0] != '-') break;
		if(++i>=argc)
			exit_with_help();
		switch(argv[i-1][1])
		{
			case 's':
				param.svm_type = atoi(argv[i]);
				break;
			case 't':
				param.kernel_type = atoi(argv[i]);
				break;
			case 'd':
				param.degree = atoi(argv[i]);
				break;
			case 'g':
				param.gamma = atof(argv[i]);
				break;
			case 'r':
				param.coef0 = atof(argv[i]);
				break;
			case 'n':
				param.nu = atof(argv[i]);
				break;
			case 'm':
				param.cache_size = atof(argv[i]);
				break;
			case 'c':
				param.C = atof(argv[i]);
				break;
			case 'e':
				param.eps = atof(argv[i]);
				break;
			case 'p':
				param.p = atof(argv[i]);
				break;
			case 'h':
				param.shrinking = atoi(argv[i]);
				break;
			case 'b':
				param.probability = atoi(argv[i]);
				break;
			case 'q':
				print_func = &print_null;
				i--;
				break;
			case 'v':
				cross_validation = 1;
				nr_fold = atoi(argv[i]);
				if(nr_fold < 2)
				{
					fprintf(stderr,"n-fold cross validation: n must >= 2\n");
					exit_with_help();
				}
				break;
			case 'w':
				++param.nr_weight;
				param.weight_label = (int *)realloc(param.weight_label,sizeof(int)*param.nr_weight);
				param.weight = (double *)realloc(param.weight,sizeof(double)*param.nr_weight);
				param.weight_label[param.nr_weight-1] = atoi(&argv[i-1][2]);
				param.weight[param.nr_weight-1] = atof(argv[i]);
				break;
			case 'W':
				weight_file = argv[i];
				break;
			default:
				fprintf(stderr,"Unknown option: -%c\n", argv[i-1][1]);
				exit_with_help();
		}
	}

	svm_set_print_string_function(print_func);

	// determine filenames

	if(i>=argc)
		exit_with_help();

	strcpy(input_file_name, argv[i]);

	if(i<argc-1)
		strcpy(model_file_name,argv[i+1]);
	else
	{
		char *p = strrchr(argv[i],'/');
		if(p==NULL)
			p = argv[i];
		else
			++p;
		sprintf(model_file_name,"%s.model",p);
	}
}
示例#17
0
void parse_command_line(int argc, char **argv, char *input_file_name, char *model_file_name)
{
    int i;
    // default values
    param.solver_type = L2R_L2LOSS_SVC_DUAL;
    param.C = 1.0;
    param.lambda = 0.0;
    param.eps = INF; // see setting below 
    param.max_iter = 50;
    param.inner_max_iter = 50;
    param.nr_weight = 0;
    param.weight_label = NULL;
    param.weight = NULL;  
    param.intermediate_result =  NULL;
    flag_cross_validation = 0;
    bias = -1;
    param.RELTOL= 0.0001;
    param.ABSTOL=0.0001;
    param.rho=1.0;
    param.relaxation=0;
    param.relax_alpha=1.6;    
    param.inner_mute=1;     
    param.primal=0;
    param.normalize=0;
    param.root= 0;
    param.eta = 1E-3;
    param.SGD_decay = 0;
    param.PSGD_more_aver = 0;
    param.fraction = 1.0;
    param.multiple = 1.0;
    // parse options
    for (i=1; i<argc; i++)
    {
        if (argv[i][0] != '-') break;
        if (++i>=argc)
            exit_with_help();
        switch( argv[i-1][1] )
        {
            case 's':
                param.solver_type = atoi(argv[i]);
                break;
            
            case 'c':
                param.C = atof(argv[i]);
                break;

            case 'e':
                param.eps = atof(argv[i]);
                break;

            case 'E':
                param.inner_eps = atof(argv[i]);
                break;
                
            case 'L':
                param.eta = atof(argv[i]);
                break;    

            case 'm':
                param.max_iter = atoi(argv[i]);
                break;
            
            case 'd':
                param.SGD_decay = atoi(argv[i]);
                break;                
            
            case 'n':
                param.normalize = atoi(argv[i]);
                break;
            
            case 'p':
                param.primal = atoi(argv[i]);
                break;    
            
            case 'F':
                param.PSGD_more_aver = atoi(argv[i]);
                break;
            
            case 'M':
                param.inner_max_iter = atoi(argv[i]);
                break;

            case 'B':
                bias = atof(argv[i]);
                break;
            case 'w':
                ++param.nr_weight;
                param.weight_label = (int *) realloc(param.weight_label,sizeof(int)*param.nr_weight);
                param.weight = (double *) realloc(param.weight,sizeof(double)*param.nr_weight);
                param.weight_label[param.nr_weight-1] = atoi(&argv[i-1][2]);
                param.weight[param.nr_weight-1] = atof(argv[i]);
                break;

            case 'v':
                flag_cross_validation = 1;
                nr_fold = atoi(argv[i]);
                if(nr_fold < 2)
                {
                    fprintf(stderr,"n-fold cross validation: n must >= 2\n");
                    exit_with_help();
                }
                break;                
            case 'q':
                param.inner_mute=atoi(argv[i]);
                break;
            case 'R':
                param.RELTOL = atof(argv[i]);
                break;
                
            case 'A':
                param.ABSTOL = atof(argv[i]);
                break;                

            case 'r':
                param.rho = atof(argv[i]);
                break;                        
            
            case 'x':
                param.relaxation = atoi(argv[i]);
                break;        
                        
            case 'l':    
                param.relax_alpha= atof(argv[i]);
                break;
            
            case 'i':
                param.intermediate_result = argv[i];
                break;
            case 'f':
                param.fraction = atof(argv[i]);
                break;

            case 't':
                param.multiple = atof(argv[i]);
                break;


            default:
                fprintf(stderr,"unknown option: -%c\n", argv[i-1][1]);
                exit_with_help();
                break;
        }
    }

    // determine filenames
    if(i>=argc)
        exit_with_help();

    strcpy(input_file_name, argv[i]);

    if(i<argc-1)
        strcpy(model_file_name,argv[i+1]);
    else
    {
        size_t len = strlen(argv[i]);
        if(argv[i][len-1] == '/') 
            argv[i][len-1] = 0;
        char *p = strrchr(argv[i],'/');
        if(p==NULL)
            p = argv[i];
        else
            ++p;
        sprintf(model_file_name,"%s.model",p);
    }   
    
    if(param.eps == INF)
    {
        if(param.solver_type == L2R_LR || param.solver_type == L2R_L2LOSS_SVC)
            param.eps = 0.01;
        else if(param.solver_type == L2R_L2LOSS_SVC_DUAL || param.solver_type == L2R_L1LOSS_SVC_DUAL)
            param.eps = 0.001;

    }
}
示例#18
0
void parse_command_line(int argc, char **argv, char *input_file_name, char *model_file_name)
{
	int i;
	void (*print_func)(const char*) = NULL;	// default printing to stdout

	// default values
	param.solver_type = L2R_L2LOSS_SVC_DUAL;
	param.C = 1;
	param.eps = INF; // see setting below
	param.p = 0.1;
	param.nr_weight = 0;
	param.weight_label = NULL;
	param.weight = NULL;
	param.init_sol = NULL;
	flag_cross_validation = 0;
	flag_warm_start = 0;
	flag_C_specified = 0;
	flag_solver_specified = 0;
	flag_find_C = 0;
	bias = -1;

	// parse options
	for(i=1;i<argc;i++)
	{
		if(argv[i][0] != '-') break;
		if(++i>=argc)
			exit_with_help();
		switch(argv[i-1][1])
		{
			case 's':
				param.solver_type = atoi(argv[i]);
				flag_solver_specified = 1;
				break;

			case 'c':
				param.C = atof(argv[i]);
				flag_C_specified = 1;
				break;

			case 'p':
				param.p = atof(argv[i]);
				break;

			case 'e':
				param.eps = atof(argv[i]);
				break;

			case 'B':
				bias = atof(argv[i]);
				break;

			case 'w':
				++param.nr_weight;
				param.weight_label = (int *) realloc(param.weight_label,sizeof(int)*param.nr_weight);
				param.weight = (double *) realloc(param.weight,sizeof(double)*param.nr_weight);
				param.weight_label[param.nr_weight-1] = atoi(&argv[i-1][2]);
				param.weight[param.nr_weight-1] = atof(argv[i]);
				break;

			case 'v':
				flag_cross_validation = 1;
				nr_fold = atoi(argv[i]);
				if(nr_fold < 2)
				{
					fprintf(stderr,"n-fold cross validation: n must >= 2\n");
					exit_with_help();
				}
				break;

			case 'q':
				print_func = &print_null;
				i--;
				break;

			case 'i':
				flag_warm_start = 1;
				if((initial_model=load_model(argv[i]))==0)
				{
					fprintf(stderr,"can't open initial model file %s\n",argv[i]);
					exit_with_help();
				}
				break;
			case 'C':
				flag_find_C = 1;
				i--;
				break;

			default:
				fprintf(stderr,"unknown option: -%c\n", argv[i-1][1]);
				exit_with_help();
				break;
		}
	}

	if(flag_warm_start)
	{
		if(param.solver_type != L2R_LR && param.solver_type != L2R_L2LOSS_SVC)
		{
			fprintf(stderr,"-i is supported only for -s 0 and 2\n");
			exit(1);
		}
		if(param.solver_type != initial_model->param.solver_type)
			fprintf(stderr,"Warning: the solver type of initial model dose not match your -s option\n");
	}

	set_print_string_function(print_func);

	// determine filenames
	if(i>=argc)
		exit_with_help();

	strcpy(input_file_name, argv[i]);

	if(i<argc-1)
		strcpy(model_file_name,argv[i+1]);
	else
	{
		char *p = strrchr(argv[i],'/');
		if(p==NULL)
			p = argv[i];
		else
			++p;
		sprintf(model_file_name,"%s.model",p);
	}

	// default solver for parameter selection is L2R_L2LOSS_SVC
	if(flag_find_C)
	{
		if(!flag_cross_validation)
			nr_fold = 5;
		if(!flag_solver_specified)
		{
			fprintf(stderr, "Solver not specified. Using -s 2\n");
			param.solver_type = L2R_L2LOSS_SVC;
		}
		else if(param.solver_type != L2R_LR && param.solver_type != L2R_L2LOSS_SVC)
		{
			fprintf(stderr, "Warm-start parameter search only available for -s 0 and -s 2\n");
			exit_with_help();
		}
	}

	if(param.eps == INF)
	{
		switch(param.solver_type)
		{
			case L2R_LR:
			case L2R_L2LOSS_SVC:
				param.eps = 0.01;
				break;
			case L2R_L2LOSS_SVR:
				param.eps = 0.001;
				break;
			case L2R_L2LOSS_SVC_DUAL:
			case L2R_L1LOSS_SVC_DUAL:
			case MCSVM_CS:
			case L2R_LR_DUAL:
				param.eps = 0.1;
				break;
			case L1R_L2LOSS_SVC:
			case L1R_LR:
				param.eps = 0.01;
				break;
			case L2R_L1LOSS_SVR_DUAL:
			case L2R_L2LOSS_SVR_DUAL:
				param.eps = 0.1;
				break;
		}
	}
}
int main(int argc, char** argv)
{
	static struct option image_net_options[] = {
		/* help */
		{"help", 0, 0, 0},
		/* required parameters */
		{"train-list", 1, 0, 0},
		{"test-list", 1, 0, 0},
		{"working-dir", 1, 0, 0},
		/* optional parameters */
		{"base-dir", 1, 0, 0},
		{"max-epoch", 1, 0, 0},
		{"iterations", 1, 0, 0},
		{0, 0, 0, 0}
	};
	char* train_list = 0;
	char* test_list = 0;
	char* working_dir = 0;
	char* base_dir = 0;
	ccv_convnet_train_param_t train_params = {
		.max_epoch = 100,
		.mini_batch = 64,
		.sgd_frequency = 1, // do sgd every sgd_frequency batches (mini_batch * device_count * sgd_frequency)
		.iterations = 50000,
		.device_count = 4,
		.peer_access = 1,
		.symmetric = 1,
		.image_manipulation = 0.2,
		.color_gain = 0.001,
		.input = {
			.min_dim = 257,
			.max_dim = 257,
		},
	};
	int i, c;
	while (getopt_long_only(argc, argv, "", image_net_options, &c) != -1)
	{
		switch (c)
		{
			case 0:
				exit_with_help();
			case 1:
				train_list = optarg;
				break;
			case 2:
				test_list = optarg;
				break;
			case 3:
				working_dir = optarg;
				break;
			case 4:
				base_dir = optarg;
				break;
			case 5:
				train_params.max_epoch = atoi(optarg);
				break;
			case 6:
				train_params.iterations = atoi(optarg);
				break;
		}
	}
	if (!train_list || !test_list || !working_dir)
		exit_with_help();
	ccv_enable_default_cache();
	FILE *r0 = fopen(train_list, "r");
	assert(r0 && "train-list doesn't exists");
	FILE* r1 = fopen(test_list, "r");
	assert(r1 && "test-list doesn't exists");
	char* file = (char*)malloc(1024);
	int dirlen = (base_dir != 0) ? strlen(base_dir) + 1 : 0;
	ccv_array_t* categorizeds = ccv_array_new(sizeof(ccv_categorized_t), 64, 0);
	while (fscanf(r0, "%d %s", &c, file) != EOF)
	{
		char* filename = (char*)ccmalloc(1024);
		if (base_dir != 0)
		{
			strncpy(filename, base_dir, 1024);
			filename[dirlen - 1] = '/';
		}
		strncpy(filename + dirlen, file, 1024 - dirlen);
		ccv_file_info_t file_info = {
			.filename = filename,
		};
		// imageNet's category class starts from 1, thus, minus 1 to get 0-index
		ccv_categorized_t categorized = ccv_categorized(c - 1, 0, &file_info);
		ccv_array_push(categorizeds, &categorized);
	}
	fclose(r0);
	ccv_array_t* tests = ccv_array_new(sizeof(ccv_categorized_t), 64, 0);
	while (fscanf(r1, "%d %s", &c, file) != EOF)
	{
		char* filename = (char*)ccmalloc(1024);
		if (base_dir != 0)
		{
			strncpy(filename, base_dir, 1024);
			filename[dirlen - 1] = '/';
		}
		strncpy(filename + dirlen, file, 1024 - dirlen);
		ccv_file_info_t file_info = {
			.filename = filename,
		};
		// imageNet's category class starts from 1, thus, minus 1 to get 0-index
		ccv_categorized_t categorized = ccv_categorized(c - 1, 0, &file_info);
		ccv_array_push(tests, &categorized);
	}
	fclose(r1);
	free(file);
// #define model_params vgg_d_params
#define model_params matt_c_params
	int depth = sizeof(model_params) / sizeof(ccv_convnet_layer_param_t);
	ccv_convnet_t* convnet = ccv_convnet_new(1, ccv_size(257, 257), model_params, depth);
	if (ccv_convnet_verify(convnet, 1000) == 0)
	{
		ccv_convnet_layer_train_param_t layer_params[depth];
		memset(layer_params, 0, sizeof(layer_params));
		for (i = 0; i < depth; i++)
		{
			layer_params[i].w.decay = 0.0005;
			layer_params[i].w.learn_rate = 0.01;
			layer_params[i].w.momentum = 0.9;
			layer_params[i].bias.decay = 0;
			layer_params[i].bias.learn_rate = 0.01;
			layer_params[i].bias.momentum = 0.9;
		}
		// set the two full connect layers to last with dropout rate at 0.5
		for (i = depth - 3; i < depth - 1; i++)
			layer_params[i].dor = 0.5;
		train_params.layer_params = layer_params;
		ccv_set_cli_output_levels(ccv_cli_output_level_and_above(CCV_CLI_INFO));
		ccv_convnet_supervised_train(convnet, categorizeds, tests, working_dir, train_params);
	} else {
		PRINT(CCV_CLI_ERROR, "Invalid convnet configuration\n");
	}
	ccv_convnet_free(convnet);
	ccv_disable_cache();
	return 0;
}
示例#20
0
void parse_command_line(int argc, char **argv, char *input_file_name, char *model_file_name)
{
	int i;

	// default values
	param.solver_type = L2R_L2LOSS_SVC_DUAL;
	param.C = 1;
	param.eps = INF; // see setting below
	param.nr_weight = 0;
	param.weight_label = NULL;
	param.weight = NULL;
	flag_cross_validation = 0;
	bias = -1;

	// parse options
	for(i=1;i<argc;i++)
	{
		if(argv[i][0] != '-') break;
		if(++i>=argc)
			exit_with_help();
		switch(argv[i-1][1])
		{
			case 's':
				param.solver_type = atoi(argv[i]);
				break;

			case 'c':
				param.C = atoff(argv[i]);
				break;

			case 'e':
				param.eps = atoff(argv[i]);
				break;

			case 'B':
				bias = atoff(argv[i]);
				break;

			case 'w':
				++param.nr_weight;
				param.weight_label = (int *) realloc(param.weight_label,sizeof(int)*param.nr_weight);
				param.weight = (float *) realloc(param.weight,sizeof(double)*param.nr_weight);
				param.weight_label[param.nr_weight-1] = atoi(&argv[i-1][2]);
				param.weight[param.nr_weight-1] = atoff(argv[i]);
				break;

			case 'v':
				flag_cross_validation = 1;
				nr_fold = atoi(argv[i]);
				if(nr_fold < 2)
				{
					fprintf(stderr,"n-fold cross validation: n must >= 2\n");
					exit_with_help();
				}
				break;

			case 'q':
				liblinear_print_string = &print_null;
				i--;
				break;

			default:
				fprintf(stderr,"unknown option: -%c\n", argv[i-1][1]);
				exit_with_help();
				break;
		}
	}

	// determine filenames
	if(i>=argc)
		exit_with_help();

	strcpy(input_file_name, argv[i]);

	if(i<argc-1)
		strcpy(model_file_name,argv[i+1]);
	else
	{
		char *p = strrchr(argv[i],'/');
		if(p==NULL)
			p = argv[i];
		else
			++p;
		sprintf(model_file_name,"%s.model",p);
	}

	if(param.eps == INF)
	{
		if(param.solver_type == L2R_LR || param.solver_type == L2R_L2LOSS_SVC)
			param.eps = 0.01;
		else if(param.solver_type == L2R_L2LOSS_SVC_DUAL || param.solver_type == L2R_L1LOSS_SVC_DUAL || param.solver_type == MCSVM_CS)
			param.eps = 0.1;
		else if(param.solver_type == L1R_L2LOSS_SVC || param.solver_type == L1R_LR)
			param.eps = 0.01;
	}
}
示例#21
0
文件: bbfcreate.c 项目: Daiver/tagit
int main(int argc, char** argv)
{
	static struct option bbf_options[] = {
		/* help */
		{"help", 0, 0, 0},
		/* required parameters */
		{"positive-list", 1, 0, 0},
		{"background-list", 1, 0, 0},
		{"working-dir", 1, 0, 0},
		{"negative-count", 1, 0, 0},
		{"width", 1, 0, 0},
		{"height", 1, 0, 0},
		/* optional parameters */
		{"base-dir", 1, 0, 0},
		{"layer", 1, 0, 0},
		{"positive-criteria", 1, 0, 0},
		{"negative-criteria", 1, 0, 0},
		{"balance", 1, 0, 0},
		{"feature-number", 1, 0, 0},
		{0, 0, 0, 0}
	};
	char* positive_list = 0;
	char* background_list = 0;
	char* working_dir = 0;
	char* base_dir = 0;
	int negnum = 0;
	int width = 0, height = 0;
	ccv_bbf_new_param_t params = {
		.pos_crit = 0.9975,
		.neg_crit = 0.50,
		.balance_k = 1.0,
		.layer = 24,
		.feature_number = 100,
		.optimizer = CCV_BBF_GENETIC_OPT | CCV_BBF_FLOAT_OPT,
	};
	int i, k;
	while (getopt_long_only(argc, argv, "", bbf_options, &k) != -1)
	{
		switch (k)
		{
			case 0:
				exit_with_help();
			case 1:
				positive_list = optarg;
				break;
			case 2:
				background_list = optarg;
				break;
			case 3:
				working_dir = optarg;
				break;
			case 4:
				negnum = atoi(optarg);
				break;
			case 5:
				width = atoi(optarg);
				break;
			case 6:
				height = atoi(optarg);
				break;
			case 7:
				base_dir = optarg;
				break;
			case 8:
				params.layer = atoi(optarg);
				break;
			case 9:
				params.pos_crit = atof(optarg);
				break;
			case 10:
				params.neg_crit = atof(optarg);
				break;
			case 11:
				params.balance_k = atof(optarg);
				break;
			case 12:
				params.feature_number = atoi(optarg);
				break;
		}
	}
	assert(positive_list != 0);
	assert(background_list != 0);
	assert(working_dir != 0);
	assert(negnum > 0);
	assert(width > 0 && height > 0);
	ccv_enable_default_cache();
	FILE* r0 = fopen(positive_list, "r");
	assert(r0 && "positive-list doesn't exists");
	FILE* r1 = fopen(background_list, "r");
	assert(r1 && "background-list doesn't exists");
	char* file = (char*)malloc(1024);
	int dirlen = (base_dir != 0) ? strlen(base_dir) + 1 : 0;
	size_t len = 1024;
	ssize_t read;
	int capacity = 32, size = 0;
	ccv_dense_matrix_t** posimg = (ccv_dense_matrix_t**)ccmalloc(sizeof(ccv_dense_matrix_t*) * capacity);
	while ((read = getline(&file, &len, r0)) != -1)
	{
		while(read > 1 && isspace(file[read - 1]))
			read--;
		file[read] = 0;
		char* posfile = (char*)ccmalloc(1024);
		if (base_dir != 0)
		{
			strncpy(posfile, base_dir, 1024);
			posfile[dirlen - 1] = '/';
		}
		strncpy(posfile + dirlen, file, 1024 - dirlen);
		posimg[size] = 0;
		ccv_read(posfile, &posimg[size], CCV_IO_GRAY | CCV_IO_ANY_FILE);
		if (posimg != 0)
		{
			++size;
			if (size >= capacity)
			{
				capacity *= 2;
				posimg = (ccv_dense_matrix_t**)ccrealloc(posimg, sizeof(ccv_dense_matrix_t*) * capacity);
			}
		}
	}
	fclose(r0);
	int posnum = size;
	capacity = 32;
	size = 0;
	char** bgfiles = (char**)ccmalloc(sizeof(char*) * capacity);
	while ((read = getline(&file, &len, r1)) != -1)
	{
		while(read > 1 && isspace(file[read - 1]))
			read--;
		file[read] = 0;
		bgfiles[size] = (char*)ccmalloc(1024);
		if (base_dir != 0)
		{
			strncpy(bgfiles[size], base_dir, 1024);
			bgfiles[size][dirlen - 1] = '/';
		}
		strncpy(bgfiles[size] + dirlen, file, 1024 - dirlen);
		++size;
		if (size >= capacity)
		{
			capacity *= 2;
			bgfiles = (char**)ccrealloc(bgfiles, sizeof(char*) * capacity);
		}
	}
	fclose(r1);
	int bgnum = size;
	free(file);
	ccv_bbf_classifier_cascade_new(posimg, posnum, bgfiles, bgnum, negnum, ccv_size(width, height), working_dir, params);
	for (i = 0; i < bgnum; i++)
		free(bgfiles[i]);
	for (i = 0; i < posnum; i++)
		ccv_matrix_free(&posimg[i]);
	free(posimg);
	free(bgfiles);
	ccv_disable_cache();
	return 0;
}
示例#22
0
文件: main.cpp 项目: douzsh/douzsh
int main(int argc,char* argv[])
{
	if ( argc<6 )
	{
		exit_with_help();
		return 0;
	}
	iDurationDay = atoi(argv[1]);
	iFromHour = atoi(argv[2]);
	iEndHour = atoi(argv[3]);
	strcpy(strDBTableList,argv[4]);
	strcpy(strDBFrom,argv[5]);
	if ( argc>6 )
	{
		strcpy(strIP,argv[6]);
	} 
	else
	{
		strcpy(strIP,"127.0.0.1");
	}//*/

	/*iDurationDay=1;
	iFromHour=9;
	iEndHour=10;
	strcpy(strDBTableList,"IMAGE_CJFD1994,IMAGE_CJFD1995,IMAGE_CJFD1996,IMAGE_CJFD1997,IMAGE_CJFD1998,IMAGE_CJFD1999,IMAGE_CJFD2000,IMAGE_CJFD2001,IMAGE_CJFD2002,IMAGE_CJFD2003,IMAGE_CJFD2004,IMAGE_CJFD2005,IMAGE_CJFD2006,IMAGE_CJFD2007,IMAGE_CJFD2007_ZHAOHUI,IMAGE_CJFD2008,IMAGE_CJFD2008_ZHAOHUI,IMAGE_CJFD2009,IMAGE_CJFD2010,IMAGE_CJFD2011,IMAGE_CJFD2011_INFOTEST,IMAGE_CJFD_UNKNOWN,IMAGE_CPFD1999,IMAGE_CPFD2000,IMAGE_CPFD2001,IMAGE_CPFD2002,IMAGE_CPFD2003,IMAGE_CPFD2004,IMAGE_CPFD2005,IMAGE_CPFD2006,IMAGE_CPFD2007,IMAGE_CPFD2008,IMAGE_CPFD2009,IMAGE_CPFD2010,IMAGE_CPFD2011,IMAGE_CPFD_UNKNOWN,IMAGE_CRFD,IMAGE_SCPD2009,INV_IMAGE_CJFD2007,INV_IMAGE_CJFD2008,INV_IMAGE_CJFD2009,INV_IMAGE_CJFD2010,INV_IMAGE_CJFD2011,INV_IMAGE_CJFD_UNKNOWN");
	strcpy(strDBFrom,"CNKIIMAGE_2011");
	strcpy(strIP,"192.168.100.101");//*/

	TPI_LOGIN_PARA logpara ;
	strcpy(logpara.szUserName,"DBOWN") ;
	strcpy(logpara.szPassWord,"") ;
	strcpy(logpara.UserIp.szIp,strIP);

	int iStat=STAT_NULL;
	time_t timer;
	struct tm *tblock;
	timer=time(NULL);
	tblock=localtime(&timer);

	int iStartDay=-1;

	LogExec("\nbackgroud update begin\n");
	while(true)
	{
		timer=time(NULL);
		tblock=localtime(&timer);
		
		if (( iStat==STAT_START || iStartDay==-1 || (tblock->tm_yday-iStartDay)==iDurationDay ))
		{
			if ( tblock->tm_hour>=iFromHour && ((iEndHour>=iFromHour && tblock->tm_hour<=iEndHour) || (iEndHour<iFromHour)) )
			{
				int errorcode = -1 ;
				kbase_handle = TPI_OpenCon(strIP,4567,logpara,&errorcode) ;
				if(errorcode < 0)
				{
					LogExec("cant connect to server\n");
					Sleep(1000*600);
					continue;
				}
				iStartDay=tblock->tm_yday;
				LogExec(asctime(tblock));
				LogExec("start update\n");
				iStat=UpdateDB();
				timer=time(NULL);
				tblock=localtime(&timer);
				LogExec(asctime(tblock));
				LogExec("update end\n");
				TPI_CloseCon(kbase_handle);
				continue;
			}
		}

		LogExec(".");
		Sleep(600*1000);
	}
	return 0;
}
示例#23
0
int main(int argc, char** argv)
{
	static struct option scd_options[] = {
		/* help */
		{"help", 0, 0, 0},
		/* required parameters */
		{"positive-list", 1, 0, 0},
		{"background-list", 1, 0, 0},
		{"negative-count", 1, 0, 0},
		{"working-dir", 1, 0, 0},
		/* optional parameters */
		{0, 0, 0, 0}
	};
	char* positive_list = 0;
	char* background_list = 0;
	char* working_dir = 0;
	char* base_dir = 0;
	int negative_count = 0;
	int k;
	while (getopt_long_only(argc, argv, "", scd_options, &k) != -1)
	{
		switch (k)
		{
			case 0:
				exit_with_help();
			case 1:
				positive_list = optarg;
				break;
			case 2:
				background_list = optarg;
				break;
			case 3:
				negative_count = atoi(optarg);
				break;
			case 4:
				working_dir = optarg;
				break;
			case 5:
				base_dir = optarg;
		}
	}
	assert(positive_list != 0);
	assert(background_list != 0);
	assert(working_dir != 0);
	assert(negative_count > 0);
	FILE* r0 = fopen(positive_list, "r");
	assert(r0 && "positive-list doesn't exists");
	FILE* r1 = fopen(background_list, "r");
	assert(r1 && "background-list doesn't exists");
	int dirlen = (base_dir != 0) ? strlen(base_dir) + 1 : 0;
	ccv_array_t* posfiles = ccv_array_new(sizeof(ccv_file_info_t), 32, 0);
	char* file = (char*)malloc(1024);
	size_t len = 1024;
	ssize_t read;
	while ((read = getline(&file, &len, r0)) != -1)
	{
		while(read > 1 && isspace(file[read - 1]))
			read--;
		file[read] = 0;
		ccv_file_info_t file_info;
		file_info.filename = (char*)ccmalloc(1024);
		if (base_dir != 0)
		{
			strncpy(file_info.filename, base_dir, 1024);
			file_info.filename[dirlen - 1] = '/';
		}
		strncpy(file_info.filename + dirlen, file, 1024 - dirlen);
		ccv_array_push(posfiles, &file_info);
	}
	fclose(r0);
	ccv_array_t* hard_mine = (ccv_array_t*)ccv_array_new(sizeof(ccv_file_info_t), 32, 0);
	while ((read = getline(&file, &len, r1)) != -1)
	{
		while(read > 1 && isspace(file[read - 1]))
			read--;
		file[read] = 0;
		ccv_file_info_t file_info;
		file_info.filename = (char*)ccmalloc(1024);
		if (base_dir != 0)
		{
			strncpy(file_info.filename, base_dir, 1024);
			file_info.filename[dirlen - 1] = '/';
		}
		strncpy(file_info.filename + dirlen, file, 1024 - dirlen);
		ccv_array_push(hard_mine, &file_info);
	}
	fclose(r1);
	free(file);
	ccv_scd_train_param_t params = {
		.boosting = 10,
		.size = ccv_size(48, 48),
		.feature = {
			.base = ccv_size(8, 8),
			.range_through = 4,
			.step_through = 4,
		},
		.stop_criteria = {
			.hit_rate = 0.995,
			.false_positive_rate = 0.5,
			.accu_false_positive_rate = 1e-7,
			.auc_crit = 1e-5,
			.maximum_feature = 2048,
			.prune_stage = 3,
			.prune_feature = 4,
		},
		.weight_trimming = 0.98,
示例#24
0
// Interface function of matlab
// now assume prhs[0]: label prhs[1]: features
void mexFunction( int nlhs, mxArray *plhs[],
		int nrhs, const mxArray *prhs[] )
{
	const char *error_msg;
	// fix random seed to have same results for each run
	// (for cross validation)
	srand(1);

	// Transform the input Matrix to libsvm format
	if(nrhs > 0 && nrhs < 5)
	{
		int err=0;

		if(!mxIsDouble(prhs[0]) || !mxIsDouble(prhs[1])) {
			mexPrintf("Error: label vector and instance matrix must be double\n");
			fake_answer(plhs);
			return;
		}

		if(parse_command_line(nrhs, prhs, NULL))
		{
			exit_with_help();
			destroy_param(&param);
			fake_answer(plhs);
			return;
		}

		if(mxIsSparse(prhs[1]))
			err = read_problem_sparse(prhs[0], prhs[1]);
		else
		{
			mexPrintf("Training_instance_matrix must be sparse\n");
			destroy_param(&param);
			fake_answer(plhs);
			return;
		}

		// train's original code
		error_msg = check_parameter(&prob, &param);

		if(err || error_msg)
		{
			if (error_msg != NULL)
				mexPrintf("Error: %s\n", error_msg);
			destroy_param(&param);
			free(prob.y);
			free(prob.x);
			free(x_space);
			fake_answer(plhs);
			return;
		}

		if(cross_validation_flag)
		{
			double *ptr;
			plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL);
			ptr = mxGetPr(plhs[0]);
			ptr[0] = do_cross_validation();
		}
		else
		{
			const char *error_msg;

			model_ = train(&prob, &param);
			error_msg = model_to_matlab_structure(plhs, model_);
			if(error_msg)
				mexPrintf("Error: can't convert libsvm model to matrix structure: %s\n", error_msg);
			destroy_model(model_);
		}
		destroy_param(&param);
		free(prob.y);
		free(prob.x);
		free(x_space);
	}
	else
	{
		exit_with_help();
		fake_answer(plhs);
		return;
	}
}
示例#25
0
int main(int argc, char **argv)
{
	FILE *input, *output;
	int i;

	// parse options
	for(i=1;i<argc;i++)
	{
		if(argv[i][0] != '-') break;
		++i;
		switch(argv[i-1][1])
		{
			case 'b':
				predict_probability = atoi(argv[i]);
				break;
			default:
				fprintf(stderr,"Unknown option: -%c\n", argv[i-1][1]);
				exit_with_help();
		}
	}
	if(i>=argc-2)
		exit_with_help();
	
	input = fopen(argv[i],"r");
	if(input == NULL)
	{
		fprintf(stderr,"can't open input file %s\n",argv[i]);
		exit(1);
	}

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

	if((model=svm_load_model(argv[i+1]))==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)
			printf("Model supports probability estimates, but disabled in prediction.\n");
	}
	predict(input,output);
	svm_free_and_destroy_model(&model);
	free(x);
	free(line);
	fclose(input);
	fclose(output);
	return 0;
}
示例#26
0
	int parse_command_line( struct osiris_parameter & osiparam, int argc, char * * argv )
	{
	  int i;

	  if ( argc < 2 )
		exit_with_help();


	  InitOsirisParam( osiparam );

	  //  osiparam.PathResults = ( char * ) malloc( 512 );
	  //  memset( osiparam.PathResults, '\0', 512 );

	  for ( i = 1; i < argc; i++ )
	  {
		while ( argv[i] [0] != '-' )
		  i++;

		switch ( argv[i] [1] )
		{
		  case 'h':
		    exit_with_help();
		    exit( 0 );
		  break;

		  case 's':
		    osiparam.script = true;
		    osiparam.notSEG = false;
		    osiparam.SaveSeg = false;
		    osiparam.saveAnalyse = false;
		    osiparam.saveCode = false;
		    osiparam.matching = false;
		    osiparam.ManuSEG = false;
		    osiparam.OnlySEG = false;
		    osiparam.OnlyCod = false;
		    osiparam.saveparamiris = false;

		    osiparam.IrisScript_Filename = ( char * ) malloc( strlen( argv[i + 1] ) + 1 );
		    memset( osiparam.IrisScript_Filename, '\0', strlen( argv[i + 1] ) + 1 );
		    strncpy( osiparam.IrisScript_Filename, argv[i + 1], strlen( argv[i + 1] ) );
		    ++i;
		    if ( VerifFile( osiparam.IrisScript_Filename ) == -1 )
		    {
		      cout << "The script file " << osiparam.IrisScript_Filename << " not found" << endl;
		      return -1;
		    }
		    goto out1;
		  break;

		  case 'n':
		    osiparam.notSEG = true;
		  break;

		  case 'k':
		    osiparam.nomatch= true;
		  break;

		  case 'f':
		    if ( osiparam.matching )
		    {
		      cout << "-m and -f could not be used together" << endl;
		      exit( 1 );
		    }
		    osiparam.OnlyCod = true;
		    osiparam.saveCode = true;
		  break;


		  case 'l':
		    osiparam.saveparamiris = true;
		  break;

		  case 'w':
		    osiparam.saveNorm = true;
		  break;

		  case 'i':
		    //tests de compatibilité
		    if ( osiparam.matching == true )
		    {
		      cout << "-m and -i could not be used together" << endl;
		      exit( 1 );
		    }
		    osiparam.SaveSeg = true;
		  break;

		  case 'a':
		    osiparam.saveAnalyse = true;
		  break;

		  case 'c':
		    osiparam.saveCode = true;
		  break;

		  case 'd':
		    if ( osiparam.matching == true || osiparam.notSEG == true )
		    {
		      cout << "-d and (-m or -n) could not be used together" << endl;
		      exit( 1 );
		    }
		    osiparam.OnlySEG = true;
		    osiparam.SaveSeg = true;
		  break;

		  case 'm':
		    //tests de compatibilité
		    if ( osiparam.OnlyCod == true || osiparam.ManuSEG == true || osiparam.SaveSeg == true || osiparam.OnlySEG == true )
		    {
		      cout << "-m and (-i , -p, -d, -f) could not be used together" << endl;
		      exit( 1 );
		    }
		    osiparam.matching = true;
		    osiparam.script = false;
		    osiparam.notSEG = true;
		    osiparam.SaveSeg = false;
		    osiparam.ManuSEG = false;
		    osiparam.OnlySEG = false;

		  break;

		  case 'p':
		    //tests de compatibilité

		    if ( osiparam.matching == true )
		    {
		      cout << "-m and (-n or -p) could not be used together" << endl;
		      exit( 1 );
		    }

		    osiparam.ManuSEG = true;
		    osiparam.notSEG = true;
		    if ( not( osiparam.irisParamexist ) )
		    {
		      osiparam.irisParam = ( char * ) malloc( strlen( argv[i + 1] ) + 1 );
		      memset( osiparam.irisParam, '\0', strlen( argv[i + 1] ) + 1 );
		      strncpy( osiparam.irisParam, argv[i + 1], strlen( argv[i + 1] ) );
		      if ( VerifFile( osiparam.irisParam ) == -1 )
		      {
		        cout << osiparam.irisParam << " not found" << endl;
		        return -1;
		      }
		      osiparam.irisParamexist = true;
		    }
		    else
		    {
		      osiparam.irisParam1 = ( char * ) malloc( strlen( argv[i + 1] ) + 1 );
		      memset( osiparam.irisParam1, '\0', strlen( argv[i + 1] ) + 1 );
		      strncpy( osiparam.irisParam1, argv[i + 1], strlen( argv[i + 1] ) );
		      if ( VerifFile( osiparam.irisParam1 ) == -1 )
		      {
		        cout << osiparam.irisParam1 << " not found" << endl;
		        return -1;
		      }
		      osiparam.irisParam1exist = true;
		      ++i;
		    }
		  break;

		  case 'o':
		    osiparam.Result_matching_Filename = ( char * ) malloc( strlen( argv[i + 1] ) + 1 );
		    memset( osiparam.Result_matching_Filename, '\0', strlen( argv[i + 1] ) + 1 );
		    strncpy( osiparam.Result_matching_Filename, argv[i + 1], strlen( argv[i + 1] ) );
		    ++i;
		  break;

		  case 'R':
		    osiparam.IrisReference_Filename = ( char * ) malloc( strlen( argv[i + 1] ) + 1 );
		    memset( osiparam.IrisReference_Filename, '\0', strlen( argv[i + 1] ) + 1 );
		    strncpy( osiparam.IrisReference_Filename, argv[i + 1], strlen( argv[i + 1] ) );
		    if ( VerifFile( osiparam.IrisReference_Filename ) == -1 )
		    {
		      cout << osiparam.IrisReference_Filename << " not found" << endl;
		      return -1;
		    }

		    ++i;
		    osiparam.Reffileload = true;
		  break;

		  case 'T':
		    osiparam.IrisTest_Filename = ( char * ) malloc( strlen( argv[i + 1] ) + 1 );
		    memset( osiparam.IrisTest_Filename, '\0', strlen( argv[i + 1] ) + 1 );
		    strncpy( osiparam.IrisTest_Filename, argv[i + 1], strlen( argv[i + 1] ) );
		    if ( VerifFile( osiparam.IrisTest_Filename ) == -1 )
		    {
		      cout << osiparam.IrisTest_Filename << " not found" << endl;
		      return -1;
		    }

		    ++i;
		    osiparam.Testfileload = true;

		  break;

		  case 'F':
		    osiparam.FILTERFILE = ( char * ) malloc( strlen( argv[i + 1] ) + 1 );
		    memset( osiparam.FILTERFILE, '\0', strlen( argv[i + 1] ) + 1 );
		    strncpy( osiparam.FILTERFILE, argv[i + 1], strlen( argv[i + 1] ) );
		    if ( VerifFile( osiparam.FILTERFILE ) == -1 )
		    {
		      cout << osiparam.FILTERFILE << " not found" << endl;
		      return -1;
		    }

		    ++i;
		    osiparam.Filterfileload = true;


		  break;

		  case 'G':
		    osiparam.POINTSFILE = ( char * ) malloc( strlen( argv[i + 1] ) + 1 );
		    memset( osiparam.POINTSFILE, '\0', strlen( argv[i + 1] ) + 1 );
		    strncpy( osiparam.POINTSFILE, argv[i + 1], strlen( argv[i + 1] ) );
		    if ( VerifFile( osiparam.POINTSFILE ) == -1 )
		    {
		      cout << osiparam.POINTSFILE << " not found" << endl;
		      return -1;
		    }

		    ++i;
		    osiparam.Pointsfileload = true;
		  break;

		  default:
		    cout << "unknown option" << endl;
		    exit_with_help();
		}
	  }


	  if ( osiparam.matching && ( not( osiparam.Testfileload ) || not( osiparam.Reffileload ) ) )
		exit_with_help();

	  if ( osiparam.OnlySEG && not( osiparam.Testfileload ) && not( osiparam.Reffileload ) )
		exit_with_help();

	  if ( osiparam.OnlyCod )
	  {
		if ( not( osiparam.Filterfileload ) || not( osiparam.Pointsfileload ) )
		{
		  cout << "Filter file or Points File missing" << endl;
		  exit_with_help();
		  return ( -1 );

		}
		if ( not( osiparam.Testfileload ) && not( osiparam.Reffileload ) )
		{
		  exit_with_help();
		  return ( -1 );
		}
		if ( osiparam.ManuSEG && not( osiparam.irisParamexist ) && not( osiparam.irisParam1exist ) )
		{
		  cout << "a parameters file must be entered " << endl;
		  return ( -1 );
		}
	  }
	  else if ( osiparam.ManuSEG )
		if ( not( osiparam.Testfileload ) && not( osiparam.Reffileload ) )
		{
		  exit_with_help();
		  return ( -1 );
		}
		else if ( ( osiparam.Testfileload && not( osiparam.irisParam1exist ) )
		     || ( osiparam.Reffileload && not( osiparam.irisParamexist ) ) )
		     {
		       cout << "a second parameters file must be entered" << endl;
		       return ( -1 );
		}


	out1:
	  return ( 0 );
	}
示例#27
0
// Interface function of matlab
// now assume prhs[0]: label prhs[1]: features
void mexFunction( int nlhs, mxArray *plhs[],
		int nrhs, const mxArray *prhs[] )
{
	const char *error_msg;

	// fix random seed to have same results for each run
	// (for cross validation and probability estimation)
	srand(1);

	if(nlhs > 1)
	{
		exit_with_help();
		fake_answer(nlhs, plhs);
		return;
	}

	// Transform the input Matrix to libsvm format
	if(nrhs > 1 && nrhs < 4)
	{
		int err;

		if(!mxIsDouble(prhs[0]) || !mxIsDouble(prhs[1])) {
			mexPrintf("Error: label vector and instance matrix must be double\n");
			fake_answer(nlhs, plhs);
			return;
		}

		if(parse_command_line(nrhs, prhs, NULL))
		{
			exit_with_help();
			svm_destroy_param(&param);
			fake_answer(nlhs, plhs);
			return;
		}

		if(mxIsSparse(prhs[1]))
		{
			if(param.kernel_type == PRECOMPUTED)
			{
				// precomputed kernel requires dense matrix, so we make one
				mxArray *rhs[1], *lhs[1];

				rhs[0] = mxDuplicateArray(prhs[1]);
				if(mexCallMATLAB(1, lhs, 1, rhs, "full"))
				{
					mexPrintf("Error: cannot generate a full training instance matrix\n");
					svm_destroy_param(&param);
					fake_answer(nlhs, plhs);
					return;
				}
				err = read_problem_dense(prhs[0], lhs[0]);
				mxDestroyArray(lhs[0]);
				mxDestroyArray(rhs[0]);
			}
			else
				err = read_problem_sparse(prhs[0], prhs[1]);
		}
		else
			err = read_problem_dense(prhs[0], prhs[1]);

		// svmtrain's original code
		error_msg = svm_check_parameter(&prob, &param);

		if(err || error_msg)
		{
			if (error_msg != NULL)
				mexPrintf("Error: %s\n", error_msg);
			svm_destroy_param(&param);
			free(prob.y);
			free(prob.x);
			free(x_space);
			fake_answer(nlhs, plhs);
			return;
		}

		if(cross_validation)
		{
			double *ptr;
			plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL);
			ptr = mxGetPr(plhs[0]);
			ptr[0] = do_cross_validation();
		}
		else
		{
			int nr_feat = (int)mxGetN(prhs[1]);
			const char *error_msg;
			model = svm_train(&prob, &param);
			error_msg = model_to_matlab_structure(plhs, nr_feat, model);
			if(error_msg)
				mexPrintf("Error: can't convert libsvm model to matrix structure: %s\n", error_msg);
			svm_free_and_destroy_model(&model);
		}
		svm_destroy_param(&param);
		free(prob.y);
		free(prob.x);
		free(x_space);
	}
	else
	{
		exit_with_help();
		fake_answer(nlhs, plhs);
		return;
	}
}
示例#28
0
int main(int argc, char** argv)
{
    Parameters param;

    // [-d] <fz_c1> <fz_c2> <fz_c3> <fn_c1> <fn_c2> <fn_c3> <alpha> <stride> <n_img> [<pz_c1> <pz_c2> <pz_c3> <nz_c1> <nz_c2> <nz_c3>]
    // -d : diferentes los tamaños de filtro, normalización y pulling
    int i = 1;
    bool diferents = false;
    if ((argc == 10) || (argc == 17)){
        if (argv[i][0] == '-') {
            if (strcmp(argv[i], "-d") == 0) {
                diferents = true;
                i++;
            }
            else {
                exit_with_help();
            }
        }

        if (diferents && argc != 17) exit_with_help();

        param.fz_c1 = atoi(argv[i++]);
        param.fz_c2 = atoi(argv[i++]);
        param.fz_c3 = atoi(argv[i++]);
        param.fn_c1 = atoi(argv[i++]);
        param.fn_c2 = atoi(argv[i++]);
        param.fn_c3 = atoi(argv[i++]);
        param.alpha = atof(argv[i++]);
        param.stride = atoi(argv[i++]);
        param.n_img = atol(argv[i++]);

        if (diferents) {
            param.pz_c1 = atoi(argv[i++]);
            param.pz_c2 = atoi(argv[i++]);
            param.pz_c3 = atoi(argv[i++]);
            param.nz_c1 = atoi(argv[i++]);
            param.nz_c2 = atoi(argv[i++]);
            param.nz_c3 = atoi(argv[i++]);
        }
        else{
            param.pz_c1 = param.nz_c1 = param.fz_c1;
            param.pz_c2 = param.nz_c2 = param.fz_c2;
            param.pz_c3 = param.nz_c3 = param.fz_c3;
        }

        param.activation = ACTIVATION_MAX;
        //return EXIT_SUCCESS;
    }
    else {
        //printf("fallo argumentos: %d\n", argc);
        exit_with_help();
    }

    //printf(" params: %d, %d, %d, %d, %d, %d, %d\n", param.fz_c1, param.fz_c2, param.fz_c3, param.fn_c1, param.fn_c2, param.fn_c3, param.n_img);

    long loops;

    /*int filterSize = atoi(argv[1]);
    int n = atoi(argv[2]);
    int n2 =atoi(argv[3]);
    int n3 =atoi(argv[4]);
    int stride = atoi(argv[5]);
    float radio = atof(argv[6]);
    float alpha = atof(argv[7]);
    int normalizationSize = atoi(argv[8]);
    int numimages = atoi(argv[9]);
    int activation = ACTIVATION_MAX;*/


    srand(time(NULL));
    //Generate Random Filter Banks
    MultibandKernel **kernels1 = generateKernelBank(param.fz_c1, param.fz_c1, 1, param.fn_c1);
    MultibandKernel **kernels2 = generateKernelBank(param.fz_c2, param.fz_c2, param.fn_c1,param.fn_c2);
    MultibandKernel **kernels3 = generateKernelBank(param.fz_c3, param.fz_c3, param.fn_c2, param.fn_c3);
    printf("Created Multiband Kernels for convolution\n");



    printf("Started bucle\n");

    #pragma omp parallel for private(loops) num_threads(16)
    for(loops=0; loops<param.n_img; loops++){
        printf("Image %d\n", loops+1);
        body(param, kernels1, kernels2, kernels3);
    }

    for(i=0; i<param.fn_c1; i++){
        DestroyMultibandKernel(&kernels1[i]);
    }
    for(i=0; i<param.fn_c2; i++){
        DestroyMultibandKernel(&kernels2[i]);
    }
    for(i=0; i<param.fn_c3; i++){
        DestroyMultibandKernel(&kernels3[i]);
    }

    free(kernels1);
    free(kernels2);
    free(kernels3);


    /*struct stat st = {0};
    if (stat("directorioPrueba", &st) == -1) {
        if (mkdir("directorioPrueba", 0777) == -1){
            Error("cannot create directory.", "WriteMultibandImageToGrayImages");
        }
    }
    char name[30] = "";
    char extencion[10] = "";
    char file[] = "nombrearchivo.extencion";
    char *ptc;

    ptc = strchr(file, '.');
    strcpy(extencion, ptc+1);
    *ptc = '\0';
    strcpy(name, file);

    printf("name: %s, ext: %s", name, extencion);
    FILE *fp=NULL;
    fp = fopen("directorioPrueba/img1.img", "wb");
    fclose(fp);*/
    return 0;
}
示例#29
0
int main(int argc,char **argv)
{
	int i,index;
	FILE *fp;
	char *save_filename = NULL;
	char *restore_filename = NULL;

	for(i=1;i<argc;i++)
	{
		if(argv[i][0] != '-') break;
		++i;
		switch(argv[i-1][1])
		{
			case 'l': lower = atof(argv[i]); break;
			case 'u': upper = atof(argv[i]); break;
			case 'y':
				y_lower = atof(argv[i]);
				++i;
				y_upper = atof(argv[i]);
				y_scaling = 1;
				break;
			case 's': save_filename = argv[i]; break;
			case 'r': restore_filename = argv[i]; break;
			default:
				fprintf(stderr,"unknown option\n");
				exit_with_help();
		}
	}

	if(!(upper > lower) || (y_scaling && !(y_upper > y_lower)))
	{
		fprintf(stderr,"inconsistent lower/upper specification\n");
		exit(1);
	}
	
	if(argc != i+1) 
		exit_with_help();

	fp=fopen(argv[i],"r");
	
	if(fp==NULL)
	{
		fprintf(stderr,"can't open file %s\n", argv[i]);
		exit(1);
	}

	line = (char *) malloc(max_line_len*sizeof(char));

#define SKIP_TARGET\
	while(isspace(*p)) ++p;\
	while(!isspace(*p)) ++p;

#define SKIP_ELEMENT\
	while(*p!=':') ++p;\
	++p;\
	while(isspace(*p)) ++p;\
	while(*p && !isspace(*p)) ++p;
	
	/* assumption: min index of attributes is 1 */
	/* pass 1: find out max index of attributes */
	max_index = 0;
	while(readline(fp)!=NULL)
	{
		char *p=line;

		SKIP_TARGET

		while(sscanf(p,"%d:%*f",&index)==1)
		{
			max_index = max(max_index, index);
			SKIP_ELEMENT
		}		
	}
	
	feature_max = (double *)malloc((max_index+1)* sizeof(double));
	feature_min = (double *)malloc((max_index+1)* sizeof(double));
	
	if(feature_max == NULL || feature_min == NULL)
	{
		fprintf(stderr,"can't allocate enough memory\n");
		exit(1);
	}

	for(i=0;i<=max_index;i++)
	{
		feature_max[i]=-DBL_MAX;
		feature_min[i]=DBL_MAX;
	}

	rewind(fp);

	/* pass 2: find out min/max value */
	while(readline(fp)!=NULL)
	{
		char *p=line;
		int next_index=1;
		double target;
		double value;

		sscanf(p,"%lf",&target);
		y_max = max(y_max,target);
		y_min = min(y_min,target);
		
		SKIP_TARGET

		while(sscanf(p,"%d:%lf",&index,&value)==2)
		{
			for(i=next_index;i<index;i++)
			{
				feature_max[i]=max(feature_max[i],0);
				feature_min[i]=min(feature_min[i],0);
			}
			
			feature_max[index]=max(feature_max[index],value);
			feature_min[index]=min(feature_min[index],value);

			SKIP_ELEMENT
			next_index=index+1;
		}		

		for(i=next_index;i<=max_index;i++)
		{
			feature_max[i]=max(feature_max[i],0);
			feature_min[i]=min(feature_min[i],0);
		}	
	}

	rewind(fp);

	/* pass 2.5: save/restore feature_min/feature_max */
	
	if(restore_filename)
	{
		FILE *fp_restore = fopen(restore_filename,"r");
		int idx, c;
		double fmin, fmax;
		
		if(fp_restore==NULL)
		{
			fprintf(stderr,"can't open file %s\n", restore_filename);
			exit(1);
		}
		if((c = fgetc(fp_restore)) == 'y')
		{
			fscanf(fp_restore, "%lf %lf\n", &y_lower, &y_upper);
			fscanf(fp_restore, "%lf %lf\n", &y_min, &y_max);
			y_scaling = 1;
		}
		else
			ungetc(c, fp_restore);

		if (fgetc(fp_restore) == 'x') {
			fscanf(fp_restore, "%lf %lf\n", &lower, &upper);
			while(fscanf(fp_restore,"%d %lf %lf\n",&idx,&fmin,&fmax)==3)
			{
				if(idx<=max_index)
				{
					feature_min[idx] = fmin;
					feature_max[idx] = fmax;
				}
			}
		}
		fclose(fp_restore);
	}
	
	if(save_filename)
	{
		FILE *fp_save = fopen(save_filename,"w");
		if(fp_save==NULL)
		{
			fprintf(stderr,"can't open file %s\n", save_filename);
			exit(1);
		}
		if(y_scaling)
		{
			fprintf(fp_save, "y\n");
			fprintf(fp_save, "%.16g %.16g\n", y_lower, y_upper);
			fprintf(fp_save, "%.16g %.16g\n", y_min, y_max);
		}
		fprintf(fp_save, "x\n");
		fprintf(fp_save, "%.16g %.16g\n", lower, upper);
		for(i=1;i<=max_index;i++)
		{
			if(feature_min[i]!=feature_max[i])
				fprintf(fp_save,"%d %.16g %.16g\n",i,feature_min[i],feature_max[i]);
		}
		fclose(fp_save);
	}
	
	/* pass 3: scale */
	while(readline(fp)!=NULL)
	{
		char *p=line;
		int next_index=1;
		int index;
		double target;
		double value;
		
		sscanf(p,"%lf",&target);
		output_target(target);

		SKIP_TARGET

		while(sscanf(p,"%d:%lf",&index,&value)==2)
		{
			for(i=next_index;i<index;i++)
				output(i,0);
			
			output(index,value);

			SKIP_ELEMENT
			next_index=index+1;
		}		

		for(i=next_index;i<=max_index;i++)
			output(i,0);

		printf("\n");
	}

	free(line);
	free(feature_max);
	free(feature_min);
	fclose(fp);
	return 0;
}
示例#30
0
int parse_command_line(int argc, char **argv, char *input_file_name, char *model_file_name)
{
	int i;
	char cmd[CMD_LEN];
	// default values
	param.solver_type = L2LOSS_SVM_DUAL;
	param.C = 1;
	param.eps = INF; // see setting below
	param.nr_weight = 0;
	param.weight_label = NULL;
	param.weight = NULL;
	cross_validation_flag = 0;
	col_format_flag = 0;
	param.flag_poly = 0;
	param.random = 0; // not for random sampling.

	param.coef0 = 1.0;
	param.gamma = 1.0;
	bias = -1;
	param.t = 1;


	param.initial_type = 0;
	param.nB = 2;
	param.K = 2000;
	param.max_iteraion = 9;
	
	// parse options
	for(i=1;i<argc;i++)
	{
		if(argv[i][0] != '-') break;
		++i;
		if(i>=argc && argv[i-1][1] != 'z') // since option -z has no parameter
			return 1;
		switch(argv[i-1][1])
		{
			case 's':
				param.solver_type = atoi(argv[i]);
				break;
			case 'c':
				param.C = atof(argv[i]);
				break;
			case 'e':
				param.eps = atof(argv[i]);
				break;
			case 'p':
				param.flag_poly = atoi(argv[i]);
				break;
			case 'b':
				bias = atof(argv[i]);
				break;
			case 'B':
				param.nB = atoi(argv[i]);
				break;
			case 't':
				param.t = atoi(argv[i]);
				break;
			case 'I':
				param.initial_type = atoi(argv[i]);
				break;
			case 'v':
				cross_validation_flag = 1;
				nr_fold = atoi(argv[i]);
				if(nr_fold < 2)
				{
					//mexPrintf("n-fold cross validation: n must >= 2\n");
					return 1;
				}
				break;
			case 'w':
				++param.nr_weight;
				param.weight_label = (int *) realloc(param.weight_label,sizeof(int)*param.nr_weight);
				param.weight = (double *) realloc(param.weight,sizeof(double)*param.nr_weight);
				param.weight_label[param.nr_weight-1] = atoi(&argv[i-1][2]);
				param.weight[param.nr_weight-1] = atof(argv[i]);
				break;
			case 'r':
				param.coef0 = atof(argv[i]);
				break;

			case 'g':
				param.gamma = atof(argv[i]);
				break;
			case 'm':
				param.max_iteraion = atof(argv[i]);
				break;
			case 'k':
				param.K = atof(argv[i]);
				break;
			case 'q':
				//print_func = &print_null;
				i--;
			default:
				printf("unknown option\n");
				//mexPrintf("unknown option\n");
				return 1;
		}
	}

	if(param.eps == INF)
	{
		if(param.solver_type == L2_LR || param.solver_type == L2LOSS_SVM)
			param.eps = 0.01;
		else if(param.solver_type == L2LOSS_SVM_DUAL || param.solver_type == L1LOSS_SVM_DUAL || param.solver_type == MCSVM_CS)
		{
			param.eps = 0.1;
		}
		else
		{
			param.eps = 0.01;
		}
	}
	prob.bias = bias;

	prob.coef0 = param.coef0;
	prob.gamma = param.gamma;

	  if(i>=argc)
		exit_with_help();

	strcpy(input_file_name, argv[i]);

	if(i<argc-1)
		strcpy(model_file_name,argv[i+1]);
	else
	{
		char *p = strrchr(argv[i],'/');
		if(p==NULL)
			p = argv[i];
		else
			++p;
		sprintf(model_file_name,"%s.model",p);
	}

	if(param.eps == INF)
	{
		if(param.solver_type == L2_LR || param.solver_type == L2LOSS_SVM)
			param.eps = 0.01;
		else if(param.solver_type == L2LOSS_SVM_DUAL || param.solver_type == L1LOSS_SVM_DUAL || param.solver_type == MCSVM_CS)
		{
			param.eps = 0.1;
		}else
		{
			param.eps = 0.1;
		}
	}
param.eps = 0.1;
	prob.bias = bias;
	return 0;
}