Exemplo n.º 1
0
/*
 * inferece of HMM parameters based on variational Bayes method
 */
int TrainVBHMM::train(const Array2D<Real>& music_spec_td, const HyperparameterVBHMM& hyper_param){
	const int T = music_spec_td.rows(), D = music_spec_td.cols();
	
	Array2D<Array2D<PN> > prev_on_s_td_kj; // 4D-array for transition probability
	// prev_on_s_td_kj(k,j)(t,d): probability of s_{t,d} being j where s_{t-1,d} = k and k = {0,1}
	
	// p_on_s_td_(t,d): probability of s_{t,d} being 1. 1-p_on_s_td_(t,d) is the probability of s_{t,d}=0.
	
	// 1. initialize
	Real active_proportion;
	if(is_silent_)
		active_proportion = init_1st_time(music_spec_td, hyper_param.m0_, hyper_param.init_active_probability_, p_on_s_td_, prev_on_s_td_kj);
	else
		active_proportion = init(music_spec_td, p_on_s_td_, prev_on_s_td_kj);
	
	if(active_proportion < hyper_param.active_proportion_){ // no inference for now
		// the observation is too biased to silence
		return 1;
	}
	is_silent_ = false;
	
	// initialize the suffcient statistics
	std::vector<Real> suff_1_j(2,0), suff_x_j(2,0), suff_xx_j(2,0);
	update_suff_stat(music_spec_td, p_on_s_td_, suff_1_j, suff_x_j, suff_xx_j);
	update_normal_gamma(music_spec_td, hyper_param, suff_1_j, suff_x_j, suff_xx_j); // hat_*** variables are updated
	
	// 2. iteration
	const Real convergence_threshold = 0.001;
	Array2D<PN> before_p_on_s_td = p_on_s_td_;
	for(int iter = 0; iter < hyper_param.max_iteration_; ++iter){
		forward_backward(music_spec_td, p_on_s_td_, prev_on_s_td_kj);
		update_alpha(hyper_param, prev_on_s_td_kj);
		update_suff_stat(music_spec_td, p_on_s_td_, suff_1_j, suff_x_j, suff_xx_j);
		update_normal_gamma(music_spec_td, hyper_param, suff_1_j, suff_x_j, suff_xx_j);
		
		// check convergence
		if(iter == 0)
			continue;
		
		Real diff_p=0;
		for(int t = 0; t < T; ++t){
			for(int d = 0; d < D; ++d){
				const Real diff_td = static_cast<Real>(p_on_s_td_(t,d) - before_p_on_s_td(t,d));
				diff_p += diff_td > 0 ? diff_td : -diff_td;
			}
		}
		diff_p /= (T*D);
		//printf("iter (%02d): diff_p = %f\n",iter,diff_p);
		
		if(diff_p < convergence_threshold){
			break; // end the iteration after converged
		}
		
		before_p_on_s_td = p_on_s_td_;
	}
	
	return 0;
}
Exemplo n.º 2
0
void Tile::start_disabling(const TimeStamp& now)
{
    if (not enabled)
        return;
    enabled = false;
    in_transition = true;
    initial_alpha = alpha;
    alpha_start = now;
    alpha_stop = now + TILE_DISABLE_DURATION;
    update_alpha(now);
}
Exemplo n.º 3
0
void CKLInference::update()
{
	SG_DEBUG("entering\n");

	CInference::update();
	update_init();
	update_alpha();
	update_chol();
	m_gradient_update=false;
	update_parameter_hash();

	SG_DEBUG("leaving\n");
}
Exemplo n.º 4
0
//TESTVERSION av ny main
int main(void)
{
	CONTROL_MODE cm = MANUAL; //Representerar aktuellt läge hos roboten
	
	//Defaultvärden
	angle = 0;
	intensity = 0;
	intensity_byte = 100;
	angle_byte = 100;
	height = 11;
	delta_h = 0.1;
	Kp = 0.001;
	Kd = 0.001;
	
	Init();
	
	//KÖR CONFIGURE-FUNKTIONERNA NÄR SERVONA BEHÖVER KALIBRERAS PÅ NÅGOT SÄTT
	//Configure_Servos_Delaytime();
	//Configure_Servos_LED();
	//Configure_Servos_No_Response();
	Configure_Servos_Angle_Limit();
	//
	
	Send_Inner_P1_Velocity(0x00F0); //DESSA SEX ANROP MÅSTE ALLTID KÖRAS EFTERSOM HASTIGHETEN LIGGER I RAM!!!
	Send_Middle_P1_Velocity(0x0100);//
	Send_Outer_P1_Velocity(0x0100);//
	Send_Inner_P2_Velocity(0x00F0);//
	Send_Middle_P2_Velocity(0x0100);//
	Send_Outer_P2_Velocity(0x0100);//
	
	memset(fromKom, 0, sizeof(fromKom)); //Nollställer fromKom & fromSen (tar bort ev skräp på minnesplatserna) så koden inte ballar ur innan första avbrottet kommit. Lägg ev in i Init!
	memset(fromSen, 0, sizeof(fromSen));
	
	sei(); //Aktivera avbrott öht (MSB=1 i SREG). Anropas EFTER all konfigurering klar!
	
	unsigned char first_kom_byte;
	Walk_Half_Cycle(intensity, angle,height);
	while(1)
	{
		first_kom_byte = fromKom[0];
		//
		//if (first_kom_byte & 0b00001000) //Växla läge?
		//{
			//unsigned char change_mode = fromKom[4];
			//
			//if (change_mode == 0) //Byt till MANUAL?
			//{
				//cm = MANUAL;
			//} 
			//
			//else if (change_mode == 1) //Byt till AUTO?
			//{
				//cm = AUTO;
			//}
			//else if (change_mode == 2) //Byt till RACE?
			//{
				//cm = RACE;
			//}
		//}
		
		switch(cm)
		{
			case MANUAL: //Manuellt läge
				intensity_byte = 100;
				angle_byte = 100;
			
				if (first_kom_byte & 0b00000011) //Skickas vinkel & intensitet?
				{
					
					intensity_byte = fromKom[2] - 100;
					intensity = (float)(intensity_byte)*((float)6)/((float)100); //100 på kontroll -> 6 i speed
					angle_byte = 0;
					//memcpy(angle_byte, fromKom[1], sizeof(angle_byte));
					angle_byte = fromKom[1] - 100;
					
					angle = (float)(angle_byte)*((float)0.57)/((float)100); //128 på kontroll -> 0.57 i vinkel	
					
					Walk_Half_Cycle(intensity, angle,height);
				}
				if (first_kom_byte & 0b00000100) //Höj/sänk gångstil?
				{
					unsigned char change_height = fromKom[3];
					
					if (change_height == 1) //Sänk?
					{
						height -= delta_h;
					}
					else if (change_height == 2) //Höj?
					{
						height += delta_h;
					}
					Walk_Half_Cycle(0, 0,height);
				}
				if (first_kom_byte & 0b00010000) //Nytt Kp?
				{
					Kp = ((float)fromKom[5])/10; //Kp skickas som 10 ggr det önskade värdet!!!
				}
				if (first_kom_byte & 0b00100000) //Nytt Kd?
				{
					Kd = ((float)fromKom[6])/10; //Kd skickas som 10 ggr det önskade värdet!!!
				}
				break;
			case AUTO: //Autonomt läge
				update_alpha();
				Walk_Half_Cycle(1, alpha_d, height);
				break;
			case RACE: 
				//if (PIND3 == 0) //Har knapp tryckts ned? PIN ist. för PORT eftersom in-port ist. för ut-port???
				//{
					//cm = AUTO; 
				//}
				break;
			default:
				break;	
		}		
	}
}
Exemplo n.º 5
0
void train_once_KernelPerceptronModel(KernelPerceptron mdl, const CoNLLCorpus corpus, int max_rec) {
    long match = 0, total = 0;
    //size_t slen=0;

    double s_initial = dsecnd();
    int max_sv = 0;


    log_info("Total number of training instances %d", (max_rec == -1) ? DArray_count(corpus->sentences) : max_rec);

    for (int si = 0; si < ((max_rec == -1) ? DArray_count(corpus->sentences) : max_rec); si++) {

        FeaturedSentence sent = (FeaturedSentence) DArray_get(corpus->sentences, si);

        debug("Building feature matrix for sentence %d", si);
        set_FeatureMatrix(NULL, corpus, si);

        set_adjacency_matrix_fast(corpus, si, mdl, false);

        max_sv += (sent->length + 1) * sent->length - sent->length;

        int *model = parse(sent);

        //printfarch(model, sent->length);
        debug("Parsing sentence %d of length %d is done", si, sent->length);
        int *empirical = get_parents(sent);

        //printfarch(empirical, sent->length);
        int nm = nmatch(model, empirical, sent->length);

        debug("Model matches %d arcs out of %d arcs", nm, sent->length);
        if (nm != sent->length) { // root has no valid parent.
            log_info("Sentence %d (section %d) of length %d (%d arcs out of %d arcs are correct)", si, sent->section, sent->length, nm, sent->length);

            int sentence_length = sent->length;
            for (int to = 1; to <= sentence_length; to++) {

                if (model[to] != empirical[to]) {

                    update_alpha(mdl, si, model[to], to, sent, -1);

                    update_alpha(mdl, si, empirical[to], to, sent, +1);
                }


            }
        } else {
            log_info("Sentence %d (section %d) of length %d (Perfect parse)", si, sent->section, sent->length);
        }

        size_t nsuccess;
        if (budget_method == RANDOMIZED) {
            if (mdl->M > budget_target) {
                size_t nbefore = mdl->M;
                size_t nasked = nbefore - budget_target;
                nsuccess = delete_n_random_hypothesis(mdl, nasked);

                log_info("%lu vectors deleted (%lu asked). Current hypothesis set size reduced from %lu to %lu", nsuccess, nasked, nbefore, mdl->M);
            }
        }

        mdl->c++;

        free_feature_matrix(corpus, si);

        match += nm;
        total += (sent->length);


        if ((si + 1) % 1000 == 0 && si != 0) {
            log_info("Running training accuracy %lf after %d sentence.", (match * 1.) / total, si + 1);

            unsigned nsv = mdl->M;
            log_info("%u (%f of total %d) support vectors", nsv, (nsv * 1.) / max_sv, max_sv);
        }

        free(model);
        free(empirical);
    }

    unsigned nsv = mdl->M;
    log_info("Running training accuracy %lf", (match * 1.) / total);
    log_info("%u (%f of total %d) support vectors", nsv, (nsv * 1.) / max_sv, max_sv);

    if (verbosity > 0) {

        dump_support_vectors(mdl);



    }

    update_average_alpha(mdl);

    return;
}
int main( int argc, char *argv[] )
{

    // struct for parsing parameters
    SimParams sim_params( argc , argv );

    // init model param and sim structs
    ModelParameters* modelParameters = new ModelParameters();
    Int seed = sim_params.get_int_param("random_seed");
    StochSimulator* stochSimulator = new StochSimulator( modelParameters , seed );

    // parsing model variants
    string partitioning_type = sim_params.get_string_param( "partitioning_type" );
    string GE_model = sim_params.get_string_param( "GE_model" );
    string alpha_model = sim_params.get_string_param( "alpha_model" );

    // parsing alpha model parameters
    modelParameters->mu_max = sim_params.get_double_param( "mu_max" ); // given in per hour
    modelParameters->alpha_max = modelParameters->mu_max * log(2.) / 60.; // we use minutes as the time-scale
    if(alpha_model == "norm_distrib" ) {
        modelParameters->alpha_CV = sim_params.get_double_param( "alpha_CV" );
    }
    else {
        modelParameters->regulation_hill = sim_params.get_double_param( "regulation_hill" );
        modelParameters->regulation_conc = sim_params.get_double_param( "regulation_conc" );
    }

    //  parsing GE model parameters
    if( GE_model == "constant_rates" )
    {
        modelParameters->set_km( sim_params.get_double_param( "km" ) );
        modelParameters->set_rm( sim_params.get_double_param( "rm" ) );
        modelParameters->set_kp( sim_params.get_double_param( "kp" ) );
        modelParameters->set_rp( sim_params.get_double_param( "rp" ) );
    }
    if( GE_model == "dependent_rates" )
    {
        modelParameters->km_0 = sim_params.get_double_param(("km_0") );
        modelParameters->km_per_size = sim_params.get_double_param(("km_per_size") );
        modelParameters->km_per_alpha = sim_params.get_double_param(("km_per_alpha") );

        modelParameters->kp_0 = sim_params.get_double_param(("kp_0") );
        modelParameters->kp_per_size = sim_params.get_double_param(("kp_per_size") );

        modelParameters->set_rm( sim_params.get_double_param( "rm" ) );
        modelParameters->set_rp( sim_params.get_double_param( "rp" ) );
    }

    // parsing size model parameters
    modelParameters->lnm_a = sim_params.get_double_param("lnm_a");
    modelParameters->lnm_b = sim_params.get_double_param("lnm_b");
    modelParameters->lnm_sigma_1 = sim_params.get_double_param("lnm_sigma_1");
    modelParameters->lnm_sigma_2 = sim_params.get_double_param("lnm_sigma_2");

    // simulation parameters(always the same, do not depend on model variant)
    Int num_lineages = sim_params.get_int_param( "num_lineages" );
    Doub sim_duration = sim_params.get_double_param( "sim_duration" );
    Doub update_period = sim_params.get_double_param("update_period" );
    Int num_updates_per_output = sim_params.get_double_param("num_updates_per_output" );
    Int num_timepoints =(Int)( sim_duration / update_period /(Doub) num_updates_per_output ) + 1;
    string out_folder = sim_params.get_string_param( "out_folder" );
    sim_params.display_params();
    sim_params.write_params();

    // for debugging
    Bool verbose = false;

    // Matrice storing data
    MatDoub lineage_traj_mRNA_data( num_timepoints , num_lineages , 0. );
    MatDoub lineage_traj_prot_data( num_timepoints , num_lineages , 0. );
    MatDoub lineage_traj_size_data( num_timepoints , num_lineages , 0. );
    MatDoub lineage_traj_alpha_data( num_timepoints , num_lineages , 0. );
    MatDoub lineage_traj_time_data( num_timepoints , num_lineages , 0. );
    Int num_timepoints_done = 0;

    // iterate on cells
    for(Int c=0;c<num_lineages;c++)
    {
        // construction of a cell(look constructor for init state)
        CellState *cell = new CellState(modelParameters);

        // update gene expression rates
        update_gene_expression_rates( cell , modelParameters , GE_model );

        // choose division size
        choose_division_size(cell,modelParameters,stochSimulator);

        // verbose
        if(verbose)
        {
            cout << endl << "Lineage start." << endl;
            cout << "L_birth = " << cell->Lb << " , L_div = " << cell->Ld << endl << endl;
        }

        // timers(all in absolute time)
        Doub t_birth = 0;
        Doub t = 0;
        Doub next_update_t = update_period;
        Doub next_div_t = t + cell->get_time_to_div();
        num_timepoints_done = 0;
        Int num_updates_since_last_output = 0;

        while( t < sim_duration )
        {
            if(verbose) cout << endl << "__ t = " << t << ", next_div_t = " << next_div_t << " __" << endl;

            // if next div before next update
            if( next_div_t < next_update_t )
            {
                // simulate until div
                stochSimulator->simulate( cell , next_div_t - t ); // remaining time before div

                // update time
                t = next_div_t;

                //verbose
                if(verbose) cout << "Division reached." << endl;
                //                if(verbose) cout << "Time average toxin conc = " << time_average_toxin_conc_previous_cycle << endl;
                if(verbose) cout << "Toxin concentration just before div = " << cell->get_prot_Level() / cell->L << endl;

                // choose birth size(splitting)
                if(verbose) cout << "about to choose birth size from div size = " << cell->Ld << endl;
                choose_birth_size(cell,modelParameters,stochSimulator);
                if(verbose) cout << "L_birth chosen = " << cell->Lb << endl;

                // binomial partitioning of mRNA and prot
                do_partitioning( partitioning_type , cell->Lb/cell->Ld , cell , stochSimulator );

                if(verbose) cout << "Toxin concentration just after div = " << cell->get_prot_Level() / cell->Lb << endl;

                // update alpha(how its done depends on the alpha_model)
                update_alpha( cell , modelParameters , alpha_model , stochSimulator );

                if(verbose) cout << "Next alpha = " << cell->alpha * 60. << endl;

                // update gene expression rates
                update_gene_expression_rates( cell , modelParameters , GE_model );

                // choose division size
                choose_division_size( cell , modelParameters , stochSimulator );

                // update timers
                t_birth = t;
                next_div_t = t + cell->get_time_to_div();
            }

            else // just simulate until next update
            {
                // if output needed
                if((num_updates_since_last_output == num_updates_per_output) ||(t == 0)  )
                {
                    if(num_timepoints_done == num_timepoints) { cout << "error output table" << endl; exit(5); }
                    lineage_traj_mRNA_data[num_timepoints_done][c] = cell->get_mRNA_Level();
                    lineage_traj_prot_data[num_timepoints_done][c] = cell->get_prot_Level();
                    lineage_traj_size_data[num_timepoints_done][c] = cell->L;
                    lineage_traj_alpha_data[num_timepoints_done][c] = cell->alpha;
                    lineage_traj_time_data[num_timepoints_done][c] = t;
                    num_timepoints_done++;
                    num_updates_since_last_output = 0;
                    if(verbose) cout << "outputs done = " << num_timepoints_done << endl;
                }

                // simulate
                stochSimulator->simulate( cell , next_update_t - t ); // remaining time before update

                // update alpha(will be done only if required by alpha_model)
                update_alpha( cell , modelParameters , alpha_model , stochSimulator );

                // update gene expression rates(if needed by GE_model)
                update_gene_expression_rates(cell , modelParameters , GE_model );

                // update time
                t = next_update_t;

                // update timers
                next_update_t = t + update_period;
                next_div_t = t + cell->get_time_to_div();
                num_updates_since_last_output++;
            }
        }

        // free memory used by the cell if not needed
        delete cell;
    }

    // verify all points in the tables have been filled, if needed, remove last point
    if(num_timepoints_done < num_timepoints)
    {
        //        cout << "timepoints not filled" << endl;
        if( num_timepoints_done < num_timepoints - 1 )
        {
            cout << "error: more than one timepoint missing ?!" << endl; exit(4);
        }
        lineage_traj_time_data[num_timepoints-1][0] = -1; // flag that will be detected by matlab
    }

    // write data on file
    ostringstream suffix; suffix << ".dat";
    if(verbose) cout << endl << endl << "writing tables" << endl;
    writeMatrixInTextFile( out_folder , "lineage_traj_mRNA_data"+suffix.str()  , lineage_traj_mRNA_data );
    writeMatrixInTextFile( out_folder , "lineage_traj_prot_data"+suffix.str()  , lineage_traj_prot_data );
    writeMatrixInTextFile( out_folder , "lineage_traj_size_data"+suffix.str()  , lineage_traj_size_data );
    writeMatrixInTextFile( out_folder , "lineage_traj_alpha_data"+suffix.str()  , lineage_traj_alpha_data );
    writeMatrixInTextFile( out_folder , "lineage_traj_time_data"+suffix.str() , lineage_traj_time_data );
    return 0;
}
Exemplo n.º 7
0
extern "C" void Smoke3d_CB(int var) {
    int i;
    char *tour_label;
    char *vol_prefixptr;

    updatemenu=1;
    switch(var) {
        float temp_min, temp_max;

    case VOL_UNLOAD_ALL:
        UnLoadVolSmoke3DMenu(-1);
        break;
    case VOL_PREFIX:
        break;
    case VOL_TOUR_LIST:
        TOUR_CB(TOUR_LIST);
        break;
    case START_FRAME:
        if(vol_startframe0<0) {
            vol_startframe0=0;
            SPINNER_startframe->set_int_val(vol_startframe0);
        }
        break;
    case SKIP_FRAME:
        if(vol_skipframe0<1) {
            vol_skipframe0=1;
            SPINNER_skipframe->set_int_val(vol_skipframe0);
        }
        break;
    case CANCEL_GENERATE_IMAGES:
        Script_CB(SCRIPT_CANCEL_NOW);
        break;
    case GENERATE_IMAGES:
        if(selected_tour==NULL) {
            tour_label=NULL;
        }
        else {
            tour_label=selected_tour->label;
        }
        trim(vol_prefix);
        vol_prefixptr=trim_front(vol_prefix);
        if(strlen(vol_prefixptr)==0)vol_prefixptr=fdsprefix;
        init_volrender_script(vol_prefixptr, tour_label, vol_startframe0, vol_skipframe0);
        break;
    case NONGPU_VOL_FACTOR:
        init_volrender_surface(NOT_FIRSTCALL);
        break;
    case GPU_VOL_FACTOR:
        break;
    case COMBINE_MESHES:
        define_volsmoke_textures();
        break;
    case SHOW_FIRECOLORMAP:
        Update_Smokecolormap(smoke_render_option);
        if(show_firecolormap==1) {
            show_glui_colorbar();
        }
        else {
            hide_glui_colorbar();
        }
        break;
    case TEMP_MIN:
        temp_min = 20.0;
        temp_max = (float)(10.0*(int)(temperature_cutoff/10.0)-10.0);
        SPINNER_temperature_min->set_float_limits(temp_min,temp_max);
        Update_Smokecolormap(smoke_render_option);
        break;
    case TEMP_CUTOFF:
        temp_min = (float)(10*(int)(temperature_min/10.0) + 10.0);
        temp_max = (float)(10*(int)(temperature_max/10.0) - 10.0);
        SPINNER_temperature_cutoff->set_float_limits(temp_min,temp_max);
        Update_Smokecolormap(smoke_render_option);
        break;
    case TEMP_MAX:
        temp_min = (float)(10*(int)(temperature_cutoff/10.0)+10.0);
        temp_max = 1800.0;
        SPINNER_temperature_max->set_float_limits(temp_min,temp_max);
        Update_Smokecolormap(smoke_render_option);
        break;
    case LOAD_COMPRESSED_DATA:
        if(load_volcompressed==1) {
            CHECKBOX_compress_volsmoke->disable();
        }
        else {
            CHECKBOX_compress_volsmoke->enable();
        }
        break;
    case SMOKE_OPTIONS:
        if(firecolormap_type!=FIRECOLORMAP_NOCONSTRAINT&&smoke_render_option==RENDER_SLICE) {
            PANEL_colormap2b->enable();
            SPINNER_hrrpuv_cutoff->enable();
            PANEL_colormap2b->open();
        }
        else {
            PANEL_colormap2b->disable();
            PANEL_colormap2b->close();
        }
        if(smoke_render_option==RENDER_SLICE) {
            if(PANEL_colormap2a!=NULL) {
                PANEL_colormap2a->disable();
                PANEL_colormap2a->close();
            }
            if(PANEL_absorption!=NULL)PANEL_absorption->enable();
            firecolormap_type=firecolormap_type_save;
            RADIO_use_colormap->set_int_val(firecolormap_type);
            RADIOBUTTON_direct->enable();
            SPINNER_smoke3d_fire_halfdepth->enable();
        }
        else {
            if(PANEL_colormap2a!=NULL) {
                PANEL_colormap2a->enable();
                PANEL_colormap2a->open();
            }
            if(PANEL_absorption!=NULL)PANEL_absorption->disable();
            firecolormap_type_save=firecolormap_type;
            firecolormap_type=FIRECOLORMAP_CONSTRAINT;
            RADIO_use_colormap->set_int_val(firecolormap_type);
            RADIOBUTTON_direct->disable();
            SPINNER_smoke3d_fire_halfdepth->disable();
        }
        Smoke3d_CB(FIRECOLORMAP_TYPE);
        Update_Smoke_Type();
        break;
    case FIRECOLORMAP_TYPE:
        if(firecolormap_type==FIRECOLORMAP_CONSTRAINT&&smoke_render_option==RENDER_VOLUME) {
            PANEL_colormap2a->open();
            PANEL_colormap2a->enable();
        }
        else {
            PANEL_colormap2a->close();
            PANEL_colormap2a->disable();
        }
        if(firecolormap_type!=FIRECOLORMAP_NOCONSTRAINT&&smoke_render_option==RENDER_SLICE) {
            PANEL_colormap2b->enable();
            SPINNER_hrrpuv_cutoff->enable();
            PANEL_colormap2b->open();
        }
        else {
            PANEL_colormap2b->disable();
            PANEL_colormap2b->close();
        }
        if(firecolormap_type!=FIRECOLORMAP_DIRECT) {
            LISTBOX_smoke_colorbar->enable();
            ROLLOUT_colormap3->disable();
            ROLLOUT_colormap3->close();
            if(fire_colorbar_index_save!=-1) {
                SmokeColorBarMenu(fire_colorbar_index_save);
            }
            else {
                SmokeColorBarMenu(fire_colorbar_index);
            }
        }
        else {
            LISTBOX_smoke_colorbar->disable();
            ROLLOUT_colormap3->enable();
            ROLLOUT_colormap3->open();
            SPINNER_smoke3d_smoke_albedo->enable();
            SPINNER_smoke3d_fire_red->enable();
            SPINNER_smoke3d_fire_green->enable();
            SPINNER_smoke3d_fire_blue->enable();
            SPINNER_smoke3d_fire_halfdepth->enable();

            fire_colorbar_index_save=fire_colorbar_index;
        }
        if(LISTBOX_smoke_colorbar->get_int_val()!=fire_colorbar_index) {
            LISTBOX_smoke_colorbar->set_int_val(fire_colorbar_index);
        }
        Update_Smokecolormap(smoke_render_option);
        break;
    case SMOKE_COLORBAR_LIST:
        SmokeColorBarMenu(fire_colorbar_index);
        Update_Smokecolormap(smoke_render_option);
        updatemenu=1;
        break;
    case SMOKETEST:
        update_alpha();
        break;
    case FRAMELOADING:
        smoke3dframestep = smoke3dframeskip+1;
        updatemenu=1;
        break;
    case SAVE_SETTINGS:
        writeini(LOCAL_INI,NULL);
        break;
    case GLOBAL_FIRE_CUTOFF:
        glutPostRedisplay();
        force_redisplay=1;
        Idle_CB();
        Update_Smokecolormap(smoke_render_option);
        break;
    case FIRE_RED:
    case FIRE_GREEN:
    case FIRE_BLUE:
    case SMOKE_SHADE:
        glutPostRedisplay();
        force_redisplay=1;
        Update_Smokecolormap(smoke_render_option);
        Idle_CB();
        break;
    case FIRE_HALFDEPTH:
        for(i=0; i<nmeshes; i++) {
            mesh *meshi;

            meshi = meshinfo + i;
            meshi->update_firehalfdepth=1;
        }
        glutPostRedisplay();
        force_redisplay=1;
        Update_Smokecolormap(smoke_render_option);
        Idle_CB();
        break;
#ifdef pp_GPU
    case SMOKE_RTHICK:

        smoke3d_thick = log_base2(smoke3d_rthick);
        glutPostRedisplay();
        force_redisplay=1;
        Idle_CB();
        break;
#else
    case SMOKE_THICK:
        glutPostRedisplay();
        force_redisplay=1;
        Idle_CB();
        break;
#endif
#ifdef pp_CULL
    case CULL_PORTSIZE:
        initcull(cullsmoke);
        break;
    case CULL_SMOKE:
        initcull(cullsmoke);
        break;
#endif
    case VOL_NGRID:
        glutPostRedisplay();
        break;
    case VOL_SMOKE:
    {
        volrenderdata *vr;

        vr = &meshinfo->volrenderinfo;
        if(vr!=NULL&&vr->smokeslice!=NULL&&vr->smokeslice->slicetype==SLICE_CENTER) {
            if(usegpu==1&&combine_meshes==1) {
                combine_meshes=0;
                update_combine_meshes();
                Smoke3d_CB(COMBINE_MESHES);
            }
            if(usegpu==0&&combine_meshes==0) {
                combine_meshes=1;
                update_combine_meshes();
                Smoke3d_CB(COMBINE_MESHES);
            }
        }
    }
    if(smoke_render_option==RENDER_SLICE) {
#ifdef pp_GPU
        if(usegpu==1) {
            RADIO_skipframes->set_int_val(0);
            RADIO_skipframes->disable();
#ifdef pp_CULL
            if(cullactive==1) {
                CHECKBOX_smokecullflag->enable();
            }
            SPINNER_cull_portsize->enable();
            CHECKBOX_show_cullports->enable();
#endif
        }
        else {
            RADIO_skipframes->enable();
#ifdef pp_CULL
            CHECKBOX_smokecullflag->disable();
            SPINNER_cull_portsize->disable();
            CHECKBOX_show_cullports->disable();
#endif
        }
#else
        RADIO_skipframes->enable();
#endif
    }
    break;
    default:
#ifdef _DEBUG
        abort();
#endif
        break;
    }
}
Exemplo n.º 8
0
extern "C" void glui_3dsmoke_setup(int main_window) {

    int i;


    if(nsmoke3dinfo<=0&&nvolrenderinfo<=0)return;
    if(CHECKBOX_meshvisptr!=NULL)FREEMEMORY(CHECKBOX_meshvisptr);
    NewMemory((void **)&CHECKBOX_meshvisptr,nmeshes*sizeof(GLUI_Checkbox *));

    glui_3dsmoke=glui_bounds;

    if(smoketest==1) {
        PANEL_testsmoke = glui_3dsmoke->add_panel_to_panel(ROLLOUT_smoke3d,_("Test smoke"));
        PANEL_testsmoke->set_alignment(GLUI_ALIGN_LEFT);
        CHECKBOX_show_smoketest=glui_3dsmoke->add_checkbox_to_panel(PANEL_testsmoke,_("Show test smoke"),&show_smoketest);
        SPINNER_extinct=glui_3dsmoke->add_spinner_to_panel(PANEL_testsmoke,_("Mass extinction coeff (m2/g)"),GLUI_SPINNER_FLOAT,&smoke_extinct,SMOKETEST,Smoke3d_CB);
        SPINNER_extinct->set_float_limits(0.0,10.0);
        SPINNER_smokedens=glui_3dsmoke->add_spinner_to_panel(PANEL_testsmoke,_("Smoke density (g/m3)"),GLUI_SPINNER_FLOAT,&smoke_dens,SMOKETEST,Smoke3d_CB);
        SPINNER_smokedens->set_float_limits(0.0,1.0);
        SPINNER_pathlength=glui_3dsmoke->add_spinner_to_panel(PANEL_testsmoke,_("Path length (m)"),GLUI_SPINNER_FLOAT,&smoke_pathlength,SMOKETEST,Smoke3d_CB);
        SPINNER_pathlength->set_float_limits(0.0,20.0);
        TEXT_smokealpha=glui_3dsmoke->add_statictext_to_panel(PANEL_testsmoke,_("Alpha"));
        TEXT_smokedepth=glui_3dsmoke->add_statictext_to_panel(PANEL_testsmoke,_("Depth"));
        update_alpha();
    }

    PANEL_overall = glui_3dsmoke->add_panel_to_panel(ROLLOUT_smoke3d,"",GLUI_PANEL_NONE);
#ifdef pp_GPU
    CHECKBOX_smokeGPU=glui_3dsmoke->add_checkbox_to_panel(PANEL_overall,_("Use GPU"),&usegpu,VOL_SMOKE,Smoke3d_CB);
#endif

    if(active_smokesensors==1) {
        PANEL_smokesensor = glui_3dsmoke->add_panel_to_panel(PANEL_overall,_("Visibility"));
        RADIO_smokesensors = glui_3dsmoke->add_radiogroup_to_panel(PANEL_smokesensor,&show_smokesensors);
        glui_3dsmoke->add_radiobutton_to_group(RADIO_smokesensors,_("Hidden"));
        glui_3dsmoke->add_radiobutton_to_group(RADIO_smokesensors,_("Grey (0-255)"));
        glui_3dsmoke->add_radiobutton_to_group(RADIO_smokesensors,"I/I0 (0.0-1.0)");
        glui_3dsmoke->add_radiobutton_to_group(RADIO_smokesensors,_("Scaled optical depth (SCD)"));
        glui_3dsmoke->add_statictext_to_panel(PANEL_smokesensor,"SCD=C/K=C*L/Ln(I/I0) (0-Inf)");
        SPINNER_cvis=glui_3dsmoke->add_spinner_to_panel(PANEL_smokesensor,"C",GLUI_SPINNER_FLOAT,&smoke3d_cvis);
        SPINNER_cvis->set_float_limits(1.0,20.0);
#ifdef _DEBUG
        CHECKBOX_test_smokesensors=glui_3dsmoke->add_checkbox_to_panel(PANEL_smokesensor,"Test visibility sensor",&test_smokesensors);
#endif
    }

    PANEL_colormap = glui_3dsmoke->add_panel_to_panel(PANEL_overall,_("Color"));

    glui_3dsmoke->add_checkbox_to_panel(PANEL_colormap,"Show colormap",&show_firecolormap,SHOW_FIRECOLORMAP,Smoke3d_CB);
    RADIO_use_colormap = glui_3dsmoke->add_radiogroup_to_panel(PANEL_colormap,&firecolormap_type,FIRECOLORMAP_TYPE,Smoke3d_CB);
    RADIOBUTTON_direct=glui_3dsmoke->add_radiobutton_to_group(RADIO_use_colormap,"Use specified color, opacity, albedo");
    RADIOBUTTON_constraint=glui_3dsmoke->add_radiobutton_to_group(RADIO_use_colormap,"Use colormap with constraints");
    RADIOBUTTON_noconstraint=glui_3dsmoke->add_radiobutton_to_group(RADIO_use_colormap,"Use colormap without constraints");

    ROLLOUT_colormap3 = glui_3dsmoke->add_rollout_to_panel(PANEL_colormap,"fire color/opacity, smoke albedo",false);

    PANEL_colormap3a = glui_3dsmoke->add_panel_to_panel(ROLLOUT_colormap3,"",GLUI_PANEL_NONE);
    SPINNER_smoke3d_fire_red=glui_3dsmoke->add_spinner_to_panel(PANEL_colormap3a,_("red"),GLUI_SPINNER_INT,&fire_red,FIRE_RED,Smoke3d_CB);
    SPINNER_smoke3d_fire_red->set_int_limits(0,255);
    SPINNER_smoke3d_fire_green=glui_3dsmoke->add_spinner_to_panel(PANEL_colormap3a,_("green"),GLUI_SPINNER_INT,&fire_green,FIRE_GREEN,Smoke3d_CB);
    SPINNER_smoke3d_fire_green->set_int_limits(0,255);
    SPINNER_smoke3d_fire_blue=glui_3dsmoke->add_spinner_to_panel(PANEL_colormap3a,_("blue"),GLUI_SPINNER_INT,&fire_blue,FIRE_BLUE,Smoke3d_CB);
    SPINNER_smoke3d_fire_blue->set_int_limits(0,255);

    PANEL_colormap3b = glui_3dsmoke->add_panel_to_panel(ROLLOUT_colormap3,"",GLUI_PANEL_NONE);
    SPINNER_smoke3d_fire_halfdepth=glui_3dsmoke->add_spinner_to_panel(PANEL_colormap3b,_("fire half depth (m)"),GLUI_SPINNER_FLOAT,&fire_halfdepth,FIRE_HALFDEPTH,Smoke3d_CB);
    SPINNER_smoke3d_fire_halfdepth->set_float_limits(0.0,10.0);
    SPINNER_smoke3d_smoke_albedo=glui_3dsmoke->add_spinner_to_panel(PANEL_colormap3b,_("smoke albedo"),GLUI_SPINNER_FLOAT,&smoke_albedo,SMOKE_SHADE,Smoke3d_CB);
    SPINNER_smoke3d_smoke_albedo->set_float_limits(0.0,1.0);

    if(ncolorbars>0) {
        LISTBOX_smoke_colorbar=glui_3dsmoke->add_listbox_to_panel(ROLLOUT_colormap3,_("colormap:"),&fire_colorbar_index,SMOKE_COLORBAR_LIST,Smoke3d_CB);

        for(i=0; i<ncolorbars; i++) {
            colorbardata *cbi;

            cbi = colorbarinfo + i;
            cbi->label_ptr=cbi->label;
            LISTBOX_smoke_colorbar->add_item(i,cbi->label_ptr);
        }
        LISTBOX_smoke_colorbar->set_int_val(fire_colorbar_index);
    }

    PANEL_colormap2 = glui_3dsmoke->add_panel_to_panel(PANEL_colormap,"",GLUI_PANEL_NONE);

#define HRRPUV_CUTOFF_MAX (hrrpuv_max_smv-0.01)

    PANEL_colormap2b = glui_3dsmoke->add_rollout_to_panel(PANEL_colormap2,"HRRPUV (kW/m3)");
    SPINNER_hrrpuv_cutoff=glui_3dsmoke->add_spinner_to_panel(PANEL_colormap2b,_("cutoff"),GLUI_SPINNER_FLOAT,&global_hrrpuv_cutoff,GLOBAL_FIRE_CUTOFF,Smoke3d_CB);

    SPINNER_hrrpuv_cutoff->set_float_limits(0.0,HRRPUV_CUTOFF_MAX);

    {
        char label[256];

        strcpy(label,"Temperature (");
        strcat(label,degC);
        strcat(label,")");
        PANEL_colormap2a = glui_3dsmoke->add_rollout_to_panel(PANEL_colormap2,label);
    }
    SPINNER_temperature_min=glui_3dsmoke->add_spinner_to_panel(PANEL_colormap2a,_("min"),GLUI_SPINNER_FLOAT,
                            &temperature_min,TEMP_MIN,Smoke3d_CB);
    SPINNER_temperature_cutoff=glui_3dsmoke->add_spinner_to_panel(PANEL_colormap2a,_("cutoff"),GLUI_SPINNER_FLOAT,
                               &temperature_cutoff,TEMP_CUTOFF,Smoke3d_CB);
    SPINNER_temperature_max=glui_3dsmoke->add_spinner_to_panel(PANEL_colormap2a,_("max"),GLUI_SPINNER_FLOAT,
                            &temperature_max,TEMP_MAX,Smoke3d_CB);

    Smoke3d_CB(TEMP_MIN);
    Smoke3d_CB(TEMP_CUTOFF);
    Smoke3d_CB(TEMP_MAX);

    if(nsmoke3dinfo>0) {
        PANEL_meshvis = glui_3dsmoke->add_rollout_to_panel(PANEL_overall,"Mesh Visibility",false);
        for(i=0; i<nmeshes; i++) {
            mesh *meshi;

            meshi = meshinfo + i;
            glui_3dsmoke->add_checkbox_to_panel(PANEL_meshvis,meshi->label,meshvisptr+i);
        }
    }

    Smoke3d_CB(FIRECOLORMAP_TYPE);

    glui_3dsmoke->add_column_to_panel(PANEL_overall,false);

    if(nsmoke3dinfo<=0||nvolrenderinfo<=0) {
        smoke_render_option=RENDER_SLICE;
        if(nsmoke3dinfo>0)smoke_render_option=RENDER_SLICE;
        if(nvolrenderinfo>0)smoke_render_option=RENDER_VOLUME;
    }

    // slice render dialog

    if(nsmoke3dinfo>0) {
        ROLLOUT_slices = glui_3dsmoke->add_rollout_to_panel(PANEL_overall,_("Slice render settings"),false, SLICERENDER_ROLLOUT, Smoke_Rollout_CB);
        ADDPROCINFO(smokeprocinfo, nsmokeprocinfo, ROLLOUT_slices, SLICERENDER_ROLLOUT);
        ROLLOUT_slices->set_alignment(GLUI_ALIGN_LEFT);

#ifdef pp_GPU
        if(gpuactive==0) {
            usegpu=0;
            CHECKBOX_smokeGPU->disable();
        }
#endif
#ifdef pp_CULL
        CHECKBOX_smokecullflag=glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_slices,_("Cull hidden slices"),&cullsmoke,CULL_SMOKE,Smoke3d_CB);
        if(cullactive==0) {
            cullsmoke=0;
            CHECKBOX_smokecullflag->disable();
        }
        CHECKBOX_show_cullports=glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_slices,_("Show cull ports"),&show_cullports);
        SPINNER_cull_portsize=glui_3dsmoke->add_spinner_to_panel(ROLLOUT_slices,_("Cull port size"),GLUI_SPINNER_INT,&cull_portsize,CULL_PORTSIZE,Smoke3d_CB);
        {
            int ijk_max=0;
            for(i=0; i<nmeshes; i++) {
                mesh *meshi;

                meshi = meshinfo + i;
                if(ijk_max<meshi->ibar+1)ijk_max=meshi->ibar+1;
                if(ijk_max<meshi->jbar+1)ijk_max=meshi->jbar+1;
                if(ijk_max<meshi->kbar+1)ijk_max=meshi->kbar+1;
            }
            SPINNER_cull_portsize->set_int_limits(3,ijk_max);
        }
