void merger::add(const model& m) { require_not_has_merged(); if (m.is_target()) add_target(m); BOOST_LOG_SEV(lg, debug) << "adding model: " << m.name().qualified(); BOOST_LOG_SEV(lg, debug) << "contents: " << m; models_.insert(std::make_pair(m.name(), m)); }
void write_all_output(model& m, const output_container& out, sz how_many, const std::string& output_name, const std::vector<std::string>& remarks) { if(out.size() < how_many) how_many = out.size(); VINA_CHECK(how_many <= remarks.size()); ofile f(make_path(output_name)); VINA_FOR(i, how_many) { m.set(out[i].c); m.write_model(f, i+1, remarks[i]); // so that model numbers start with 1 }
void chain3DOF( model &M) { cout << "Creating a chain3DOF model" << endl; // make a chain model double m = 0.0; // mass of links double L = 1.0; // length of each chain link int N = 3; // define N, parent, pitch, Xtree, I M.setN(N); // deifne size M.setParent( linspace<irowvec>( 0, N-1, N) ); // define vector (3D pos) argument for xtree M.setXtree(0, xlt( zeros<vec>(3) ) ); M.setXtree(1, rotx( -math::pi()/2 ) ); M.setXtree(2, roty( math::pi()/2 ) ); // cdefine center of mass 3D pos vector vec com = zeros<vec>(3); vec inertia = zeros<vec>(3); M.setI(0, mcI( m, com, diagmat(inertia)) ); M.setI(1, mcI( m, com, diagmat(inertia)) ); com(0) = L/2.0; m = 1.0; // define inertia inertia = m*pow(L,2)/12.0 * ones<vec>(3); inertia(0) = 0.01; // no thickness in this direction M.setI(2, mcI( m, com, diagmat(inertia)) ); // RIGID BODY RBbox* box1 = new RBbox( m, L, L/5, L/5); RBnull* null1 = new RBnull(); M.setRB( 0, null1); M.setRB( 1, null1); M.setRB( 2, box1); // define pitch M.setPitch( 2*ones<rowvec>(N) ); /* M.setXtree(0, xlt(zeros<vec>(3))); M.setXtree(1, rotx( math::pi()/2) ); M.setXtree(2, roty( math::pi()/2) ); */ }
int Init ( ESContext *esContext ) { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_DEPTH_TEST); m.SetIdentity(); woman.loadModel("../Resources/Models/Woman1.nfg"); woman.loadTexture("../Resources/Textures/Woman1.tga"); //creation of shaders and program return myShaders.Init("../Resources/Shaders/TriangleShaderVS.vs", "../Resources/Shaders/TriangleShaderFS.fs"); }
void concept_indexer::index_objects(model& m) { BOOST_LOG_SEV(lg, debug) << "Indexing objects: " << m.objects().size(); std::unordered_set<qname> processed_qnames; for (auto& pair : m.objects()) { auto& o(pair.second); if (o.generation_type() == generation_types::no_generation) continue; index_object(o, m, processed_qnames); } }
void property_indexer::index_concepts(model& m) { BOOST_LOG_SEV(lg, debug) << "Indexing concepts: " << m.concepts().size(); std::unordered_set<sml::qname> processed_qnames; for (auto& pair : m.concepts()) { auto& c(pair.second); if (c.generation_type() == generation_types::no_generation) continue; index_concept(c, m, processed_qnames); } }
void parameters::Mstep(datafile dat, model mod){ const MatrixXi & omega=mod.Get_model(),mat=dat.Get_mat_datafile(); const VectorXd & eff=dat.Get_eff_datafile(); for (int k=0;k<m_proba.cols();k++){ m_propor(k)= (eff.array()*(m_proba.col(k)).array()/m_proba.rowwise().sum().array()).sum() / eff.sum(); for (int b=0;b<mat.cols();b++){ if ((omega.row(k).array()==b).any()){ const VectorXi & who=mod.Get_var_block(k,b); m_param[k][b].Mstep(who,mat,m_proba_block[k].col(b),m_proba.col(k).array()/m_proba.rowwise().sum().array(),eff); } } } }
void read_notify_list(model& aModel, std::function<bool()> aErrorFunction) { notify& theNotifyList = aModel.notify_list(); neolib::xml xmlNotifyList(true); std::ifstream input((aModel.root_path() + "notify_list.xml").c_str()); xmlNotifyList.read(input); if (xmlNotifyList.error() && aErrorFunction && aErrorFunction()) { theNotifyList.entries().clear(); write_notify_list(aModel); return; } theNotifyList.loading(true); for (neolib::xml::element::const_iterator i = xmlNotifyList.root().begin(); i != xmlNotifyList.root().end(); ++i) { if (i->name() == "entry") { notify_entry_ptr e(new notify_entry); for (neolib::xml::element::const_iterator j = i->begin(); j != i->end(); ++j) { if (j->name() == "user") e->user() = user(j->attribute_value("value"), casemapping::rfc1459, false, true); if (j->name() == "server_network" || j->name() == "server_group") e->server().first = j->attribute_value("value"); if (j->name() == "server_name") e->server().second = j->attribute_value("value"); if (j->name() == "channel") e->channel() = j->attribute_value("value"); if (j->name() == "action") e->action() = static_cast<notify_entry::action_e>(neolib::string_to_integer<char>(j->attribute_value("value"))); if (j->name() == "event") e->event() = static_cast<notify_entry::event_e>(neolib::string_to_integer<char>(j->attribute_value("value"))); if (j->name() == "data") e->data() = j->attribute_value("value"); } if (e->user().nick_name().empty()) e->user().nick_name() = "*"; if (e->channel().empty()) e->channel() = "*"; theNotifyList.entries().push_back(e); } } theNotifyList.loading(false); }
void EvaluateModel( const Config& config, const model& nn, propagator& prop_validation, const shared_ptr<Corpus>& test_corpus, const shared_ptr<Vocabulary>& vocab, double& current_learning_rate, double& current_validation_ll) { if (test_corpus->size() > 0) { double log_likelihood = 0.0; Matrix<double,Dynamic,Dynamic> scores(vocab->size(), config.minibatch_size); Matrix<double,Dynamic,Dynamic> output_probs(vocab->size(), config.minibatch_size); MinibatchExtractor extractor(test_corpus, vocab, config); cerr << endl; cerr << "Validation minibatches: " << endl; int num_batches = (test_corpus->size() - 1) / config.minibatch_size + 1; for (int batch = 0; batch < num_batches; batch++) { if (batch % 50 == 0) { cerr << batch << "... "; } data_size_t start_index = config.minibatch_size * batch; MatrixInt minibatch = extractor.extract(start_index); prop_validation.fProp(minibatch.topRows(config.ngram_size - 1)); // Do full forward prop through output word embedding layer start_timer(4); prop_validation.output_layer_node.param->fProp(prop_validation.second_hidden_activation_node.fProp_matrix, scores); stop_timer(4); // And softmax and loss. Be careful of short minibatch double minibatch_log_likelihood; start_timer(5); SoftmaxLogLoss().fProp( scores.leftCols(minibatch.cols()), minibatch.row(config.ngram_size - 1), output_probs, minibatch_log_likelihood); stop_timer(5); log_likelihood += minibatch_log_likelihood; } cerr << endl; cerr << "Validation log-likelihood: " << log_likelihood << endl; cerr << " perplexity: " << exp(-log_likelihood / test_corpus->size()) << endl; // If the validation perplexity decreases, halve the learning rate. if (current_validation_ll != 0 && log_likelihood < current_validation_ll) { current_learning_rate /= 2; } else { current_validation_ll = log_likelihood; if (config.model_output_file != "") { cerr << "Writing model to " << config.model_output_file << endl; ofstream fout(config.model_output_file); nn.write(fout); vocab->write(fout); cerr << "Done writing model" << endl; } } } }
void helper_expander::expand( const variability::meta_model::feature_model& feature_model, const formatters::repository& frp, model& fm) const { const auto fg(make_feature_group(feature_model)); const auto cfg(make_configuration(fg, fm)); populate_helper_properties(cfg, frp, fm.formattables()); }
//--Implementations void render(){ //--Render the scene //clear the screen glClearColor(0.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Enable Shader glUseProgram(program); sunMVP = projection * view * sunModel; glUniformMatrix4fv(loc_mvpmat, 1, GL_FALSE, glm::value_ptr(sunMVP)); sun.renderModel(program); for(int i = 0; i < numModels; i++){ mvp[i] = projection * view * model[i]; } //upload the matrix to the shader for(int i = 0; i < numModels; i++){ glUniformMatrix4fv(loc_mvpmat, 1, GL_FALSE, glm::value_ptr(mvp[i])); models[i].renderModel(program); } //swap the buffers glutSwapBuffers(); }
/* parse a give model, to fill in a map We use map to sort assignments */ void parseModel(solver *sv, model m, std::map<std::string, VARIBLE_VALUE> *res) { for (unsigned j = 0; j < m.size(); j++) { Z3_ast a, av; VARIBLE_VALUE vv; context *ctx = &(sv->ctx()); Z3_func_decl constant = Z3_get_model_constant(*ctx, m, j); std::string var = m[j].name().str();//get variable's name vv.name = var; Z3_sort var_sort = Z3_get_range(*ctx, m[j]); std::string var_type = Z3_sort_to_string(*ctx, var_sort); if (var_type == "Bool") { vv.type = "bool"; Z3_eval_func_decl(*ctx, m, constant, &av); std::stringstream ss; ss << to_expr(*ctx, av); vv.value = ss.str(); vv.size = 1; } else if (var_type.find("(_ BitVec", 0) == 0) //bitvector { vv.type = "bitvector"; vv.size = Z3_get_bv_sort_size(*ctx, var_sort); a = Z3_mk_app(*ctx, Z3_get_model_constant(*ctx, m, j), 0, 0); av = a; Z3_eval(*ctx, m, a, &av);//get variable's value vv.value = Z3_get_numeral_string(*ctx, av); } res->erase(vv.name); res->insert(std::make_pair(vv.name, vv)); } }
void reducer::reduce(model& fm) const { BOOST_LOG_SEV(lg, debug) << "Starting reduction."; BOOST_LOG_SEV(lg, debug) << "Original size: " << fm.formattables().size(); std::unordered_map<std::string, formattable> reduced; for (const auto& pair : fm.formattables()) { const auto& formattable(pair.second); const auto& e(*formattable.element()); if (e.origin_type() != yarn::origin_types::target) continue; reduced.insert(pair); } fm.formattables().swap(reduced); BOOST_LOG_SEV(lg, debug) << "Reduced size: " << fm.formattables().size(); }
std::list<name> generalization_indexer:: recurse_generalization(const model& m, const name& leaf, const object& o, generalization_details& d) const { if (!o.is_child()) return std::list<name> { o.name() }; const auto i(o.relationships().find(relationship_types::parents)); if (i == o.relationships().end() || i->second.empty()) { const auto qn(o.name().qualified()); BOOST_LOG_SEV(lg, error) << child_with_no_parents << qn; BOOST_THROW_EXCEPTION(indexing_error(child_with_no_parents + qn)); } std::list<name> original_parents; for (const auto& parent : i->second) { auto j(m.objects().find(parent)); if (j == m.objects().end()) { const auto qn(parent.qualified()); BOOST_LOG_SEV(lg, error) << parent_not_found << qn; BOOST_THROW_EXCEPTION(indexing_error(parent_not_found + qn)); } const auto op(recurse_generalization(m, leaf, j->second, d)); if (op.empty()) { const auto qn(parent.qualified()); BOOST_LOG_SEV(lg, error) << child_with_no_original_parent << qn; BOOST_THROW_EXCEPTION( indexing_error(child_with_no_original_parent + qn)); } for (const auto qn : op) original_parents.push_back(qn); d.original_parents[parent] = op; BOOST_LOG_SEV(lg, debug) << "Type: " << parent.qualified() << " has original parents: " << op; d.leaves[parent].push_back(leaf); BOOST_LOG_SEV(lg, debug) << "Type is a leaf of: " << parent.qualified(); } d.original_parents[o.name()] = original_parents; return original_parents; }
void DrawForEditor() { for (int i = 0; i < s.c.p.size(); i++) { mEmpty.Draw(s.c.p[i].pos, 0); } }
bool sls_engine::full_eval(model & mdl) { model::scoped_model_completion _scm(mdl, true); for (expr* a : m_assertions) { checkpoint(); if (!mdl.is_true(a)) { TRACE("sls", tout << "Evaluation: false\n";); return false; }
parameters::parameters(datafile dat, model nv_mod, model ref_mod,parameters ref_param,int compo,int iter){ const MatrixXi & omega=nv_mod.Get_model(),ref_omega=ref_mod.Get_model(),mat=dat.Get_mat_datafile(); const int g=omega.rows(),unique=mat.rows(); m_proba=ref_param.m_proba; m_proba_block.resize(g); m_param.resize(g); for (int k=0;k<g;k++){ if (k!=compo){ m_param[k].resize(omega.rowwise().maxCoeff()(k)+1); m_param[k]=ref_param.m_param[k]; m_proba_block[k].resize(unique,omega.rowwise().maxCoeff()(k)+1); m_proba_block[k]=ref_param.m_proba_block[k]; for (int b=0;b<(omega.rowwise().maxCoeff()(k)+1) ;b++){ if ((omega.row(k).array()==b).any()){ m_param[k][b]=ref_param.m_param[k][b]; } } }else{ m_param[k].resize(omega.rowwise().maxCoeff()(k)+1); m_proba_block[k].resize(unique,omega.rowwise().maxCoeff()(k)+1); for (int b=0;b<(omega.rowwise().maxCoeff()(k)+1) ;b++){ if ((omega.row(k).array()==b).any()){ if ((((omega.row(k).array()==b)==(ref_omega.row(k).array()==b)).prod())==1){ m_param[k][b]=ref_param.m_param[k][b]; }else{ m_param[k][b]=param_block(k,b,dat,nv_mod,m_proba.col(k).array()/m_proba.rowwise().sum().array(),1); if ((omega.row(k).array()==b).count()>1){ int prem=0; while(omega(k,prem)!=b){prem++;} if (mat.col(prem).maxCoeff()>5){ m_param[k][b]=m_param[k][b].Optimise_gamma(k,b,dat,nv_mod,5,m_proba.col(k).array()/m_proba.rowwise().sum().array(),dat.Get_eff_datafile()); } } } } } } } m_propor=uniforme(g); Probapost( nv_mod , mat ); Compte_nbparam(dat,nv_mod); Likelihood(dat.Get_eff_datafile()); Estimation(1,0,iter,dat,nv_mod); }
void Draw3d() { Setup3dWorld(); DrawWorld(); //pointer u.pointer = GetOGLPos(int(u.mp.x), int(u.mp.y)); mPointer.Draw(u.pointer, 0); }
void json_hydrator:: read_element(const boost::property_tree::ptree& pt, model& m) const { qname qn; qn.model_name(model_name(m)); read_module_path(pt, m, qn); const auto simple_name_value(pt.get<std::string>(simple_name_key)); qn.simple_name(simple_name_value); const auto documentation(pt.get_optional<std::string>(documentation_key)); const auto lambda([&](type& t) { BOOST_LOG_SEV(lg, debug) << "Processing type: " << sml::string_converter::convert(qn); t.name(qn); t.origin_type(m.origin_type()); t.generation_type(m.generation_type()); if (documentation) t.documentation(*documentation); const auto scope(dynamic::scope_types::entity); t.extensions(create_dynamic_extensions(pt, scope)); }); const auto meta_type_value(pt.get<std::string>(meta_type_key)); if (meta_type_value == meta_type_object_value) { object o; lambda(o); const auto ot(pt.get_optional<std::string>(object_type_key)); o.object_type(to_object_type(ot)); m.objects().insert(std::make_pair(qn, o)); } else if (meta_type_value == meta_type_primitive_value) { primitive p; lambda(p); m.primitives().insert(std::make_pair(qn, p)); } else { BOOST_LOG_SEV(lg, error) << invalid_meta_type << meta_type_value; BOOST_THROW_EXCEPTION( hydration_error(invalid_meta_type + meta_type_value)); } }
void generalization_indexer:: populate(const generalization_details& d, model& m) const { for (const auto& pair : d.leaves) { const auto& n(pair.first); auto i(m.objects().find(n)); if (i == m.objects().end()) { const auto qn(n.qualified()); BOOST_LOG_SEV(lg, error) << object_not_found << qn; BOOST_THROW_EXCEPTION(indexing_error(object_not_found + qn)); } const auto rt(relationship_types::leaves); i->second.relationships()[rt] = pair.second; i->second.relationships()[rt].sort(); const auto omn(m.name().location().original_model_name()); for (const auto& l : pair.second) { if (l.location().original_model_name() == omn) m.leaves().insert(l); } } for (const auto& pair : d.original_parents) { const auto& n(pair.first); auto i(m.objects().find(n)); if (i == m.objects().end()) { const auto qn(n.qualified()); BOOST_LOG_SEV(lg, error) << object_not_found << qn; BOOST_THROW_EXCEPTION(indexing_error(object_not_found + qn)); } auto& o(i->second); if (!o.is_child()) { // a bit of a hack, top-level types have themselves as the // original parent of the container just to make our life easier BOOST_LOG_SEV(lg, debug) << "Type has parents but is not a child: " << n.qualified(); continue; } const auto rt(relationship_types::original_parents); o.relationships()[rt] = pair.second; for (const auto& opn : pair.second) { const auto j(m.objects().find(opn)); if (j == m.objects().end()) { const auto qn(opn.qualified()); BOOST_LOG_SEV(lg, error) << object_not_found << qn; BOOST_THROW_EXCEPTION(indexing_error(object_not_found + qn)); } o.is_original_parent_visitable(j->second.is_visitable()); } } }
void parameters::Probapost(model mod, const MatrixXi & mat){ const MatrixXi & omega=mod.Get_model(); m_proba=MatrixXd::Ones(mat.rows(),omega.rows()); for (int k = 0; k < omega.rows(); ++k) { m_proba_block[k]=m_proba_block[k].Ones(mat.rows(),(omega.rowwise().maxCoeff()(k)+1)); for (int b = 0; b < (omega.rowwise().maxCoeff()(k)+1); ++b){ if ((omega.row(k).array()==b).any()){ const VectorXi & who=mod.Get_var_block(k,b); if (who.rows()>1){ m_proba_block[k].col(b)=m_param[k][b].proba_indpt(who,mat)+m_param[k][b].proba_dpt(who,mat); }else{ m_proba_block[k].col(b)=m_param[k][b].proba_indpt(who,mat); } } } m_proba.col(k)=m_propor(k)* (m_proba_block[k].rowwise().prod()).array(); } }
// clean up void ssd::operator()(model& m, const precalculate& p, const igrid& ig, output_type& out, change& g, const vec& v) const { // g must have correct size out.e = m.eval_deriv(p, ig, v, out.c, g); fl factor = initial_factor; VINA_U_FOR(i, evals) { if(factor < min_factor) break; output_type candidate(out); candidate.c.increment(g, -factor); change candidate_g(g); candidate.e = m.eval_deriv(p, ig, v, candidate.c, candidate_g); if(candidate.e <= out.e) { out = candidate; g = candidate_g; factor *= up; } else { factor *= down; } } out.coords = m.get_heavy_atom_movable_coords(); }
void parameters::Estimation_discrete(int nbtent, datafile dat, model mod){ const MatrixXi & omega=mod.Get_model(); const int g=omega.rows(); for (int k=0;k<g;k++){ for (int b=0;b<(omega.row(k).maxCoeff()+1);b++){ if ((omega.row(k).array()==b).count()>1){ m_param[k][b]=m_param[k][b].Optimise_gamma(k,b,dat,mod,nbtent, m_proba.col(k).array()/m_proba.rowwise().sum().array(),dat.Get_eff_datafile()); } } } }
void decoration_expander:: expand(const dogen::formatters::decoration_properties_factory& dpf, model& fm) const { const auto dc(dpf.make(cs_modeline_name)); for (auto& pair : fm.formattables()) { const auto id(pair.first); auto& formattable(pair.second); auto& eprops(formattable.element_properties()); eprops.decoration_properties(dc); } }
inline void update_containing_module(model& m, AssociativeContainerOfContainable& c) { for (auto& pair : c) { auto& s(pair.second); s.containing_module(containing_module(m, s.name())); if (!s.containing_module()) continue; auto i(m.modules().find(*s.containing_module())); if (i == m.modules().end()) { const auto sn(s.containing_module()->simple()); BOOST_LOG_SEV(lg, error) << missing_module << sn; BOOST_THROW_EXCEPTION(expansion_error(missing_module + sn)); } BOOST_LOG_SEV(lg, debug) << "Adding type to module. Type: '" << s.name().qualified() << "' Module: '" << i->first.qualified(); i->second.members().push_back(s.name()); } }
void parameters::Compte_nbparam(datafile dat,model mod){ const MatrixXi & omega=mod.Get_model(); int g=omega.rows(); m_nbparam=g-1; for (int k=0;k<g;k++){ for (int b=0;b<(omega.rowwise().maxCoeff()(k)+1) ;b++){ if ((omega.row(k).array()==b).any()){ const VectorXi & who=mod.Get_var_block(k,b); const VectorXi modalite=dat.Get_modalite(who); if (who.rows()==1){ m_nbparam+=modalite(0)-1; }else{ for (int h=0;h<modalite.rows();h++){ m_nbparam+=modalite(h)-1; } m_nbparam+=modalite(0); if ((modalite(1)==2)&&(who.rows()==2)){m_nbparam--;} } } } } }
helper_configuration helper_expander:: make_configuration(const feature_group& fg, const model& fm) const { BOOST_LOG_SEV(lg, debug) << "Started making the configuration."; helper_configuration r; r.streaming_properties(fm.streaming_properties()); for (auto& pair : fm.formattables()) { const auto id(pair.first); BOOST_LOG_SEV(lg, debug) << "Procesing element: " << id; auto& formattable(pair.second); auto& segment(*formattable.master_segment()); const auto& cfg(*segment.configuration()); const variability::helpers::configuration_selector s(cfg); const auto fam(s.get_text_content_or_default(fg.family)); r.helper_families()[id] = fam; } BOOST_LOG_SEV(lg, debug) << "Finished making the configuration. Result:" << r; return r; }
void file_path_and_guard_expander:: expand(const formatters::repository& frp, const locator& l, model& fm) const { const auto safba(frp.stock_artefact_formatters_by_archetype()); for (auto& pair : fm.formattables()) { const auto id(pair.first); auto& formattable(pair.second); /* * It doesn't really matter which segment we choose here since * they are both mapped to the same name. */ const auto& e(*formattable.master_segment()); const auto n(e.name()); auto& eprops(formattable.element_properties()); /* * Go thorough all the artefact properties and, for each, find * the associated formatter. */ for (auto& pair : eprops.artefact_properties()) { const auto arch(pair.first); auto& art_props(pair.second); const auto i(safba.find(arch)); if (i == safba.end()) { BOOST_LOG_SEV(lg, error) << missing_archetype << arch; BOOST_THROW_EXCEPTION( expansion_error(missing_archetype + arch)); } /* * Ask the formatter to generate the full path for the * artefact. */ const auto& fmt(i->second); art_props.file_path(fmt->full_path(l, n)); /* * If the formatter supports inclusion, we need to compute * the header guard as well. */ const auto ns(formatters::inclusion_support_types::not_supported); if (fmt->inclusion_support_type() != ns) { const auto ip(fmt->inclusion_path(l, n)); art_props.header_guard(to_header_guard(ip)); } } } }
BEGIN_NAMESPACE_CORE final_snapshot::final_snapshot(model &model_ref, property_tree const &pt) : final_snapshot(model_ref, pt.count("final_estimator") ? factory_create_from_property_tree<advance_estimator>( pt.get_child("final_estimator")) : nullptr, factory_create_from_property_tree<stream_printer>( pt.get_child("configuration_printer")), stacked_view_configuration( model_ref.current_configuration(), pt.get_child("stacked_view", property_tree()))) { }
bool sls_engine::full_eval(model & mdl) { bool res = true; unsigned sz = m_assertions.size(); for (unsigned i = 0; i < sz && res; i++) { checkpoint(); expr_ref o(m_manager); if (!mdl.eval(m_assertions[i], o, true)) exit(ERR_INTERNAL_FATAL); res = m_manager.is_true(o.get()); } TRACE("sls", tout << "Evaluation: " << res << std::endl;);