int my_ls(char *path, int *apply) { t_file *file; DIR *dir_p; t_dirent *entry; if (init_t(&file, dir_p) == -1) return (-1); if ((dir_p = opendir(path)) == NULL) { if (check_if_file(path, apply) == 1) return (0); my_printf("ERROR: opendir: "); my_printf("%s\n", strerror(errno)); return (-1); } while (entry = readdir(dir_p)) { if (entry->d_name[0] != '.' && apply[3] != 1) stack_sort_list(&file, entry, path, apply); else if (apply[3] == 1) stack_sort_list(&file, entry, path, apply); } apply_flags(file, apply, path); closedir(dir_p); }
static int cmp_exact(char *source, int index) { #ifdef MD5_SSE_PARA return 1; #else init_t(); return !memcmp(MD5_std_get_binary(source), MD5_out[index], sizeof(MD5_binary)); #endif }
static void init_setup_tab( void ) { init_w(); init_g(); init_wg(); init_t(); init_wt(); init_gt(); init_wgt(); }
Decoder_void::Decoder_void (const RaptorQ_type type, const RaptorQ_Block_Size symbols, const size_t symbol_size, const RaptorQ_Compute computation) : _type (init_t (type, false)) { _decoder = nullptr; Impl::Dec_Report report = Impl::Dec_Report::NONE; switch (computation) { case RQ_COMPUTE_PARTIAL_FROM_BEGINNING: case RQ_COMPUTE_PARTIAL_ANY: case RQ_COMPUTE_COMPLETE: report = static_cast<Impl::Dec_Report> (computation); break; case RQ_COMPUTE_NO_BACKGROUND: case RQ_COMPUTE_NO_POOL: case RQ_COMPUTE_NO_RETRY: case RQ_COMPUTE_NONE: break; } if (report == Impl::Dec_Report::NONE) { _type = RaptorQ_type::RQ_NONE; return; } switch (_type) { case RaptorQ_type::RQ_DEC_8: _decoder = new Decoder<uint8_t*, uint8_t*> ( static_cast<Block_Size> (symbols), symbol_size, report); return; case RaptorQ_type::RQ_DEC_16: _decoder = new Decoder<uint16_t*, uint16_t*> ( static_cast<Block_Size> (symbols), symbol_size, report); return; case RaptorQ_type::RQ_DEC_32: _decoder = new Decoder<uint32_t*, uint32_t*> ( static_cast<Block_Size> (symbols), symbol_size, report); return; case RaptorQ_type::RQ_DEC_64: _decoder = new Decoder<uint64_t*, uint64_t*> ( static_cast<Block_Size> (symbols), symbol_size, report); return; case RaptorQ_type::RQ_ENC_8: case RaptorQ_type::RQ_ENC_16: case RaptorQ_type::RQ_ENC_32: case RaptorQ_type::RQ_ENC_64: case RaptorQ_type::RQ_NONE: _type = RaptorQ_type::RQ_NONE; break; } }
static int get_hash_6(int index) { #ifdef MD5_SSE_PARA unsigned int x,y; x = index&3; y = index/4; return ((MD5_word *)sout)[x+y*MMX_COEF*4] & 0x7FFFFFF; #else init_t(); return MD5_out[index][0] & 0x7FFFFFF; #endif }
static char *get_key(int index) { static char out[8]; unsigned char *src; char *dst; init_t(); src = DES_bs_all.pxkeys[index]; dst = out; while (dst < &out[7] && (*dst = *src)) { src += sizeof(DES_bs_vector) * 8; dst++; } *dst = 0; return out; }
static int cmp_one(void *binary, int index) { #ifdef MD5_SSE_PARA unsigned int x,y; x = index&3; y = index/4; if( ((unsigned int *)binary)[0] != ((unsigned int *)sout)[x+y*MMX_COEF*4] ) return 0; if( ((unsigned int *)binary)[1] != ((unsigned int *)sout)[x+y*MMX_COEF*4+4] ) return 0; if( ((unsigned int *)binary)[2] != ((unsigned int *)sout)[x+y*MMX_COEF*4+8] ) return 0; if( ((unsigned int *)binary)[3] != ((unsigned int *)sout)[x+y*MMX_COEF*4+12] ) return 0; return 1; #else init_t(); return *(MD5_word *)binary == MD5_out[index][0]; #endif }
void MD5_std_set_key(char *key, int index) { int length; MD5_pool *current; init_t(); for (length = 0; key[length] && length < 15; length++); current = &pool[index]; memcpy(current->o.p.b, key, current->l.p = length); memcpy(¤t->o.p.b[length + 16], PADDING, 40 - length); current->o.p.w[14] = (length + 16) << 3; memcpy(current->o.pp.b, key, length); memcpy(¤t->o.pp.b[length], key, length); current->l.pp = length << 1; memcpy(¤t->o.pp.b[current->l.pp + 16], PADDING, 40 - current->l.pp); current->o.pp.w[14] = (current->l.pp + 16) << 3; memcpy(¤t->e.p.b[16], key, length); memcpy(¤t->e.p.b[16 + length], PADDING, 40 - length); current->e.p.w[14] = (length + 16) << 3; MD5_swap(current->e.p.w, current->e.p.w, 14); memcpy(¤t->e.pp.b[16], current->o.pp.b, current->l.pp); memcpy(¤t->e.pp.b[16 + current->l.pp], PADDING, 40 - current->l.pp); current->e.pp.w[14] = (current->l.pp + 16) << 3; MD5_swap(current->e.pp.w, current->e.pp.w, 14); order[1][index].length = current->l.pp; order[4][index].length = current->l.pp; order[7][index].length = current->l.pp; order[10][index].length = length; order[13][index].length = current->l.pp; order[16][index].length = current->l.pp; order[19][index].length = current->l.pp; }
static char *get_key(int index) { static char out[PLAINTEXT_LENGTH + 1]; #if DES_BS unsigned char *src; char *dst; init_t(); src = DES_bs_all.pxkeys[index]; dst = out; while (dst < &out[PLAINTEXT_LENGTH] && (*dst = *src)) { src += sizeof(DES_bs_vector) * 8; dst++; } *dst = 0; #else memcpy(out, buffer[index].key, PLAINTEXT_LENGTH); out[PLAINTEXT_LENGTH] = 0; #endif return out; }
static int mod_init(void) { DBG( "TM - (sizeof cell=%ld, sip_msg=%ld) initializing...\n", (long)sizeof(struct cell), (long)sizeof(struct sip_msg)); /* checking if we have sufficient bitmap capacity for given maximum number of branches */ if (MAX_BRANCHES+1>31) { LOG(L_CRIT, "Too many max UACs for UAC branch_bm_t bitmap: %d\n", MAX_BRANCHES ); return -1; } if (init_callid() < 0) { LOG(L_CRIT, "Error while initializing Call-ID generator\n"); return -1; } /* building the hash table*/ if (!init_hash_table()) { LOG(L_ERR, "ERROR: mod_init: initializing hash_table failed\n"); return -1; } /* init static hidden values */ init_t(); if (tm_init_selects()==-1) { LOG(L_ERR, "ERROR: mod_init: select init failed\n"); return -1; } if (tm_init_timers()==-1) { LOG(L_ERR, "ERROR: mod_init: timer init failed\n"); return -1; } /* First tm_stat initialization function only allocates the top level stat * structure in shared memory, the initialization will complete in child * init with init_tm_stats_child when the final value of estimated_process_count is * known */ if (init_tm_stats() < 0) { LOG(L_CRIT, "ERROR: mod_init: failed to init stats\n"); return -1; } if (uac_init()==-1) { LOG(L_ERR, "ERROR: mod_init: uac_init failed\n"); return -1; } if (init_tmcb_lists()!=1) { LOG(L_CRIT, "ERROR:tm:mod_init: failed to init tmcb lists\n"); return -1; } tm_init_tags(); init_twrite_lines(); if (init_twrite_sock() < 0) { LOG(L_ERR, "ERROR:tm:mod_init: Unable to create socket\n"); return -1; } /* register post-script clean-up function */ if (register_script_cb( w_t_unref, POST_SCRIPT_CB|REQ_TYPE_CB, 0)<0 ) { LOG(L_ERR,"ERROR:tm:mod_init: failed to register POST request " "callback\n"); return -1; } if (register_script_cb( script_init, PRE_SCRIPT_CB|REQ_TYPE_CB , 0)<0 ) { LOG(L_ERR,"ERROR:tm:mod_init: failed to register PRE request " "callback\n"); return -1; } if (init_avp_params( fr_timer_param, fr_inv_timer_param)<0 ){ LOG(L_ERR,"ERROR:tm:mod_init: failed to process timer AVPs\n"); return -1; } tm_init = 1; return 0; }
static int mod_init(void) { unsigned int timer_sets,set; unsigned int roundto_init; LM_INFO("TM - initializing...\n"); /* checking if we have sufficient bitmap capacity for given maximum number of branches */ if (MAX_BRANCHES+1>31) { LM_CRIT("Too many max UACs for UAC branch_bm_t bitmap: %d\n", MAX_BRANCHES ); return -1; } fix_flag_name(minor_branch_flag_str, minor_branch_flag); minor_branch_flag = get_flag_id_by_name(FLAG_TYPE_BRANCH, minor_branch_flag_str); if (minor_branch_flag!=-1) { if (minor_branch_flag > (8*sizeof(int)-1)) { LM_CRIT("invalid minor branch flag\n"); return -1; } minor_branch_flag = 1<<minor_branch_flag; } else { minor_branch_flag = 0; } /* if statistics are disabled, prevent their registration to core */ if (tm_enable_stats==0) #ifdef STATIC_TM tm_exports.stats = 0; #else exports.stats = 0; #endif if (init_callid() < 0) { LM_CRIT("Error while initializing Call-ID generator\n"); return -1; } /* how many timer sets do we need to create? */ timer_sets = (timer_partitions<=1)?1:timer_partitions ; /* try first allocating all the structures needed for syncing */ if (lock_initialize( timer_sets )==-1) return -1; /* building the hash table*/ if (!init_hash_table( timer_sets )) { LM_ERR("initializing hash_table failed\n"); return -1; } /* init static hidden values */ init_t(); if (!tm_init_timers( timer_sets ) ) { LM_ERR("timer init failed\n"); return -1; } /* the ROUNDTO macro taken from the locking interface */ #ifdef ROUNDTO roundto_init = ROUNDTO; #else roundto_init = sizeof(void *); #endif while (roundto_init != 1) { tm_timer_shift++; roundto_init >>= 1; } LM_DBG("timer set shift is %d\n", tm_timer_shift); /* register the timer functions */ for ( set=0 ; set<timer_sets ; set++ ) { if (register_timer( "tm-timer", timer_routine, (void*)(long)set, 1, TIMER_FLAG_DELAY_ON_DELAY) < 0 ) { LM_ERR("failed to register timer for set %d\n",set); return -1; } if (register_utimer( "tm-utimer", utimer_routine, (void*)(long)set, 100*1000, TIMER_FLAG_DELAY_ON_DELAY)<0) { LM_ERR("failed to register utimer for set %d\n",set); return -1; } } if (uac_init()==-1) { LM_ERR("uac_init failed\n"); return -1; } if (init_tmcb_lists()!=1) { LM_CRIT("failed to init tmcb lists\n"); return -1; } tm_init_tags(); init_twrite_lines(); if (init_twrite_sock() < 0) { LM_ERR("failed to create socket\n"); return -1; } /* register post-script clean-up function */ if (register_script_cb( do_t_cleanup, POST_SCRIPT_CB|REQ_TYPE_CB, 0)<0 ) { LM_ERR("failed to register POST request callback\n"); return -1; } if (register_script_cb( script_init, PRE_SCRIPT_CB|REQ_TYPE_CB , 0)<0 ) { LM_ERR("failed to register PRE request callback\n"); return -1; } if(register_pv_context("request", tm_pv_context_request)< 0) { LM_ERR("Failed to register pv contexts\n"); return -1; } if(register_pv_context("reply", tm_pv_context_reply)< 0) { LM_ERR("Failed to register pv contexts\n"); return -1; } if ( parse_avp_spec( &uac_ctx_avp, &uac_ctx_avp_id)<0 ) { LM_ERR("failed to register AVP name <%s>\n",uac_ctx_avp.s); return -1; } if ( register_async_script_handlers( t_handle_async, t_resume_async )<0 ) { LM_ERR("failed to register async handler to core \n"); return -1; } return 0; }
static int mod_init(void) { DBG( "TM - initializing...\n"); /* checking if we have sufficient bitmap capacity for given maximum number of branches */ if (MAX_BRANCHES+1>31) { LOG(L_CRIT, "Too many max UACs for UAC branch_bm_t bitmap: %d\n", MAX_BRANCHES ); return -1; } if (init_callid() < 0) { LOG(L_CRIT, "Error while initializin Call-ID generator\n"); return -1; } if (register_fifo_cmd(fifo_uac, "t_uac_dlg", 0) < 0) { LOG(L_CRIT, "cannot register fifo t_uac\n"); return -1; } if (register_fifo_cmd(fifo_hash, "t_hash", 0)<0) { LOG(L_CRIT, "cannot register hash\n"); return -1; } if (!init_hash_table()) { LOG(L_ERR, "ERROR: mod_init: initializing hash_table failed\n"); return -1; } /* init static hidden values */ init_t(); if (!tm_init_timers()) { LOG(L_ERR, "ERROR: mod_init: timer init failed\n"); return -1; } /* register the timer function */ register_timer( timer_routine , 0 /* empty attr */, 1 ); /* init_tm_stats calls process_count, which should * NOT be called from mod_init, because one does not * now, if a timer is used and thus how many processes * will be started; however we started already our * timers, so we know and process_count should not * change any more */ if (init_tm_stats()<0) { LOG(L_CRIT, "ERROR: mod_init: failed to init stats\n"); return -1; } /* building the hash table*/ if (uac_init()==-1) { LOG(L_ERR, "ERROR: mod_init: uac_init failed\n"); return -1; } /* register post-script clean-up function */ register_script_cb( w_t_unref, POST_SCRIPT_CB, 0 /* empty param */ ); register_script_cb( script_init, PRE_SCRIPT_CB , 0 /* empty param */ ); tm_init_tags(); return 0; }
inline static void final_response_handler( struct timer_link *fr_tl ) { #define CANCEL_REASON_SIP_480 \ "Reason: SIP;cause=480;text=\"NO_ANSWER\"" CRLF static context_p my_ctx = NULL; context_p old_ctx; struct retr_buf* r_buf; struct cell *t; if (fr_tl==0){ /* or BUG?, ignoring it for now */ LM_CRIT("final_response_handler(0) called\n"); return; } r_buf = get_fr_timer_payload(fr_tl); t=r_buf->my_T; # ifdef EXTRA_DEBUG if (t->damocles) { LM_ERR("transaction %p scheduled for deletion and" " called from FR timer\n",r_buf->my_T); abort(); } # endif reset_timer( &(r_buf->retr_timer) ); /* the transaction is already removed from FR_LIST by the timer */ /* FR for local cancels.... */ if (r_buf->activ_type==TYPE_LOCAL_CANCEL) { LM_DBG("stop retr for Local Cancel\n"); return; } /* FR for replies (negative INVITE replies) */ if (r_buf->activ_type>0) { # ifdef EXTRA_DEBUG if (t->uas.request->REQ_METHOD!=METHOD_INVITE || t->uas.status < 200 ) { LM_ERR("unknown type reply buffer\n"); abort(); } # endif put_on_wait( t ); return; }; /* as this processing is outside the scope of other messages (it is trigger from timer), a processing context must be attached to it */ old_ctx = current_processing_ctx; if (my_ctx==NULL) { my_ctx = context_alloc(CONTEXT_GLOBAL); if (my_ctx==NULL) { LM_ERR("failed to alloc new ctx in pkg\n"); } } memset( my_ctx, 0, context_size(CONTEXT_GLOBAL) ); current_processing_ctx = my_ctx; /* set the T context too */ set_t( t ); /* out-of-lock do the cancel I/O */ if (is_invite(t) && should_cancel_branch(t, r_buf->branch) ) { set_cancel_extra_hdrs( CANCEL_REASON_SIP_480, sizeof(CANCEL_REASON_SIP_480)-1); cancel_branch(t, r_buf->branch ); set_cancel_extra_hdrs( NULL, 0); } /* lock reply processing to determine how to proceed reliably */ LOCK_REPLIES( t ); LM_DBG("Cancel sent out, sending 408 (%p)\n", t); fake_reply(t, r_buf->branch, 408 ); /* flush the context */ if (current_processing_ctx==NULL) my_ctx=NULL; else context_destroy(CONTEXT_GLOBAL, my_ctx); /* switch back to the old context */ current_processing_ctx = old_ctx; /* reset the T context */ init_t(); LM_DBG("done\n"); }
/* This is a test main program. It should compile and print 11 0's. */ int main (void) { unsigned int i; uint32_t k; settable(12345, 65435, 34221, 12345, 9983651, 95746118); init_t(); /* for (i = 0; i < 256; i++) { printf("%"PRIu32"\n", t[i]); } */ /* for (i = 0; i < 256; i++) { printf("%"PRIu32"\n", LFIB4); } */ for (i = 0; i < 1000000; i++) { k = LFIB4; } printf ("%"PRIu32"\n", k - 3673084687U); for (i = 0; i < 1000000; i++) { k = SWB; } printf ("%"PRIu32"\n", k - 319777393U); for (i = 0; i < 1000000; i++) { k = KISS; } printf ("%"PRIu32"\n", k - 2100035942U); for (i = 0; i < 1000000; i++) { k = CONG; } printf ("%"PRIu32"\n", k - 2416584377U); for (i = 0; i < 1000000; i++) { k = SHR3; } printf ("%"PRIu32"\n", k - 1153302609U); for (i = 0; i < 1000000; i++) { k = MWC; } printf ("%"PRIu32"\n", k - 904977562U); for (i = 0; i < 1000000; i++) { k = FIB; } printf ("%"PRIu32"\n", k - 3519793928U); for (i = 0; i < 1000000; i++) { k = MWC64; } printf ("%"PRIu32"\n", k - 3377343606U); mwc64 = MWC64_SEED(7654321, 521288629); shr3 = 362436000; cong = 123456789; for (i = 0; i < 1000000; i++) { k = KISS2; } printf ("%"PRIu32"\n", k - 1010846401U); return 0; }
int main(int argc,char *argv[]) { // decode arguments args(argc,argv); inits(); if(run_type==6) to_year=2010; // Read in Data // cout<< "Reading Data\n"; read_data(); // Set initial Params // cout<< "Initiallizing...\n"; init_state(); init_t(); calc_state(); if(fixed_d != 0) //run traf_mat once and only once (for faster prototyping) { calc_traf(); /* _vbc_vec<float> Uj(1,n_lakes); for(int j=1;j<=n_lakes;j++) { Uj(j) = 0; for(int i=1;i<=n_sources;i++) { Uj(j) += sources(i).Gij(j) * sources(i).Oi; } cout << Uj(j) << "\t" << 1-exp(- pow(0.001 * Uj(j), 1 ) ) << "\n"; } */ calc_traf_mat(); calc_pp(); } ofstream ll_("output/ll_test.dat"); if(FALSE) { calc_traf(); calc_traf_mat(); calc_pp(); //!! int tmp_t; for(int lake=1;lake<=n_lakes;lake++) { if(lakes(lake).invaded == 0 && lakes(lake).last_abs == 0 ) { for(int t=from_year;t<=to_year+2;t++) { // sample_t(); tmp_t=t_vec(lake); t_vec(lake)=t; calc_state(); calc_pp(); cout << lake << "\t" << t <<endl; ll_ << lake << "\t" << t <<"\t"<<l_hood()<<endl; } t_vec(lake)=tmp_t; } } } if(FALSE) // likelihood profile of d and e //if init_t is random, MLE d=e=0 (no effect of distance or size: CHECK) { d_par=-1; e_par=0; for(int i=0;i<=60;i++) { d_par=d_par+0.1; e_par=0; for(int j=0;j<=10;j++) { e_par=e_par + 0.1; calc_traf(); calc_traf_mat(); calc_pp(); ll_ << d_par << "\t" << e_par << "\t" << l_hood()<< endl; cout << d_par <<"\t"<< e_par << "\t" << l_hood()<< endl; } } } if(FALSE) //likelihood profile of alpha { chem_pars(1)=0; for(int i=0;i<=1000;i++) { chem_pars(1)+=0.0001; ll_ << chem_pars(1) << "\t" << l_hood()<< endl; } } //Just sim under the true alpha to see the t_vec distribution // to compare with sim_dat.R if(FALSE) { for(int lake_index=1;lake_index<=n_lakes;lake_index++) { lakes(lake_index).discovered=0; lakes(lake_index).last_abs=0; } for(int i=1;i<=1000;i++) { sim_spread(); write_t(); } } /// SEEDS /// //i d e c B_o NAUT KKUT MGUT //8394 1.06513 0.531416 0.000125572 -13.713 0.00405104 -0.00475339 0.0038181 // CAUT PPUT1 SIO3UR DOC COLTR ALKTI ALKT //0.00403173 0.0571088 1.28896 -0.31447 -0.00654376 0.0621327 -0.000480646 // PH COND25 SECCHI.DEPTH NA //0.00852002 0.00335544 0.0995729 -380.192 //0.407766 1.44137 0.417034 -10.8476 0.708086 -0.0150081 -0.404532 -0.512538 0.689779 0.43177-0.584563 -0.224491 0.786624 1.0269 0.868935 -0.0982729 0.37267 chem_pars(1)=-10; chem_pars(2)=0.7; chem_pars(3)=-0.01; //-2:1 MLE ~0 chem_pars(4)=-0.38; //-1.5:1.5 MLE ~0 chem_pars(5)=-0.5; //-0.4:0.2 MLE ~0 chem_pars(6)=0.68; //0:0.1 MLE 0.05 *** chem_pars(7)=0.43; //-0.4:0.2 MLE ~1.3 **** chem_pars(8)=-0.58; //-0.7:0.1 MLE ~-0.31 **** chem_pars(9)=-0.22; //-0.4:0.2 MLE ~-0.01 ** chem_pars(10)=0.78; //-0.1:0.1 MLE ~0.06 * chem_pars(11)=1.02; //-0.16:0.1 MLE ~0 chem_pars(12)=0.85; //-0.2:0.2 MLE ~0 chem_pars(13)=-0.09; //-0.04:0.01 MLE ~0 chem_pars(14)=0.37; //-0.3:0.3 MLE ~0.1 int test_ch=14; d_par=1.54; //float bb = l_hood(); if(ll) { float tmplhood; for(int i=1;i<=20;i++) { cerr << i << "\n"; //chem_pars(test_ch)=chem_pars(test_ch)+0.0013; d_par=d_par+0.05; calc_traf(); cerr << "A" << "\n"; calc_traf_mat(); cerr << "B" << "\n"; sim_spread(); cerr << "C" << "\n"; //write_t(); tmplhood = l_hood(); cerr << "D" << "\n"; ll_ << chem_pars(test_ch) << "\t" << tmplhood << "\n"; cout << d_par << "\t" << tmplhood << "\n"; } } ll_.close(); cout << "# sampled\t" << n_sampled << "\n"; if(run_type==1) { // FIT ON TRAF_PARS & SPREAD PARS ONLY (NO ENV) // // need a likelihood function wrapper to call l_hood() multiple times and average the result // to smooth out stochastic surface. // BOOTSTRAP RESAMPLING OF DATA (SAMPLED LAKES) TO GENERATE CI // float garbage=l_hood(); int n_reps = 1000; ofstream par_file; int n_pars; //13 env + intercept + d,c,gamma _vbc_vec<float> params1; _vbc_vec<float> dat1; _vbc_vec<float> MLE_params; if(!env) { if(sim) par_file.open("sims/gb_output/pred_pars.tab"); else par_file.open("output/pred_pars.tab"); n_pars=4; // d,c,gamma,alpha params1.redim(1,n_pars); dat1.redim(1,n_pars); MLE_params.redim(1,n_pars); params1(1)=1.27; params1(2)=1.48; params1(3)=0.0000489; params1(4)=0.00105; }else{ if(sim) par_file.open("sims/gb_output/pred_parsENV.tab"); else par_file.open("output/pred_parsENV.tab"); n_pars=18; //13 env + intercept + d,e,c,gamma params1.redim(1,n_pars); dat1.redim(1,n_pars); MLE_params.redim(1,n_pars); params1(1)=1.79; params1(2)=2; params1(3)=0.69; params1(4)=0.0000489; /// SEEDS /// params1(5)=-6.2; params1(6)=0.014; params1(7)=-0.08; //-2:1 MLE ~0 params1(8)=0.15; //-1.5:1.5 MLE ~0 params1(9)=0.21; //-0.4:0.2 MLE ~0 params1(10)=0.03; //0:0.1 MLE 0.05 *** params1(11)=-0.13; //-0.4:0.2 MLE ~1.3 **** params1(12)=-0.43; //-0.7:0.1 MLE ~-0.31 **** params1(13)=-0.007; //-0.4:0.2 MLE ~-0.01 ** params1(14)=0.056; //-0.1:0.1 MLE ~0.06 * params1(15)=0.0087; //-0.16:0.1 MLE ~0 params1(16)=0.081; //-0.2:0.2 MLE ~0 params1(17)=-0.015; //-0.04:0.01 MLE ~0 params1(18)=0.013; //-0.3:0.3 MLE ~0.1 } _vbc_vec<int> tmp_index_sampled; tmp_index_sampled = sampled_index; if(boot) { ofstream boot_file; if(sim) boot_file.open("sims/gb_output/boot_lakes.tab"); else boot_file.open("output/boot_lakes.tab"); for(int i=1;i<=n_reps;i++) { //Bootstrap resample // sampled_index = sample_w_replace(tmp_index_sampled); for(int j=1;j<=n_sampled;j++) boot_file << sampled_index(j) << "\t"; boot_file << "\n"; boot_file.flush(); // --- // simplex::clsSimplex<float> gertzen_rep; //gertzen_rep.set_param_small(1e-3); gertzen_rep.start(&dat1,¶ms1, &MLE_l_hood,n_pars, 1e-2); gertzen_rep.getParams(&MLE_params); cout << "\n\nMLE "<< i << " of " << n_reps << "\n\n"; for(int p=1;p<=n_pars;p++) par_file << MLE_params(p) <<"\t"; par_file << "\n"; par_file.flush(); } boot_file.close(); }else{ simplex::clsSimplex<float> gertzen_rep; //gertzen_rep.set_param_small(1e-3); gertzen_rep.start(&dat1,¶ms1, &MLE_l_hood,n_pars, 1e-2); gertzen_rep.getParams(&MLE_params); cout << "\n\nMLE\n"; for(int p=1;p<=n_pars;p++) par_file << MLE_params(p) <<"\t"; par_file << "\n"; par_file.flush(); // Print out distribution of alpha values at MLE ofstream alphas_file; alphas_file.open("output/alphas.tab",std::fstream::app); for(int i=1;i<=n_lakes;i++) { alphas_file << calc_alpha(i) << "\n"; } alphas_file.close(); } par_file.close(); } if(run_type==2) { //MCMC lib string mcmc_file("output/lib.mcmc"); if(env) { _vbc_vec<float> params(1,4+n_chem_var); _vbc_vec<float> prop_width(1,4+n_chem_var,1,4+n_chem_var); prop_width(1)=0.05; prop_width(2)=0.05; prop_width(3)=0.05; params(1)=0.4; params(2)=1.4; params(3)=0.42; for(int i=1;i<=n_chem_var+1;i++) { prop_width(i+3)=0.0001; params(i+3)=chem_pars(i); } prop_width(4)=0.1; _vbc_vec<float> prop_sigma; prop_sigma = diag(prop_width); // Print out prop_sigma for(int i=1;i<=n_chem_var+4;i++) { for(int j=1;j<=n_chem_var+4;j++) cout << prop_sigma(i,j) << " | "; cout << "\n"; } mcmcMD::run_mcmc(params, prop_sigma, &likelihood_wrapperMCMC_MD, &prior_MD, &restrict_MCMC_MD, 50000, 50, 1, mcmc_file.c_str(), true, true, true, 500, 4); }else { /// No env. _vbc_vec<float> params(1,4); _vbc_vec<float> prop_width(1,4,1,4); prop_width(1)=0.05; prop_width(2)=0.05; prop_width(3)=0.000001; prop_width(4)=0.00001; params(1)=1.27; params(2)=1.48; params(3)=0.0000489; params(4)=0.00105; _vbc_vec<float> prop_sigma; prop_sigma = diag(prop_width); // Print out prop_sigma for(int i=1;i<=4;i++) { for(int j=1;j<=4;j++) cout << prop_sigma(i,j) << " | "; cout << "\n"; } mcmcMD::run_mcmc(params, prop_sigma, &likelihood_wrapperMCMC_MD, &prior_MD, &restrict_MCMC_MD, 500000, 1, 1, mcmc_file.c_str(), true, true, true, 500, 5); } /* mcmcMD::run_mcmc(pms, props, &like, &prior, &restrictions, 500000, 1, 100, file_name.c_str(), TRUE, TRUE, 1000); */ } /// Sim from posterior /// if(run_type==3) sim_spread_posterior(); /// Traf tests //// if(run_type==4) { ofstream traf_ll_file("output/traf_ll.dat"); d_par=1.54; e_par=2; c_par=0.8; calc_traf(); calc_traf_mat(); calc_pp(); sim_spread(); cout << l_hood() <<"\n"; /* for(int i=1;i<=70;i++) { e_par=e_par+0.05; cout << e_par << "\t"; calc_traf(); calc_traf_mat(); calc_pp(); sim_spread(); traf_ll_file << e_par << "\t" << l_hood() << "\n"; cout << l_hood() <<"\t"; sim_spread(); traf_ll_file << e_par << "\t" << l_hood() << "\n"; cout << l_hood() <<"\t"; sim_spread(); traf_ll_file << e_par << "\t" << l_hood() << "\n"; cout << l_hood() <<"\n"; traf_ll_file << e_par << "\t" << l_hood() << "\n"; } for(int i=1;i<=10;i++) { e_par=e_par+0.2; c_par=0.8; calc_traf(); calc_traf_mat(); calc_pp(); for(int j = 1;j<=10;j++) { c_par=c_par+0.2; glb_alpha=0; //from MLE for(int k=1;k<=500;k++) { glb_alpha=glb_alpha+0.00001; sim_spread(); sim_spread(); sim_spread(); cout << e_par << "\t" << c_par << "\t" << glb_alpha << "\t" << l_hood() << "\n"; traf_ll_file << e_par << "\t" << c_par << "\t" << glb_alpha << "\t" << l_hood() << "\n"; } } } */ traf_ll_file.close(); calc_pp(); write_pp(); write_inv_stat(); } /// Holdout sets for internal AUC //// if(run_type==5) { int n_pars=4; _vbc_vec<float>params1(1,n_pars); // Read parameters values from file // ifstream pred_pars; if(sim) pred_pars.open("sims/gb_output/pred_pars.tab"); else pred_pars.open("output/pred_pars.tab"); for(int j=1;j<=n_pars;j++) pred_pars >> params1(j); pred_pars.close(); // -- // d_par=params1(1); e_par = 1; c_par=params1(2); gamma_par=params1(3); glb_alpha=params1(4); calc_traf(); calc_traf_mat(); //write_traf_mat(); //Sub-sample a holdout set from sampled lakes (pre-2010) int n_sub_sampled = 100,choose_from=0; _vbc_vec<int> index_2006_big(1,n_lakes); for(int i = 1; i<=n_lakes;i++) { if( (lakes(i).last_abs==2006 || lakes(i).discovered == 2006) ) { choose_from += 1; index_2006_big(choose_from)=i; } } _vbc_vec<int> index_2006(1,choose_from); for(int i = 1; i<=choose_from;i++) index_2006(i)=index_2006_big(i); ofstream prop_holdout_file; prop_holdout_file.open("output/holdout_sim_props.csv"); ofstream holdout_inv_file("output/holdout2006_data_status.csv"); _vbc_vec<int> holdout_inv_status(1,n_sub_sampled); _vbc_vec<int> indicies_holdout(1,n_sub_sampled); _vbc_vec<int> tmp_discovered(1,n_sub_sampled); _vbc_vec<int> tmp_last_abs(1,n_sub_sampled); cout << "Total 2006 lakes to choose from " << choose_from << "\n"; for(int rep=1;rep<=50;rep++) { indicies_holdout = sample_wo_replace(index_2006,n_sub_sampled); //Record the year_discovered of holdoutset for(int i = 1; i<=n_sub_sampled;i++) { if(lakes(indicies_holdout(i)).discovered == 2006) holdout_inv_status(i) = 1; else holdout_inv_status(i) = 0; //write year discovered if(i == n_sub_sampled) holdout_inv_file << holdout_inv_status(i) << "\n"; else holdout_inv_file << holdout_inv_status(i) << ","; //save last_abs and discoved tmp_discovered(i) = lakes(indicies_holdout(i)).discovered; tmp_last_abs(i) = lakes(indicies_holdout(i)).last_abs; //remove year discovered lakes(indicies_holdout(i)).discovered = 0; lakes(indicies_holdout(i)).last_abs = 0; } //SIM SPREAD _vbc_vec<float> prop_holdout_invaded(1,n_sub_sampled); for(int i=1;i<=n_sub_sampled;i++) prop_holdout_invaded(i) = 0; int n_sims=1000; for(int s=1; s<= n_sims; s++) { sim_spread(); for(int i=1;i<=n_sub_sampled;i++) { if(t_vec(indicies_holdout(i)) <= 2006) prop_holdout_invaded(i) += 1; } } //write prop inv for(int i=1;i<=n_sub_sampled;i++) { prop_holdout_invaded(i) = prop_holdout_invaded(i)/n_sims; if(i < n_sub_sampled) prop_holdout_file << prop_holdout_invaded(i) << ","; else prop_holdout_file << prop_holdout_invaded(i) << "\n"; //reset last_abs and discoved lakes(indicies_holdout(i)).discovered = tmp_discovered(i); lakes(indicies_holdout(i)).last_abs = tmp_last_abs(i); } } holdout_inv_file.close(); prop_holdout_file.close(); }
static int mod_init(void) { DBG( "TM - (size of cell=%ld, sip_msg=%ld) initializing...\n", (long)sizeof(struct cell), (long)sizeof(struct sip_msg)); /* checking if we have sufficient bitmap capacity for given maximum number of branches */ if (MAX_BRANCHES+1>31) { LOG(L_CRIT, "Too many max UACs for UAC branch_bm_t bitmap: %d\n", MAX_BRANCHES ); return -1; } if (init_callid() < 0) { LOG(L_CRIT, "Error while initializing Call-ID generator\n"); return -1; } if (register_fifo_cmd(fifo_uac, "t_uac_dlg", 0) < 0) { LOG(L_CRIT, "cannot register fifo t_uac\n"); return -1; } if (register_fifo_cmd(fifo_uac_cancel, "t_uac_cancel", 0) < 0) { LOG(L_CRIT, "cannot register fifo t_uac_cancel\n"); return -1; } if (register_fifo_cmd(fifo_hash, "t_hash", 0)<0) { LOG(L_CRIT, "cannot register hash\n"); return -1; } if (register_fifo_cmd(fifo_t_reply, "t_reply", 0)<0) { LOG(L_CRIT, "cannot register t_reply\n"); return -1; } if (unixsock_register_cmd("t_uac_dlg", unixsock_uac) < 0) { LOG(L_CRIT, "cannot register t_uac with the unix server\n"); return -1; } if (unixsock_register_cmd("t_uac_cancel", unixsock_uac_cancel) < 0) { LOG(L_CRIT, "cannot register t_uac_cancel with the unix server\n"); return -1; } if (unixsock_register_cmd("t_hash", unixsock_hash) < 0) { LOG(L_CRIT, "cannot register t_hash with the unix server\n"); return -1; } if (unixsock_register_cmd("t_reply", unixsock_t_reply) < 0) { LOG(L_CRIT, "cannot register t_reply with the unix server\n"); return -1; } /* building the hash table*/ if (!init_hash_table()) { LOG(L_ERR, "ERROR: mod_init: initializing hash_table failed\n"); return -1; } /* init static hidden values */ init_t(); if (!tm_init_timers()) { LOG(L_ERR, "ERROR: mod_init: timer init failed\n"); return -1; } /* register the timer function */ register_timer( timer_routine , 0 /* empty attr */, 1 ); /* init_tm_stats calls process_count, which should * NOT be called from mod_init, because one does not * now, if a timer is used and thus how many processes * will be started; however we started already our * timers, so we know and process_count should not * change any more */ if (init_tm_stats()<0) { LOG(L_CRIT, "ERROR: mod_init: failed to init stats\n"); return -1; } if (uac_init()==-1) { LOG(L_ERR, "ERROR: mod_init: uac_init failed\n"); return -1; } if (init_tmcb_lists()!=1) { LOG(L_CRIT, "ERROR:tm:mod_init: failed to init tmcb lists\n"); return -1; } tm_init_tags(); init_twrite_lines(); if (init_twrite_sock() < 0) { LOG(L_ERR, "ERROR:tm:mod_init: Unable to create socket\n"); return -1; } /* register post-script clean-up function */ if (register_script_cb( w_t_unref, POST_SCRIPT_CB|REQ_TYPE_CB, 0)<0 ) { LOG(L_ERR,"ERROR:tm:mod_init: failed to register POST request " "callback\n"); return -1; } if (register_script_cb( script_init, PRE_SCRIPT_CB|REQ_TYPE_CB , 0)<0 ) { LOG(L_ERR,"ERROR:tm:mod_init: failed to register PRE request " "callback\n"); return -1; } if ( init_avp_params( fr_timer_param, fr_inv_timer_param)<0 ){ LOG(L_ERR,"ERROR:tm:mod_init: failed to process timer AVPs\n"); return -1; } if ( init_gf_mask( bf_mask_param )<0 ) { LOG(L_ERR,"ERROR:tm:mod_init: failed to process " "\"branch_flag_mask\" param\n"); return -1; } return 0; }
int main(void) { /* Local scalars */ char compq, compq_i; lapack_int n, n_i; lapack_int ldt, ldt_i; lapack_int ldt_r; lapack_int ldq, ldq_i; lapack_int ldq_r; lapack_int ifst, ifst_i; lapack_int ilst, ilst_i; lapack_int info, info_i; lapack_int i; int failed; /* Local arrays */ lapack_complex_double *t = NULL, *t_i = NULL; lapack_complex_double *q = NULL, *q_i = NULL; lapack_complex_double *t_save = NULL; lapack_complex_double *q_save = NULL; lapack_complex_double *t_r = NULL; lapack_complex_double *q_r = NULL; /* Iniitialize the scalar parameters */ init_scalars_ztrexc( &compq, &n, &ldt, &ldq, &ifst, &ilst ); ldt_r = n+2; ldq_r = n+2; compq_i = compq; n_i = n; ldt_i = ldt; ldq_i = ldq; ifst_i = ifst; ilst_i = ilst; /* Allocate memory for the LAPACK routine arrays */ t = (lapack_complex_double *) LAPACKE_malloc( ldt*n * sizeof(lapack_complex_double) ); q = (lapack_complex_double *) LAPACKE_malloc( ldq*n * sizeof(lapack_complex_double) ); /* Allocate memory for the C interface function arrays */ t_i = (lapack_complex_double *) LAPACKE_malloc( ldt*n * sizeof(lapack_complex_double) ); q_i = (lapack_complex_double *) LAPACKE_malloc( ldq*n * sizeof(lapack_complex_double) ); /* Allocate memory for the backup arrays */ t_save = (lapack_complex_double *) LAPACKE_malloc( ldt*n * sizeof(lapack_complex_double) ); q_save = (lapack_complex_double *) LAPACKE_malloc( ldq*n * sizeof(lapack_complex_double) ); /* Allocate memory for the row-major arrays */ t_r = (lapack_complex_double *) LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_double) ); q_r = (lapack_complex_double *) LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_double) ); /* Initialize input arrays */ init_t( ldt*n, t ); init_q( ldq*n, q ); /* Backup the ouptut arrays */ for( i = 0; i < ldt*n; i++ ) { t_save[i] = t[i]; } for( i = 0; i < ldq*n; i++ ) { q_save[i] = q[i]; } /* Call the LAPACK routine */ ztrexc_( &compq, &n, t, &ldt, q, &ldq, &ifst, &ilst, &info ); /* Initialize input data, call the column-major middle-level * interface to LAPACK routine and check the results */ for( i = 0; i < ldt*n; i++ ) { t_i[i] = t_save[i]; } for( i = 0; i < ldq*n; i++ ) { q_i[i] = q_save[i]; } info_i = LAPACKE_ztrexc_work( LAPACK_COL_MAJOR, compq_i, n_i, t_i, ldt_i, q_i, ldq_i, ifst_i, ilst_i ); failed = compare_ztrexc( t, t_i, q, q_i, info, info_i, compq, ldq, ldt, n ); if( failed == 0 ) { printf( "PASSED: column-major middle-level interface to ztrexc\n" ); } else { printf( "FAILED: column-major middle-level interface to ztrexc\n" ); } /* Initialize input data, call the column-major high-level * interface to LAPACK routine and check the results */ for( i = 0; i < ldt*n; i++ ) { t_i[i] = t_save[i]; } for( i = 0; i < ldq*n; i++ ) { q_i[i] = q_save[i]; } info_i = LAPACKE_ztrexc( LAPACK_COL_MAJOR, compq_i, n_i, t_i, ldt_i, q_i, ldq_i, ifst_i, ilst_i ); failed = compare_ztrexc( t, t_i, q, q_i, info, info_i, compq, ldq, ldt, n ); if( failed == 0 ) { printf( "PASSED: column-major high-level interface to ztrexc\n" ); } else { printf( "FAILED: column-major high-level interface to ztrexc\n" ); } /* Initialize input data, call the row-major middle-level * interface to LAPACK routine and check the results */ for( i = 0; i < ldt*n; i++ ) { t_i[i] = t_save[i]; } for( i = 0; i < ldq*n; i++ ) { q_i[i] = q_save[i]; } LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, t_i, ldt, t_r, n+2 ); if( LAPACKE_lsame( compq, 'v' ) ) { LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, q_i, ldq, q_r, n+2 ); } info_i = LAPACKE_ztrexc_work( LAPACK_ROW_MAJOR, compq_i, n_i, t_r, ldt_r, q_r, ldq_r, ifst_i, ilst_i ); LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, t_r, n+2, t_i, ldt ); if( LAPACKE_lsame( compq, 'v' ) ) { LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, q_r, n+2, q_i, ldq ); } failed = compare_ztrexc( t, t_i, q, q_i, info, info_i, compq, ldq, ldt, n ); if( failed == 0 ) { printf( "PASSED: row-major middle-level interface to ztrexc\n" ); } else { printf( "FAILED: row-major middle-level interface to ztrexc\n" ); } /* Initialize input data, call the row-major high-level * interface to LAPACK routine and check the results */ for( i = 0; i < ldt*n; i++ ) { t_i[i] = t_save[i]; } for( i = 0; i < ldq*n; i++ ) { q_i[i] = q_save[i]; } /* Init row_major arrays */ LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, t_i, ldt, t_r, n+2 ); if( LAPACKE_lsame( compq, 'v' ) ) { LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, q_i, ldq, q_r, n+2 ); } info_i = LAPACKE_ztrexc( LAPACK_ROW_MAJOR, compq_i, n_i, t_r, ldt_r, q_r, ldq_r, ifst_i, ilst_i ); LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, t_r, n+2, t_i, ldt ); if( LAPACKE_lsame( compq, 'v' ) ) { LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, q_r, n+2, q_i, ldq ); } failed = compare_ztrexc( t, t_i, q, q_i, info, info_i, compq, ldq, ldt, n ); if( failed == 0 ) { printf( "PASSED: row-major high-level interface to ztrexc\n" ); } else { printf( "FAILED: row-major high-level interface to ztrexc\n" ); } /* Release memory */ if( t != NULL ) { LAPACKE_free( t ); } if( t_i != NULL ) { LAPACKE_free( t_i ); } if( t_r != NULL ) { LAPACKE_free( t_r ); } if( t_save != NULL ) { LAPACKE_free( t_save ); } if( q != NULL ) { LAPACKE_free( q ); } if( q_i != NULL ) { LAPACKE_free( q_i ); } if( q_r != NULL ) { LAPACKE_free( q_r ); } if( q_save != NULL ) { LAPACKE_free( q_save ); } return 0; }
static int mod_init(void) { LM_INFO("TM - initializing...\n"); /* checking if we have sufficient bitmap capacity for given maximum number of branches */ if (MAX_BRANCHES+1>31) { LM_CRIT("Too many max UACs for UAC branch_bm_t bitmap: %d\n", MAX_BRANCHES ); return -1; } if (minor_branch_flag!=-1) { if (minor_branch_flag > (8*sizeof(int)-1)) { LM_CRIT("invalid minor branch flag\n"); return -1; } minor_branch_flag = 1<<minor_branch_flag; } else { minor_branch_flag = 0; } /* if statistics are disabled, prevent their registration to core */ if (tm_enable_stats==0) #ifdef STATIC_TM tm_exports.stats = 0; #else exports.stats = 0; #endif if (init_callid() < 0) { LM_CRIT("Error while initializing Call-ID generator\n"); return -1; } /* building the hash table*/ if (!init_hash_table()) { LM_ERR("initializing hash_table failed\n"); return -1; } /* init static hidden values */ init_t(); if (!tm_init_timers()) { LM_ERR("timer init failed\n"); return -1; } /* register the timer functions */ if (register_timer( timer_routine , 0, 1 )<0) { LM_ERR("failed to register timer\n"); return -1; } if (register_utimer( utimer_routine , 0, 100*1000 )<0) { LM_ERR("failed to register utimer\n"); return -1; } if (uac_init()==-1) { LM_ERR("uac_init failed\n"); return -1; } if (init_tmcb_lists()!=1) { LM_CRIT("failed to init tmcb lists\n"); return -1; } tm_init_tags(); init_twrite_lines(); if (init_twrite_sock() < 0) { LM_ERR("failed to create socket\n"); return -1; } /* register post-script clean-up function */ if (register_script_cb( do_t_cleanup, POST_SCRIPT_CB|REQ_TYPE_CB, 0)<0 ) { LM_ERR("failed to register POST request callback\n"); return -1; } if (register_script_cb( script_init, PRE_SCRIPT_CB|REQ_TYPE_CB , 0)<0 ) { LM_ERR("failed to register PRE request callback\n"); return -1; } if ( init_avp_params( fr_timer_param, fr_inv_timer_param)<0 ){ LM_ERR("ERROR:tm:mod_init: failed to process timer AVPs\n"); return -1; } if(register_pv_context("request", tm_pv_context_request)< 0) { LM_ERR("Failed to register pv contexts\n"); return -1; } if(register_pv_context("reply", tm_pv_context_reply)< 0) { LM_ERR("Failed to register pv contexts\n"); return -1; } return 0; }