📄 old_code.svn-base
字号:
st >> burnoff; st.str (argv[8]); st.clear(); st >> particles; current_discrete_experiment->set_running_time(time); current_discrete_experiment->set_burnoff(burnoff); current_discrete_experiment->set_running_particles(particles); current_discrete_experiment->run(argv[9], argv[9]); } } else { //NPGraph * g = make_mrf_graph < NPGraph > ( mrf_rows, mrf_columns); //NPGraph * g = make_simple_chain_graph <NPGraph > ( 20); //current_experiment = new Experiment <NPGraph> ( * g, 1, 300, true, true); current_experiment = new Experiment <NPGraph> (); string gr_tr = "ground"; if ( gr_tr.compare( argv[ 3] ) == 0) { if ( argc < 7 ) { cout << "Give more args for ground: method time particles file_name" << endl; return 0; } current_experiment->set_ground_truth_method(argv[ 4]); unsigned int time, particles; st.str (argv[5]); st.clear(); st >> time; st.str (argv[6]); st.clear(); st >> particles; current_experiment->set_running_particles(particles); current_experiment->obtain_ground_truth(argv[7], time); } string run_str = "run"; if ( run_str.compare( argv[ 3] ) == 0) { if ( argc < 7 ) { cout << "Give more args for run: run time particles input_file add_on" << endl; return 0; } unsigned int time, particles; st.str (argv[4]); st.clear(); st >>time; st.str (argv[5]); st.clear(); st >> particles; current_experiment->set_running_time(time); current_experiment->set_running_particles(particles); current_experiment->run(argv[6], argv[6]); } } //Make product over ALL edges /* Unnecessary for (tie(u,u_end) = vertices (*current_tree); u!= u_end; ++u) { if ( !cut_edges[current_tree->local_to_global(*u)].empty()) { for (unsigned int xi = 0; xi < (*current_tree)[*u]->get_random_variable()->get_number_values(); ++xi) { DiscreteRandomVariable * current_rv = (*current_tree)[*u]->get_random_variable(); current_rv->set_value(xi); original_potentials[current_tree->local_to_global(*u)]->set_variable_value(*current_rv); double a = original_potentials[current_tree->local_to_global(*u)]->get_potential_value(); // Maybe we could somehow put the cut_edges list on the vertices. This would allow us to not all the time use the local_to_global function //cout << "vertex number " << current_tree->local_to_global(*u)+1 << endl; for (typename list< EdgeDescriptor>::iterator it = cut_edges[current_tree->local_to_global(*u)].begin(); it != cut_edges[current_tree->local_to_global(*u)].end(); ++it) { g[*it]->set_variable_value(*current_rv); a = a * g[*it]->get_potential_value(); //cout << "edge number " << source(*it,g)+1 << ", " << target(*it,g)+1 << ", " << a << endl; } // Change our SinglePotential so as to incorporate the changes (*current_tree)[*u]->get_potential()->set_variable_value ( *current_rv); // the first number is not important since it is a SinglePotential static_cast < DiscretePotential *> ( (*current_tree)[*u]->get_potential() )->modify_potential_value( a); } } (*current_tree)[*u]->initialize(); } *//*template <class RanVar, class VertexDescriptor >inline VertexDescriptor MessageNode <RanVar, VertexDescriptor >::get_parent_node() const{ return parent_node;}template <class RanVar, class VertexDescriptor >inline void MessageNode <RanVar, VertexDescriptor >::set_parent_node(VertexDescriptor a){ parent_node = a;}*//*template <class Graph>void tree_gibbs_sampler(Graph & g, const unsigned int max_steps, const unsigned int burnoff){ typename property_map<Graph, vertex_index_t>::type vertex_index_map = get(vertex_index, g); typedef typename graph_traits<Graph>::vertex_iterator VertexIterator; VertexIterator u, u_end; vector < DiscretePotential * > original_potentials (num_vertices(g)); for (tie(u,u_end) = vertices (g); u!= u_end; ++u) { original_potentials[ get(vertex_index_map, *u)] = static_cast < DiscretePotential *> (g[*u]->get_potential()); //Potential * p = g[*u]->get_potential()->clone(); ChainedSingleDiscretePotential * p = new ChainedSingleDiscretePotential(); p->add_potential (original_potentials[get(vertex_index_map, *u)]); g[*u]->set_potential(p); } //tree_gibbs_sampler_implementation ( g, make_iterator_property_map(original_potentials.begin(), get(vertex_index,g)), max_steps, burnoff); tree_gibbs_sampler_implementation ( g, max_steps, burnoff); }*/// Reading a Graph from a file/*template <class Graph>bool read_graph_from_file(string input_file_name, Graph * & g){ typedef typename boost::graph_traits<Graph>::vertex_descriptor VertexDescriptor; string code_string; unsigned int a, b; unsigned int number_of_edges = 0; bool no_command_tag = true; g = NULL; ifstream input_file (input_file_name.c_str()); if (!input_file.good()) { cout << "Failed to open the file '" << input_file_name << "'" << endl; return false; } while (true) { //cout << "Beginning of main loop" << endl; while ( (input_file.get() != '<') && (input_file.good()) ) { } //cout << "Found '<'" << endl; if (input_file.eof()) { if (no_command_tag) { cout << "No valid Command Tag found" << endl; return false; } break; } getline(input_file, code_string, '>'); if ( code_string.compare("number of vertices") == 0) { no_command_tag = false; //cout << "number of vertices" << endl; while (input_file.get() != '(' && !input_file.eof()) { } if (input_file.eof()) { cout << "Command Tag with no data tag" << endl; return false; } if (!(input_file >> a)) { input_file.clear(); cout << "Malformed 'number of vertices' data tag" << endl; return false; } else { cout << "Number of vertices tags found: " << a << endl; g = new Graph(a); } while (input_file.get() != ')' && !input_file.eof()) { } if (input_file.eof()) { cout << "Malformed data tag" << endl; return false; } } if ( code_string.compare("link") == 0) { //cout << "Found command tag 'link'" << endl; no_command_tag = false; while (true) { //cout << "Beginning of link loop" << endl; while ( (input_file.get() != '(') && (!input_file.eof()) ) { } if (input_file.eof()) { cout << "Error: 'link' command Tag with no data tag" << endl; return false; } //cout << "ert" << endl; if (!(input_file >> a >> b)) { input_file.clear(); cout << "Error: Malformed 'link' data tag" << endl; return false; } else { if (g == NULL) { cout << "Error: link found before a 'number of vertices' tag" << endl; return false; } VertexDescriptor u = vertex(a-1, *g); VertexDescriptor v = vertex(b-1, *g); //cout << "Link between " << a << " and " << b << endl; add_edge(u,v,*g); ++number_of_edges; } //cout << "ert 2" << endl; while ( (input_file.get() != ')') && (!input_file.eof()) ) { } //cout << "ert 3" << endl; if (input_file.eof()) { cout << "Error: malformed 'link' data tag" << endl; return false; } // here we have to check whether next is '(' or '<' //cout << "Checking for '<' or '(' " << endl; char c = input_file.get(); while ( !((c == '(') || (c == '<')) && (!input_file.eof()) ) { c = input_file.get(); //cout << c << endl; } if (input_file.eof()) { //cout << "No New '(' or '>'" << endl; break; } input_file.unget(); if (c == '(') { //cout << "Next '(' after link tag" << endl; } if (c == '<') { //cout << "Next '<' after link tag" << endl; break; } } } } cout << "Number of edges: " << number_of_edges << endl; return true;}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -