static int FUNC(quant_matrix_extension)(CodedBitstreamContext *ctx, RWContext *rw, MPEG2RawQuantMatrixExtension *current) { int err, i; HEADER("Quant Matrix Extension"); ui(1, load_intra_quantiser_matrix); if (current->load_intra_quantiser_matrix) { for (i = 0; i < 64; i++) uis(8, intra_quantiser_matrix[i], 1, i); } ui(1, load_non_intra_quantiser_matrix); if (current->load_non_intra_quantiser_matrix) { for (i = 0; i < 64; i++) uis(8, non_intra_quantiser_matrix[i], 1, i); } ui(1, load_chroma_intra_quantiser_matrix); if (current->load_chroma_intra_quantiser_matrix) { for (i = 0; i < 64; i++) uis(8, intra_quantiser_matrix[i], 1, i); } ui(1, load_chroma_non_intra_quantiser_matrix); if (current->load_chroma_non_intra_quantiser_matrix) { for (i = 0; i < 64; i++) uis(8, chroma_non_intra_quantiser_matrix[i], 1, i); } return 0; }
static int FUNC(sequence_header)(CodedBitstreamContext *ctx, RWContext *rw, MPEG2RawSequenceHeader *current) { CodedBitstreamMPEG2Context *mpeg2 = ctx->priv_data; int err, i; HEADER("Sequence Header"); ui(8, sequence_header_code); ui(12, horizontal_size_value); ui(12, vertical_size_value); mpeg2->horizontal_size = current->horizontal_size_value; mpeg2->vertical_size = current->vertical_size_value; ui(4, aspect_ratio_information); ui(4, frame_rate_code); ui(18, bit_rate_value); marker_bit(); ui(10, vbv_buffer_size_value); ui(1, constrained_parameters_flag); ui(1, load_intra_quantiser_matrix); if (current->load_intra_quantiser_matrix) { for (i = 0; i < 64; i++) uis(8, intra_quantiser_matrix[i], 1, i); } ui(1, load_non_intra_quantiser_matrix); if (current->load_non_intra_quantiser_matrix) { for (i = 0; i < 64; i++) uis(8, non_intra_quantiser_matrix[i], 1, i); } return 0; }
TEST_F(test_d3_array, uiostream) { d3_array a(1, 2, 1, 2, 1, 2); double d = 2.0; for (int i = 1; i <= 2; ++i) { for (int j = 1; j <= 2; ++j) { for (int k = 1; k <= 2; ++k) { a(i, j, k) = d; d += 2.0; } } } uostream uos("uos.txt"); uos << a; uos.close(); d3_array ret(1, 2, 1, 2, 1, 2); uistream uis("uos.txt"); uis >> ret; uis.close(); d = 2.0; for (int i = 1; i <= 2; ++i) { for (int j = 1; j <= 2; ++j) { for (int k = 1; k <= 2; ++k) { ASSERT_DOUBLE_EQ(a(i, j, k), ret(i, j, k)); d += 2.0; } } } }
//you need to implement a container that can alter the current parameter (type should be std::map) //it will be a wrapper container for a map, which will allow the usage of certain operations on that map (for example shifting the values) //these operations WILL alter the current map's structure //you can change the current map, by calling the use() member function (this will ditch the old map, and set the current map to the given parameter) int main() { int your_mark = 1; std::map<int, std::string> mis; std::map<int, std::string> amis; for( int i = 0; i < max; ++i ) { mis[ i ] = std::string( i, 'A' ); amis[ i ] = std::string( i, 0 == i % 2 ? 'R' : 'r' ); } map_util<int, std::string> uis( mis ); //it will "use" mis uis.shift(); //it will shift the currently used map's values to the right uis.use( amis ); //it will change the map being used uis.shift(); std::map<std::string, int> msi; msi[ "Hello" ] = 4; msi[ "World" ] = 7; map_util<std::string, int> usi( msi ); usi.shift(); if ( 4 == msi[ "World" ] && max - 1u == mis[ 0 ].length() && max * 1u == mis.size() && mis[ 1 ].empty() && "r" == amis[ 2 ] ) { your_mark = amis[ 3 ].length(); } uis.shift( max / 2 ); //shift by value uis.use( mis ); uis.shift( 2 ); uis.erase( "AAA" ); //erase key-value pair with the given value uis.erase( "AAAAA" ); uis.erase( "A" ); usi.erase( 4 ); //it currently uses msi if ( 1 == msi.size() && 0 == msi.count( "World" ) && 0 == mis.count( 6 ) && amis[ max / 2 + 1 ].empty() && 'r' == amis.begin()->second.at( 0 ) && "AAAA" == mis[ 7 ] ) { your_mark = amis.size() - mis.size(); } msi[ "World" ] = 1; usi >> 1; //overloaded operator>> uis >> 2; uis.erase_if( contains() ); //erase_if with unary predicate uis.use( amis ); uis.erase_if( size_pred() ); uis >> 3; if ( 7 == msi[ "World" ] && 1 == mis.size() && max / 2u + 1 == amis.size() && 1 == amis.count( 0 ) && 1 == amis.count( max - 1 ) && 0 == amis.count( max / 2 ) ) { your_mark = msi.size() + mis.size() + msi[ "Hello" ]; } std::map<std::string, int, string_size_less> ls; //sort by binary predicate ls[ "C++" ] = 5; ls[ "Eiffel" ] = 1; ls[ "Java" ] = 0; ls[ "Go" ] = 2; //ls[ "Go" ] = 2; //ls[ "C++" ] = 5; //ls[ "Java" ] = 0; //ls[ "Eiffel" ] = 1; map_util<std::string, int, string_size_less> uls( ls ); uls >> 2; uls.erase( 2 ); if ( 0 == ls.count( "Java" ) && 3 == ls.size() && 0 == ls.begin()->second ) { your_mark = ls[ "Eiffel" ]; } std::cout << "Your mark is " << your_mark; std::endl( std::cout ); }
/** * Description not yet available. * \param */ void function_minimizer::trust_region_update(int nvar,int _crit, independent_variables& x,const dvector& _g,const double& _f) { double & f= (double&)_f; dvector & g= (dvector&)_g; fmm fmc(nvar); if (random_effects_flag) { initial_params::set_active_only_random_effects(); //int unvar=initial_params::nvarcalc(); // get the number of active initial_params::restore_start_phase(); initial_params::set_inactive_random_effects(); int nvar1=initial_params::nvarcalc(); // get the number of active if (nvar1 != nvar) { cerr << "failed sanity check in " "void function_minimizer::quasi_newton_block" << endl; ad_exit(1); } } uistream uis("admodel.hes"); if (!uis) { cerr << "Error trying to open file admodel.hes" << endl; ad_exit(1); } int hnvar = 0; uis >> hnvar; dmatrix Hess(1,hnvar,1,hnvar); uis >> Hess; if (!uis) { cerr << "Error trying to read Hessian from admodel.hes" << endl; ad_exit(1); } dmatrix tester(1,hnvar,1,hnvar); tester=Hess; dvector e=sort(eigenvalues(Hess)); double lambda=-e(1)+100.; for (int i=1;i<=hnvar;i++) { tester(i,i)+=lambda; } dvector step = x-solve(tester,g); { // calculate the number of random effects unvar // this turns on random effects variables and turns off // everything else //cout << nvar << endl; initial_params::set_active_only_random_effects(); //cout << nvar << endl; int unvar=initial_params::nvarcalc(); // get the number of active //df1b2_gradlist::set_no_derivatives(); if (lapprox) { delete lapprox; lapprox=0; df1b2variable::pool->deallocate(); for (int i=0;i<df1b2variable::adpool_counter;i++) { delete df1b2variable::adpool_vector[i]; df1b2variable::adpool_vector[i]=0; df1b2variable::nvar_vector[i]=0; df1b2variable::adpool_counter=0; } } lapprox=new laplace_approximation_calculator(nvar,unvar,1,nvar+unvar, this); initial_df1b2params::current_phase=initial_params::current_phase; initial_df1b2params::save_varsptr(); allocate(); initial_df1b2params::restore_varsptr(); df1b2_gradlist::set_no_derivatives(); int ynvar=initial_params::nvarcalc_all(); dvector y(1,ynvar); initial_params::xinit_all(y); initial_df1b2params::reset_all(y); g=(*lapprox)(step,f,this); } } // end block for quasi newton minimization
void function_minimizer::pvm_master_mcmc_routine(int nmcmc,int iseed0,double dscale, int restart_flag) { uostream * pofs_psave=NULL; dmatrix mcmc_display_matrix; int mcmc_save_index=1; int mcmc_wrap_flag=0; int mcmc_gui_length=10000; int no_sd_mcmc=0; int on2=-1; if ( (on2=option_match(ad_comm::argc,ad_comm::argv,"-nosdmcmc"))>-1) no_sd_mcmc=1; if (stddev_params::num_stddev_params==0) { cerr << " You must declare at least one object of type sdreport " << endl << " to do the mcmc calculations" << endl; return; } { //ofstream of_bf("testbf"); //if (adjm_ptr) set_labels_for_mcmc(); ivector number_offsets; dvector lkvector; //double current_bf=0; double lcurrent_bf=0; double size_scale=1.0; double total_spread=200; //double total_spread=2500; uostream * pofs_sd = NULL; int nvar=initial_params::nvarcalc(); // get the number of active parameters int scov_option=0; dmatrix s_covar; dvector s_mean; int on=-1; int ncsim=25000; int nslots=800; //int nslots=3600; int initial_nsim=4800; int ntmp=0; int ncor=0; double bfsum=0; int ibfcount=0; double llbest; double lbmax; //if ( (on=option_match(ad_comm::argc,ad_comm::argv,"-mcscov",ntmp))>-1) //{ scov_option=1; s_covar.allocate(1,nvar,1,nvar); s_mean.allocate(1,nvar); s_mean.initialize(); s_covar.initialize(); int ndvar=stddev_params::num_stddev_calc(); int numdvar=stddev_params::num_stddev_number_calc(); /* if (adjm_ptr) { mcmc_display_matrix.allocate(1,numdvar,1,mcmc_gui_length); number_offsets.allocate(1,numdvar); number_offsets=stddev_params::copy_all_number_offsets(); } */ dvector x(1,nvar); dvector scale(1,nvar); dmatrix values; int have_hist_flag=0; initial_params::xinit(x); dvector pen_vector(1,nvar); { initial_params::reset(dvar_vector(x),pen_vector); cout << pen_vector << endl << endl; } initial_params::mc_phase=0; initial_params::stddev_scale(scale,x); initial_params::mc_phase=1; dvector bmn(1,nvar); dvector mean_mcmc_values(1,ndvar); dvector s(1,ndvar); dvector h(1,ndvar); //dvector h; dvector square_mcmc_values(1,ndvar); square_mcmc_values.initialize(); mean_mcmc_values.initialize(); bmn.initialize(); int use_empirical_flag=0; int diag_option=0; int topt=0; if ( (on=option_match(ad_comm::argc,ad_comm::argv,"-mcdiag"))>-1) { diag_option=1; cout << " Setting covariance matrix to diagonal with entries " << dscale << endl; } dmatrix S(1,nvar,1,nvar); dvector sscale(1,nvar); if (!diag_option) { int on,nopt; int rescale_bounded_flag=0; double rescale_bounded_power=0.5; if ( (on=option_match(ad_comm::argc,ad_comm::argv,"-mcrb",nopt))>-1) { if (nopt) { int iii=atoi(ad_comm::argv[on+1]); if (iii < 1 || iii > 9) { cerr << " -mcrb argument must be integer between 1 and 9 --" " using default of 5" << endl; rescale_bounded_power=0.5; } else rescale_bounded_power=iii/10.0; } else { rescale_bounded_power=0.5; } rescale_bounded_flag=1; } if ( (on=option_match(ad_comm::argc,ad_comm::argv,"-mcec"))>-1) { use_empirical_flag=1; } if (use_empirical_flag) { read_empirical_covariance_matrix(nvar,S,ad_comm::adprogram_name); } else if (!rescale_bounded_flag) { int tmp; read_covariance_matrix(S,nvar,tmp,sscale); } else { read_hessian_matrix_and_scale1(nvar,S,rescale_bounded_power, mcmc2_flag); //read_hessian_matrix_and_scale(nvar,S,pen_vector); } { // scale covariance matrix for model space dmatrix tmp(1,nvar,1,nvar); for (int i=1;i<=nvar;i++) { tmp(i,i)=S(i,i)*(scale(i)*scale(i)); for (int j=1;j<i;j++) { tmp(i,j)=S(i,j)*(scale(i)*scale(j)); tmp(j,i)=tmp(i,j); } } S=tmp; } } else { S.initialize(); for (int i=1;i<=nvar;i++) { S(i,i)=dscale; } } cout << sort(eigenvalues(S)) << endl; dmatrix chd = choleski_decomp( (dscale*2.4/sqrt(double(nvar))) * S); dmatrix chdinv=inv(chd); int sgn; dmatrix symbds(1,2,1,nvar); initial_params::set_all_simulation_bounds(symbds); ofstream ofs_sd1((char*)(ad_comm::adprogram_name + adstring(".mc2"))); { long int iseed=0; int number_sims; if (nmcmc<=0) { number_sims= 100000; } else { number_sims= nmcmc; } //cin >> iseed; if (iseed0<=0) { iseed=-36519; } else { iseed=-iseed0; } if (iseed>0) { iseed=-iseed; } cout << "Initial seed value " << iseed << endl; random_number_generator rng(iseed); rng.better_rand(); //better_rand(iseed); double lprob=0.0; double lpinv=0.0; double lprob3=0.0; // get lower and upper bounds independent_variables y(1,nvar); independent_variables parsave(1,nvar); // read in the mcmc values to date int ii=1; dmatrix hist; if (restart_flag) { int tmp=0; if (!no_sd_mcmc) { hist.allocate(1,ndvar,-nslots,nslots); tmp=read_hist_data(hist,h,mean_mcmc_values,s,parsave,iseed, size_scale); values.allocate(1,ndvar,-nslots,nslots); for (int i=1;i<=ndvar;i++) { values(i).fill_seqadd(mean_mcmc_values(i)-0.5*total_spread*s(i) +.5*h(i),h(i)); } } if (iseed>0) { iseed=-iseed; } double br=rng.better_rand(); if (tmp) have_hist_flag=1; chd=size_scale*chd; chdinv=chdinv/size_scale; } else { int on=-1; int nopt=0; if ( (on=option_match(ad_comm::argc,ad_comm::argv,"-mcpin",nopt))>-1) { if (nopt) { cifstream cif((char *)ad_comm::argv[on+1]); if (!cif) { cerr << "Error trying to open mcmc par input file " << ad_comm::argv[on+1] << endl; exit(1); } cif >> parsave; if (!cif) { cerr << "Error reading from mcmc par input file " << ad_comm::argv[on+1] << endl; exit(1); } } else { cerr << "Illegal option with -mcpin" << endl; } } else { ii=1; initial_params::copy_all_values(parsave,ii); } } ii=1; initial_params::restore_all_values(parsave,ii); gradient_structure::set_NO_DERIVATIVES(); ofstream ogs("sims"); ogs << nvar << " " << number_sims << endl; initial_params::xinit(y); send_int_to_slaves(1); double llc=-pvm_master_get_monte_carlo_value(nvar,y); send_int_to_slaves(1); llbest=-pvm_master_get_monte_carlo_value(nvar,y); lbmax=llbest; // store current mcmc variable values in param_values //dmatrix store_mcmc_values(1,number_sims,1,ndvar); #if defined(USE_BAYES_FACTORS) lkvector.allocate(1,number_sims); #endif dvector mcmc_values(1,ndvar); dvector mcmc_number_values; //if (adjm_ptr) mcmc_number_values.allocate(1,numdvar); int offs=1; stddev_params::copy_all_values(mcmc_values,offs); /* if (adjm_ptr) { offs=1; stddev_params::copy_all_number_values(mcmc_number_values,offs); } */ int change_ball=2500; int nopt; if ( (on=option_match(ad_comm::argc,ad_comm::argv,"-mcscale",nopt))>-1) { if (nopt) { int iii=atoi(ad_comm::argv[on+1]); if (iii <=0) { cerr << " Invalid option following command line option -mcball -- " << endl << " ignored" << endl; } else change_ball=iii; } } int iac=0; int liac=0; int isim=0; int itmp=0; double logr; int u_option=0; double ll; int s_option=1; int psvflag=0; if ( (on=option_match(ad_comm::argc,ad_comm::argv,"-mcu"))>-1) { u_option=1; } if ( (on=option_match(ad_comm::argc,ad_comm::argv,"-mcnoscale"))>-1) { s_option=0; } //cout << llc << " " << llc << endl; int iac_old=0; int i_old=0; { if (!restart_flag) { pofs_sd = new uostream((char*)(ad_comm::adprogram_name + adstring(".mcm"))); } int mcsave_flag=0; int mcrestart_flag=option_match(ad_comm::argc,ad_comm::argv,"-mcr"); if ( (on=option_match(ad_comm::argc,ad_comm::argv,"-mcsave"))>-1) { int jj=(int)atof(ad_comm::argv[on+1]); if (jj <=0) { cerr << " Invalid option following command line option -mcsave -- " << endl; } else { mcsave_flag=jj; if ( mcrestart_flag>-1) { // check that nvar is correct { uistream uis((char*)(ad_comm::adprogram_name + adstring(".psv"))); if (!uis) { cerr << "Error trying to open file" << ad_comm::adprogram_name + adstring(".psv") << " for mcrestart" << endl; cerr << " I am starting a new file " << endl; psvflag=1; } else { int nv1; uis >> nv1; if (nv1 !=nvar) { cerr << "wrong number of independent variables in" << ad_comm::adprogram_name + adstring(".psv") << cerr << " I am starting a new file " << endl; psvflag=1; } } } if (!psvflag) { pofs_psave= new uostream( (char*)(ad_comm::adprogram_name + adstring(".psv")),ios::app); } else { pofs_psave= new uostream((char*)(ad_comm::adprogram_name + adstring(".psv"))); } } else {