10 "Usage: svm-scale [options] data_filename\n" 12 "-l lower : x scaling lower limit (default -1)\n" 13 "-u upper : x scaling upper limit (default +1)\n" 14 "-y y_lower y_upper : y scaling limits (default: no y scaling)\n" 15 "-s save_filename : save scaling parameters to save_filename\n" 16 "-r restore_filename : restore scaling parameters from restore_filename\n" 33 #define max(x,y) (((x)>(y))?(x):(y)) 34 #define min(x,y) (((x)<(y))?(x):(y)) 40 int main(
int argc,
char **argv)
43 FILE *fp, *fp_restore = NULL;
44 char *save_filename = NULL;
45 char *restore_filename = NULL;
49 if(argv[i][0] !=
'-')
break;
53 case 'l':
lower = atof(argv[i]);
break;
54 case 'u':
upper = atof(argv[i]);
break;
61 case 's': save_filename = argv[i];
break;
62 case 'r': restore_filename = argv[i];
break;
64 fprintf(stderr,
"unknown option\n");
71 fprintf(stderr,
"inconsistent lower/upper specification\n");
75 if(restore_filename && save_filename)
77 fprintf(stderr,
"cannot use -r and -s simultaneously\n");
84 fp=fopen(argv[i],
"r");
88 fprintf(stderr,
"can't open file %s\n", argv[i]);
95 while(isspace(*p)) ++p;\ 96 while(!isspace(*p)) ++p; 101 while(isspace(*p)) ++p;\ 102 while(*p && !isspace(*p)) ++p; 112 fp_restore = fopen(restore_filename,
"r");
115 fprintf(stderr,
"can't open file %s\n", restore_filename);
119 c = fgetc(fp_restore);
129 while(fscanf(fp_restore,
"%d %*f %*f\n",&idx) == 1)
140 while(sscanf(p,
"%d:%*f",&index)==1)
154 fprintf(stderr,
"can't allocate enough memory\n");
172 sscanf(p,
"%lf",&target);
178 while(sscanf(p,
"%d:%lf",&index,&value)==2)
180 for(i=next_index;i<
index;i++)
210 if((c = fgetc(fp_restore)) ==
'y')
213 fscanf(fp_restore,
"%lf %lf\n", &
y_min, &
y_max);
217 ungetc(c, fp_restore);
219 if (fgetc(fp_restore) ==
'x') {
220 fscanf(fp_restore,
"%lf %lf\n", &
lower, &
upper);
221 while(fscanf(fp_restore,
"%d %lf %lf\n",&idx,&fmin,&fmax)==3)
235 FILE *fp_save = fopen(save_filename,
"w");
238 fprintf(stderr,
"can't open file %s\n", save_filename);
243 fprintf(fp_save,
"y\n");
245 fprintf(fp_save,
"%.16g %.16g\n",
y_min,
y_max);
247 fprintf(fp_save,
"x\n");
248 fprintf(fp_save,
"%.16g %.16g\n",
lower,
upper);
265 sscanf(p,
"%lf",&target);
270 while(sscanf(p,
"%d:%lf",&index,&value)==2)
272 for(i=next_index;i<
index;i++)
289 "WARNING: original #nonzeros %ld\n" 290 " new #nonzeros %ld\n" 291 "Use -l 0 if many original feature values are zeros\n",
308 while(strrchr(
line,
'\n') == NULL)
312 len = (int) strlen(
line);
325 else if(value ==
y_max)
350 printf(
"%d:%g ",index, value);
long int new_num_nonzeros
void output_target(double value)
char * readline(FILE *input)
void output(int index, double value)
int main(int argc, char **argv)