void FULLCOND_rj_mix::update(void) { step_aborted = true; /********* in principle like FULLCOND_rj::rj_step, but now depending on the var_type functions of FULLCOND_rj or FULLCOND_rj_int are used **********************/ while (step_aborted==true) { // two variables are randomly chosen unsigned int i,j; i= rand() % nvar; j=i; while(i==j) j= rand() % nvar; // decide which kind of step (birth, death, switch) if (zeta(i,j) == 1) { if(preg_mods[j]->tell_var_type()=='d') { if(conditions == false) FULLCOND_rj_int::death_step(i,j); else if(conditions_okay_d(i,j) ==true) FULLCOND_rj_int::death_step(i,j); } else { if(conditions == false) FULLCOND_rj::death_step(i,j); else if(conditions_okay_d(i,j) ==true) FULLCOND_rj::death_step(i,j); } } else if (zeta(j,i)==1) { if(preg_mods[j]->tell_var_type()=='d' || preg_mods[i]->tell_var_type()=='d') { if(conditions == false) FULLCOND_rj_int::switch_step(i,j); else if(conditions_okay_s(i,j) ==true) { FULLCOND_rj_int::switch_step(i,j); //cout<<"s_int: "<<i<<" "<<j<<endl; } } else if(preg_mods[j]->tell_var_type()=='c' && preg_mods[i]->tell_var_type()=='c') { if(conditions == false) FULLCOND_rj::switch_step(i,j); else if(conditions_okay_s(i,j) ==true) FULLCOND_rj::switch_step(i,j); } } else { if(preg_mods[j]->tell_var_type()=='d') { if(conditions == false) FULLCOND_rj_int::birth_step(i,j); else if(conditions_okay_b(i,j) ==true) FULLCOND_rj_int::birth_step(i,j); } else { if(conditions == false) FULLCOND_rj::birth_step(i,j); else if(conditions_okay_b(i,j) ==true) FULLCOND_rj::birth_step(i,j); } } } /************* from this point on like in Fullcond_rj::update ***************/ nrtrials++; update_zeta(); //std::set < ST::string, unsigned int> freq; if((optionsp->get_nriter() > optionsp->get_burnin()) && (optionsp->get_nriter() % (optionsp->get_step()) == 0)) { store_model(); } }
/* call as model = mexsvmlearn(data,labels,options) */ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { char **argv; int argc; DOC **docs; /* training examples */ long totwords,totdoc,i; double *target; double *alpha_in=NULL; KERNEL_CACHE *kernel_cache; LEARN_PARM learn_parm; KERNEL_PARM kernel_parm; MODEL model; /* check for valid calling format */ if ((nrhs != 3) || (nlhs != 1)) mexErrMsgTxt(ERR001); if (mxGetM(prhs[0]) != mxGetM(prhs[1])) mexErrMsgTxt(ERR002); if (mxGetN(prhs[1]) != 1) mexErrMsgTxt(ERR003); /* reset static variables -- as a .DLL, static things are sticky */ global_init( ); /* convert the parameters (given in prhs[2]) into an argv/argc combination */ argv = make_argv((mxArray *)prhs[2],&argc); /* send the options */ /* this was originally supposed to be argc, argv, re-written for MATLAB ... its cheesy - but it workss :: convert the options array into an argc, argv pair and let svm_lite handle it from there. */ read_input_parameters(argc,argv,docfile,modelfile,restartfile,&verbosity, &learn_parm,&kernel_parm); extract_user_opts((mxArray *)prhs[2], &kernel_parm); totdoc = mxGetM(prhs[0]); totwords = mxGetN(prhs[0]); /* prhs[0] = samples (mxn) array prhs[1] = labels (mx1) array */ mexToDOC((mxArray *)prhs[0], (mxArray *)prhs[1], &docs, &target, NULL, NULL); /* TODO modify to accept this array if(restartfile[0]) alpha_in=read_alphas(restartfile,totdoc); */ if(kernel_parm.kernel_type == LINEAR) { /* don't need the cache */ kernel_cache=NULL; } else { /* Always get a new kernel cache. It is not possible to use the same cache for two different training runs */ kernel_cache=kernel_cache_init(totdoc,learn_parm.kernel_cache_size); } if(learn_parm.type == CLASSIFICATION) { svm_learn_classification(docs,target,totdoc,totwords,&learn_parm, &kernel_parm,kernel_cache,&model,alpha_in); } else if(learn_parm.type == REGRESSION) { svm_learn_regression(docs,target,totdoc,totwords,&learn_parm, &kernel_parm,&kernel_cache,&model); } else if(learn_parm.type == RANKING) { svm_learn_ranking(docs,target,totdoc,totwords,&learn_parm, &kernel_parm,&kernel_cache,&model); } else if(learn_parm.type == OPTIMIZATION) { svm_learn_optimization(docs,target,totdoc,totwords,&learn_parm, &kernel_parm,kernel_cache,&model,alpha_in); } else { mexErrMsgTxt(ERR004); } if(kernel_cache) { /* Free the memory used for the cache. */ kernel_cache_cleanup(kernel_cache); } /* ********************************** * After the training/learning portion has finished, * copy the model back to the output arrays for MATLAB * ********************************** */ store_model(&model, plhs); free_kernel(); global_destroy( ); }