s32 menu_cb_choose_file (s32 idx, void *param) { s32 curidx = idx; s32 loaded = 0; while (aptMainLoop()) { gspWaitForVBlank(); curidx = print_file_list(curidx, &g_file_list); u32 kDown = wait_key(); if (kDown & KEY_B) { break; } else if (kDown & KEY_A) { consoleClear(); loaded = menu_execute_function(curidx, &g_file_list, &curidx); printf("%s\n", loaded? "[+] Success":"[!] Failure"); wait_any_key(); if (loaded) break; } else if (kDown & KEY_UP) { curidx--; } else if (kDown & KEY_DOWN) { curidx++; } gfxFlushBuffers(); gfxSwapBuffers(); } return 0; }
static void select_items(int n) { int fsel = 0; while (42) { if (n > 0) print_item(fsel, STATUS_BG, STATUS_FG); switch (wait_any_key()) { case KEY_ENTER: setvar(V_sel_item, intobj[fsel]); goto exit_select; case KEY_ESCAPE: setvar(V_sel_item, 0xff); goto exit_select; case KEY_UP: if (fsel >= 2) fsel -= 2; break; case KEY_DOWN: if (fsel + 2 < n) fsel += 2; break; case KEY_LEFT: if (fsel % 2 == 1) fsel--; break; case KEY_RIGHT: if (fsel % 2 == 0 && fsel + 1 < n) fsel++; break; case BUTTON_LEFT:{ int i = find_item(); if (i >= 0 && i < n) { setvar(V_sel_item, intobj[fsel = i]); debugC(6, kDebugLevelInventory, "item found: %d", fsel); show_items(); print_item(fsel, STATUS_BG, STATUS_FG); do_update(); goto exit_select; } break; } default: break; } show_items(); do_update(); } exit_select: debugC(6, kDebugLevelInventory, "selected: %d", fsel); }
/** * Display inventory items. */ void inventory () { int old_fg, old_bg; int n; /* screen is white with black text */ old_fg = game.color_fg; old_bg = game.color_bg; game.color_fg = 0; game.color_bg = 15; clear_screen (game.color_bg); print_text (YOUHAVE_MSG, 0, YOUHAVE_X, YOUHAVE_Y, 40, STATUS_FG, STATUS_BG); /* FIXME: doesn't check if objects overflow off screen... */ intobj = malloc (4 + game.num_objects); memset(intobj, 0, (4 + game.num_objects)); n = show_items (); if (getflag (F_status_selects_items)) { print_text (SELECT_MSG, 0, SELECT_X, SELECT_Y, 40, STATUS_FG, STATUS_BG); } else { print_text (ANY_KEY_MSG, 0, ANY_KEY_X, ANY_KEY_Y, 40, STATUS_FG, STATUS_BG); } flush_screen (); /* If flag 13 is set, we want to highlight & select an item. * opon selection, put objnum in var 25. Then on esc put in * var 25 = 0xff. */ if (getflag (F_status_selects_items)) select_items (n); free (intobj); if (!getflag (F_status_selects_items)) wait_any_key(); clear_screen (0); write_status (); show_pic (); game.color_fg = old_fg; game.color_bg = old_bg; game.has_prompt = 0; flush_lines (game.line_user_input, 24); }
s32 main (void) { // Initialize services gfxInitDefault(); // Make sure the settings applied by gfxInitDefault come into effect gfxSwapBuffers(); // Memory for the arm9 payload u32 payload_size = 0x10000; void *payload = malloc(payload_size); if (!payload) goto error; int rc; // Load the arm9 payload into memory FILE *file = fopen("/" LAUNCHER_PATH, "r"); if (!file) goto error; rc = fseek(file, 0x12000, SEEK_SET); if (rc != 0) goto error; fread(payload, payload_size, 1, file); if (ferror(file) != 0) goto error; fclose(file); if (brahma_init()) { rc = load_arm9_payload_from_mem(payload, payload_size); if (rc != 1) goto error; firm_reboot(); brahma_exit(); } free(payload); gfxExit(); // Return to hbmenu return 0; error: consoleInit(GFX_BOTTOM, NULL); printf("An error occurred while loading the payload.\nMake sure your launcher is located at:\n/" LAUNCHER_PATH); wait_any_key(); if (payload) free(payload); gfxExit(); return 1; }
s32 main (void) { // Initialize services srvInit(); aptInit(); hidInit(NULL); gfxInitDefault(); fsInit(); sdmcInit(); hbInit(); qtmInit(); Handle fileHandle; u32 bytesRead; FS_archive sdmcArchive=(FS_archive){ARCH_SDMC, (FS_path){PATH_EMPTY, 1, (u8*)""}}; FS_path filePath=FS_makePath(PATH_CHAR, "/rxTools.dat"); Result ret=FSUSER_OpenFileDirectly(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_NONE); if(ret) goto EXIT; FSFILE_Read(fileHandle, &bytesRead, 0x20000, 0x14400000, 320*1024); FSFILE_Close(fileHandle); consoleInit(GFX_BOTTOM, NULL); if (brahma_init()) { quick_boot_firm(1); printf("[!] Quickload failed\n"); brahma_exit(); } else { printf("* BRAHMA *\n\n[!]Not enough memory\n"); wait_any_key(); } EXIT: hbExit(); sdmcExit(); fsExit(); gfxExit(); hidExit(); aptExit(); srvExit(); // Return to hbmenu return 0; }
void print_help() { printf("\nSVM-struct learning module: %s, %s, %s\n",INST_NAME,INST_VERSION,INST_VERSION_DATE); printf(" includes SVM-struct %s for learning complex outputs, %s\n",STRUCT_VERSION,STRUCT_VERSION_DATE); printf(" includes SVM-light %s quadratic optimizer, %s\n",VERSION,VERSION_DATE); copyright_notice(); printf(" usage: svm_struct_learn [options] example_file model_file\n\n"); printf("Arguments:\n"); printf(" example_file-> file with training data\n"); printf(" model_file -> file to store learned decision rule in\n"); printf("General Options:\n"); printf(" -? -> this help\n"); printf(" -v [0..3] -> verbosity level (default 1)\n"); printf(" -y [0..3] -> verbosity level for svm_light (default 0)\n"); printf("Learning Options:\n"); printf(" -c float -> C: trade-off between training error\n"); printf(" and margin (default 0.01)\n"); printf(" -p [1,2] -> L-norm to use for slack variables. Use 1 for L1-norm,\n"); printf(" use 2 for squared slacks. (default 1)\n"); printf(" -o [1,2] -> Rescaling method to use for loss.\n"); printf(" 1: slack rescaling\n"); printf(" 2: margin rescaling\n"); printf(" (default %d)\n",DEFAULT_RESCALING); printf(" -l [0..] -> Loss function to use.\n"); printf(" 0: zero/one loss\n"); printf(" ?: see below in application specific options\n"); printf(" (default %d)\n",DEFAULT_LOSS_FCT); printf("Optimization Options (see [2][5]):\n"); printf(" -w [0,..,9] -> choice of structural learning algorithm (default %d):\n",(int)DEFAULT_ALG_TYPE); printf(" 0: n-slack algorithm described in [2]\n"); printf(" 1: n-slack algorithm with shrinking heuristic\n"); printf(" 2: 1-slack algorithm (primal) described in [5]\n"); printf(" 3: 1-slack algorithm (dual) described in [5]\n"); printf(" 4: 1-slack algorithm (dual) with constraint cache [5]\n"); printf(" 9: custom algorithm in svm_struct_learn_custom.c\n"); printf(" -e float -> epsilon: allow that tolerance for termination\n"); printf(" criterion (default %f)\n",DEFAULT_EPS); printf(" -k [1..] -> number of new constraints to accumulate before\n"); printf(" recomputing the QP solution (default 100) (-w 0 and 1 only)\n"); printf(" -f [5..] -> number of constraints to cache for each example\n"); printf(" (default 5) (used with -w 4)\n"); printf(" -b [1..100] -> percentage of training set for which to refresh cache\n"); printf(" when no epsilon violated constraint can be constructed\n"); printf(" from current cache (default 100%%) (used with -w 4)\n"); printf("SVM-light Options for Solving QP Subproblems (see [3]):\n"); printf(" -n [2..q] -> number of new variables entering the working set\n"); printf(" in each svm-light iteration (default n = q). \n"); printf(" Set n < q to prevent zig-zagging.\n"); printf(" -m [5..] -> size of svm-light cache for kernel evaluations in MB\n"); printf(" (default 40) (used only for -w 1 with kernels)\n"); printf(" -h [5..] -> number of svm-light iterations a variable needs to be\n"); printf(" optimal before considered for shrinking (default 100)\n"); printf(" -# int -> terminate svm-light QP subproblem optimization, if no\n"); printf(" progress after this number of iterations.\n"); printf(" (default 100000)\n"); printf("Kernel Options:\n"); printf(" -t int -> type of kernel function:\n"); printf(" 0: linear (default)\n"); printf(" 1: polynomial (s a*b+c)^d\n"); printf(" 2: radial basis function exp(-gamma ||a-b||^2)\n"); printf(" 3: sigmoid tanh(s a*b + c)\n"); printf(" 4: user defined kernel from kernel.h\n"); printf(" -d int -> parameter d in polynomial kernel\n"); printf(" -g float -> parameter gamma in rbf kernel\n"); printf(" -s float -> parameter s in sigmoid/poly kernel\n"); printf(" -r float -> parameter c in sigmoid/poly kernel\n"); printf(" -u string -> parameter of user defined kernel\n"); printf("Output Options:\n"); printf(" -a string -> write all alphas to this file after learning\n"); printf(" (in the same order as in the training set)\n"); printf("Application-Specific Options:\n"); print_struct_help(); wait_any_key(); printf("\nMore details in:\n"); printf("[1] T. Joachims, Learning to Align Sequences: A Maximum Margin Aproach.\n"); printf(" Technical Report, September, 2003.\n"); printf("[2] I. Tsochantaridis, T. Joachims, T. Hofmann, and Y. Altun, Large Margin\n"); printf(" Methods for Structured and Interdependent Output Variables, Journal\n"); printf(" of Machine Learning Research (JMLR), Vol. 6(Sep):1453-1484, 2005.\n"); printf("[3] T. Joachims, Making Large-Scale SVM Learning Practical. Advances in\n"); printf(" Kernel Methods - Support Vector Learning, B. Schölkopf and C. Burges and\n"); printf(" A. Smola (ed.), MIT Press, 1999.\n"); printf("[4] T. Joachims, Learning to Classify Text Using Support Vector\n"); printf(" Machines: Methods, Theory, and Algorithms. Dissertation, Kluwer,\n"); printf(" 2002.\n"); printf("[5] T. Joachims, T. Finley, Chun-Nam Yu, Cutting-Plane Training of Structural\n"); printf(" SVMs, Machine Learning Journal, to appear.\n"); }
void read_input_parameters(int argc,char *argv[],char *trainfile, char *modelfile, long *verbosity,long *struct_verbosity, STRUCT_LEARN_PARM *struct_parm, LEARN_PARM *learn_parm, KERNEL_PARM *kernel_parm, int *alg_type) { long i; char type[100]; /* set default */ (*alg_type)=DEFAULT_ALG_TYPE; struct_parm->C=-0.01; struct_parm->slack_norm=1; struct_parm->epsilon=DEFAULT_EPS; struct_parm->custom_argc=0; struct_parm->loss_function=DEFAULT_LOSS_FCT; struct_parm->loss_type=DEFAULT_RESCALING; struct_parm->newconstretrain=100; struct_parm->ccache_size=5; struct_parm->batch_size=100; strcpy (modelfile, "svm_struct_model"); strcpy (learn_parm->predfile, "trans_predictions"); strcpy (learn_parm->alphafile, ""); (*verbosity)=0;/*verbosity for svm_light*/ (*struct_verbosity)=1; /*verbosity for struct learning portion*/ learn_parm->biased_hyperplane=1; learn_parm->remove_inconsistent=0; learn_parm->skip_final_opt_check=0; learn_parm->svm_maxqpsize=10; learn_parm->svm_newvarsinqp=0; learn_parm->svm_iter_to_shrink=-9999; learn_parm->maxiter=100000; learn_parm->kernel_cache_size=40; learn_parm->svm_c=99999999; /* overridden by struct_parm->C */ learn_parm->eps=0.001; /* overridden by struct_parm->epsilon */ learn_parm->transduction_posratio=-1.0; learn_parm->svm_costratio=1.0; learn_parm->svm_costratio_unlab=1.0; learn_parm->svm_unlabbound=1E-5; learn_parm->epsilon_crit=0.001; learn_parm->epsilon_a=1E-10; /* changed from 1e-15 */ learn_parm->compute_loo=0; learn_parm->rho=1.0; learn_parm->xa_depth=0; kernel_parm->kernel_type=0; kernel_parm->poly_degree=3; kernel_parm->rbf_gamma=1.0; kernel_parm->coef_lin=1; kernel_parm->coef_const=1; strcpy(kernel_parm->custom,"empty"); strcpy(type,"c"); for(i=1;(i<argc) && ((argv[i])[0] == '-');i++) { switch ((argv[i])[1]) { case '?': print_help(); exit(0); case 'a': i++; strcpy(learn_parm->alphafile,argv[i]); break; case 'c': i++; struct_parm->C=atof(argv[i]); break; case 'p': i++; struct_parm->slack_norm=atol(argv[i]); break; case 'e': i++; struct_parm->epsilon=atof(argv[i]); break; case 'k': i++; struct_parm->newconstretrain=atol(argv[i]); break; case 'h': i++; learn_parm->svm_iter_to_shrink=atol(argv[i]); break; case '#': i++; learn_parm->maxiter=atol(argv[i]); break; case 'm': i++; learn_parm->kernel_cache_size=atol(argv[i]); break; case 'w': i++; (*alg_type)=atol(argv[i]); break; case 'o': i++; struct_parm->loss_type=atol(argv[i]); break; case 'n': i++; learn_parm->svm_newvarsinqp=atol(argv[i]); break; case 'q': i++; learn_parm->svm_maxqpsize=atol(argv[i]); break; case 'l': i++; struct_parm->loss_function=atol(argv[i]); break; case 'f': i++; struct_parm->ccache_size=atol(argv[i]); break; case 'b': i++; struct_parm->batch_size=atof(argv[i]); break; case 't': i++; kernel_parm->kernel_type=atol(argv[i]); break; case 'd': i++; kernel_parm->poly_degree=atol(argv[i]); break; case 'g': i++; kernel_parm->rbf_gamma=atof(argv[i]); break; case 's': i++; kernel_parm->coef_lin=atof(argv[i]); break; case 'r': i++; kernel_parm->coef_const=atof(argv[i]); break; case 'u': i++; strcpy(kernel_parm->custom,argv[i]); break; case '-': strcpy(struct_parm->custom_argv[struct_parm->custom_argc++],argv[i]);i++; strcpy(struct_parm->custom_argv[struct_parm->custom_argc++],argv[i]);break; case 'v': i++; (*struct_verbosity)=atol(argv[i]); break; case 'y': i++; (*verbosity)=atol(argv[i]); break; default: printf("\nUnrecognized option %s!\n\n",argv[i]); print_help(); exit(0); } } if(i>=argc) { printf("\nNot enough input parameters!\n\n"); wait_any_key(); print_help(); exit(0); } strcpy (trainfile, argv[i]); if((i+1)<argc) { strcpy (modelfile, argv[i+1]); } if(learn_parm->svm_iter_to_shrink == -9999) { learn_parm->svm_iter_to_shrink=100; } if((learn_parm->skip_final_opt_check) && (kernel_parm->kernel_type == LINEAR)) { printf("\nIt does not make sense to skip the final optimality check for linear kernels.\n\n"); learn_parm->skip_final_opt_check=0; } if((learn_parm->skip_final_opt_check) && (learn_parm->remove_inconsistent)) { printf("\nIt is necessary to do the final optimality check when removing inconsistent \nexamples.\n"); wait_any_key(); print_help(); exit(0); } if((learn_parm->svm_maxqpsize<2)) { printf("\nMaximum size of QP-subproblems not in valid range: %ld [2..]\n",learn_parm->svm_maxqpsize); wait_any_key(); print_help(); exit(0); } if((learn_parm->svm_maxqpsize<learn_parm->svm_newvarsinqp)) { printf("\nMaximum size of QP-subproblems [%ld] must be larger than the number of\n",learn_parm->svm_maxqpsize); printf("new variables [%ld] entering the working set in each iteration.\n",learn_parm->svm_newvarsinqp); wait_any_key(); print_help(); exit(0); } if(learn_parm->svm_iter_to_shrink<1) { printf("\nMaximum number of iterations for shrinking not in valid range: %ld [1,..]\n",learn_parm->svm_iter_to_shrink); wait_any_key(); print_help(); exit(0); } if(struct_parm->C<0) { printf("\nYou have to specify a value for the parameter '-c' (C>0)!\n\n"); wait_any_key(); print_help(); exit(0); } if(((*alg_type) < 0) || (((*alg_type) > 5) && ((*alg_type) != 9))) { printf("\nAlgorithm type must be either '0', '1', '2', '3', '4', or '9'!\n\n"); wait_any_key(); print_help(); exit(0); } if(learn_parm->transduction_posratio>1) { printf("\nThe fraction of unlabeled examples to classify as positives must\n"); printf("be less than 1.0 !!!\n\n"); wait_any_key(); print_help(); exit(0); } if(learn_parm->svm_costratio<=0) { printf("\nThe COSTRATIO parameter must be greater than zero!\n\n"); wait_any_key(); print_help(); exit(0); } if(struct_parm->epsilon<=0) { printf("\nThe epsilon parameter must be greater than zero!\n\n"); wait_any_key(); print_help(); exit(0); } if((struct_parm->ccache_size<=0) && ((*alg_type) == 4)) { printf("\nThe cache size must be at least 1!\n\n"); wait_any_key(); print_help(); exit(0); } if(((struct_parm->batch_size<=0) || (struct_parm->batch_size>100)) && ((*alg_type) == 4)) { printf("\nThe batch size must be in the interval ]0,100]!\n\n"); wait_any_key(); print_help(); exit(0); } if((struct_parm->slack_norm<1) || (struct_parm->slack_norm>2)) { printf("\nThe norm of the slacks must be either 1 (L1-norm) or 2 (L2-norm)!\n\n"); wait_any_key(); print_help(); exit(0); } if((struct_parm->loss_type != SLACK_RESCALING) && (struct_parm->loss_type != MARGIN_RESCALING)) { printf("\nThe loss type must be either 1 (slack rescaling) or 2 (margin rescaling)!\n\n"); wait_any_key(); print_help(); exit(0); } if(learn_parm->rho<0) { printf("\nThe parameter rho for xi/alpha-estimates and leave-one-out pruning must\n"); printf("be greater than zero (typically 1.0 or 2.0, see T. Joachims, Estimating the\n"); printf("Generalization Performance of an SVM Efficiently, ICML, 2000.)!\n\n"); wait_any_key(); print_help(); exit(0); } if((learn_parm->xa_depth<0) || (learn_parm->xa_depth>100)) { printf("\nThe parameter depth for ext. xi/alpha-estimates must be in [0..100] (zero\n"); printf("for switching to the conventional xa/estimates described in T. Joachims,\n"); printf("Estimating the Generalization Performance of an SVM Efficiently, ICML, 2000.)\n"); wait_any_key(); print_help(); exit(0); } parse_struct_parameters(struct_parm); }
void print_help() { printf("\nSVM-light %s: Support Vector Machine, learning module %s\n",VERSION,VERSION_DATE); copyright_notice(); printf(" usage: svm_learn [options] example_file model_file\n\n"); printf("Arguments:\n"); printf(" example_file-> file with training data\n"); printf(" model_file -> file to store learned decision rule in\n"); printf("General options:\n"); printf(" -? -> this help\n"); printf(" -v [0..3] -> verbosity level (default 1)\n"); printf("Learning options:\n"); printf(" -z {c,r,p} -> select between classification (c), regression (r),\n"); printf(" and preference ranking (p) (default classification)\n"); printf(" -c float -> C: trade-off between training error\n"); printf(" and margin (default [avg. x*x]^-1)\n"); printf(" -w [0..] -> epsilon width of tube for regression\n"); printf(" (default 0.1)\n"); printf(" -j float -> Cost: cost-factor, by which training errors on\n"); printf(" positive examples outweight errors on negative\n"); printf(" examples (default 1) (see [4])\n"); printf(" -b [0,1] -> use biased hyperplane (i.e. x*w+b>0) instead\n"); printf(" of unbiased hyperplane (i.e. x*w>0) (default 1)\n"); printf(" -i [0,1] -> remove inconsistent training examples\n"); printf(" and retrain (default 0)\n"); printf("Performance estimation options:\n"); printf(" -x [0,1] -> compute leave-one-out estimates (default 0)\n"); printf(" (see [5])\n"); printf(" -o ]0..2] -> value of rho for XiAlpha-estimator and for pruning\n"); printf(" leave-one-out computation (default 1.0) (see [2])\n"); printf(" -k [0..100] -> search depth for extended XiAlpha-estimator \n"); printf(" (default 0)\n"); printf("Transduction options (see [3]):\n"); printf(" -p [0..1] -> fraction of unlabeled examples to be classified\n"); printf(" into the positive class (default is the ratio of\n"); printf(" positive and negative examples in the training data)\n"); printf("Kernel options:\n"); printf(" -t int -> type of kernel function:\n"); printf(" 0: linear (default)\n"); printf(" 1: polynomial (s a*b+c)^d\n"); printf(" 2: radial basis function exp(-gamma ||a-b||^2)\n"); printf(" 3: sigmoid tanh(s a*b + c)\n"); printf(" 4: user defined kernel from kernel.h\n"); printf(" -d int -> parameter d in polynomial kernel\n"); printf(" -g float -> parameter gamma in rbf kernel\n"); printf(" -s float -> parameter s in sigmoid/poly kernel\n"); printf(" -r float -> parameter c in sigmoid/poly kernel\n"); printf(" -u string -> parameter of user defined kernel\n"); printf("Optimization options (see [1]):\n"); printf(" -q [2..] -> maximum size of QP-subproblems (default 10)\n"); printf(" -n [2..q] -> number of new variables entering the working set\n"); printf(" in each iteration (default n = q). Set n<q to prevent\n"); printf(" zig-zagging.\n"); printf(" -m [5..] -> size of cache for kernel evaluations in MB (default 40)\n"); printf(" The larger the faster...\n"); printf(" -e float -> eps: Allow that error for termination criterion\n"); printf(" [y [w*x+b] - 1] >= eps (default 0.001)\n"); printf(" -y [0,1] -> restart the optimization from alpha values in file\n"); printf(" specified by -a option. (default 0)\n"); printf(" -h [5..] -> number of iterations a variable needs to be\n"); printf(" optimal before considered for shrinking (default 100)\n"); printf(" -f [0,1] -> do final optimality check for variables removed\n"); printf(" by shrinking. Although this test is usually \n"); printf(" positive, there is no guarantee that the optimum\n"); printf(" was found if the test is omitted. (default 1)\n"); printf(" -y string -> if option is given, reads alphas from file with given\n"); printf(" and uses them as starting point. (default 'disabled')\n"); printf(" -# int -> terminate optimization, if no progress after this\n"); printf(" number of iterations. (default 100000)\n"); printf("Output options:\n"); printf(" -l string -> file to write predicted labels of unlabeled\n"); printf(" examples into after transductive learning\n"); printf(" -a string -> write all alphas to this file after learning\n"); printf(" (in the same order as in the training set)\n"); wait_any_key(); printf("\nMore details in:\n"); printf("[1] T. Joachims, Making Large-Scale SVM Learning Practical. Advances in\n"); printf(" Kernel Methods - Support Vector Learning, B. Scholkopf and C. Burges and\n"); printf(" A. Smola (ed.), MIT Press, 1999.\n"); printf("[2] T. Joachims, Estimating the Generalization performance of an SVM\n"); printf(" Efficiently. International Conference on Machine Learning (ICML), 2000.\n"); printf("[3] T. Joachims, Transductive Inference for Text Classification using Support\n"); printf(" Vector Machines. International Conference on Machine Learning (ICML),\n"); printf(" 1999.\n"); printf("[4] K. Morik, P. Brockhausen, and T. Joachims, Combining statistical learning\n"); printf(" with a knowledge-based approach - A case study in intensive care \n"); printf(" monitoring. International Conference on Machine Learning (ICML), 1999.\n"); printf("[5] T. Joachims, Learning to Classify Text Using Support Vector\n"); printf(" Machines: Methods, Theory, and Algorithms. Dissertation, Kluwer,\n"); printf(" 2002.\n\n"); }
void _read_input_parameters(int argc,char *argv[],char *docfile,char *modelfile, char *restartfile,long *verbosity, LEARN_PARM *learn_parm,KERNEL_PARM *kernel_parm) { long i; char type[100]; /* set default */ set_learning_defaults(learn_parm, kernel_parm); strcpy (modelfile, "svm_model"); strcpy (restartfile, ""); (*verbosity)=1; strcpy(type,"c"); for(i=1;(i<argc) && ((argv[i])[0] == '-');i++) { switch ((argv[i])[1]) { case '?': print_help(); exit(0); case 'z': i++; strcpy(type,argv[i]); break; case 'v': i++; (*verbosity)=atol(argv[i]); break; case 'b': i++; learn_parm->biased_hyperplane=atol(argv[i]); break; case 'i': i++; learn_parm->remove_inconsistent=atol(argv[i]); break; case 'f': i++; learn_parm->skip_final_opt_check=!atol(argv[i]); break; case 'q': i++; learn_parm->svm_maxqpsize=atol(argv[i]); break; case 'n': i++; learn_parm->svm_newvarsinqp=atol(argv[i]); break; case '#': i++; learn_parm->maxiter=atol(argv[i]); break; case 'h': i++; learn_parm->svm_iter_to_shrink=atol(argv[i]); break; case 'm': i++; learn_parm->kernel_cache_size=atol(argv[i]); break; case 'c': i++; learn_parm->svm_c=atof(argv[i]); break; case 'w': i++; learn_parm->eps=atof(argv[i]); break; case 'p': i++; learn_parm->transduction_posratio=atof(argv[i]); break; case 'j': i++; learn_parm->svm_costratio=atof(argv[i]); break; case 'e': i++; learn_parm->epsilon_crit=atof(argv[i]); break; case 'o': i++; learn_parm->rho=atof(argv[i]); break; case 'k': i++; learn_parm->xa_depth=atol(argv[i]); break; case 'x': i++; learn_parm->compute_loo=atol(argv[i]); break; case 't': i++; kernel_parm->kernel_type=atol(argv[i]); break; case 'd': i++; kernel_parm->poly_degree=atol(argv[i]); break; case 'g': i++; kernel_parm->rbf_gamma=atof(argv[i]); break; case 's': i++; kernel_parm->coef_lin=atof(argv[i]); break; case 'r': i++; kernel_parm->coef_const=atof(argv[i]); break; case 'u': i++; strcpy(kernel_parm->custom,argv[i]); break; case 'l': i++; strcpy(learn_parm->predfile,argv[i]); break; case 'a': i++; strcpy(learn_parm->alphafile,argv[i]); break; case 'y': i++; strcpy(restartfile,argv[i]); break; default: printf("\nUnrecognized option %s!\n\n",argv[i]); print_help(); exit(0); } } if(i>=argc) { printf("\nNot enough input parameters!\n\n"); wait_any_key(); print_help(); exit(0); } strcpy (docfile, argv[i]); if((i+1)<argc) { strcpy (modelfile, argv[i+1]); } if(learn_parm->svm_iter_to_shrink == -9999) { if(kernel_parm->kernel_type == LINEAR) learn_parm->svm_iter_to_shrink=2; else learn_parm->svm_iter_to_shrink=100; } if(strcmp(type,"c")==0) { learn_parm->type=CLASSIFICATION; } else if(strcmp(type,"r")==0) { learn_parm->type=REGRESSION; } else if(strcmp(type,"p")==0) { learn_parm->type=RANKING; } else if(strcmp(type,"o")==0) { learn_parm->type=OPTIMIZATION; } else if(strcmp(type,"s")==0) { learn_parm->type=OPTIMIZATION; learn_parm->sharedslack=1; } else { printf("\nUnknown type '%s': Valid types are 'c' (classification), 'r' regession, and 'p' preference ranking.\n",type); wait_any_key(); print_help(); exit(0); } if (!check_learning_parms(learn_parm, kernel_parm)) { wait_any_key(); print_help(); exit(0); } }
void print_help() { printf("\nTree Kernels in SVM-light %s : SVM Learning module %s\n",VERSION,VERSION_DATE); printf("by Alessandro Moschitti, [email protected]\n"); printf("University of Rome \"Tor Vergata\"\n\n"); copyright_notice(); printf(" usage: svm_learn [options] example_file model_file\n\n"); printf("Arguments:\n"); printf(" example_file-> file with training data\n"); printf(" model_file -> file to store learned decision rule in\n"); printf("General options:\n"); printf(" -? -> this help\n"); printf(" -v [0..3] -> verbosity level (default 1)\n"); printf("Learning options:\n"); printf(" -z {c,r,p} -> select between classification (c), regression (r),\n"); printf(" and preference ranking (p) (default classification)\n"); printf(" -c float -> C: trade-off between training error\n"); printf(" and margin (default [avg. x*x]^-1)\n"); printf(" -w [0..] -> epsilon width of tube for regression\n"); printf(" (default 0.1)\n"); printf(" -j float -> Cost: cost-factor, by which training errors on\n"); printf(" positive examples outweight errors on negative\n"); printf(" examples (default 1) (see [4])\n"); printf(" -b [0,1] -> use biased hyperplane (i.e. x*w+b>0) instead\n"); printf(" of unbiased hyperplane (i.e. x*w>0) (default 1)\n"); printf(" -i [0,1] -> remove inconsistent training examples\n"); printf(" and retrain (default 0)\n"); printf("Performance estimation options:\n"); printf(" -x [0,1] -> compute leave-one-out estimates (default 0)\n"); printf(" (see [5])\n"); printf(" -o ]0..2] -> value of rho for XiAlpha-estimator and for pruning\n"); printf(" leave-one-out computation (default 1.0) (see [2])\n"); printf(" -k [0..100] -> search depth for extended XiAlpha-estimator \n"); printf(" (default 0)\n"); printf("Transduction options (see [3]):\n"); printf(" -p [0..1] -> fraction of unlabeled examples to be classified\n"); printf(" into the positive class (default is the ratio of\n"); printf(" positive and negative examples in the training data)\n"); printf("Kernel options:\n"); printf(" -t int -> type of kernel function:\n"); printf(" 0: linear (default)\n"); printf(" 1: polynomial (s a*b+c)^d\n"); printf(" 2: radial basis function exp(-gamma ||a-b||^2)\n"); printf(" 3: sigmoid tanh(s a*b + c)\n"); printf(" 4: user defined kernel from kernel.h\n"); printf(" 5: combination of forest and vector sets according to W, V, S, C options\n"); printf(" 11: re-ranking based on trees (each instance must have two trees),\n"); printf(" 12: re-ranking based on vectors (each instance must have two vectors)\n"); printf(" 13: re-ranking based on both tree and vectors (each instance must have\n"); printf(" two trees and two vectors) \n"); printf(" -W [S,A] -> with an 'S', a tree kernel is applied to the sequence of trees of two input\n"); printf(" forests and the results are summed; \n"); printf(" -> with an 'A', a tree kernel is applied to all tree pairs from the two forests\n"); printf(" (default 'S')\n"); printf(" -V [S,A] -> same as before but regarding sequences of vectors are used (default 'S' and\n"); printf(" the type of vector-based kernel is specified by the option -S)\n"); printf(" -S [0,4] -> kernel to be used with vectors (default polynomial of degree 3,\n"); printf(" i.e. -S = 1 and -d = 3)\n"); printf(" -C [*,+,T,V]-> combination operator between forests and vectors (default 'T')\n"); printf(" -> 'T' only the contribution from trees is used (specified by option -W)\n"); printf(" -> 'V' only the contribution from vectors is used (specified by option -V)\n"); printf(" -> '+' or '*' sum or multiplication of the contributions from vectors and \n"); printf(" trees (default T) \n"); printf(" -F [0,1,2,3]-> 0 = ST kernel, 1 = SST kernel, 2 = SST-bow, 3 = PT kernel (default 1)\n"); printf(" -M float -> Mu decay factor for PT kernel (default 0.4)\n"); printf(" -L float -> decay factor in tree kernel (default 0.4)\n"); printf(" -S [0,4] -> kernel to be used with vectors (default polynomial of degree 3, \n"); printf(" i.e. -S = 1 and -d = 3)\n"); printf(" -T float -> multiplicative constant for the contribution of tree kernels when -C = '+'\n"); printf(" -N float -> 0 = no normalization, 1 = tree normalization, 2 = vector normalization and \n"); printf(" 3 = tree normalization of both trees and vectors. The normalization is applied \n"); printf(" to each individual tree or vector (default 3).\n"); printf(" -u string -> parameter of user defined kernel\n"); printf(" -d int -> parameter d in polynomial kernel\n"); printf(" -g float -> parameter gamma in rbf kernel\n"); printf(" -s float -> parameter s in sigmoid/poly kernel\n"); printf(" -r float -> parameter c in sigmoid/poly kernel\n"); printf(" -u string -> parameter of user defined kernel\n"); printf("Optimization options (see [1]):\n"); printf(" -q [2..] -> maximum size of QP-subproblems (default 10)\n"); printf(" -n [2..q] -> number of new variables entering the working set\n"); printf(" in each iteration (default n = q). Set n<q to prevent\n"); printf(" zig-zagging.\n"); printf(" -m [5..] -> size of cache for kernel evaluations in MB (default 40)\n"); printf(" The larger the faster...\n"); printf(" -e float -> eps: Allow that error for termination criterion\n"); printf(" [y [w*x+b] - 1] >= eps (default 0.001)\n"); printf(" -h [5..] -> number of iterations a variable needs to be\n"); printf(" optimal before considered for shrinking (default 100)\n"); printf(" -f [0,1] -> do final optimality check for variables removed\n"); printf(" by shrinking. Although this test is usually \n"); printf(" positive, there is no guarantee that the optimum\n"); printf(" was found if the test is omitted. (default 1)\n"); printf("Output options:\n"); printf(" -l string -> file to write predicted labels of unlabeled\n"); printf(" examples into after transductive learning\n"); printf(" -a string -> write all alphas to this file after learning\n"); printf(" (in the same order as in the training set)\n"); wait_any_key(); printf("\nMore details in:\n"); printf("[1] T. Joachims, Making Large-Scale SVM Learning Practical. Advances in\n"); printf(" Kernel Methods - Support Vector Learning, B. Schölkopf and C. Burges and\n"); printf(" A. Smola (ed.), MIT Press, 1999.\n"); printf("[2] T. Joachims, Estimating the Generalization performance of an SVM\n"); printf(" Efficiently. International Conference on Machine Learning (ICML), 2000.\n"); printf("[3] T. Joachims, Transductive Inference for Text Classification using Support\n"); printf(" Vector Machines. International Conference on Machine Learning (ICML),\n"); printf(" 1999.\n"); printf("[4] K. Morik, P. Brockhausen, and T. Joachims, Combining statistical learning\n"); printf(" with a knowledge-based approach - A case study in intensive care \n"); printf(" monitoring. International Conference on Machine Learning (ICML), 1999.\n"); printf("[5] T. Joachims, Learning to Classify Text Using Support Vector\n"); printf(" Machines: Methods, Theory, and Algorithms. Dissertation, Kluwer,\n"); printf(" 2002.\n\n"); printf("\nFor Tree-Kernel details:\n"); printf("[6] A. Moschitti, A study on Convolution Kernels for Shallow Semantic Parsing.\n"); printf(" In proceedings of the 42-th Conference on Association for Computational\n"); printf(" Linguistic, (ACL-2004), Barcelona, Spain, 2004.\n\n"); printf("[7] A. Moschitti, Making tree kernels practical for natural language learning.\n"); printf(" In Proceedings of the Eleventh International Conference for Computational\n"); printf(" Linguistics, (EACL-2006), Trento, Italy, 2006.\n\n"); }
void read_input_parameters(int argc,char *argv[],char *docfile,char *modelfile, long *verbosity,long *kernel_cache_size, LEARN_PARM *learn_parm,KERNEL_PARM *kernel_parm) { long i; char type[100]; /* set default */ strcpy (modelfile, "svm_model"); strcpy (learn_parm->predfile, "trans_predictions"); strcpy (learn_parm->alphafile, ""); (*verbosity)=1; learn_parm->biased_hyperplane=1; learn_parm->remove_inconsistent=0; learn_parm->skip_final_opt_check=0; learn_parm->svm_maxqpsize=10; learn_parm->svm_newvarsinqp=0; learn_parm->svm_iter_to_shrink=-9999; (*kernel_cache_size)=40; learn_parm->svm_c=0.0; learn_parm->eps=0.1; learn_parm->transduction_posratio=-1.0; learn_parm->svm_costratio=1.0; learn_parm->svm_costratio_unlab=1.0; learn_parm->svm_unlabbound=1E-5; learn_parm->epsilon_crit=0.001; learn_parm->epsilon_a=1E-15; learn_parm->compute_loo=0; learn_parm->rho=1.0; learn_parm->xa_depth=0; kernel_parm->kernel_type=0; kernel_parm->poly_degree=3; kernel_parm->rbf_gamma=1.0; kernel_parm->coef_lin=1; kernel_parm->coef_const=1; kernel_parm->lambda=.4; kernel_parm->tree_constant=1; kernel_parm->second_kernel=1; kernel_parm->first_kernel=1; kernel_parm->normalization=3; kernel_parm->combination_type='T'; //no combination kernel_parm->vectorial_approach_standard_kernel='S'; kernel_parm->vectorial_approach_tree_kernel='S'; kernel_parm->mu=.4; // Default Duffy and Collins Kernel kernel_parm->tree_kernel_params=0; // Default no params strcpy(kernel_parm->custom,"empty"); strcpy(type,"c"); for(i=1;(i<argc) && ((argv[i])[0] == '-');i++) { switch ((argv[i])[1]) { case '?': print_help(); exit(0); case 'z': i++; strcpy(type,argv[i]); break; case 'v': i++; (*verbosity)=atol(argv[i]); break; case 'b': i++; learn_parm->biased_hyperplane=atol(argv[i]); break; case 'i': i++; learn_parm->remove_inconsistent=atol(argv[i]); break; case 'f': i++; learn_parm->skip_final_opt_check=!atol(argv[i]); break; case 'q': i++; learn_parm->svm_maxqpsize=atol(argv[i]); break; case 'n': i++; learn_parm->svm_newvarsinqp=atol(argv[i]); break; case 'h': i++; learn_parm->svm_iter_to_shrink=atol(argv[i]); break; case 'm': i++; (*kernel_cache_size)=atol(argv[i]); break; case 'c': i++; learn_parm->svm_c=atof(argv[i]); break; case 'w': i++; learn_parm->eps=atof(argv[i]); break; case 'p': i++; learn_parm->transduction_posratio=atof(argv[i]); break; case 'j': i++; learn_parm->svm_costratio=atof(argv[i]); break; case 'e': i++; learn_parm->epsilon_crit=atof(argv[i]); break; case 'o': i++; learn_parm->rho=atof(argv[i]); break; case 'k': i++; learn_parm->xa_depth=atol(argv[i]); break; case 'x': i++; learn_parm->compute_loo=atol(argv[i]); break; case 't': i++; kernel_parm->kernel_type=atol(argv[i]); break; case 'd': i++; kernel_parm->poly_degree=atol(argv[i]); break; case 'g': i++; kernel_parm->rbf_gamma=atof(argv[i]); break; case 's': i++; kernel_parm->coef_lin=atof(argv[i]); break; case 'r': i++; kernel_parm->coef_const=atof(argv[i]); break; case 'u': i++; strcpy(kernel_parm->custom,argv[i]); break; case 'l': i++; strcpy(learn_parm->predfile,argv[i]); break; case 'a': i++; strcpy(learn_parm->alphafile,argv[i]); break; case 'L': i++; kernel_parm->lambda=atof(argv[i]); break; case 'T': i++; kernel_parm->tree_constant=atof(argv[i]); break; case 'C': i++; kernel_parm->combination_type=*argv[i]; break; case 'F': i++; kernel_parm->first_kernel=atoi(argv[i]); break; case 'S': i++; kernel_parm->second_kernel=atoi(argv[i]); break; case 'V': i++; kernel_parm->vectorial_approach_standard_kernel=*argv[i]; break; case 'W': i++; kernel_parm->vectorial_approach_tree_kernel=*argv[i]; break; case 'M': i++; kernel_parm->mu=atof(argv[i]); break; case 'N': i++; kernel_parm->normalization=atoi(argv[i]); break; case 'U': i++; kernel_parm->tree_kernel_params=atoi(argv[i]); break; // user defined parameters default: printf("\nUnrecognized option %s!\n\n",argv[i]); print_help(); exit(0); } } LAMBDA = kernel_parm->lambda; // to make faster the kernel evaluation LAMBDA2 = LAMBDA*LAMBDA; MU= kernel_parm->mu; TKGENERALITY=kernel_parm->first_kernel; PARAM_VECT=kernel_parm->tree_kernel_params; if(PARAM_VECT == 1) read_input_tree_kernel_param(tree_kernel_params); // if there is the file tree_kernels.param load paramters if(i>=argc) { printf("\nNot enough input parameters!\n\n"); wait_any_key(); print_help(); exit(0); } strcpy (docfile, argv[i]); if((i+1)<argc) { strcpy (modelfile, argv[i+1]); } if(learn_parm->svm_iter_to_shrink == -9999) { if(kernel_parm->kernel_type == LINEAR) learn_parm->svm_iter_to_shrink=2; else learn_parm->svm_iter_to_shrink=100; } if(strcmp(type,"c")==0) { learn_parm->type=CLASSIFICATION; } else if(strcmp(type,"r")==0) { learn_parm->type=REGRESSION; } else if(strcmp(type,"p")==0) { learn_parm->type=RANKING; } else if(strcmp(type,"P")==0) { learn_parm->type=PERCEPTRON; } else if(strcmp(type,"B")==0) { learn_parm->type=PERCEPTRON_BATCH; } else { printf("\nUnknown type '%s': Valid types are 'c' (classification), 'r' regession, and 'p' preference ranking.\n",type); wait_any_key(); print_help(); exit(0); } if((learn_parm->skip_final_opt_check) && (kernel_parm->kernel_type == LINEAR)) { printf("\nIt does not make sense to skip the final optimality check for linear kernels.\n\n"); learn_parm->skip_final_opt_check=0; } if((learn_parm->skip_final_opt_check) && (learn_parm->remove_inconsistent)) { printf("\nIt is necessary to do the final optimality check when removing inconsistent \nexamples.\n"); wait_any_key(); print_help(); exit(0); } if((learn_parm->svm_maxqpsize<2)) { printf("\nMaximum size of QP-subproblems not in valid range: %ld [2..]\n",learn_parm->svm_maxqpsize); wait_any_key(); print_help(); exit(0); } if((learn_parm->svm_maxqpsize<learn_parm->svm_newvarsinqp)) { printf("\nMaximum size of QP-subproblems [%ld] must be larger than the number of\n",learn_parm->svm_maxqpsize); printf("new variables [%ld] entering the working set in each iteration.\n",learn_parm->svm_newvarsinqp); wait_any_key(); print_help(); exit(0); } /* if(learn_parm->svm_iter_to_shrink<1) { printf("\nMaximum number of iterations for shrinking not in valid range: %ld [1,..]\n",learn_parm->svm_iter_to_shrink); wait_any_key(); print_help(); exit(0); }*/ if(learn_parm->svm_c<0) { printf("\nThe C parameter must be greater than zero!\n\n"); wait_any_key(); print_help(); exit(0); } if(learn_parm->transduction_posratio>1) { printf("\nThe fraction of unlabeled examples to classify as positives must\n"); printf("be less than 1.0 !!!\n\n"); wait_any_key(); print_help(); exit(0); } if(learn_parm->svm_costratio<=0) { printf("\nThe COSTRATIO parameter must be greater than zero!\n\n"); wait_any_key(); print_help(); exit(0); } if(learn_parm->epsilon_crit<=0) { printf("\nThe epsilon parameter must be greater than zero!\n\n"); wait_any_key(); print_help(); exit(0); } if(learn_parm->rho<0) { printf("\nThe parameter rho for xi/alpha-estimates and leave-one-out pruning must\n"); printf("be greater than zero (typically 1.0 or 2.0, see T. Joachims, Estimating the\n"); printf("Generalization Performance of an SVM Efficiently, ICML, 2000.)!\n\n"); wait_any_key(); print_help(); exit(0); } if((learn_parm->xa_depth<0) || (learn_parm->xa_depth>100)) { printf("\nThe parameter depth for ext. xi/alpha-estimates must be in [0..100] (zero\n"); printf("for switching to the conventional xa/estimates described in T. Joachims,\n"); printf("Estimating the Generalization Performance of an SVM Efficiently, ICML, 2000.)\n"); wait_any_key(); print_help(); exit(0); } }
void print_help() { printf("\nSVM-struct learning module: %s, %s, %s\n",INST_NAME,INST_VERSION,INST_VERSION_DATE); printf(" includes SVM-struct %s for learning complex outputs, %s\n",STRUCT_VERSION,STRUCT_VERSION_DATE); printf(" includes SVM-light %s quadratic optimizer, %s\n",VERSION,VERSION_DATE); copyright_notice(); printf(" usage: svm_struct_learn [options] example_file model_file\n\n"); printf("Arguments:\n"); printf(" example_file-> file with training data\n"); printf(" model_file -> file to store learned decision rule in\n"); printf("General options:\n"); printf(" -? -> this help\n"); printf(" -v [0..3] -> verbosity level (default 1)\n"); printf(" -y [0..3] -> verbosity level for svm_light (default 0)\n"); printf("Learning options:\n"); printf(" -c float -> C: trade-off between training error\n"); printf(" and margin (default 0.01)\n"); printf(" -p [1,2] -> L-norm to use for slack variables. Use 1 for L1-norm,\n"); printf(" use 2 for squared slacks. (default 1)\n"); printf(" -o [1,2] -> Slack rescaling method to use for loss.\n"); printf(" 1: slack rescaling\n"); printf(" 2: margin rescaling\n"); printf(" (default 1)\n"); printf(" -l [0..] -> Loss function to use.\n"); printf(" 0: zero/one loss\n"); printf(" (default 0)\n"); printf("Kernel options:\n"); printf(" -t int -> type of kernel function:\n"); printf(" 0: linear (default)\n"); printf(" 1: polynomial (s a*b+c)^d\n"); printf(" 2: radial basis function exp(-gamma ||a-b||^2)\n"); printf(" 3: sigmoid tanh(s a*b + c)\n"); printf(" 4: user defined kernel from kernel.h\n"); printf(" -d int -> parameter d in polynomial kernel\n"); printf(" -g float -> parameter gamma in rbf kernel\n"); printf(" -s float -> parameter s in sigmoid/poly kernel\n"); printf(" -r float -> parameter c in sigmoid/poly kernel\n"); printf(" -u string -> parameter of user defined kernel\n"); printf("Optimization options (see [2][3]):\n"); printf(" -q [2..] -> maximum size of QP-subproblems (default 10)\n"); printf(" -n [2..q] -> number of new variables entering the working set\n"); printf(" in each iteration (default n = q). Set n<q to prevent\n"); printf(" zig-zagging.\n"); printf(" -m [5..] -> size of cache for kernel evaluations in MB (default 40)\n"); printf(" The larger the faster...\n"); printf(" -e float -> eps: Allow that error for termination criterion\n"); printf(" (default 0.01)\n"); printf(" -h [5..] -> number of iterations a variable needs to be\n"); printf(" optimal before considered for shrinking (default 100)\n"); printf(" -k [1..] -> number of new constraints to accumulate before\n"); printf(" recomputing the QP solution (default 100)\n"); printf(" -# int -> terminate optimization, if no progress after this\n"); printf(" number of iterations. (default 100000)\n"); printf("Output options:\n"); printf(" -a string -> write all alphas to this file after learning\n"); printf(" (in the same order as in the training set)\n"); printf("Structure learning options:\n"); print_struct_help(); wait_any_key(); printf("\nMore details in:\n"); printf("[1] T. Joachims, Learning to Align Sequences: A Maximum Margin Aproach.\n"); printf(" Technical Report, September, 2003.\n"); printf("[2] I. Tsochantaridis, T. Hofmann, T. Joachims, and Y. Altun, Support Vector \n"); printf(" Learning for Interdependent and Structured Output Spaces, ICML, 2004.\n"); printf("[3] T. Joachims, Making Large-Scale SVM Learning Practical. Advances in\n"); printf(" Kernel Methods - Support Vector Learning, B. Schölkopf and C. Burges and\n"); printf(" A. Smola (ed.), MIT Press, 1999.\n"); printf("[4] T. Joachims, Learning to Classify Text Using Support Vector\n"); printf(" Machines: Methods, Theory, and Algorithms. Dissertation, Kluwer,\n"); printf(" 2002.\n\n"); }
int main(void) { // First allocate the buffer for the Linux image + DTB void *linux_buffer = linearAlloc(LINUX_BUFFER_SIZE); memset(linux_buffer, 0, LINUX_BUFFER_SIZE); // Initialize services gfxInitDefault(); gfxSwapBuffers(); consoleInit(GFX_BOTTOM, NULL); printf("Linux loader by xerpi\n\n"); if (brahma_init()) { printf("[+] Opening the linux image...\n"); FILE *zImage = fopen(LINUXIMAGE_FILENAME, "rb"); printf("[+] fopen returned: %p\n", zImage); if (zImage == NULL) { printf("[+] Error opening the Linux zImage\n" "Press any key to reboot."); wait_any_key(); firm_reboot(); } //Load the kernel image code to ZIMAGE_ADDR unsigned int n = 0; unsigned int linux_bin_size = 0; while ((n = fread(fcram_phys2linear(linux_buffer, ZIMAGE_ADDR)+linux_bin_size, 1, 0x10000, zImage)) > 0) { linux_bin_size += n; } fclose(zImage); printf("[+] Loaded kernel:\n"); printf("[+] address: %p,\n", ZIMAGE_ADDR); printf("[+] size: 0x%08X bytes\n", linux_bin_size); //Load the device tree to PARAMS_TMP_ADDR printf("\n[+] Opening " DTB_FILENAME "\n"); FILE *dtb = fopen(DTB_FILENAME, "rb"); printf("[+] FileOpen returned: %p\n", dtb); if (dtb == NULL) { printf("[+] Error opening " DTB_FILENAME "\n" "Press any key to reboot."); wait_any_key(); firm_reboot(); } n = 0; unsigned int dtb_bin_size = 0; while ((n = fread(fcram_phys2linear(linux_buffer, PARAMS_TMP_ADDR)+dtb_bin_size, 1, 0x10000, dtb)) > 0) { dtb_bin_size += n; } fclose(dtb); //Load the arm9linuxfw to ARM9LINUXFW_TMP_ADDR printf("\n[+] Opening " ARM9LINUXFW_FILENAME "\n"); FILE *arm9fw = fopen(ARM9LINUXFW_FILENAME, "rb"); printf("[+] FileOpen returned: %p\n", arm9fw); if (arm9fw != NULL) { n = 0; unsigned int arm9fw_bin_size = 0; while ((n = fread(fcram_phys2linear(linux_buffer, ARM9LINUXFW_TMP_ADDR)+arm9fw_bin_size, 1, 0x10000, arm9fw)) > 0) { arm9fw_bin_size += n; } fclose(arm9fw); printf("[+] Loaded " ARM9LINUXFW_FILENAME ":\n"); printf("[+] temp address: %p,\n", ARM9LINUXFW_TMP_ADDR); printf("[+] dest address: %p,\n", ARM9LINUXFW_ADDR); printf("[+] size: 0x%08X bytes\n", arm9fw_bin_size); // Store the arm9linuxfw size to *ARM9LINUXFW_SIZE_ADDR *(unsigned int *)fcram_phys2linear(linux_buffer, ARM9LINUXFW_SIZE_ADDR) = arm9fw_bin_size; } else { printf("\n\n[+] WARNING " ARM9LINUXFW_FILENAME " not found!\n\n"); // Store a 0 size to *ARM9LINUXFW_SIZE_ADDR *(unsigned int *)fcram_phys2linear(linux_buffer, ARM9LINUXFW_SIZE_ADDR) = 0; } // Store the DTB size to *PARAMS_SIZE_ADDR *(unsigned int *)fcram_phys2linear(linux_buffer, PARAMS_SIZE_ADDR) = dtb_bin_size; GSPGPU_FlushDataCache(fcram_phys2linear(linux_buffer, ZIMAGE_ADDR), linux_bin_size); GSPGPU_FlushDataCache(fcram_phys2linear(linux_buffer, PARAMS_ADDR), dtb_bin_size); GSPGPU_FlushDataCache(fcram_phys2linear(linux_buffer, PARAMS_SIZE_ADDR), sizeof(unsigned int)); GSPGPU_FlushDataCache(fcram_phys2linear(linux_buffer, ARM9LINUXFW_SIZE_ADDR), sizeof(unsigned int)); printf("[+] Loading Linux Payloads...\n"); unsigned int linux_payloads_size = (u32)&linux_payloads_end - (u32)&linux_payloads_start; printf("[+] size %i\n", linux_payloads_size); load_arm9_payload_from_mem(&linux_payloads_start, linux_payloads_size); flush_dcache(); //soc_init(); //soc_exit(); //wait_any_key(); printf("[+] Running ARM9 payload\n"); firm_reboot(); //soc_exit(); brahma_exit(); } else { printf("* BRAHMA *\n\n[!]Not enough memory\n"); wait_any_key(); } linearFree(linux_buffer); gfxExit(); // Return to hbmenu return 0; }
/* Support for binary input file added by N. Dalal*/ void read_input_parameters(int argc,char *argv[],char *docfile,char *modelfile, char *restartfile,long *verbosity, long* format, LEARN_PARM *learn_parm,KERNEL_PARM *kernel_parm) { long i; char type[100]; /* set default */ strcpy (modelfile, "svm_model"); strcpy (learn_parm->predfile, "trans_predictions"); strcpy (learn_parm->alphafile, ""); strcpy (restartfile, ""); (*verbosity)=1; /* Support for binary input file added by N. Dalal*/ (*format)=1; learn_parm->biased_hyperplane=1; learn_parm->sharedslack=0; learn_parm->remove_inconsistent=0; learn_parm->skip_final_opt_check=0; learn_parm->svm_maxqpsize=10; learn_parm->svm_newvarsinqp=0; learn_parm->svm_iter_to_shrink=-9999; learn_parm->maxiter=100000; learn_parm->kernel_cache_size=40; learn_parm->svm_c=0.0; learn_parm->eps=0.1; learn_parm->transduction_posratio=-1.0; learn_parm->svm_costratio=1.0; learn_parm->svm_costratio_unlab=1.0; learn_parm->svm_unlabbound=1E-5; learn_parm->epsilon_crit=0.001; learn_parm->epsilon_a=1E-15; learn_parm->compute_loo=0; learn_parm->rho=1.0; learn_parm->xa_depth=0; kernel_parm->kernel_type=0; kernel_parm->poly_degree=3; kernel_parm->rbf_gamma=1.0; kernel_parm->coef_lin=1; kernel_parm->coef_const=1; strcpy(kernel_parm->custom,"empty"); strcpy(type,"c"); for(i=1;(i<argc) && ((argv[i])[0] == '-');i++) { switch ((argv[i])[1]) { case '?': print_help(); exit(0); case 'z': i++; strcpy(type,argv[i]); break; case 'v': i++; (*verbosity)=atol(argv[i]); break; /* Support for binary input file added by N. Dalal*/ case 'B': i++; (*format)= atol(argv[i]); break; case 'b': i++; learn_parm->biased_hyperplane=atol(argv[i]); break; case 'i': i++; learn_parm->remove_inconsistent=atol(argv[i]); break; case 'f': i++; learn_parm->skip_final_opt_check=!atol(argv[i]); break; case 'q': i++; learn_parm->svm_maxqpsize=atol(argv[i]); break; case 'n': i++; learn_parm->svm_newvarsinqp=atol(argv[i]); break; case '#': i++; learn_parm->maxiter=atol(argv[i]); break; case 'h': i++; learn_parm->svm_iter_to_shrink=atol(argv[i]); break; case 'm': i++; learn_parm->kernel_cache_size=atol(argv[i]); break; case 'c': i++; learn_parm->svm_c=atof(argv[i]); break; case 'w': i++; learn_parm->eps=atof(argv[i]); break; case 'p': i++; learn_parm->transduction_posratio=atof(argv[i]); break; case 'j': i++; learn_parm->svm_costratio=atof(argv[i]); break; case 'e': i++; learn_parm->epsilon_crit=atof(argv[i]); break; case 'o': i++; learn_parm->rho=atof(argv[i]); break; case 'k': i++; learn_parm->xa_depth=atol(argv[i]); break; case 'x': i++; learn_parm->compute_loo=atol(argv[i]); break; case 't': i++; kernel_parm->kernel_type=atol(argv[i]); break; case 'd': i++; kernel_parm->poly_degree=atol(argv[i]); break; case 'g': i++; kernel_parm->rbf_gamma=atof(argv[i]); break; case 's': i++; kernel_parm->coef_lin=atof(argv[i]); break; case 'r': i++; kernel_parm->coef_const=atof(argv[i]); break; case 'u': i++; strcpy(kernel_parm->custom,argv[i]); break; case 'l': i++; strcpy(learn_parm->predfile,argv[i]); break; case 'a': i++; strcpy(learn_parm->alphafile,argv[i]); break; case 'y': i++; strcpy(restartfile,argv[i]); break; default: printf("\nUnrecognized option %s!\n\n",argv[i]); print_help(); exit(0); } } if(i>=argc) { printf("\nNot enough input parameters!\n\n"); wait_any_key(); print_help(); exit(0); } strcpy (docfile, argv[i]); if((i+1)<argc) { strcpy (modelfile, argv[i+1]); } if(learn_parm->svm_iter_to_shrink == -9999) { if(kernel_parm->kernel_type == LINEAR) learn_parm->svm_iter_to_shrink=2; else learn_parm->svm_iter_to_shrink=100; } if(strcmp(type,"c")==0) { learn_parm->type=CLASSIFICATION; } else if(strcmp(type,"r")==0) { learn_parm->type=REGRESSION; } else if(strcmp(type,"p")==0) { learn_parm->type=RANKING; } else if(strcmp(type,"o")==0) { learn_parm->type=OPTIMIZATION; } else if(strcmp(type,"s")==0) { learn_parm->type=OPTIMIZATION; learn_parm->sharedslack=1; } else { printf("\nUnknown type '%s': Valid types are 'c' (classification), 'r' regession, and 'p' preference ranking.\n",type); wait_any_key(); print_help(); exit(0); } if((learn_parm->skip_final_opt_check) && (kernel_parm->kernel_type == LINEAR)) { printf("\nIt does not make sense to skip the final optimality check for linear kernels.\n\n"); learn_parm->skip_final_opt_check=0; } if((learn_parm->skip_final_opt_check) && (learn_parm->remove_inconsistent)) { printf("\nIt is necessary to do the final optimality check when removing inconsistent \nexamples.\n"); wait_any_key(); print_help(); exit(0); } if((learn_parm->svm_maxqpsize<2)) { printf("\nMaximum size of QP-subproblems not in valid range: %ld [2..]\n",learn_parm->svm_maxqpsize); wait_any_key(); print_help(); exit(0); } if((learn_parm->svm_maxqpsize<learn_parm->svm_newvarsinqp)) { printf("\nMaximum size of QP-subproblems [%ld] must be larger than the number of\n",learn_parm->svm_maxqpsize); printf("new variables [%ld] entering the working set in each iteration.\n",learn_parm->svm_newvarsinqp); wait_any_key(); print_help(); exit(0); } if(learn_parm->svm_iter_to_shrink<1) { printf("\nMaximum number of iterations for shrinking not in valid range: %ld [1,..]\n",learn_parm->svm_iter_to_shrink); wait_any_key(); print_help(); exit(0); } if(learn_parm->svm_c<0) { printf("\nThe C parameter must be greater than zero!\n\n"); wait_any_key(); print_help(); exit(0); } if(learn_parm->transduction_posratio>1) { printf("\nThe fraction of unlabeled examples to classify as positives must\n"); printf("be less than 1.0 !!!\n\n"); wait_any_key(); print_help(); exit(0); } if(learn_parm->svm_costratio<=0) { printf("\nThe COSTRATIO parameter must be greater than zero!\n\n"); wait_any_key(); print_help(); exit(0); } if(learn_parm->epsilon_crit<=0) { printf("\nThe epsilon parameter must be greater than zero!\n\n"); wait_any_key(); print_help(); exit(0); } if(learn_parm->rho<0) { printf("\nThe parameter rho for xi/alpha-estimates and leave-one-out pruning must\n"); printf("be greater than zero (typically 1.0 or 2.0, see T. Joachims, Estimating the\n"); printf("Generalization Performance of an SVM Efficiently, ICML, 2000.)!\n\n"); wait_any_key(); print_help(); exit(0); } if((learn_parm->xa_depth<0) || (learn_parm->xa_depth>100)) { printf("\nThe parameter depth for ext. xi/alpha-estimates must be in [0..100] (zero\n"); printf("for switching to the conventional xa/estimates described in T. Joachims,\n"); printf("Estimating the Generalization Performance of an SVM Efficiently, ICML, 2000.)\n"); wait_any_key(); print_help(); exit(0); } }