#else
        CHECKBOX_smokecullflag=glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_slices,"Cull hidden slices",&smokecullflag);
#endif
#ifdef _DEBUG
        CHECKBOX_smokedrawtest=glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_slices,"Show only back slices",&smokedrawtest);
        CHECKBOX_smokedrawtest2=glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_slices,"Show only X slices",&smokedrawtest2);

        SPINNER_smokedrawtest_nummin=glui_3dsmoke->add_spinner_to_panel(ROLLOUT_slices,"Back slice",GLUI_SPINNER_INT,&smokedrawtest_nummin);
        SPINNER_smokedrawtest_nummin->set_int_limits(1,ijkbarmax);

        SPINNER_smokedrawtest_nummax=glui_3dsmoke->add_spinner_to_panel(ROLLOUT_slices,"Front slice",GLUI_SPINNER_INT,&smokedrawtest_nummax);
        SPINNER_smokedrawtest_nummax->set_int_limits(1,ijkbarmax);
#endif
        RADIO_skipframes = glui_3dsmoke->add_radiogroup_to_panel(ROLLOUT_slices,&smokeskipm1);
        glui_3dsmoke->add_radiobutton_to_group(RADIO_skipframes,_("Display all"));
        glui_3dsmoke->add_radiobutton_to_group(RADIO_skipframes,_("   ... Every 2nd"));
        glui_3dsmoke->add_radiobutton_to_group(RADIO_skipframes,_("   ... Every 3rd"));
