1 /*****************************************************************************/ 2 /* */ 3 /* 3dsvm_common.h */ 4 /* */ 5 /* Definitions and functions used by 3dsvm */ 6 /* */ 7 /* Copyright (C) 2007 Stephen LaConte */ 8 /* */ 9 /* This file is part of 3dsvm */ 10 /* */ 11 /* 3dsvm is free software: you can redistribute it and/or modify */ 12 /* it under the terms of the GNU General Public License as published by */ 13 /* the Free Software Foundation, either version 3 of the License, or */ 14 /* (at your option) any later version. */ 15 /* */ 16 /* 3dsvm is distributed in the hope that it will be useful, */ 17 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 18 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ 19 /* GNU General Public License for more details. */ 20 /* */ 21 /* You should have received a copy of the GNU General Public License */ 22 /* along with 3dsvm. If not, see <http://www.gnu.org/licenses/>. */ 23 /* */ 24 /* */ 25 /* The SVM-light software is copyrighted by Thorsten Joachims */ 26 /* and is redistributed by permission. */ 27 /* */ 28 /* The SVM-light software is free only for non-commercial use. It must not */ 29 /* be distributed without prior permission of the author. The author is not */ 30 /* responsible for implications from the use of this software. */ 31 /* */ 32 /* */ 33 /* For AFNI's copyright please refer to ../README.copyright. */ 34 /* */ 35 /*****************************************************************************/ 36 37 38 #ifndef _3DSVM_COMMON_H 39 #define _3DSVM_COMMON_H 40 #endif 41 42 #include "afni.h" 43 #include "svm_common.h" 44 #include "svm_learn.h" 45 #include <stdio.h> 46 #include <string.h> 47 #include <stdlib.h> 48 #include <math.h> 49 #include "mrilib.h" 50 51 /* JL Apr 2010: Added version number and version date for 3dsvm 52 * and changed VERSION in svm-light source to avoid conflicts with afni. 53 * readAllocateAfniModel is using the version number to read in model 54 * parameters correctly */ 55 56 #define VERSION_3DSVM "V1.31" 57 #define VERSION_DATE_3DSVM "08/16/2021" 58 #define CLASS_MAX 300 59 #define SCALE 4000000 60 #define MAX_FILE_NAME_LENGTH 500 61 #define LONG_STRING 500 62 63 #define PROGRAM_NAME "3dsvm" /* name of this program -used to include 64 command-line history in model etc. */ 65 66 #define CSV_STRING 20 /* JL: CSV_STRING: size of comma separated value 67 string. Strings of this size are used to store class-combination and 68 custom-kernel, which is plenty for comb_names, but for some reason 69 size 50 is causing memory corruption problems. */ 70 71 #define DatasetType float /* JL: Internal data representation of dataset 72 arrays. This used to be short */ 73 #define MaskType byte 74 #define LabelType double 75 76 #define MODEL_MSK_EXT "_mask" /* JL: Used for mask file naming before mask was 77 written as a sub-brick into the model */ 78 #define MASK_YES 1 /* mask was used for training */ 79 #define MASK_NO 0 /* mask was not used for training */ 80 #define MASK_UNKNOWN -1 /* unknown if mask was used for training. Only the 81 case if version < V1.10 was used for training */ 82 #define SVM_HOST_NCTRY 3 /* max number of attempts to connect to SVM host 83 (relevant for real-time action */ 84 85 #define IFree(x) do{ if( (x)!=NULL ){ free(x) ; (x)=NULL ; } } while(0) 86 87 /* JL: Used to define the kernel type. CUSTOM stands for custom kernel. 88 * LINEAR 0 89 * POLY 1 90 * RBF 2 91 * SIGMOID 3 92 * are defined in svm_common.h */ 93 #define CUSTOM 4 94 enum calling_fcn { ASL_PLUGIN, ASL_COMMAND_LINE }; 95 enum modes { NOTHING, TRAIN, TEST, TRAIN_AND_TEST, 96 RT_TRAIN, RT_TEST /* JL. Sep 2010 */ }; 97 98 typedef struct ASLoptions{ 99 /* initialize at instantiation */ 100 char labelFile[LONG_STRING]; /* training class (label) file */ 101 char censorFile[LONG_STRING]; /* training censor (ignore) file */ 102 char trainFile[LONG_STRING]; /* training dataset file */ 103 char maskFile[LONG_STRING]; /* mask dataset */ 104 char modelFile[LONG_STRING]; /* training output - model file */ 105 char docFile[LONG_STRING]; /* JL June 2009: write brick data into 106 svm-light formated textfile */ 107 char docFileOnly[LONG_STRING];/* JL June 2009: write brick data into 108 svm-light formated textfile */ 109 char kernelName[LONG_STRING]; /* JL Feb. 2009: tring specifying 110 kernel functions */ 111 char svmType[LONG_STRING]; /* JL May 2009: classification, regression 112 or ranking */ 113 int outModelNoMask; /* flag signifying that no mask 114 should be applied to output model */ 115 int noModelOut; /* JL Oct. 2017: flag: don't write model file */ 116 int noPredDetrend; /* flag signifying that no detrending 117 should be applied to output predictions 118 in test mode */ 119 int noPredCensor; /* flag signifying that predictions for 120 censored timepoints are not written 121 into prediction file */ 122 int noPredScale; /* flag signifying that predcitions are 123 not scaled to {0,1} */ 124 int classout; /* flag signifying thresholded class 125 predictions should be written to 126 prediction files (rather than 127 continuous valued "distances") */ 128 int rtTrain; /* flag indicating real-time training */ 129 int rtTest; /* flag indicating real-time testing */ 130 char rtIP[LONG_STRING]; /* IP address to which values are being send 131 during real-time testing (for feedback etc.) */ 132 int rtPort; /* port to which values are being send 133 during real-time testing (for feedback etc.) */ 134 char testFile[LONG_STRING]; /* testing dataset file */ 135 char multiclass[LONG_STRING]; /* type of classifyer for a mulitclass dataset */ 136 char predFile[LONG_STRING]; /* predictions file */ 137 char testLabelFile[LONG_STRING]; /* testing target classes for test samples */ 138 char modelAlphaFile[LONG_STRING]; 139 char modelWeightFile[LONG_STRING]; 140 int linearWmap; /* JL May 2011: flag signifying that user has 141 specified -wout flag: Write sum of weighted 142 linear sv into bucket file. This is currently 143 the only activation map that is implemeted. */ 144 } ASLoptions; 145 146 typedef struct labels { 147 LabelType* lbls; /* the class labels indicating the stimulus 148 categories for fMRI data */ 149 LabelType* cnsrs; /* indicates which labels to ignore 150 (value == 0) or use (value == 1) */ 151 LabelType* lbls_cont; /* JL: labels converted to continuous values */ 152 int *class_list; /* hold class numbers appearing in classfile 153 JL: changed allocation due to corruption 154 problems */ 155 int n_classes; /* number of different classes allowed 156 (for multiclass) */ 157 int *lbls_count; /* occurrence of each class label 158 (continuous index) */ 159 long n; /* the number of labels and censors */ 160 int n_cnsrs; /* JL: number of censored time points 161 (i.e., label 9999) */ 162 } LABELS; 163 164 typedef struct afniSvmModelHead { 165 166 /* General comment: The following int and float would be ideally 167 * long and double, but their ultimate destination is in the model 168 * header file (.HEAD). Unfortunately, there is no double or long 169 * functionality in THD_set_atr... */ 170 171 float version; /* JL Oct. 2010 */ 172 int mask_used; /* JL: flag indicating if mask was used 173 * MASK_YES, MASK_NO, MASK_UNKNOWN */ 174 int class_count; /* number of classes (stimulus categories) */ 175 int combinations; /* all possible pair-wise combinations of 176 * class_count - would like to be long */ 177 int timepoints; /* total number (even counting censored data) */ 178 179 long max_iterations; /* JL July 2011: Maximum number of iterations */ 180 char **combName; 181 /* short string describing the class combinations (e.g. '0_1','0_3') 182 ZSS: Changed from [10][...] to [...][10] 183 See how combName was used in function train_classification 184 where classCount is the variable used to index into combName's 185 first dimension. classCount goes to (CLASS_MAX * (CLASS_MAX-1))/2 186 and the previous declaration was causing bad corruption with other 187 pointers. 188 JL Apr. 2010: Now allocated at run time in allocateAfniModel 189 */ 190 char **kernel_custom; /* JL: string describing user-defined kernel */ 191 /* JL: now allocated at run time in allocateAfniModel */ 192 char svm_type[LONG_STRING]; /* JL: string describing svm (learn) type */ 193 int *kernel_type; 194 int *polynomial_degree; 195 float *rbf_gamma; 196 float *linear_coefficient; 197 float *constant_coefficient; 198 int *total_masked_features; 199 int *total_samples; /* number of time points per class */ 200 int *total_support_vectors; 201 float **alphas; /* alphas[class][timepoints] */ 202 float *b; 203 204 205 /* JL Oct. 2009: Added remaining svm-light parameters that can be specified 206 * from the command-line. */ 207 float *eps; /* epsilon for regression */ 208 float *svm_c; /* upper bound C on alphas */ 209 int *biased_hyperplane; /* if nonzero, use hyperplane w*x+b=0 210 otherwise w*x=0 */ 211 int *skip_final_opt_check; /* do not check KT-Conditions at the end of 212 optimization for examples removed by shrinking. WARNING: This might 213 lead to sub-optimal solutions! */ 214 int *svm_maxqpsize; /* size q of working set */ 215 int *svm_newvarsinqp; /* new variables to enter the working set 216 in each iteration */ 217 int *svm_iter_to_shrink; /* iterations h after which an example can 218 be removed by shrinking */ 219 float *transduction_posratio; /* fraction of unlabeled examples to be 220 classified as positives */ 221 float *svm_costratio; /* factor to multiply C for positive examples */ 222 float *svm_costratio_unlab; /* for svm-ligth internal use */ 223 float *svm_unlabbound; /* for svm-light internal use */ 224 float *epsilon_a; /* for svm-light internal use */ 225 float *epsilon_crit; /* tolerable error for distances used in 226 stopping criterion */ 227 int *compute_loo; /* if nonzero, computes leave-one-out 228 estimates */ 229 float *rho; /* parameter in xi/alpha-estimates and for 230 pruning leave-one-out range [1..2] */ 231 int *xa_depth; /* parameter in xi/alpha-estimates upper 232 bounding the number of SV the current 233 alpha_t is distributed over */ 234 } AFNI_MODEL; 235 236 /* JL: Holds maps to be written into a functional bucket dataset */ 237 typedef struct ModelMaps { 238 long nmaps; /* number of maps */ 239 long nvox; /* number of voxels in each map */ 240 long index; /* index over nmaps (keeps track of how many 241 maps were written into this structure) */ 242 char ** names; /* name for each map: names[nmaps][LONG_STRING] 243 shows up in the AFNI GUI (define overlay) */ 244 double ** data; /* data for each map: data[nmaps][nvox] */ 245 } MODEL_MAPS; 246 247 /* JL: Holds variables and structures for real-time action */ 248 typedef struct rt_svm_vars { 249 ASLoptions * options; /* ptr to ASLoptions structure */ 250 enum modes mode; /* mode (RT_TRAIN, RT_TEST, ...) */ 251 DatasetType ** dsetModelArray; /* contains the model data for every voxel at 252 every time-point */ 253 MaskType * dsetMaskArray; /* mask specifying a subset of voxels */ 254 AFNI_MODEL * afniModel; /* ptr to AFNI_MODEL structure */ 255 int svm_type; /* svm learn type (CLASSIFICATION, REGRESSION) */ 256 long nvox_model; /* number of voxels (featurs) in model */ 257 long nt_model; /* number of time-points (observations) in model */ 258 int myargc; /* number of "command-line arguments" */ 259 char ** myargv; /* "command line arguments" */ 260 char SVM_iochan[128]; /* I/O channel name SVM_host */ 261 IOCHAN * SVM_ioc; /* ptr to I/O channel */ 262 int SVM_HOST_OK; /* flag indicating if I/O with SVM_host (host that 263 supposedly wants to receive svm data) is ok */ 264 FILE * fp_pred; /* file pointer to prediction file */ 265 KERNEL_PARM * kernel_parm; /* svm-light kernel parameters */ 266 LEARN_PARM * learn_parm; /* svm-light learn parameters */ 267 long kernel_cache_size; /* svm-light kernel parameter */ 268 269 /* Added by Cameron to test for new data */ 270 long nt_processed; /* number of volumes processed */ 271 272 /* Cameron Craddock added to support prediction from bucket */ 273 int bucket_predict; /* flag to predict from bucket */ 274 int n_wvec; /* number of weight vectors in bueckt */ 275 float * bias_value; /* SVM model bias value (b) */ 276 277 int initialized; /* flag to indicate whether initializations 278 from the BEGIN phase of the callback 279 have occured */ 280 /* End CC additions */ 281 282 } RT_SVM_VARS; 283 284 /* --- advanced user command line help-string --- */ 285 static char advanced_helpstring[] = "\n" 286 "3dsvm Advanced Usage:\n" 287 "---------------------\n\n" 288 "Usage:\n" 289 " 3dsvm [options] \n" 290 "\n\n" 291 "Options: \n" 292 " -docout docname Write training data to a SVM-light formated text-file.\n" 293 " (in addition to training/testing)\n" 294 "\n" 295 " -doconly docname Write training data to a SVM-light formated text-file.\n" 296 " (without training/testing)\n" 297 "\n" 298 " e.g. 3dsvm -type classification \\ \n" 299 " -trainvol run1+orig \\ \n" 300 " -trainlabels run1_categories.1D \\ \n" 301 " -mask mask+orig \\ \n" 302 " -doconly doc_run1 \n" 303 "\n" 304 " -nopredscale Do not scale predictions. Using this flag \n" 305 " with -nodetrend and -nopredcensored\n" 306 " will give results that are most closely comparable with \n" 307 " SVM-light predictions \n" 308 "\n" 309 " -getenv Will specify ALL command line options using the current environment\n" 310 " e.g. 3dsvm -getenv\n" 311 "\n" 312 " The use of environment variables was primarily motivated for plugin development.\n" 313 " Several environment variables are available - \n" 314 " here is a hypothetical example of a .afnirc file:\n" 315 "\n" 316 " AFNI_3DSVM_RT_TRAIN = YES\n" 317 " AFNI_3DSVM_RT_TEST = NO\n" 318 " AFNI_3DSVM_RT_IP = 172.21.4.33\n" 319 " AFNI_3DSVM_RT_PORT = 5000\n" 320 " AFNI_3DSVM_TRAIN_TYPE = classification // classification or regression\n" 321 " AFNI_3DSVM_TRAIN_DSET = ~/data/trn_small+orig\n" 322 " AFNI_3DSVM_TRAIN_LBLS = ~/data/lbls_trn_small.1D\n" 323 " AFNI_3DSVM_MASK_DSET = ~/msk_small+orig\n" 324 " AFNI_3DSVM_MODEL_DSET = ./xxx_model_small+orig // used for training and testing\n" 325 " AFNI_3DSVM_BUCKET_DSET = ./xxx_bucket_small\n" 326 " AFNI_3DSVM_ALPHA_FILE = ./xxx_alpha_small\n" 327 " AFNI_3DSVM_PARM_C = 1000\n" 328 " AFNI_3DSVM_PARM_EPS = 0.001\n" 329 " AFNI_3DSVM_KERNEL_TYPE = linear // linear, polynomial, rbf, sigmoid\n" 330 " AFNI_3DSVM_KERNEL_PARM_D = 3\n" 331 " AFNI_3DSVM_KERNEL_PARM_G = 1.0\n" 332 " AFNI_3DSVM_KERNEL_PARM_S = 1.0\n" 333 " AFNI_3DSVM_KERNEL_PARM_R = 1.0\n" 334 " AFNI_3DSVM_TEST_DSET = ~/data/tst_small+orig\n" 335 " AFNI_3DSVM_TEST_LBLS = ~/data/lbls_tst_small.1D\n" 336 " AFNI_3DSVM_PRED_FILE = ./xxx_pred_small\n" 337 " AFNI_3DSVM_MCLASS_TYPE = DAG // DAG or vote\n" 338 " AFNI_3DSVM_NOMASK = YES\n" 339 " AFNI_3DSVM_NODETREND = NO\n" 340 " AFNI_3DSVM_CENSOR_FILE =~/data/censors.1D\n" 341 "\n" 342 "\n\n"; 343 344 /* --- command line help-string --- */ 345 static char cl_helpstring[] = "\n" 346 "Program: 3dsvm\n" 347 "\n" 348 "+++++++++++ 3dsvm: support vector machine analysis of brain data +++++++++++\n\n" 349 "3dsvm - temporally predictive modeling with the support vector machine\n" 350 "\n" 351 " This program provides the ability to perform support vector machine\n" 352 " (SVM) learning on AFNI datasets using the SVM-light package (version 5)\n" 353 " developed by Thorsten Joachims (http://svmlight.joachims.org/).\n" 354 "\n" 355 "-----------------------------------------------------------------------------\n" 356 "Usage:\n" 357 "------\n" 358 "\t 3dsvm [options] \n" 359 "\n" 360 "Examples:\n" 361 "---------\n" 362 "1. Training: basic options require a training run, category (class) labels \n" 363 " for each timepoint, and an output model. In general, it usually makes \n" 364 " sense to include a mask file to exclude at least non-brain voxels\n" 365 "\n" 366 "\t 3dsvm -trainvol run1+orig \\ \n" 367 "\t -trainlabels run1_categories.1D \\ \n" 368 "\t -mask mask+orig \\ \n" 369 "\t -model model_run1\n" 370 "\n" 371 "2. Training: obtain model alphas (a_run1.1D) and \n" 372 " model weights (fim: run1_fim+orig)\n" 373 "\n" 374 "\t 3dsvm -alpha a_run1 \\\n" 375 "\t -trainvol run1+orig \\ \n" 376 "\t -trainlabels run1_categories.1D \\ \n" 377 "\t -mask mask+orig \\ \n" 378 "\t -model model_run1\n" 379 "\t -bucket run1_fim\n" 380 "\n" 381 "3. Training: exclude some time points using a censor file \n" 382 "\n" 383 "\t 3dsvm -alpha a_run1 \\\n" 384 "\t -trainvol run1+orig \\ \n" 385 "\t -trainlabels run1_categories.1D \\ \n" 386 "\t -censor censor.1D \\ \n" 387 "\t -mask mask+orig \\ \n" 388 "\t -model model_run1\n" 389 "\t -bucket run1_fim\n" 390 "\n" 391 "4. Training: control svm model complexity (C value)\n" 392 "\n" 393 "\t 3dsvm -c 100.0 \\\n" 394 "\t -alpha a_run1 \\\n" 395 "\t -trainvol run1+orig \\ \n" 396 "\t -trainlabels run1_categories.1D \\ \n" 397 "\t -censor censor.1D \\ \n" 398 "\t -mask mask+orig \\ \n" 399 "\t -model model_run1\n" 400 "\t -bucket run1_fim\n" 401 "\n" 402 "5. Training: using a kernel \n" 403 "\n" 404 "\t 3dsvm -c 100.0 \\\n" 405 "\t -kernel polynomial -d 2 \\\n" 406 "\t -alpha a_run1 \\\n" 407 "\t -trainvol run1+orig \\ \n" 408 "\t -trainlabels run1_categories.1D \\ \n" 409 "\t -censor censor.1D \\ \n" 410 "\t -mask mask+orig \\ \n" 411 "\t -model model_run1\n" 412 "\n" 413 "6. Training: using regression \n" 414 "\n" 415 "\t 3dsvm -type regression \\\n" 416 "\t -c 100.0 \\\n" 417 "\t -e 0.001 \\\n" 418 "\t -alpha a_run1 \\\n" 419 "\t -trainvol run1+orig \\ \n" 420 "\t -trainlabels run1_categories.1D \\ \n" 421 "\t -censor censor.1D \\ \n" 422 "\t -mask mask+orig \\ \n" 423 "\t -model model_run1\n" 424 "\n" 425 "7. Testing: basic options require a testing run, a model, and an output\n" 426 " predictions file\n" 427 "\n" 428 "\t 3dsvm -testvol run2+orig \\\n" 429 "\t -model model_run1+orig \\\n" 430 "\t -predictions pred2_model1\n" 431 "\n" 432 "8. Testing: compare predictions with 'truth' \n" 433 "\n" 434 "\t 3dsvm -testvol run2+orig \\\n" 435 "\t -model model_run1+orig \\\n" 436 "\t -testlabels run2_categories.1D \\\n" 437 "\t -predictions pred2_model1\n" 438 "\n" 439 "9. Testing: use -classout to output integer thresholded class predictions\n" 440 " (rather than continuous valued output)\n" 441 "\n" 442 "\t 3dsvm -classout \\\n" 443 "\t -testvol run2+orig \\\n" 444 "\t -model model_run1+orig \\\n" 445 "\t -testlabels run2_categories.1D \\\n" 446 "\t -predictions pred2_model1\n" 447 "\n" 448 "\n" 449 "options:\n" 450 "--------\n" 451 "\n" 452 "------------------- TRAINING OPTIONS -------------------------------------------\n" 453 "-type tname Specify tname:\n" 454 "\n" 455 " classification [default]\n" 456 " regression\n" 457 "\n" 458 " to select between classification or regression.\n" 459 "\n" 460 "-trainvol trnname A 3D+t AFNI brik dataset to be used for training. \n" 461 "\n" 462 "-mask mname Specify a mask dataset to only perform the analysis\n" 463 " on non-zero mask voxels.\n" 464 " ++ If '-mask' is not used '-nomodelmask must be\n" 465 " specified. \n" 466 " For example, a mask of the whole brain can be \n" 467 " generated by using 3dAutomask, or more specific ROIs\n" 468 " could be generated with the Draw Dataset plugin or\n" 469 " converted from a thresholded functional dataset. \n" 470 " The mask is specified during training but is also \n" 471 " considered part of the model output and is \n" 472 " automatically applied to test data. \n" 473 "\n" 474 "-nomodelmask Flag to enable the omission of a mask file. This is \n" 475 " required if '-mask' is not used.\n" 476 "\n" 477 "-trainlabels lname lname = filename of class category .1D labels \n" 478 " corresponding to the stimulus paradigm for the \n" 479 " training data set. The number of labels in the \n" 480 " selected file must be equal to the number of \n" 481 " time points in the training dataset. The labels\n" 482 " must be arranged in a single column, and they can\n" 483 " be any of the following values: \n" 484 "\n" 485 " 0 - class 0\n" 486 " 1 - class 1\n" 487 " n - class n (where n is a positive integer)\n" 488 " 9999 - censor this point \n" 489 "\n" 490 " See also -censor.\n" 491 "\n" 492 "-censor cname Specify a .1D censor file that allows the user\n" 493 " to ignore certain samples in the training data.\n" 494 " To ignore a specific sample, put a 0 in the\n" 495 " row corresponding to the time sample - i.e., to\n" 496 " ignore sample t, place a 0 in row t of the file.\n" 497 " All samples that are to be included for training\n" 498 " must have a 1 in the corresponding row. If no\n" 499 " censor file is specified, all samples will be used \n" 500 " for training. Note the lname file specified by\n" 501 " trainlabels can also be used to censor time points\n" 502 " (see -trainlabels).\n" 503 "\n" 504 "-kernel kfunc kfunc = string specifying type of kernel function:\n" 505 "\n" 506 " linear : <u,v> [default] \n" 507 " polynomial : (s<u,v> + r)^d \n" 508 " rbf : radial basis function\n" 509 " exp(-gamma ||u-v||^2) \n" 510 " sigmoid : tanh(s <u,v> + r)) \n" 511 "\n" 512 " note: kernel parameters use SVM-light syntax:\n" 513 "\n" 514 " -d int : d parameter in polyniomial kernel\n" 515 " 3 [default]\n" 516 " -g float : gamma parameter in rbf kernel\n" 517 " 1.0 [default]\n" 518 " -s float : s parameter in sigmoid/poly kernel\n" 519 " 1.0 [default]\n" 520 " -r float : r parameter in sigmoid/poly kernel\n" 521 " 1.0 [default]\n" 522 "\n" 523 "-max_iterations int Specify the maximum number of iterations for the\n" 524 " optimization. 1 million [default].\n" 525 "\n" 526 "-alpha aname Write the alphas to aname.1D \n" 527 "\n" 528 "-wout Flag to output sum of weighted linear support \n" 529 " vectors to the bucket file. This is one means of\n" 530 " generating an \"activation map\" from linear kernel\n" 531 " SVMs see (LaConte et al., 2005). NOTE: this is \n" 532 " currently not required since it is the only output\n" 533 " option.\n" 534 "\n" 535 "-bucket bprefix Currently only outputs the sum of weighted linear \n" 536 " support vectors written out to a functional (fim) \n" 537 " brik file. This is one means of generating an \n" 538 " \"activation map\" from linear kernel SVMS \n" 539 " (see LaConte et al, 2005). \n" 540 "\n" 541 "------------------- TRAINING AND TESTING MUST SPECIFY MODNAME ------------------\n" 542 "-model modname modname = basename for the model brik.\n" 543 "\n" 544 " Training: modname is the basename for the output\n" 545 " brik containing the SVM model\n" 546 "\n" 547 " 3dsvm -trainvol run1+orig \\ \n" 548 " -trainlabels run1_categories.1D \\ \n" 549 " -mask mask+orig \\ \n" 550 " -model model_run1\n" 551 "\n" 552 " Testing: modname is the name for the input brik\n" 553 " containing the SVM model.\n" 554 "\n" 555 " 3dsvm -testvol run2+orig \\ \n" 556 " -model model_run1+orig \\ \n" 557 " -predictions pred2_model1\n" 558 "\n" 559 "-nomodelfile Flag to enable the omission of a model file. This is \n" 560 " required if '-model' is not used during training. \n" 561 " ** Be careful, you might not be able to perform testing!\n" 562 "\n" 563 "------------------- TESTING OPTIONS --------------------------------------------\n" 564 "-testvol tstname A 3D or 3D+t AFNI brik dataset to be used for testing. \n" 565 " A major assumption is that the training and testing \n" 566 " volumes are aligned, and that voxels are of same number, \n" 567 " volume, etc. \n" 568 "\n" 569 "-predictions pname pname = basename for .1D prediction file(s). \n" 570 " Prediction files contain a single column, where each line \n" 571 " holds the predicted value for the corresponding volume in\n" 572 " the test dataset. By default, the predicted values take \n" 573 " on a continuous range; to output integer-valued class\n" 574 " decision values use the -classout flag.\n" 575 " For classification: Values bellow 0.5 correspond to \n" 576 " (class A) and values above 0.5 to (class B), where A < B. \n" 577 " For more than two classes a separate prediction file for \n" 578 " each possible pair of training classes and one additional \n" 579 " \"overall\" file containing the predicted (integer-valued)\n" 580 " class membership is generated.\n" 581 " For regression: Each value is the predicted parametric rate \n" 582 " for the corresponding volume in the test dataset. \n" 583 "\n" 584 "-classout Flag to specify that pname files should be integer-\n" 585 " valued, corresponding to class category decisions.\n" 586 "\n" 587 "-nopredcensored Do not write predicted values for censored time-points\n" 588 " to predictions file.\n" 589 "\n" 590 "-nodetrend Flag to specify that pname files should NOT be \n" 591 " linearly detrended (detrending is performed by default).\n" 592 " ** Set this options if you are using GLM beta maps as\n" 593 " input for example. Temporal detrending only \n" 594 " makes sense if you are using time-dependent\n" 595 " data (chronological order!) as input.\n" 596 "\n" 597 "-nopredscale Do not scale predictions. If used, values below 0.0 \n" 598 " correspond to (class A) and values above 0.0 to\n" 599 " (class B).\n" 600 "\n" 601 "-testlabels tlname tlname = filename of 'true' class category .1D labels \n" 602 " for the test dataset. It is used to calculate the \n" 603 " prediction accuracy performance of SVM classification. \n" 604 " If this option is not specified, then performance \n" 605 " calculations are not made. Format is the same as \n" 606 " lname specified for -trainlabels. \n" 607 "\n" 608 "-multiclass mctype mctype specifies the multiclass algorithm for \n" 609 " classification. Current implementations use 1-vs-1\n" 610 " two-class SVM models.\n" 611 "\n" 612 " mctype must be one of the following: \n" 613 "\n" 614 " DAG : Directed Acyclic Graph [default] \n" 615 " vote : Max Wins from votes of all 1-vs-1 models \n" 616 "\n" 617 " see https://lacontelab.org/3dsvm.htm for details and\n" 618 " references.\n" 619 "\n" 620 "------------------- INFORMATION OPTIONS ---------------------------------------\n" 621 "-help this help\n" 622 "\n" 623 "-version print version history including rough description\n" 624 " of changes\n" 625 "\n\n"; 626 627 628 /* --- plugin helpstring --- */ 629 /* this string is currently at its maximum length */ 630 static char plugin_helpstring[] = "\n" 631 "+++++++++++++++ 3dsvm: support vector machine analysis of brain data +++++++++++++++\n\n" 632 633 "This plugin provides the ability to perform support vector machine \n" 634 "(SVM) analyses (training and testing) using SVM-Light (version 5),\n" 635 "developed by Thorsten Joachims, (http://svmlight.joachims.org/).\n" 636 "\n" 637 "General notes:\n" 638 "--------------\n" 639 " This plugin gui provides basic functionality and the most common \n" 640 " control options. More control options are available with the \n" 641 " command-line version, 3dsvm. For example, the full set of \n" 642 " SVM-Light command line options are available in 3dsvm. \n" 643 "\n" 644 "Using the Plugin:\n" 645 "-----------------\n" 646 " - The user can choose to perform SVM training and testing either \n" 647 "alone or together. This is done by selecting the \"Training\" and \n" 648 "or \"Testing\" options. The interface is organized by rows:\n" 649 "\n" 650 " 1) Training - Select this option to perform SVM training. \n" 651 "\n" 652 " a. Type - Choose classification or regression.\n" 653 " classification: labels for stimulus/behavioral categories\n" 654 " regression: labels for parametric tasks\n" 655 "\n" 656 " 2) Train Data - Perform SVM learning using the data specified.\n" 657 "\n" 658 " a. Dataset - Choose a 3D+t training dataset from the current session.\n" 659 "\n" 660 " b. Labels - Choose a .1D file indicating the class labels or regression\n" 661 " values for each TR in the dataset. (one value per line).\n" 662 "\n" 663 " For classification, labels can take on any of the following values: \n" 664 " 0 - class 0\n" 665 " 1 - class 1\n" 666 " n - class n\n" 667 " 9999 - censor this point\n" 668 "\n" 669 " For regression, labels can take any value. Censoring is only possible \n" 670 " through a censor file.\n" 671 "\n" 672 " c. Censors - Choose a .1D file to ignore training samples. To ignore\n" 673 " a specific sample, put a 0 in the line corresponding to\n" 674 " that TR (i.e., to censor the first TR place a 0 in the \n" 675 " first line). All samples to be included must have a 1 \n" 676 " in the corresponding line.\n" 677 "\n" 678 " 3) Train Params - parameters to control training. \n" 679 "\n" 680 " a. Mask - The plugin requires a mask to specify the voxels included\n" 681 " in the SVM analysis. For example, a mask of the whole brain\n" 682 " can be generated by using 3dAutomask. Or ROIs could be \n" 683 " specified with the Draw Dataset plugin or converted from\n" 684 " a thresholded functional dataset. The mask is specified \n" 685 " during training but is also part of the model and is \n" 686 " automatically applied to the test data. \n" 687 "\n" 688 " b. C - An SVM parameter that represents the trade off between \n" 689 " the training error and the margin. Default value is 100. \n" 690 "\n" 691 " c. Epsilon - For regression, the SVM loss function is insensitive \n" 692 " to training errors whos absolute value are smaller than epsilon. \n" 693 " Default value is 0.1. \n" 694 "\n" 695 " 4) Kernel Params - Kernel parameters to control training\n" 696 "\n" 697 " a. Kernel Type - Choose a kernel function \n" 698 " linear : <u,v> [Default] \n" 699 " polynomial : (s<u,v> + r)^d \n" 700 " rbf : radial basis function exp(-g ||u-v||^2) \n" 701 " sigmoid : tanh(s <u,v> + r)) \n" 702 "\n" 703 " b. 'poly order (d)' - For the polynomial kernel select parameter 'd'\n" 704 "\n" 705 " c. 'rbf gamma (g)' - For the rbf kernel select parameter 'g'\n" 706 "\n" 707 " 5) Model Output \n" 708 "\n" 709 " a. Prefix - enter a prefix for the basename of the output model \n" 710 "\n" 711 " 6) Model Inspection - specify output files to examine the SVM model.\n" 712 "\n" 713 " a. FIM prefix - The user can choose to write out the sum of weighted \n" 714 " linear support vectors to a functional (fim) brik file. This is \n" 715 " one way to generating a map from linear kernel SVMs (see \n" 716 " LaConte et al, 2005).\n" 717 "\n" 718 " b. Alpha Prefix - save the alphas (Lagrange Multipliers) to a .1D file.\n" 719 "\n" 720 " 7) Testing - Test a set of volumes using a training model.\n" 721 " If both training and testing options are specified to be run by\n" 722 " the plugin, the model produced by training is applied directly to\n" 723 " the test data. If testing is done alone, the SVM model file must\n" 724 " be specified.\n" 725 "\n" 726 " 8) Test Data - Perform SVM testing using the data specified on \n" 727 " this line.\n" 728 "\n" 729 " a. Dataset - The 3D or 3D+t dataset to test. \n" 730 "\n" 731 " b. Model - The AFNI BRIK/HEAD file is generated by SVM training. \n" 732 " Currently, if training and testing are done at once then a model\n" 733 " should not be selected here.\n" 734 "\n" 735 " 9) Predictions - Output .1D prediction file(s)\n" 736 " Prediction files contain a single column. Each line holds the\n" 737 " predicted value for the corresponding volume in the test dataset\n" 738 " These values are continuous. For classification: 0.5 is the default\n" 739 " threshold. For more than two classes a separate prediction file is\n" 740 " written for each pair of training classes and one additional \n" 741 " \"overall\" file containing the predicted (integer-valued) \n" 742 " class membership is generated.\n" 743 "\n" 744 " a. Prefix - The prefix for the .1D prediction file(s).\n" 745 "\n" 746 " 10) 'True' Labels - A .1D label file that contains the true class values \n" 747 " of the samples in the test dataset. It is used to calculate the \n" 748 " performance of the SVM test. If this option is not chosen, then \n" 749 " performance calculations (like prediction accuracy) are not made. \n" 750 " Note: Prediction accuracy and RMS errors are sent to STDOUT\n" 751 "\n" 752 " a. File - Choose the .1D file with the 'True' labels. \n" 753 "\n" 754 755 "Summary:\n" 756 "-----------------\n" 757 " Train \n" 758 " Required: Train Data (Dataset, Labels); Train Params (Mask); \n" 759 " Model Output (Prefix).\n" 760 " Optional: Train Data (Censors); Train Params (Kernel, C); \n" 761 " Model Inspection (FIM Prefix, Alpha Prefix (.1D)). \n" 762 " Test \n" 763 " Required: Test Data (Dataset, Model); Label Output (.1D).\n" 764 " Optional: 'True' Labels (.1D File). \n" 765 "\n\n\n"; 766 767 /* --- realtime plugin helpstring --- */ 768 static char plugin_helpstring_rt[] = "\n" 769 "+++++++++ 3dsvm: real-time SVM +++++++++\n\n" 770 "\n" 771 "This plugin is integrated into AFNI's real-time framework and \n" 772 "provides the ability to perform real-time support vector machine (SVM) \n" 773 "analysis using SVM-Light (V5.00) developed by Thorsten Joachims,\n" 774 "(See http://svmlight.joachims.org/).\n" 775 "\n" 776 "General notes:\n" 777 "--------------\n" 778 " A connection between the scanner and AFNI is required for real-time\n" 779 " experiments and AFNI must be configured before data acquisition.\n" 780 " See README.realtime for more details.\n" 781 "\n" 782 " This plugin gui provides basic functionality and the most common \n" 783 " control options. More control options are available for real-time \n" 784 " analysis via the plugout_drive command. See README.3dsvm.realtime \n" 785 "\n" 786 "Using the Plugin: \n" 787 "------------------\n" 788 "\n" 789 " The user can choose to either perform SVM training or SVM testing. \n" 790 " This is done by selecting the 'Training' or the 'Testing' option.\n" 791 " The interface is organized by rows: \n" 792 "\n" 793 " 1) Training - Select this option to perform SVM training. \n" 794 "\n" 795 " a. Type - Choose classification or regression for training.\n" 796 " classification: labels represent stimulus/behavioral categories\n" 797 " NOTE: only 2-class classification - for now. \n" 798 " regression: labels for parametric tasks\n" 799 "\n" 800 "\n" 801 " 2) Train Data - Perform SVM training using the data specified. \n" 802 "\n" 803 " a. Labels - Choose a .1D file indicating the class labels \n" 804 " or regression values for each TR that will be \n" 805 " acquired (one value per line). \n" 806 "\n" 807 " For classification, labels can take on the following \n" 808 " values: \n" 809 " 0 - class 0\n" 810 " 1 - class 1\n" 811 " 9999 - censor this time point\n" 812 " See also the next section on censors.\n" 813 "\n" 814 " For regression, labels can take any value. \n" 815 " Censoring is only possible through a censor file.\n" 816 "\n" 817 " b. Censors - Choose a .1D file to ignore training samples. \n" 818 " To ignore a specific sample, put a 0 in the line \n" 819 " corresponding to that TR (i.e., to censor the first TR\n" 820 " place a 0 in the first line). All samples to be \n" 821 " included must have a 1 in the corresponding line.\n" 822 "\n" 823 " 3) Train Params - Parameters to control training.\n" 824 "\n" 825 " a. Mask - The plugin requires a mask to specify the voxels\n" 826 " included in the SVM analysis. For example, a mask \n" 827 " of the whole brain can be generated by using \n" 828 " 3dAutomask. Or ROIs could be specified with the \n" 829 " Draw Dataset plugin or converted from a thresholded \n" 830 " functional dataset. The mask is specified during \n" 831 " training but is also part of the model and is \n" 832 " automatically applied to the test data. \n" 833 "\n" 834 " b. C - An SVM parameter that represents the trade off \n" 835 " between the training error and the margin. \n" 836 " Default value is 100.\n" 837 "\n" 838 " c. Epsilon - For regression, the SVM loss function is \n" 839 " insensitive to training errors whos absolute \n" 840 " value are smaller than epsilon. Default value is 0.1.\n" 841 "\n" 842 " 4) Kernel Params - Kernel parameters to control training \n" 843 "\n" 844 " a. Kernel Type - Choose a kernel function\n" 845 " linear : <u,v> [Default]\n" 846 " polynomial : (s<u,v> + r)^d\n" 847 " rbf : radial basis function exp(-gamma ||u-v||^2)\n" 848 " sigmoid : tanh(s <u,v> + r))\n" 849 "\n" 850 " b. poly order (d) - For the polynomial kernel select parameter 'd'\n" 851 "\n" 852 " c. rbf gamma (g) - For the rbf kernel select parameter 'g'\n" 853 "\n" 854 " 5) Model Output \n" 855 "\n" 856 " a. Prefix - enter a prefix for the basename of the output model \n" 857 "\n" 858 " 6) Model Inspection - specify output files to examine the SVM model\n" 859 "\n" 860 " a. FIM prefix - The user can write out the sum of weighted\n" 861 " linear support vectors to a functional (fim) \n" 862 " brik file. This is one way to generate a map \n" 863 " from linear kernel SVMs (see LaConte et al, 2005).\n" 864 "\n" 865 " b. Alpha Prefix - save the alphas (Lagrange Multipliers) to a \n" 866 " .1D file.\n" 867 "\n" 868 " 7) Testing - Select this option to perform SVM testing. \n" 869 " \n" 870 " 8) Test Data - Perform SVM testing using the model specified on \n" 871 " this line. The actual test data are arriving in real time!\n" 872 "\n" 873 " a. Model - Select a model file for testing. This model \n" 874 " is generated from independent training data. \n" 875 "\n" 876 " 9) Predictions - Output a .1D file with the values of the \n" 877 " classification or regression results.\n" 878 " The values are continuous - even for classification.\n" 879 " By default 0.5 is the threshold for class 0 and \n" 880 " class 1. \n" 881 " \n" 882 " a. Prefix - The prefix for the .1D predictions output file.\n" 883 "\n" 884 " 10) Stimulus - Send the prediction results to a stimulus computer via\n" 885 " TCP/IP.\n" 886 "\n" 887 " a. IP - Specify the IP of the stimulus computer receiving the \n" 888 " prediction results.\n" 889 "\n" 890 " b. PORT - Specify the port of the stimulus computer receiving the\n" 891 " prediction results.\n" 892 "\n\n\n"; 893 894 895 /* ---- string with contributions ---- */ 896 static char contribution_string [] = 897 "Significant programming contributions by: \n" 898 "\n" 899 " Jeff W. Prescott, William A. Curtis, Ziad Saad, Rick Reynolds, \n" 900 " R. Cameron Craddock, Jonathan M. Lisinski, and Stephen M. LaConte \n" 901 "\n" 902 903 "Original version written by JP and SL, August 2006 \n" 904 "Released to general public, July 2007 \n" 905 "\n" 906 "Questions/Comments/Bugs - email slaconte@vtc.vt.edu \n" 907 "\n\n" 908 "Reference:\n" 909 "LaConte, S., Strother, S., Cherkassky, V. and Hu, X. 2005. Support vector\n" 910 " machines for temporal classification of block design fMRI data. \n" 911 " NeuroImage, 26, 317-329.\n" 912 "\n" 913 "Specific to real-time fMRI:\n" 914 "S. M. LaConte. (2011). Decoding fMRI brain states in real-time. \n" 915 " NeuroImage, 56:440-54.\n" 916 "S. M. LaConte, S. J. Peltier, and X. P. Hu. (2007). Real-time fMRI using \n" 917 "brain-state classification. Hum Brain Mapp, 208:1033–1044. \n" 918 "\n" 919 "Please also consider to reference:\n" 920 "T. Joachims, Making Large-Scale SVM Learning Practical.\n" 921 " Advances in Kernel Methods - Support Vector Learning,\n" 922 " B. Schoelkopf and C. Burges and A. Smola (ed.), MIT Press, 1999.\n" 923 "\n" 924 "RW Cox. AFNI: Software for analysis and visualization of\n" 925 " functional magnetic resonance neuroimages.\n" 926 " Computers and Biomedical Research, 29:162-173, 1996.\n" 927 "\n"; 928 929 /*----- String that briefly describes changes -------------------*/ 930 static char change_string[] = "\n" 931 "V1.31 (08/16/2021)\n" 932 " 1) Real-time: Cameron Craddock's general improvements and fast\n" 933 " linear predictions using weight vector (option: -bucket) instead\n" 934 " of full SVM-light model (option: -model).\n" 935 "\n" 936 "V1.30 (11/21/17)\n" 937 " 1) Write prediction and alpha output files using four significant digits,\n" 938 " since Lagrange multipliers (alphas) are currently written/read using\n" 939 " single precision.\n" 940 "\n" 941 "V1.29 (10/31/17)\n" 942 " 1) Added flag: -nomodelfile.\n" 943 "\n" 944 "V1.28 (10/25/15)\n" 945 " 1) Bugfix: Flag -nopredcensored was not working for multi-class.\n" 946 "\n" 947 "V1.27 (07/21/15)\n" 948 " 1) Bugfix: Forgot to update plug_3dsvm in V1.26. Thanks Rick!\n" 949 "\n" 950 "V1.26 (07/07/15)\n" 951 " 1) Bugfix: Model was not initialized properly during regression training\n" 952 " when excluding timepoints (-censor). This might have caused a\n" 953 " crash (depending on platform) during testing\n" 954 " 2) Changed alpha file output (-alpha) for regression. Always write both\n" 955 " sets of alphas even if they are zero\n" 956 "\n" 957 "V1.25 (08/25/14)\n" 958 " 1) Bugfix: Non-linear kernels were not working for regression and caused\n" 959 " 3dsvm to crash. Classification was not affected by this.\n" 960 "\n" 961 "V1.24 (04/03/14)\n" 962 " 1) Allow data type short and float for the mask (previously only byte).\n" 963 " 2) Fixed option -classout and mulit-class accuracy report for non-\n" 964 " continuous class labels (e.g., {4, 1, 9} instead of {0, 1, 2})\n" 965 "\n" 966 "V1.23 (08/16/13)\n" 967 " 1) Bugfix: Fixed -censor during testing.\n" 968 "\n" 969 "V1.22 (01/04/12)\n" 970 " 1) Bugfix: Fixed -max_iterations flag.\n" 971 "\n" 972 "V1.21 (01/04/12)\n" 973 " 1) Bugfix: 3dsvm real-time plugin caused AFNI crash for subsequent runs.\n" 974 "\n" 975 "V1.20 (10/18/11)\n" 976 " 1) Integrated the 3dsvm plugin into AFNI's real-time framework, which\n" 977 " enables SVM-based experiments in real time.\n" 978 " 2) Improved stability and error handling of the plugin.\n" 979 "\n" 980 "V1.13 (07/26/11)\n" 981 " 1) Added option -max_iterations. Allows user to specify maximum\n" 982 " number of iterations for optimization. Default: 1 million iterations.\n" 983 "\n" 984 "V1.12 (10/26/10)\n" 985 " 1) Bugfix: Model was written incorrectly for datum type float\n" 986 " (only .HEAD no .BRIK)\n" 987 "\n" 988 "V1.11 (09/31/10)\n" 989 " 1) Improved error checking for censor file and fixed a bug in deter- \n" 990 " mining the length of the censor file.\n" 991 "\n" 992 "V1.10 (09/08/10)\n" 993 " 1) Removed restriction that class labels had to start from 0 and be \n" 994 " continuous integers. Now it is possible to have, say, a labels.1D that\n" 995 " has {3,10,14}. Previously the user would have had to rename these\n" 996 " as {0,1,2}.\n" 997 " 2) Mask is now the last (two - don't ask why) brik(s) in the model dataset.\n" 998 " Previously the mask was a separate file. If you have old models laying\n" 999 " around. We have kept backwards compatibility to handle this.\n" 1000 " 3) Writing command-line history to bucket header now (still also writing\n" 1001 " to model header).\n" 1002 " 4) Added option -version: Print 3dsvm's and SVM-light's version and brief\n" 1003 " description of changes\n" 1004 " 5) Added option -HELP: Advanced user command-line options (mainly for\n" 1005 " debugging).\n" 1006 "\n" 1007 "V1.10 (09/08/10)\n" 1008 " 1) Added support for non-continuous (arbitrary positive integers) class labels\n" 1009 " 2) Merged model dataset and model-mask dataset to a single model dataset\n" 1010 " 3) Writing command-line history to bucket header now\n" 1011 " 4) Added option -version: Print 3dsvm's and SVM-light's version\n" 1012 " and rough description of changes\n" 1013 " 5) Added option -HELP: Advanced user command-line options\n" 1014 "\n" 1015 "V1.00 (05/14/08) \n" 1016 " 1) Added support for datum type float\n" 1017 " 2) Changed internal representation for datasets to float\n" 1018 " 3) Fixed a memory allocation bug for multi-class strings, that caused\n" 1019 " crashes for more than ~ 6 classes\n" 1020 " 3) Writing weight-vector-maps (into the bucket) as float now\n" 1021 " 4) Enabled SVM-light-provided kernels in regression\n" 1022 " 5) Writing the b-value(s) of the model into bucket header now\n" 1023 " 6) Added version number and version date\n" 1024 "\n" 1025 "Circa Nov 2009\n" 1026 " 1) fixed a memory allocation bug that caused crashes in linux\n" 1027 " 2) fixed a bug in bucket file that caused a one pixel shift in weight\n" 1028 " vector map \n" 1029 " 3) enabled SVM-light-provided kernels\n" 1030 " 4) enabled SVM-light regression\n" 1031 " 5) combined multiclass bucket output to actually be a bucket, rather than\n" 1032 " individual briks\n" 1033 "\n" 1034 "Circa Nov/Dec 2008\n" 1035 " Note that 3dsvm's -predictions files have always been correct, however changes\n" 1036 " 1 and 3 (below) are important for those who only rely on prediction accuracy \n" 1037 " summaries.\n\n" 1038 " 1) Fixed a bug in calculating prediction accuracies.\n" 1039 " 2) Changed multiclass for testvols - old method may have had problems in\n" 1040 " special cases. Now using DAG and Max Wins voting for or one vs. one\n" 1041 " multiclass.\n" 1042 " 3) Improved handling of prediction accuracy calculations for censored test\n" 1043 " data labels\n" 1044 "\n\n"; 1045 1046 /* --- JL Jul 2011: Added funciton prototypes --- */ 1047 void print_version( void ); 1048 int detrend_linear_cnsrs( float *, LABELS *, char * ); 1049 void write_svmLight_doc( DOC *, long , long , LabelType *, char *, char * ); 1050 void printASLoptions( ASLoptions* ); 1051 void printAfniModel( AFNI_MODEL * ); 1052 void printArgv( char **, int *); 1053 void argvAppend( char **, int *, char *, char * ); 1054 void freeArgv( char **, int ); 1055 void getEnvArgv( char **, int *, char *); 1056 int argvCheck( char **, int *, char *, char * ); 1057 void getAllocateCmdlArgv( char *, char *, int *, char *** ); 1058 double cpxtwonorm_sq( WORD *a ); 1059 char * trimString( char * ); 1060 long getFileSize( char * ); 1061 double ** Allocate2d( long, long ); 1062 void free2d( double **, long ); 1063 void Clear2d( double **, long, long ); 1064 float ** Allocate2f( long , long ); 1065 void free2f( float **, long ); 1066 void Clear2f( float **, long, long ); 1067 DatasetType ** Allocate2DT( long, long ); 1068 void free2DT( DatasetType **, long ); 1069 void Clear2DT( DatasetType **, long, long ); 1070 char ** Allocate2c( long, long ); 1071 void Clear2c( char **, long ); 1072 void free2c( char **, long ); 1073 int compare_ints( const int *, const int * ); 1074 DOC * allocateDOCs( long , long ); 1075 void freeDOCs( DOC *, long ); 1076 int allocateMultiClassArrays( float ***, float **, float **, int **, 1077 int **, long, long, long, char * ); 1078 void freeMultiClassArrays( float **, float *, float *, int*, int *, long ); 1079 DatasetType** getAllocateDsetArray(THD_3dim_dataset *, char *); 1080 void freeDsetArray( THD_3dim_dataset *, DatasetType ** ); 1081 int allocateModel( MODEL *, AFNI_MODEL *, char * ); 1082 void freeModel( MODEL *, AFNI_MODEL *, enum modes ); 1083 void updateModel( MODEL *, AFNI_MODEL *, int ); 1084 void freeModelArrays( DatasetType**, MaskType*, long, int ); 1085 int getAllocateModelArrays( THD_3dim_dataset*, DatasetType***, 1086 MaskType**, long *, long *, int *, int, char * ); 1087 int get_svm_model( MODEL *, DatasetType **, MaskType *, AFNI_MODEL *, 1088 long, int, char * ); 1089 int readAllocateAfniModel( THD_3dim_dataset *, AFNI_MODEL *, char * ); 1090 int allocateModelMaps( MODEL_MAPS *, long, long, char * ); 1091 void freeModelMaps( MODEL_MAPS * ); 1092 void addToModelMap_bucket( MODEL_MAPS *, AFNI_MODEL *, DatasetType **, 1093 MaskType *, char *, long ); 1094 int writeModelMap_bucket ( MODEL_MAPS *, MaskType *, THD_3dim_dataset *, 1095 char *, char *, float *, long, ASLoptions*, int, char ** , char *); 1096 void writeModelMask( THD_3dim_dataset *, MaskType*, char * ); 1097 int writeModelBrik( AFNI_MODEL *, THD_3dim_dataset *, DatasetType **, 1098 MaskType *, ASLoptions*, char *, int , char **, char *); 1099 void addToAfniModel( AFNI_MODEL *, MODEL *, LEARN_PARM *, LabelType *, 1100 ASLoptions *, long, long, int, int ); 1101 DatasetType** getAllocateCensoredRegressionArray( DatasetType **, LABELS *, 1102 long ); 1103 void freeCensoredRegressionArray(DatasetType **, LABELS *); 1104 void getClassTrainArrayAndTarget( DatasetType **, LabelType *, 1105 DatasetType **, LabelType *, long, long ); 1106 void afni_dset_to_svm_doc( DOC *, DatasetType **, MaskType*, long, 1107 long, long ); 1108 int getCensoredClassTarget( LabelType *, long *, LABELS *, long, 1109 long, enum modes, char *); 1110 void getTmpLabels( LabelType *, long *, LABELS *, long, long ); 1111 void freeAfniModel( AFNI_MODEL *); 1112 int allocateAfniModel( AFNI_MODEL *, LABELS *, ASLoptions *, char *); 1113 void freeAfniModelAndArrays( AFNI_MODEL *, DatasetType **, MaskType *, 1114 long nt_model ); 1115 int readAllocateAfniModelAndArrays( ASLoptions *, AFNI_MODEL *, 1116 THD_3dim_dataset *, DatasetType ***, MaskType **dsetMaskArray, 1117 long *, long *, enum modes, int *, char * ); 1118 void freeClassificationLabels( LABELS * ); 1119 int getAllocateClassificationLabels (LABELS *, char *, char *, char * ); 1120 int getAllocateRegressionLabelsAndTarget( LABELS *, LabelType **, char *, 1121 char *, char * ); 1122 void freeRegressionLabelsAndTarget( LABELS *, LabelType * ); 1123 int test_classification( ASLoptions *, MODEL *, AFNI_MODEL *, 1124 THD_3dim_dataset *, DatasetType **, MaskType *, long, long, 1125 int, char **, char * ); 1126 int test_rt( DatasetType **, long, double *, char *errorString ); 1127 1128 int test_regression( ASLoptions *, MODEL *, AFNI_MODEL *, 1129 THD_3dim_dataset *, DatasetType **, MaskType *, long, long, int, 1130 char **, char * ); 1131 int train_classification( MODEL *, LEARN_PARM *, KERNEL_PARM *, long *, 1132 ASLoptions *,THD_3dim_dataset *, THD_3dim_dataset *, MaskType *, 1133 int, char **, char *); 1134 int train_regression( MODEL *, LEARN_PARM *, KERNEL_PARM *, long *, 1135 ASLoptions *, THD_3dim_dataset *, THD_3dim_dataset *, MaskType *, 1136 int, char **, char * ); 1137 int ppi (int , int , char **); 1138 int input_parse(int , char **, long *, long *, LEARN_PARM *, 1139 KERNEL_PARM *, ASLoptions*, enum modes *, int *, char *); 1140