Esempio n. 1
0
void init() {
    for (int i = 0; i < maxn; i++) {
        for (int j = 0; j < maxm; j++) {
            for (int k = 0; k < 8; k++) {
                dp[i][j][k] = 0;
            }
        }
    }
    dp[0][0][0] = 1;
    for (int i = 1; i < 101; i ++) {
        for (int j = 0; j <= 30 *(i-1); j++) {
            for (int k = 0; k < 8; k++) if (dp[i - 1][j][k] > 0){
                for (int x = 0 ; x <= 10; x++) {
                    for (int y = 0; x + y <= 10; y++) {
                        int jj = j + calc_value(k, x, y) + x + y;
                        int state = calc_state(k , x, y);  
                        dp[i][jj][state] = (dp[i][jj][state] + dp[i - 1][j][k]) % MOD;
                    }
                }
            }
        }
    }
    for (int i = 1; i < 101; i ++) {
        for (int j = 0; j <= 30 *i; j++) {
            for (int k = 0; k < 8; k++) if (dp[i][j][k] > 0){
               if ((k % 2) == 1) { // two ball 
    
                    for (int x = 0 ; x <= 10; x++) {
                        for (int y = 0; y <= 10; y++) {
                            if (x < 10 && (x + y) > 10) continue;

                            int add  = j + calc_value(k, x, y);

                            dp[i][add][0] = (dp[i][add][0] + dp[i][j][k]) % MOD; 
                        }
                    }
                } else if ((k / 4) == 1){ // only one ball
                    for (int x = 0 ; x <= 10; x++) {
                        int add  = j + x;
                        dp[i][add][0] = (dp[i][add][0] + dp[i][j][k] ) % MOD; 
                    }
                }
            }
        }
    }
}
void silk_warped_autocorrelation_FIX_neon(
          opus_int32                *corr,                                  /* O    Result [order + 1]                                                          */
          opus_int                  *scale,                                 /* O    Scaling of the correlation vector                                           */
    const opus_int16                *input,                                 /* I    Input data to correlate                                                     */
    const opus_int                  warping_Q16,                            /* I    Warping coefficient                                                         */
    const opus_int                  length,                                 /* I    Length of input                                                             */
    const opus_int                  order                                   /* I    Correlation order (even)                                                    */
)
{
    if( ( MAX_SHAPE_LPC_ORDER > 24 ) || ( order < 6 ) ) {
        silk_warped_autocorrelation_FIX_c( corr, scale, input, warping_Q16, length, order );
    } else {
        opus_int       n, i, lsh;
        opus_int64     corr_QC[ MAX_SHAPE_LPC_ORDER + 1 ] = { 0 }; /* In reverse order */
        opus_int64     corr_QC_orderT;
        int64x2_t      lsh_s64x2;
        const opus_int orderT = ( order + 3 ) & ~3;
        opus_int64     *corr_QCT;
        opus_int32     *input_QS;
        VARDECL( opus_int32, input_QST );
        VARDECL( opus_int32, state );
        SAVE_STACK;

        /* Order must be even */
        silk_assert( ( order & 1 ) == 0 );
        silk_assert( 2 * QS - QC >= 0 );

        ALLOC( input_QST, length + 2 * MAX_SHAPE_LPC_ORDER, opus_int32 );

        input_QS = input_QST;
        /* input_QS has zero paddings in the beginning and end. */
        vst1q_s32( input_QS, vdupq_n_s32( 0 ) );
        input_QS += 4;
        vst1q_s32( input_QS, vdupq_n_s32( 0 ) );
        input_QS += 4;
        vst1q_s32( input_QS, vdupq_n_s32( 0 ) );
        input_QS += 4;
        vst1q_s32( input_QS, vdupq_n_s32( 0 ) );
        input_QS += 4;
        vst1q_s32( input_QS, vdupq_n_s32( 0 ) );
        input_QS += 4;
        vst1q_s32( input_QS, vdupq_n_s32( 0 ) );
        input_QS += 4;

        /* Loop over samples */
        for( n = 0; n < length - 7; n += 8, input_QS += 8 ) {
            const int16x8_t t0_s16x4 = vld1q_s16( input + n );
            vst1q_s32( input_QS + 0, vshll_n_s16( vget_low_s16( t0_s16x4 ), QS ) );
            vst1q_s32( input_QS + 4, vshll_n_s16( vget_high_s16( t0_s16x4 ), QS ) );
        }
        for( ; n < length; n++, input_QS++ ) {
            input_QS[ 0 ] = silk_LSHIFT32( (opus_int32)input[ n ], QS );
        }
        vst1q_s32( input_QS, vdupq_n_s32( 0 ) );
        input_QS += 4;
        vst1q_s32( input_QS, vdupq_n_s32( 0 ) );
        input_QS += 4;
        vst1q_s32( input_QS, vdupq_n_s32( 0 ) );
        input_QS += 4;
        vst1q_s32( input_QS, vdupq_n_s32( 0 ) );
        input_QS += 4;
        vst1q_s32( input_QS, vdupq_n_s32( 0 ) );
        input_QS += 4;
        vst1q_s32( input_QS, vdupq_n_s32( 0 ) );
        input_QS = input_QST + MAX_SHAPE_LPC_ORDER - orderT;

        /* The following loop runs ( length + order ) times, with ( order ) extra epilogues.                  */
        /* The zero paddings in input_QS guarantee corr_QC's correctness even with the extra epilogues.       */
        /* The values of state_QS will be polluted by the extra epilogues, however they are temporary values. */

        /* Keep the C code here to help understand the intrinsics optimization. */
        /*
        {
            opus_int32 state_QS[ 2 ][ MAX_SHAPE_LPC_ORDER + 1 ] = { 0 };
            opus_int32 *state_QST[ 3 ];
            state_QST[ 0 ] = state_QS[ 0 ];
            state_QST[ 1 ] = state_QS[ 1 ];
            for( n = 0; n < length + order; n++, input_QS++ ) {
                state_QST[ 0 ][ orderT ] = input_QS[ orderT ];
                for( i = 0; i < orderT; i++ ) {
                    corr_QC[ i ] += silk_RSHIFT64( silk_SMULL( state_QST[ 0 ][ i ], input_QS[ i ] ), 2 * QS - QC );
                    state_QST[ 1 ][ i ] = silk_SMLAWB( state_QST[ 1 ][ i + 1 ], state_QST[ 0 ][ i ] - state_QST[ 0 ][ i + 1 ], warping_Q16 );
                }
                state_QST[ 2 ] = state_QST[ 0 ];
                state_QST[ 0 ] = state_QST[ 1 ];
                state_QST[ 1 ] = state_QST[ 2 ];
            }
        }
        */

        {
            const int32x4_t warping_Q16_s32x4 = vdupq_n_s32( warping_Q16 << 15 );
            const opus_int32 *in = input_QS + orderT;
            opus_int o = orderT;
            int32x4_t state_QS_s32x4[ 3 ][ 2 ];

            ALLOC( state, length + orderT, opus_int32 );
            state_QS_s32x4[ 2 ][ 1 ] = vdupq_n_s32( 0 );

            /* Calculate 8 taps of all inputs in each loop. */
            do {
                state_QS_s32x4[ 0 ][ 0 ] = state_QS_s32x4[ 0 ][ 1 ] =
                state_QS_s32x4[ 1 ][ 0 ] = state_QS_s32x4[ 1 ][ 1 ] = vdupq_n_s32( 0 );
                n = 0;
                do {
                    calc_corr( input_QS + n, corr_QC, o - 8, state_QS_s32x4[ 0 ][ 0 ] );
                    calc_corr( input_QS + n, corr_QC, o - 4, state_QS_s32x4[ 0 ][ 1 ] );
                    state_QS_s32x4[ 2 ][ 1 ] = vld1q_s32( in + n );
                    vst1q_lane_s32( state + n, state_QS_s32x4[ 0 ][ 0 ], 0 );
                    state_QS_s32x4[ 2 ][ 0 ] = vextq_s32( state_QS_s32x4[ 0 ][ 0 ], state_QS_s32x4[ 0 ][ 1 ], 1 );
                    state_QS_s32x4[ 2 ][ 1 ] = vextq_s32( state_QS_s32x4[ 0 ][ 1 ], state_QS_s32x4[ 2 ][ 1 ], 1 );
                    state_QS_s32x4[ 0 ][ 0 ] = calc_state( state_QS_s32x4[ 0 ][ 0 ], state_QS_s32x4[ 2 ][ 0 ], state_QS_s32x4[ 1 ][ 0 ], warping_Q16_s32x4 );
                    state_QS_s32x4[ 0 ][ 1 ] = calc_state( state_QS_s32x4[ 0 ][ 1 ], state_QS_s32x4[ 2 ][ 1 ], state_QS_s32x4[ 1 ][ 1 ], warping_Q16_s32x4 );
                    state_QS_s32x4[ 1 ][ 0 ] = state_QS_s32x4[ 2 ][ 0 ];
                    state_QS_s32x4[ 1 ][ 1 ] = state_QS_s32x4[ 2 ][ 1 ];
                } while( ++n < ( length + order ) );
                in = state;
                o -= 8;
            } while( o > 4 );

            if( o ) {
                /* Calculate the last 4 taps of all inputs. */
                opus_int32 *stateT = state;
                silk_assert( o == 4 );
                state_QS_s32x4[ 0 ][ 0 ] = state_QS_s32x4[ 1 ][ 0 ] = vdupq_n_s32( 0 );
                n = length + order;
                do {
                    calc_corr( input_QS, corr_QC, 0, state_QS_s32x4[ 0 ][ 0 ] );
                    state_QS_s32x4[ 2 ][ 0 ] = vld1q_s32( stateT );
                    vst1q_lane_s32( stateT, state_QS_s32x4[ 0 ][ 0 ], 0 );
                    state_QS_s32x4[ 2 ][ 0 ] = vextq_s32( state_QS_s32x4[ 0 ][ 0 ], state_QS_s32x4[ 2 ][ 0 ], 1 );
                    state_QS_s32x4[ 0 ][ 0 ] = calc_state( state_QS_s32x4[ 0 ][ 0 ], state_QS_s32x4[ 2 ][ 0 ], state_QS_s32x4[ 1 ][ 0 ], warping_Q16_s32x4 );
                    state_QS_s32x4[ 1 ][ 0 ] = state_QS_s32x4[ 2 ][ 0 ];
                    input_QS++;
                    stateT++;
                } while( --n );
            }
        }

        {
            const opus_int16 *inputT = input;
            int32x4_t t_s32x4;
            int64x1_t t_s64x1;
            int64x2_t t_s64x2 = vdupq_n_s64( 0 );
            for( n = 0; n <= length - 8; n += 8 ) {
                int16x8_t input_s16x8 = vld1q_s16( inputT );
                t_s32x4 = vmull_s16( vget_low_s16( input_s16x8 ), vget_low_s16( input_s16x8 ) );
                t_s32x4 = vmlal_s16( t_s32x4, vget_high_s16( input_s16x8 ), vget_high_s16( input_s16x8 ) );
                t_s64x2 = vaddw_s32( t_s64x2, vget_low_s32( t_s32x4 ) );
                t_s64x2 = vaddw_s32( t_s64x2, vget_high_s32( t_s32x4 ) );
                inputT += 8;
            }
            t_s64x1 = vadd_s64( vget_low_s64( t_s64x2 ), vget_high_s64( t_s64x2 ) );
            corr_QC_orderT = vget_lane_s64( t_s64x1, 0 );
            for( ; n < length; n++ ) {
                corr_QC_orderT += silk_SMULL( input[ n ], input[ n ] );
            }
            corr_QC_orderT = silk_LSHIFT64( corr_QC_orderT, QC );
            corr_QC[ orderT ] = corr_QC_orderT;
        }

        corr_QCT = corr_QC + orderT - order;
        lsh = silk_CLZ64( corr_QC_orderT ) - 35;
        lsh = silk_LIMIT( lsh, -12 - QC, 30 - QC );
        *scale = -( QC + lsh );
        silk_assert( *scale >= -30 && *scale <= 12 );
        lsh_s64x2 = vdupq_n_s64( lsh );
        for( i = 0; i <= order - 3; i += 4 ) {
            int32x4_t corr_s32x4;
            int64x2_t corr_QC0_s64x2, corr_QC1_s64x2;
            corr_QC0_s64x2 = vld1q_s64( corr_QCT + i );
            corr_QC1_s64x2 = vld1q_s64( corr_QCT + i + 2 );
            corr_QC0_s64x2 = vshlq_s64( corr_QC0_s64x2, lsh_s64x2 );
            corr_QC1_s64x2 = vshlq_s64( corr_QC1_s64x2, lsh_s64x2 );
            corr_s32x4     = vcombine_s32( vmovn_s64( corr_QC1_s64x2 ), vmovn_s64( corr_QC0_s64x2 ) );
            corr_s32x4     = vrev64q_s32( corr_s32x4 );
            vst1q_s32( corr + order - i - 3, corr_s32x4 );
        }
        if( lsh >= 0 ) {
            for( ; i < order + 1; i++ ) {
                corr[ order - i ] = (opus_int32)silk_CHECK_FIT32( silk_LSHIFT64( corr_QCT[ i ], lsh ) );
            }
        } else {
            for( ; i < order + 1; i++ ) {
                corr[ order - i ] = (opus_int32)silk_CHECK_FIT32( silk_RSHIFT64( corr_QCT[ i ], -lsh ) );
            }
        }
        silk_assert( corr_QCT[ order ] >= 0 ); /* If breaking, decrease QC*/
        RESTORE_STACK;
    }

#ifdef OPUS_CHECK_ASM
    {
        opus_int32 corr_c[ MAX_SHAPE_LPC_ORDER + 1 ];
        opus_int   scale_c;
        silk_warped_autocorrelation_FIX_c( corr_c, &scale_c, input, warping_Q16, length, order );
        silk_assert( !memcmp( corr_c, corr, sizeof( corr_c[ 0 ] ) * ( order + 1 ) ) );
        silk_assert( scale_c == *scale );
    }
#endif
}
Esempio n. 3
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,&params1, &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,&params1, &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();
}