#ifdef pp_GPU
        SPINNER_smoke3d_rthick=glui_3dsmoke->add_spinner_to_panel(ROLLOUT_slices,_("Thickness"),
                               GLUI_SPINNER_FLOAT,&smoke3d_rthick,SMOKE_RTHICK,Smoke3d_CB);
        SPINNER_smoke3d_rthick->set_float_limits(1.0,255.0);
        smoke3d_thick = log_base2(smoke3d_rthick);
#else
        SPINNER_smoke3d_thick=glui_3dsmoke->add_spinner_to_panel(PANEL_colormap,"Thickness",
                              GLUI_SPINNER_INT,&smoke3d_thick,SMOKE_THICK,Smoke3d_CB);
        SPINNER_smoke3d_thick->set_int_limits(0,7);
#endif

        PANEL_absorption = glui_3dsmoke->add_panel_to_panel(ROLLOUT_slices,_("Absorption adjustments"));
        PANEL_absorption->set_alignment(GLUI_ALIGN_LEFT);
        RADIO_alpha = glui_3dsmoke->add_radiogroup_to_panel(PANEL_absorption,&adjustalphaflag);
        glui_3dsmoke->add_radiobutton_to_group(RADIO_alpha,_("None"));
        glui_3dsmoke->add_radiobutton_to_group(RADIO_alpha,_("adjust off-center"));
        glui_3dsmoke->add_radiobutton_to_group(RADIO_alpha,_("zero at boundaries"));
        glui_3dsmoke->add_radiobutton_to_group(RADIO_alpha,_("both"));
    }

    // volume render dialog

    if(nvolrenderinfo > 0) {
        ROLLOUT_volume = glui_3dsmoke->add_rollout_to_panel(PANEL_overall, _("Volume render settings"), false, VOLRENDER_ROLLOUT, Smoke_Rollout_CB);
        ADDPROCINFO(smokeprocinfo, nsmokeprocinfo, ROLLOUT_volume, VOLRENDER_ROLLOUT);

        if(have_volcompressed == 1) {
            RADIO_loadvol = glui_3dsmoke->add_radiogroup_to_panel(ROLLOUT_volume, &glui_load_volcompressed, LOAD_COMPRESSED_DATA, Smoke3d_CB);
            glui_3dsmoke->add_radiobutton_to_group(RADIO_loadvol, _("Load full data"));
            glui_3dsmoke->add_radiobutton_to_group(RADIO_loadvol, _("Load compressed data"));
        }
        glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_volume, _("Load data in background"), &use_multi_threading);
        CHECKBOX_compress_volsmoke = glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_volume, _("Compress data while loading"), &glui_compress_volsmoke);
        if(have_volcompressed == 1) {
            Smoke3d_CB(LOAD_COMPRESSED_DATA);
        }
        glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_volume, _("Display data as b/w"), &volbw);
        glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_volume, _("Show data while moving scene"), &show_volsmoke_moving);
        glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_volume, _("Load data only at render times"), &load_at_rendertimes);

        SPINNER_fire_opacity_factor = glui_3dsmoke->add_spinner_to_panel(ROLLOUT_volume, _("Fire opacity multiplier"), GLUI_SPINNER_FLOAT, &fire_opacity_factor);
        SPINNER_fire_opacity_factor->set_float_limits(1.0, 10.0);
        SPINNER_mass_extinct = glui_3dsmoke->add_spinner_to_panel(ROLLOUT_volume, _("Mass extinction coeff"), GLUI_SPINNER_FLOAT, &mass_extinct);
        SPINNER_mass_extinct->set_float_limits(100.0, 100000.0);
        glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_volume, _("Freeze"), &freeze_volsmoke);
#ifdef _DEBUG
        CHECKBOX_usevolrender = glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_volume, _("Show"), &usevolrender, VOL_SMOKE, Smoke3d_CB);
        glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_volume, "block smoke", &block_volsmoke);
        glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_volume, "debug", &smoke3dVoldebug);
#endif
        CHECKBOX_combine_meshes = glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_volume, _("Combine meshes"), &combine_meshes, COMBINE_MESHES, Smoke3d_CB);
        SPINNER_nongpu_vol_factor = glui_3dsmoke->add_spinner_to_panel(ROLLOUT_volume, _("non-gpu grid multiplier"), GLUI_SPINNER_FLOAT, &nongpu_vol_factor, NONGPU_VOL_FACTOR, Smoke3d_CB);
        SPINNER_nongpu_vol_factor->set_float_limits(1.0, 10.0);
        SPINNER_gpu_vol_factor = glui_3dsmoke->add_spinner_to_panel(ROLLOUT_volume, _("gpu grid multiplier"), GLUI_SPINNER_FLOAT, &gpu_vol_factor, GPU_VOL_FACTOR, Smoke3d_CB);
        SPINNER_gpu_vol_factor->set_float_limits(1.0, 10.0);

        PANEL_generate_images = glui_3dsmoke->add_rollout_to_panel(ROLLOUT_volume, _("Generate images"), false);

        SPINNER_startframe = glui_3dsmoke->add_spinner_to_panel(PANEL_generate_images, _("start frame"), GLUI_SPINNER_INT, &vol_startframe0, START_FRAME, Smoke3d_CB);
        SPINNER_skipframe = glui_3dsmoke->add_spinner_to_panel(PANEL_generate_images, _("skip frame"), GLUI_SPINNER_INT, &vol_skipframe0, SKIP_FRAME, Smoke3d_CB);
        Smoke3d_CB(START_FRAME);
        Smoke3d_CB(SKIP_FRAME);
        if(ntours > 0) {
            selectedtour_index = -1;
            selectedtour_index_old = -1;
            LISTBOX_VOL_tour = glui_3dsmoke->add_listbox_to_panel(PANEL_generate_images, "Tour:", &selectedtour_index, VOL_TOUR_LIST, Smoke3d_CB);

            LISTBOX_VOL_tour->add_item(-1, "Manual");
            LISTBOX_VOL_tour->add_item(-999, "-");
            for(i = 0; i < ntours; i++) {
                tourdata *touri;

                touri = tourinfo + i;
                LISTBOX_VOL_tour->add_item(i, touri->label);
            }
            LISTBOX_VOL_tour->set_int_val(selectedtour_index);
        }

        strcpy(vol_prefix, fdsprefix);
        EDIT_vol_prefix = glui_3dsmoke->add_edittext_to_panel(PANEL_generate_images, "image prefix:", GLUI_EDITTEXT_TEXT, vol_prefix, VOL_PREFIX, Smoke3d_CB);
        EDIT_vol_prefix->set_w(200);

        BUTTON_startrender = glui_3dsmoke->add_button_to_panel(PANEL_generate_images, _("Generate images"), GENERATE_IMAGES, Smoke3d_CB);
        BUTTON_cancelrender = glui_3dsmoke->add_button_to_panel(PANEL_generate_images, _("Cancel"), CANCEL_GENERATE_IMAGES, Smoke3d_CB);
        BUTTON_volunload = glui_3dsmoke->add_button_to_panel(PANEL_generate_images, _("Unload"), VOL_UNLOAD_ALL, Smoke3d_CB);
    }

    Update_Smoke_Type();

#ifdef pp_GPU
    Smoke3d_CB(VOL_SMOKE);
#endif
    Smoke3d_CB(SMOKE_OPTIONS);
}
Exemplo n.º 9
0
Arquivo: main.cpp Projeto: radi9/svm
int main() {

	BEGIN
		messager("loading training data, test data....", MEKEY);
		loadTrain(trainData, l_low, l_up);
		loadTest(testData);
		messager("done loading", MEKEY);
	END

	//initialize alpha values :
	//separate initialize the alpha values,
	//norAlpha and attAlhpa all 1

	messager("initialize optimized index table", MEKEY);
	messager("initialize all alpha to 0", MEKEY);
	messager("initialize all gradient to 0", MEKEY);
	messager("initialize all gradient bar to 0", MEKEY);

	BEGIN
	for (int i = 0; i < train_num; i++)
	{
		b.push_back(init_p);
		alpha.push_back(0.0);
		optimied_index[i] = false;
		if (encounter[i] == 1) {
			penalty.push_back(nor_penalty);
			pro.push_back(57378/62367);
		}
		else
		{
			penalty.push_back(att_penalty);
			pro.push_back(4989/62367);
		}
			grad.push_back(b[i]);
	}
	for (int i = 0; i < train_num; i++)
	{
		grad_bar.push_back(0); //no alpha is C at first, so all for zero
	}

	for(int i = 0; i < train_num; i++)
	{
		if(!is_lowerBound(i))
		{
			vector<double> column_i = get_Q(i);
			for(int j = 0; j < train_num; j++)
			{
				grad[j] += alpha[i] * column_i[j];
			}
			if(is_upperBound(i))
			{
				for(int j = 0; j < train_num; j++)
				{
					grad_bar[j] += penalty[i] * column_i[j];
				}
			}
		}
	}
	END

	/*
	 * iterator procedure
	 */
	//Values newAlpha;
	messager("modeling...", MEKEY);

	bool examALL = false;
	Values violating_pair;

	int iter = 0;
	while ( iter < train_num)
	{
		//test select WSS1, fixed l_up but not calculate all of it, it's too expense
		//test_ktt();

		cout << iter << endl;
		int i;
		int j;
		vector<double> qColu_i;
		vector<double> qColu_j;

//		if(iter%1000 == 0)
//		{
//			do_shrinking();
//		}

		if(selectWSS(i, j, violating_pair))
		{
			updateGrad();
			active_size = train_num;
			cout << "finished optimized" << endl;
			break;
		}
		else
		{
			qColu_i = get_Q(i);
			qColu_j = get_Q(j);
			update_alpha(violating_pair, i, j, qColu_i, qColu_j);
			updateGrad();
		}
		iter++;
	}
	int count = 0;
	for(int i = 0; i < alpha.size(); i ++)
	{
		if(alpha[i] != 0)
		{
			cout << "not zero alpha " << alpha[i] << "grad : " << grad[i] << endl;
		}
	}
	messager("alpha not zero", count, MEKEY);
	return 0;
}