void DisplayData(void) { int iTask; printf("Display of the instance:\n"); printf("\t Time Horizon T: %ld\n",T()); printf("\t Number of Tasks N: %ld\n",N()); printf("\t Number of Machines M: %ld\n",M()); ConsoleTable ct("Tasks", N(), 6); ct.SetColHeader(0, "QtyCPU") .SetColHeader(1, "QtyGPU") .SetColHeader(2, "QtyRAM") .SetColHeader(3, "QtyHDD") .SetColHeader(4, "IsPreemp") .SetColHeader(5, "CostPreemp"); for (iTask=0;iTask<N();iTask++) { ct.Print(nc(iTask)); ct.Print(ng(iTask)); ct.Print(nr(iTask)); ct.Print(nh(iTask)); ct.Print(R(iTask)); ct.Print(rho(iTask)); } }
NNGraph MSConnectivityScore::pick_graph(EdgeSet const &picked) const { EdgeSet::const_iterator p; std::map<unsigned int, int> idx_to_vtx; int n_vert = 0; for (p = picked.begin(); p != picked.end(); ++p) { std::map<unsigned int, int>::iterator q = idx_to_vtx.find(p->first); if (q == idx_to_vtx.end()) idx_to_vtx[p->first] = n_vert++; q = idx_to_vtx.find(p->second); if (q == idx_to_vtx.end()) idx_to_vtx[p->second] = n_vert++; } NNGraph ng(n_vert); boost::property_map<NNGraph, boost::vertex_name_t>::type vertex_id = boost::get(boost::vertex_name, ng); boost::property_map<NNGraph, boost::edge_weight_t>::type dist = boost::get(boost::edge_weight, ng); for (std::map<unsigned int, int>::iterator q = idx_to_vtx.begin(); q != idx_to_vtx.end(); ++q) { boost::put(vertex_id, q->second, q->first); } for (p = picked.begin(); p != picked.end(); ++p) { NNGraph::edge_descriptor e = boost::add_edge(idx_to_vtx[p->first], idx_to_vtx[p->second], ng).first; double d = restraint_.particle_matrix_.get_distance(p->first, p->second); boost::put(dist, e, d); } return ng; }
void MomentumEstimator::registerCollectables(vector<observable_helper*>& h5desc , hid_t gid) const { if (hdf5_out) { //descriptor for the data, 1-D data vector<int> ng(1); //add nofk ng[0]=nofK.size(); observable_helper* h5o=new observable_helper("nofk"); h5o->set_dimensions(ng,myIndex); h5o->open(gid); h5o->addProperty(const_cast<vector<PosType>&>(kPoints),"kpoints"); h5o->addProperty(const_cast<vector<int>&>(kWeights),"kweights"); h5desc.push_back(h5o); //add compQ ng[0]=Q.size(); h5o=new observable_helper("compQ"); h5o->set_dimensions(ng,myIndex+nofK.size()); h5o->open(gid); h5o->addProperty(const_cast<vector<RealType>&>(Q),"q"); h5desc.push_back(h5o); } }
int main( ) { FPGroup G; cout << "Enter nilpotentcy class first then group "; int NilpotentcyClass; cin >> NilpotentcyClass; Chars errMsg = cin >> G; if (errMsg.length()>0) return 1; NilpotentGroup ng(G.namesOfGenerators(), NilpotentcyClass,makeVectorOf(G.getRelators())); ng.initialize(); VectorOf<Word> vw; Word w; for (int i=1;true;i++){ cout << endl << "Enter the "<<i<<" generator of subgroup"<< endl; cout << "Empty word to finish: "; w = G.readWord(cin,errMsg); if (w.length()==0) break; if (errMsg.length()>0) return 1; vw.append(w); } SGOfNilpotentGroup sg(ng,vw); sg.initBasis(); sg.printBasis(cout); cout << "The Hirsch number :" << sg.theHirschNumber() << endl; cout << "Index in parent group :" << sg.index() << endl; cout << "Is Trivial :" << sg.isTrivial() << endl; cout << "Is Central :" << sg.isCentral() << endl; cout << "Is normal :" << sg.isNormal() << endl; cout << "Is abelian :" << sg.isAbelian() << endl; cout << "Subgroup class :" << sg.subgroupClass() << endl; cout << "Generators of normal closure :" << endl; vw = sg.normalClosureGens(); for (int i=0;i<vw.length();i++){ G.printWord(cout,vw[i]); cout << endl; } PresentationForSNG sgp = sg.makePresentation(); cout << "Presentation of subgroup :" << endl; sgp.print(cout); cout << endl << "Enter the word :"; errMsg = ""; w = G.readWord(cin,errMsg); if (errMsg.length()>0){ cout << errMsg; return 1; } cout << endl << "Does subgroup contain the word :" << sg.contains(w) << endl; PolyWord result; if (sg.decompose(ng.decompose(w),result)) cout << "Decomposition in sg basis :" << sg.asDecomposition(result); else cout << "Subgroup does not contain this word"; }
int shiftone::discount(ngram ng_,int size,double& fstar,double& lambda, int cv) { ngram ng(dict); ng.trans(ng_); // cout << "size :" << size << " " << ng <<"\n"; if (size > 1) { ngram history=ng; if (ng.ckhisto(size) && get(history,size,size-1) && (history.freq>cv) && ((size < 3) || ((history.freq-cv) > prunethresh))) { // this history is not pruned out get(ng,size,size); cv=(cv>ng.freq)?ng.freq:cv; if (ng.freq > cv) { fstar=(double)((double)(ng.freq - cv) - beta)/(double)(history.freq-cv); lambda=beta * ((double)history.succ/(double)(history.freq-cv)); } else { // ng.freq == cv: do like if ng was deleted from the table fstar=0.0; lambda=beta * ((double)(history.succ-1)/ //one successor has disappeared! (double)(history.freq-cv)); } //cerr << "ngram :" << ng << "\n"; //check if the last word is OOV if (*ng.wordp(1)==dict->oovcode()) { lambda+=fstar; fstar=0.0; } else { //complete lambda with oovcode probability *ng.wordp(1)=dict->oovcode(); if (get(ng,size,size)) lambda+=(double)((double)ng.freq - beta)/(double)(history.freq-cv); } } else { fstar=0; lambda=1; } } else { fstar=unigr(ng); lambda=0.0; } return 1; }
void ParticleSet::resetGroups() { int nspecies=mySpecies.getTotalNum(); if(nspecies==0) { APP_ABORT("ParticleSet::resetGroups() Failed. No species exisits"); } int natt=mySpecies.numAttributes(); int qind=mySpecies.addAttribute("charge"); if(natt==qind) { app_log() << " Missing charge attribute of the SpeciesSet " << myName << " particleset" << endl; app_log() << " Assume neutral particles Z=0.0 " << endl; for(int ig=0; ig<nspecies; ig++) mySpecies(qind,ig)=0.0; } for(int iat=0; iat<Z.size(); iat++) Z[iat]=mySpecies(qind,GroupID[iat]); natt=mySpecies.numAttributes(); int massind=mySpecies.addAttribute("mass"); if(massind==natt) { for(int ig=0; ig<nspecies; ig++) mySpecies(massind,ig)=1.0; } for(int iat=0; iat<Mass.size(); iat++) Mass[iat]=mySpecies(massind,GroupID[iat]); vector<int> ng(nspecies,0); for(int iat=0; iat<GroupID.size(); iat++) { if(GroupID[iat]<nspecies) ng[GroupID[iat]]++; else APP_ABORT("ParticleSet::resetGroups() Failed. GroupID is out of bound."); } SubPtcl.resize(nspecies+1); SubPtcl[0]=0; for(int i=0; i<nspecies; ++i) SubPtcl[i+1]=SubPtcl[i]+ng[i]; int membersize= mySpecies.addAttribute("membersize"); for(int ig=0; ig<nspecies; ++ig) mySpecies(membersize,ig)=ng[ig]; //orgID=ID; //orgGroupID=GroupID; int new_id=0; for(int i=0; i<nspecies; ++i) for(int iat=0; iat<GroupID.size(); ++iat) if(GroupID[iat]==i) IndirectID[new_id++]=ID[iat]; IsGrouped=true; for(int iat=0; iat<ID.size(); ++iat) IsGrouped &= (IndirectID[iat]==ID[iat]); if(IsGrouped) app_log() << "Particles are grouped. Safe to use groups " << endl; else app_log() << "ID is not grouped. Need to use IndirectID for species-dependent operations " << endl; }
int main(int argc, char **argv) { Vocab3 vocab; Splitter s(vocab,3,true); s.load_vocab(argv[1]); s.go(); NgramCounter unigrams(1); ifstream ifs1(argv[1]); LineTokenizer lt1(ifs1); while(lt1.next()){ Tokenizer tok(lt1.token(),' '); while(tok.next()){ int wid = vocab.Add(tok.token()); unigrams.increase_count(&wid,1); } } ifstream ifs(argv[1]); LineTokenizer lt(ifs); NgramCounter ng(2); while(lt.next()){ Tokenizer tok(lt.token(),' '); while(tok.next()){ int wid = vocab.Add(tok.token()); int clid = s.get_class(wid); if (clid < 0 || unigrams.get_count(&wid) > 100 ){ clid = wid; } else { string cl = "-" + s.class_set.Get(clid).str(); clid = vocab.Add(LString(cl)); } int key[2] = {clid,wid}; ng.increase_count(key,1); cout << vocab.Get(clid) << " "; } cout << endl; } BtreeIterator it = ng.iterator(); ofstream ofs("my.classes"); while(it.next()){ ofs << vocab.Get(it.key()[1]) << "\t" << vocab.Get(it.key()[0]) << "\t" << (int)it.double_value()[0] << endl; } ofstream ofs2("my.classmap"); it = s.class_map.iterator(); while (it.next()){ ofs2 << vocab.Get(it.key()[0]) << "\t" << s.class_set.Get(it.key()[1]) << endl; } }
void AMI_Buffering::receive_data (const Test::Payload &the_payload) { try { AMI_Buffering::Nest_Guard ng(*this); this->admin_->request_received (the_payload.length ()); } catch (const CORBA::Exception&) { ACE_DEBUG ((LM_DEBUG,"(%P|%t) DEBUG: AMI_Buffering::receive_data")); } this->try_shutdown(); }
//Symmetric Shiftbeta int symshiftbeta::discount(ngram ng_,int size,double& fstar,double& lambda, int /* unused parameter: cv */) { ngram ng(dict); ng.trans(ng_); // cout << "size :" << size << " " << ng <<"\n"; // Pr(x/y)= max{(c([x,y])-beta)/(N Pr(y)),0} + lambda Pr(x) // lambda=#bigrams/N assert(size<=2); // only works with bigrams // if (size == 3) { ngram history=ng; } if (size == 2) { //compute unigram probability of denominator ngram unig(dict,1); *unig.wordp(1)=*ng.wordp(2); double prunig=unigr(unig); //create symmetric bigram if (*ng.wordp(1) > *ng.wordp(2)) { int tmp=*ng.wordp(1); *ng.wordp(1)=*ng.wordp(2); *ng.wordp(2)=tmp; } lambda=beta[2] * (double) entries(2)/(double)totfreq(); if (get(ng,2,2)) { fstar=(double)((double)ng.freq - beta[2])/ (totfreq() * prunig); } else { fstar=0; } } else { fstar=unigr(ng); lambda=0.0; } return 1; }
void MSConnectivityScore::add_edges_to_set(NNGraph &G, EdgeSet &edge_set) const { boost::property_map<NNGraph, boost::vertex_name_t>::type vertex_id = boost::get(boost::vertex_name, G); NNGraph ng(num_vertices(G)); Ints vertex_id_to_n(restraint_.particle_matrix_.size(), -1); for (unsigned int i = 0; i < num_vertices(ng); ++i) { unsigned int id = boost::get(vertex_id, i); vertex_id_to_n[id] = i; } for (EdgeSet::iterator p = edge_set.begin(); p != edge_set.end(); ++p) { unsigned int i_from = vertex_id_to_n[(*p).first]; unsigned int i_to = vertex_id_to_n[(*p).second]; add_edge(i_from, i_to, ng); } Ints components(num_vertices(ng)); int ncomp = boost::connected_components(ng, &components[0]); if (ncomp == 1) return; Vector<std::pair<unsigned int, unsigned int> > candidates; NNGraph::edge_iterator e, end; for (boost::tie(e, end) = edges(G); e != end; ++e) { unsigned int src = boost::get(vertex_id, source(*e, G)); unsigned int dst = boost::get(vertex_id, target(*e, G)); if (src > dst) std::swap(src, dst); std::pair<unsigned int, unsigned int> candidate = std::make_pair(src, dst); if (edge_set.find(candidate) == edge_set.end()) candidates.push_back(candidate); } std::sort(candidates.begin(), candidates.end(), EdgeScoreComparator(restraint_)); unsigned int idx = 0; while (ncomp > 1 && idx < candidates.size()) { unsigned int i_from = vertex_id_to_n[candidates[idx].first]; unsigned int i_to = vertex_id_to_n[candidates[idx].second]; if (components[i_from] != components[i_to]) { int old_comp = components[i_to]; for (unsigned int i = 0; i < components.size(); ++i) if (components[i] == old_comp) components[i] = components[i_from]; --ncomp; edge_set.insert(candidates[idx]); } ++idx; } BOOST_ASSERT(ncomp == 1); }
Optimizer::Optimizer(System& user_sys, Bsc& bsc, Ctc& ctc, double prec, double goal_rel_prec, double goal_abs_prec, int sample_size, double equ_eps, bool rigor) : user_sys(user_sys), sys(user_sys,equ_eps), n(user_sys.nb_var), m(sys.nb_ctr) /* (warning: not user_sys.nb_ctr) */, ext_sys(user_sys,equ_eps), bsc(bsc), ctc(ctc), buffer(n), prec(prec), goal_rel_prec(goal_rel_prec), goal_abs_prec(goal_abs_prec), sample_size(sample_size), mono_analysis_flag(true), in_HC4_flag(true), trace(false), timeout(1e08), loup(POS_INFINITY), uplo(NEG_INFINITY), pseudo_loup(POS_INFINITY), loup_point(n), loup_box(n), df(*user_sys.goal,Function::DIFF), rigor(rigor), uplo_of_epsboxes(POS_INFINITY), nb_cells(0), loup_changed(false) { // ==== build the system of equalities only ==== try { equs= new System(user_sys,System::EQ_ONLY); } catch(EmptySystemException&) { equs= NULL; } // ====== build the reversed inequalities g_i(x)>0 =============== if(m>0) { Array<Ctc> ng(m); for (int i=0; i<m; i++) { ng.set_ref(i, *new CtcFwdBwd(sys.f[i],GT)); } is_inside=new CtcUnion(ng); } else is_inside=NULL; // ============================================================= if (trace) cout.precision(12); // objshaver= new Ctc3BCid (*new CtcHC4 (ext_sys.ctrs,0.1,true),100,1,1); nb_simplex=0; diam_simplex=0; nb_rand=0; diam_rand=0; int niter=100; if (niter < 3*n) niter=3*n; //==================================== mylp = new LinearSolver(n+1,m,niter ); }
static void fixinit(Node *orig) { Graph *p1, *g; Symbol *q1, *q2 = ZS; ng(tl_lookup("init"), ZS, ZN, ZN, ZN); p1 = pop_stack(); p1->nxt = Nodes_Set; p1->Other = p1->Old = orig; Nodes_Set = p1; for (g = Nodes_Set; g; g = g->nxt) { for (q1 = g->incoming; q1; q1 = q2) { q2 = q1->next; Addout(g->name->name, q1->name); tfree((void *) q1); } g->incoming = ZS; } }
int mixture::discount(ngram ng_,int size,double& fstar,double& lambda,int /* unused parameter: cv */) { ngram ng(dict); ng.trans(ng_); double lambda2,fstar2; fstar=0.0; lambda=0.0; int p=pmap(ng,size); assert(p <= pmax); double lsum=0; for (int i=0; i<numslm; i++) { sublm[i]->discount(ng,size,fstar2,lambda2,0); ngram ngslm(sublm[i]->dict); ngslm.trans(ng); if (dict->dub() > sublm[i]->dict->size()){ if (*ngslm.wordp(1) == sublm[i]->dict->oovcode()) { fstar2/=(double)(sublm[i]->dict->dub() - sublm[i]->dict->size()+1); } } fstar+=(l[size][p][i]*fstar2); lambda+=(l[size][p][i]*lambda2); lsum+=l[size][p][i]; } if (dict->dub() > dict->size()) if (*ng.wordp(1) == dict->oovcode()) { fstar*=(double)(dict->dub() - dict->size()+1); } assert((lsum>LOWER_DOUBLE_PRECISION_OF_1) && (lsum<=UPPER_DOUBLE_PRECISION_OF_1)); return 1; }
NNGraph MSConnectivityScore::build_subgraph_from_assignment( NNGraph &G, Assignment const &assignment) const { unsigned int num_particles = restraint_.particle_matrix_.size(); Ints vertices; for (unsigned int i = 0; i < assignment.size(); ++i) if (!assignment[i].empty()) { Ints const &conf = assignment[i].get_tuple(); for (unsigned int j = 0; j < conf.size(); ++j) vertices.push_back(conf[j]); } boost::property_map<NNGraph, boost::vertex_name_t>::type vertex_id = boost::get(boost::vertex_name, G); boost::property_map<NNGraph, boost::edge_weight_t>::type dist = boost::get(boost::edge_weight, G); NNGraph ng(vertices.size()); boost::property_map<NNGraph, boost::vertex_name_t>::type new_vertex_id = boost::get(boost::vertex_name, ng); boost::property_map<NNGraph, boost::edge_weight_t>::type new_dist = boost::get(boost::edge_weight, ng); for (unsigned int i = 0; i < vertices.size(); ++i) boost::put(new_vertex_id, i, vertices[i]); Ints vertex_id_to_idx(num_particles, -1); for (unsigned int i = 0; i < vertices.size(); ++i) vertex_id_to_idx[vertices[i]] = i; NNGraph::edge_iterator e, end; for (boost::tie(e, end) = edges(G); e != end; ++e) { unsigned int source_id = boost::get(vertex_id, source(*e, G)); unsigned int dest_id = boost::get(vertex_id, target(*e, G)); unsigned int p_src = vertex_id_to_idx[source_id]; unsigned int p_dst = vertex_id_to_idx[dest_id]; if (p_src == static_cast<unsigned int>(-1) || p_dst == static_cast<unsigned int>(-1)) continue; NNGraph::edge_descriptor ed = boost::add_edge(p_src, p_dst, ng).first; double d = boost::get(dist, *e); boost::put(new_dist, ed, d); } return ng; }
void trans(Node *p) { Node *op; Graph *g; if (!p || tl_errs) return; p = twocases(p); if (tl_verbose || tl_terse) { fprintf(tl_out, "\t/* Normlzd: "); dump(p); fprintf(tl_out, " */\n"); } if (tl_terse) return; op = dupnode(p); ng(ZS, getsym(tl_lookup("init")), p, ZN, ZN); while ((g = Nodes_Stack) != (Graph *) 0) { Nodes_Stack = g->nxt; expand_g(g); } if (newstates) return; fixinit(p); liveness(flatten(op)); /* was: liveness(op); */ mkbuchi(); if (tl_verbose) { printf("/*\n"); printf(" * %d states in Streett automaton\n", Base); printf(" * %d Streett acceptance conditions\n", Max_Red); printf(" * %d Buchi states\n", Total); printf(" */\n"); } }
void Viewer::updateNodeView(bool honorDisplayFlag) { if (nodeScene != 0) { delete nodeScene; nodeScene = 0; } // invalid QModelIndex signifies the root. NodeGenerator ng(this->dataSource_->modelRoot(), nodeOpt, honorDisplayFlag); // calculate the layout based on options and number of nodes ng.calcLayout(this->dataSource_->modelRoot(), 1, 1); nodeScene = new QGraphicsScene(0, 0, ng.getSceneWidth(), ng.getSceneHeight()); this->ui.nodeView->setScene(nodeScene); ng.draw(nodeScene); std::stringstream msg; msg << "Node View Updated " << ng.getSceneWidth() << "x" << ng.getSceneHeight(); this->ui.statusbar->showMessage( tr(msg.str().c_str())); }
static void expand_g(Graph *g) { Node *now, *n1, *n2, *nx; int can_release; if (!g->New) { Debug2("\nDone with %s", g->name->name); if (tl_verbose) dump_graph(g); if (not_new(g)) { if (tl_verbose) printf("\tIs Not New\n"); return; } if (g->Next) { Debug(" Has Next ["); for (n1 = g->Next; n1; n1 = n1->nxt) { Dump(n1); Debug(", "); } Debug("]\n"); ng(ZS, getsym(g->name), g->Next, ZN, ZN); } return; } if (tl_verbose) { Symbol *z; printf("\nExpand %s, from ", g->name->name); for (z = g->incoming; z; z = z->next) printf("%s, ", z->name); printf("\n\thandle:\t"); Explain(g->New->ntyp); dump_graph(g); } if (g->New->ntyp == AND) { if (g->New->nxt) { n2 = g->New->rgt; while (n2->nxt) n2 = n2->nxt; n2->nxt = g->New->nxt; } n1 = n2 = g->New->lft; while (n2->nxt) n2 = n2->nxt; n2->nxt = g->New->rgt; releasenode(0, g->New); g->New = n1; push_stack(g); return; } can_release = 0; /* unless it need not go into Old */ now = g->New; g->New = g->New->nxt; now->nxt = ZN; if (now->ntyp != TRUE) { if (g->Old) { for (n1 = g->Old; n1->nxt; n1 = n1->nxt) if (isequal(now, n1)) { can_release = 1; goto out; } n1->nxt = now; } else g->Old = now; } out: switch (now->ntyp) { case FALSE: push_stack(g); break; case TRUE: releasenode(1, now); push_stack(g); break; case PREDICATE: case NOT: if (can_release) releasenode(1, now); push_stack(g); break; case V_OPER: Assert(now->rgt != ZN, now->ntyp); Assert(now->lft != ZN, now->ntyp); Assert(now->rgt->nxt == ZN, now->ntyp); Assert(now->lft->nxt == ZN, now->ntyp); n1 = now->rgt; n1->nxt = g->New; if (can_release) nx = now; else nx = getnode(now); /* now also appears in Old */ nx->nxt = g->Next; n2 = now->lft; n2->nxt = getnode(now->rgt); n2->nxt->nxt = g->New; g->New = flatten(n2); push_stack(g); ng(ZS, g->incoming, n1, g->Old, nx); break; case U_OPER: Assert(now->rgt->nxt == ZN, now->ntyp); Assert(now->lft->nxt == ZN, now->ntyp); n1 = now->lft; if (can_release) nx = now; else nx = getnode(now); /* now also appears in Old */ nx->nxt = g->Next; n2 = now->rgt; n2->nxt = g->New; goto common; #ifdef NXT case NEXT: Assert(now->lft != ZN, now->ntyp); nx = dupnode(now->lft); nx->nxt = g->Next; g->Next = nx; if (can_release) releasenode(0, now); push_stack(g); break; #endif case OR: Assert(now->rgt->nxt == ZN, now->ntyp); Assert(now->lft->nxt == ZN, now->ntyp); n1 = now->lft; nx = g->Next; n2 = now->rgt; n2->nxt = g->New; common: n1->nxt = g->New; ng(ZS, g->incoming, n1, g->Old, nx); g->New = flatten(n2); if (can_release) releasenode(1, now); push_stack(g); break; } }
int mixture::train() { double zf; srand(1333); genpmap(); if (dub()<dict->size()) { std::stringstream ss_msg; ss_msg << "\nERROR: DUB value is too small: the LM will possibly compute wrong probabilities if sub-LMs have different vocabularies!\n"; ss_msg << "This exception should already have been handled before!!!\n"; exit_error(IRSTLM_ERROR_MODEL, ss_msg.str()); } cerr << "mixlm --> DUB: " << dub() << endl; for (int i=0; i<numslm; i++) { cerr << i << " sublm --> DUB: " << sublm[i]->dub() << endl; cerr << "eventually generate OOV code "; cerr << sublm[i]->dict->encode(sublm[i]->dict->OOV()) << "\n"; sublm[i]->train(); } //initialize parameters for (int i=0; i<=lmsize(); i++) { l[i]=new double*[pmax]; for (int j=0; j<pmax; j++) { l[i][j]=new double[numslm]; for (int k=0; k<numslm; k++) l[i][j][k]=1.0/(double)numslm; } } if (ipfname) { //load parameters from file loadpar(ipfname); } else { //start training of mixture model double oldl[pmax][numslm]; char alive[pmax],used[pmax]; int totalive; ngram ng(sublm[0]->dict); for (int lev=1; lev<=lmsize(); lev++) { zf=sublm[0]->zerofreq(lev); cerr << "Starting training at lev:" << lev << "\n"; for (int i=0; i<pmax; i++) { alive[i]=1; used[i]=0; } totalive=1; int iter=0; while (totalive && (iter < 20) ) { iter++; for (int i=0; i<pmax; i++) if (alive[i]) for (int j=0; j<numslm; j++) { oldl[i][j]=l[lev][i][j]; l[lev][i][j]=1.0/(double)numslm; } sublm[0]->scan(ng,INIT,lev); while(sublm[0]->scan(ng,CONT,lev)) { //do not include oov for unigrams if ((lev==1) && (*ng.wordp(1)==sublm[0]->dict->oovcode())) continue; int par=pmap(ng,lev); used[par]=1; //controllo se aggiornare il parametro if (alive[par]) { double backoff=(lev>1?prob(ng,lev-1):1); //backoff double denom=0.0; double* numer = new double[numslm]; double fstar,lambda; //int cv=(int)floor(zf * (double)ng.freq + rand01()); //int cv=1; //old version of leaving-one-out int cv=(int)floor(zf * (double)ng.freq)+1; //int cv=1; //old version of leaving-one-out //if (lev==3)q //if (iter>10) // cout << ng // << " backoff " << backoff // << " level " << lev // << "\n"; for (int i=0; i<numslm; i++) { //use cv if i=0 sublm[i]->discount(ng,lev,fstar,lambda,(i==0)*(cv)); numer[i]=oldl[par][i]*(fstar + lambda * backoff); ngram ngslm(sublm[i]->dict); ngslm.trans(ng); if ((*ngslm.wordp(1)==sublm[i]->dict->oovcode()) && (dict->dub() > sublm[i]->dict->size())) numer[i]/=(double)(dict->dub() - sublm[i]->dict->size()); denom+=numer[i]; } for (int i=0; i<numslm; i++) { l[lev][par][i]+=(ng.freq * (numer[i]/denom)); //if (iter>10) //cout << ng << " l: " << l[lev][par][i] << "\n"; } delete []numer; } } //normalize all parameters totalive=0; for (int i=0; i<pmax; i++) { double tot=0; if (alive[i]) { for (int j=0; j<numslm; j++) tot+=(l[lev][i][j]); for (int j=0; j<numslm; j++) l[lev][i][j]/=tot; //decide if to continue to update if (!used[i] || (reldist(l[lev][i],oldl[i],numslm)<=0.05)) alive[i]=0; } totalive+=alive[i]; } cerr << "Lev " << lev << " iter " << iter << " tot alive " << totalive << "\n"; } } } if (opfname) savepar(opfname); return 1; }
std::vector<int> mpsxx::compress_qc_mpos ( const std::vector<int>& groups, std::vector<std::vector<btas::QSTArray<double,4,fermion>>>& mpos, std::vector<std::vector<btas::QSTArray<double,4,fermion>>>& comp) { const size_t MAXBUF = 200; size_t ig; std::set<int> ng(groups.begin(),groups.end()); comp.resize(ng.size()); std::vector<std::vector<size_t>> Ds(ng.size()); std::cout << "\t\tThere are " << ng.size() << " groups to be separatory compressed." << std::endl; ig = 0; for(auto it = ng.begin(); it != ng.end(); ++it, ++ig) { int label = *it; std::cout << "\t\tCompressing operator group " << label << std::endl; size_t t = 0; for(; t < groups.size() && groups[t] != label; ++t); size_t ngen = 1; size_t nbuf = 1; comp[ig].swap(mpos[t]); ++t; size_t norb = comp[ig].size(); for(; t < groups.size(); ++t) { if(groups[t] == label) { ++ngen; { btas::QSTArray<double,4,fermion> temp(comp[ig][0]); comp[ig][0].clear(); btas::IVector<3> traceIdx = {0,1,2}; btas::QSTdsum(temp,mpos[t][0],traceIdx,comp[ig][0]); } for(size_t s = 1; s < norb-1; ++s) { btas::QSTArray<double,4,fermion> temp(comp[ig][s]); comp[ig][s].clear(); btas::IVector<2> traceIdx = {1,2}; btas::QSTdsum(temp,mpos[t][s],traceIdx,comp[ig][s]); } { btas::QSTArray<double,4,fermion> temp(comp[ig][norb-1]); comp[ig][norb-1].clear(); btas::IVector<3> traceIdx = {1,2,3}; btas::QSTdsum(temp,mpos[t][norb-1],traceIdx,comp[ig][norb-1]); } // deallocation std::vector<btas::QSTArray<double,4,fermion>>().swap(mpos[t]); if(++nbuf >= MAXBUF) { std::cout << "\t\t\tdo compress mpos up to " << std::setw(6) << t << std::endl; Ds[ig] = compress_mpos_cycle(comp[ig]); std::cout << "\t\t\t"; for(size_t s = 0; s < Ds[ig].size(); ++s) std::cout << Ds[ig][s] << ":"; std::cout << std::endl; nbuf = 1; } } } // if(nbuf > 1) Ds[ig] = compress_mpos_cycle(comp[ig]); std::cout << "\t\t\t"; for(size_t s = 0; s < Ds[ig].size(); ++s) std::cout << Ds[ig][s] << ":"; std::cout << ":compressed by " << ngen << " terms." << std::endl; } std::cout << "\t\tCheck boundary size..." << std::endl; ig = 0; for(auto it = ng.begin(); it != ng.end(); ++it, ++ig) { std::cout << "\t\t\t"; for(size_t s = 0; s < Ds[ig].size(); ++s) std::cout << Ds[ig][s] << ":"; std::cout << ":group = " << *it << std::endl; } return std::vector<int>(ng.begin(),ng.end()); }
int mshiftbeta::train() { trainunigr(); gencorrcounts(); gensuccstat(); ngram ng(dict); int n1,n2,n3,n4; int unover3=0; oovsum=0; for (int l=1; l<=lmsize(); l++) { cerr << "level " << l << "\n"; cerr << "computing statistics\n"; n1=0; n2=0; n3=0,n4=0; scan(ng,INIT,l); while(scan(ng,CONT,l)) { //skip ngrams containing _OOV if (l>1 && ng.containsWord(dict->OOV(),l)) { //cerr << "skp ngram" << ng << "\n"; continue; } //skip n-grams containing </s> in context if (l>1 && ng.containsWord(dict->EoS(),l-1)) { //cerr << "skp ngram" << ng << "\n"; continue; } //skip 1-grams containing <s> if (l==1 && ng.containsWord(dict->BoS(),l)) { //cerr << "skp ngram" << ng << "\n"; continue; } ng.freq=mfreq(ng,l); if (ng.freq==1) n1++; else if (ng.freq==2) n2++; else if (ng.freq==3) n3++; else if (ng.freq==4) n4++; if (l==1 && ng.freq >=3) unover3++; } if (l==1) { cerr << " n1: " << n1 << " n2: " << n2 << " n3: " << n3 << " n4: " << n4 << " unover3: " << unover3 << "\n"; } else { cerr << " n1: " << n1 << " n2: " << n2 << " n3: " << n3 << " n4: " << n4 << "\n"; } if (n1 == 0 || n2 == 0 || n1 <= n2) { cerr << "Error: lower order count-of-counts cannot be estimated properly\n"; cerr << "Hint: use another smoothing method with this corpus.\n"; exit(1); } double Y=(double)n1/(double)(n1 + 2 * n2); beta[0][l] = Y; //equivalent to 1 - 2 * Y * n2 / n1 if (n3 ==0 || n4 == 0 || n2 <= n3 || n3 <= n4 ){ cerr << "Warning: higher order count-of-counts cannot be estimated properly\n"; cerr << "Fixing this problem by resorting only on the lower order count-of-counts\n"; beta[1][l] = Y; beta[2][l] = Y; } else{ beta[1][l] = 2 - 3 * Y * n3 / n2; beta[2][l] = 3 - 4 * Y * n4 / n3; } if (beta[1][l] < 0){ cerr << "Warning: discount coefficient is negative \n"; cerr << "Fixing this problem by setting beta to 0 \n"; beta[1][l] = 0; } if (beta[2][l] < 0){ cerr << "Warning: discount coefficient is negative \n"; cerr << "Fixing this problem by setting beta to 0 \n"; beta[2][l] = 0; } if (l==1) oovsum=beta[0][l] * (double) n1 + beta[1][l] * (double)n2 + beta[2][l] * (double)unover3; cerr << beta[0][l] << " " << beta[1][l] << " " << beta[2][l] << "\n"; } return 1; };
int shiftbeta::train() { ngram ng(dict); int n1,n2; trainunigr(); beta[1]=0.0; for (int l=2; l<=lmsize(); l++) { cerr << "level " << l << "\n"; n1=0; n2=0; scan(ng,INIT,l); while(scan(ng,CONT,l)) { if (l<lmsize()) { //Computing succ1 statistics for this ngram //to correct smoothing due to singleton pruning ngram hg=ng; get(hg,l,l); int s1=0; ngram ng2=hg; ng2.pushc(0); succscan(hg,ng2,INIT,l+1); while(succscan(hg,ng2,CONT,l+1)) { if (ng2.freq==1) s1++; } succ1(hg.link,s1); } //skip ngrams containing _OOV if (l>1 && ng.containsWord(dict->OOV(),l)) { //cerr << "skp ngram" << ng << "\n"; continue; } //skip n-grams containing </s> in context if (l>1 && ng.containsWord(dict->EoS(),l-1)) { //cerr << "skp ngram" << ng << "\n"; continue; } //skip 1-grams containing <s> if (l==1 && ng.containsWord(dict->BoS(),l)) { //cerr << "skp ngram" << ng << "\n"; continue; } if (ng.freq==1) n1++; else if (ng.freq==2) n2++; } //compute statistics of shiftbeta smoothing if (beta[l]==-1) { if (n1>0) beta[l]=(double)n1/(double)(n1 + 2 * n2); else { cerr << "no singletons! \n"; beta[l]=1.0; } } cerr << beta[l] << "\n"; } return 1; };
void makePlots2() { gROOT->ProcessLine(".x lhcbStyle.C"); gStyle->SetOptStat(0); Double_t ignore, eff, massfit1, massfit2, bias1, bias2; Double_t value[6][19], stat[6][19], syst[6][19]; Int_t ng(4); TH1D pull("pull","",15,-3.0,3.0); std::ifstream fin("errs.dat"); fin.ignore(256,'\n'); for(Int_t q=0; q<19; ++q) { for(Int_t g=1; g<ng+1; ++g) { fin >> ignore >> ignore >> value[g+1][q] >> stat[g+1][q] >> eff >> massfit1 >> massfit2 >> bias1 >> bias2; syst[g+1][q] = TMath::Sqrt(stat[g+1][q]*stat[g+1][q] + eff*eff + massfit1*massfit1 + massfit2*massfit2 + bias1*bias1 + bias2*bias2); //plot syst errors on top of stats if(q<17) pull.Fill(value[g+1][q]/syst[g+1][q]); } value[0][q] = value[2][q]; stat[0][q] = stat[2][q]; syst[0][q] = syst[2][q]; value[1][q] = 2*value[3][q]+1; stat[1][q] = 2*stat[3][q]; syst[1][q] = 2*syst[3][q]; } fin.close(); Double_t xs[19] = { 0.54, 1.55, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 11.375, 12.125, 15.5, 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 3.55, 18.5}; Double_t exs[19] = { 0.44, 0.45, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.375, 0.375, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 2.45, 3.5}; TCanvas c; TF1 gaus("gaus","gaus(0)",-3.,3.); gaus.SetParameter(0,68); gaus.SetParameter(1,pull.GetBinCenter(pull.GetMaximumBin())); gaus.SetParameter(2,pull.GetStdDev()); gaus.SetParLimits(1,-2.0,2.0); gaus.SetParLimits(2,0.3,3.0); pull.Fit(&gaus,"S"); pull.Draw(); c.SaveAs("gPulls.pdf"); for(Int_t i=0; i<ng+2; ++i) { TString varName(""); TString varName2(""); switch(i) { case 0: varName="A_{FB}"; varName2="AFB"; break; case 1: varName="F_{H}"; varName2="FH"; break; default: varName="G^{("; varName+=(i-1); varName+=")}"; varName2="G"; varName2+=(i-1); } Double_t yMin = getMin(19,value[i])-getMax(19,syst[i]); Double_t yMax = getMax(19,value[i])+getMax(19,syst[i]); if(yMax-yMin == 0) continue; TH2D h("h","",1,0.0,22.,1,yMin,yMax); TLine l(0.0,0.0,22.0,0.0); l.SetLineStyle(kDashed); l.SetLineColor(kRed); h.GetYaxis()->SetTitle(varName); h.GetXaxis()->SetTitle("q^{2} [GeV^{2}/c^{4}]"); TGraphErrors g1(17,xs, value[i], exs, stat[i] ); TGraphErrors g2( 2,xs+17,value[i]+17,exs+17,stat[i]+17); TGraphErrors g3(17,xs, value[i], exs, syst[i] ); TGraphErrors g4( 2,xs+17,value[i]+17,exs+17,syst[i]+17); g2.SetLineColor(kBlue); g2.SetMarkerColor(kBlue); g3.SetLineColor(kRed); g4.SetLineColor(kRed); g2.SetFillColor(kBlue); g4.SetFillColor(kRed); g2.SetFillStyle(3001); g4.SetFillStyle(3002); h.Draw(); l.Draw(); g4.Draw("E2same"); g2.Draw("E2same"); g3.Draw("PEsame"); g1.Draw("PEsame"); c.SaveAs("plots/fromPatrickNew/"+varName2+".pdf"); c.SaveAs("plots/fromPatrickNew/"+varName2+".png"); } }
void CODECHECK_STI_infectivity_curves() { /// CHECK ALL INFECTIVITY CURVES /// will be plotted in R ofstream f("./CODECHECK/codecheck_STI_IC.out"); double timestep = 1.0 / 365.0; Gender defaultgender = female; // --- Syphilis --- cout << "CODECHECK: IC Tp (syphilis)"<<endl; STI s(Tp,"./in_STI.csv"); s.set_is_recurrent(true); s.set_is_recurrent_2(true); s.set_is_symptomatic(false); for (double t=0; t<2; t+=timestep) f << "Tp," << t<<","<<s.infectivityCurve(t,defaultgender)<<endl; s.set_is_symptomatic(true); for (double t=0; t<2; t+=timestep) f << "Tp_condy," << t<<","<<s.infectivityCurve(t,defaultgender)<<endl; // --- Ct --- cout << "CODECHECK: IC Ct"<<endl; STI ct(Ct,"./in_STI.csv"); ct.set_is_symptomatic(false); for (double t=0; t<2; t+=timestep) f << "Ct asymptom," << t<<","<<ct.infectivityCurve(t,defaultgender)<<endl; ct.set_is_symptomatic(true); for (double t=0; t<2; t+=timestep) f << "Ct symptom," << t<<","<<ct.infectivityCurve(t,defaultgender)<<endl; // --- Ng --- cout << "CODECHECK: IC Ng"<<endl; STI ng(Ng,"./in_STI.csv"); //ng.set_is_symptomatic(true); for (double t=0; t<2; t+=timestep) f << "Ng," << t<<","<<ng.infectivityCurve(t,defaultgender)<<endl; // --- Hd --- cout << "CODECHECK: IC Hd"<<endl; STI hd(Hd,"./in_STI.csv"); hd.set_is_symptomatic(false); for (double t=0; t<1; t+=timestep) f << "Hd asymptom," << t<<","<<hd.infectivityCurve(t,defaultgender)<<endl; hd.set_is_symptomatic(true); for (double t=0; t<1; t+=timestep) f << "Hd symptom," << t<<","<<hd.infectivityCurve(t,defaultgender)<<endl; // --- HPV --- cout << "CODECHECK: IC HPV"<<endl; STI hpv(HPV,"./in_STI.csv"); hpv.set_is_recurrent(false); for (double t=0; t<1; t+=timestep) f << "HPV not recurrent," << t<<","<<hpv.infectivityCurve(t,defaultgender)<<endl; hpv.set_is_recurrent(true); for (double t=0; t<3; t+=timestep) f << "HPV recurrent," << t<<","<<hpv.infectivityCurve(t,defaultgender)<<endl; // --- HSV2 --- cout << "CODECHECK: IC HSV2"<<endl; STI hsv2(HSV2,"./in_STI.csv"); hsv2.set_is_symptomatic(false); for (double t=0; t<5; t+=timestep) f << "HSV2," << t<<","<<hsv2.infectivityCurve(t,defaultgender)<<endl; hsv2.set_is_symptomatic(true); for (double t=0; t<5; t+=timestep) f << "HSV2 symptomatic," << t<<","<<hsv2.infectivityCurve(t,defaultgender)<<endl; // --- HIV --- cout << "CODECHECK: IC HIV"<<endl; STI hiv(HIV,"./in_STI.csv"); for (double t=0; t<12; t+=timestep) f << "HIV," << t<<","<<hiv.infectivityCurve(t,defaultgender)<<endl; // --- Tv --- cout << "CODECHECK: IC Tv"<<endl; STI tv(Tv,"./in_STI.csv"); Gender gmale = male; tv.set_is_symptomatic(false); for (double t=0; t<2; t+=timestep) f << "Tv female asympt," << t<<","<<tv.infectivityCurve(t,defaultgender)<<endl; for (double t=0; t<2; t+=timestep) f << "Tv male asympt," << t<<","<<tv.infectivityCurve(t,gmale)<<endl; tv.set_is_symptomatic(true); for (double t=0; t<2; t+=timestep) f << "Tv female symptom," << t<<","<<tv.infectivityCurve(t,defaultgender)<<endl; for (double t=0; t<2; t+=timestep) f << "Tv male symptom," << t<<","<<tv.infectivityCurve(t,gmale)<<endl; }
int mshiftbeta::discount(ngram ng_,int size,double& fstar,double& lambda, int cv) { ngram ng(dict); ng.trans(ng_); //cout << "size :" << size << " " << ng <<"\n"; if (size > 1) { ngram history=ng; //singleton pruning only on real counts!! if (ng.ckhisto(size) && get(history,size,size-1) && (history.freq > cv) && ((size < 3) || ((history.freq-cv) > prunethresh ))) { // no history pruning with corrected counts! int suc[3]; suc[0]=succ1(history.link); suc[1]=succ2(history.link); suc[2]=history.succ-suc[0]-suc[1]; if (get(ng,size,size) && (!prunesingletons() || mfreq(ng,size)>1 || size<3) && (!prunetopsingletons() || mfreq(ng,size)>1 || size<maxlevel())) { ng.freq=mfreq(ng,size); cv=(cv>ng.freq)?ng.freq:cv; if (ng.freq>cv) { double b=(ng.freq-cv>=3?beta[2][size]:beta[ng.freq-cv-1][size]); fstar=(double)((double)(ng.freq - cv) - b)/(double)(history.freq-cv); lambda=(beta[0][size] * suc[0] + beta[1][size] * suc[1] + beta[2][size] * suc[2]) / (double)(history.freq-cv); if ((size>=3 && prunesingletons()) || (size==maxlevel() && prunetopsingletons())) //correction lambda+=(double)(suc[0] * (1-beta[0][size])) / (double)(history.freq-cv); } else { // ng.freq==cv ng.freq>=3?suc[2]--:suc[ng.freq-1]--; //update successor stat fstar=0.0; lambda=(beta[0][size] * suc[0] + beta[1][size] * suc[1] + beta[2][size] * suc[2]) / (double)(history.freq-cv); if ((size>=3 && prunesingletons()) || (size==maxlevel() && prunetopsingletons())) //correction lambda+=(double)(suc[0] * (1-beta[0][size])) / (double)(history.freq-cv); ng.freq>=3?suc[2]++:suc[ng.freq-1]++; //resume successor stat } } else { fstar=0.0; lambda=(beta[0][size] * suc[0] + beta[1][size] * suc[1] + beta[2][size] * suc[2]) / (double)(history.freq-cv); if ((size>=3 && prunesingletons()) || (size==maxlevel() && prunetopsingletons())) //correction lambda+=(double)(suc[0] * (1-beta[0][size])) / (double)(history.freq-cv); } //cerr << "ngram :" << ng << "\n"; if (*ng.wordp(1)==dict->oovcode()) { lambda+=fstar; fstar=0.0; } else { *ng.wordp(1)=dict->oovcode(); if (get(ng,size,size)) { ng.freq=mfreq(ng,size); if ((!prunesingletons() || mfreq(ng,size)>1 || size<3) && (!prunetopsingletons() || mfreq(ng,size)>1 || size<maxlevel())) { double b=(ng.freq>=3?beta[2][size]:beta[ng.freq-1][size]); lambda+=(double)(ng.freq - b)/(double)(history.freq-cv); } } } } else { fstar=0; lambda=1; } } else { // unigram case, no cross-validation lambda=0.0; int unigrtotfreq=(size<lmsize()?btotfreq():totfreq()); if (get(ng,size,size)) fstar=(double) mfreq(ng,size)/(double)unigrtotfreq; else { cerr << "Missing probability for word: " << dict->decode(*ng.wordp(1)) << "\n"; exit(1); } } return 1; }
int main(int argc, char *argv[]) { QApplication a(argc, argv); QCommandLineParser cmdline_parser; // cmdline_parser.addHelpOption(); // create commandline options // QCommandLineOption serverOption(QStringList() << "h" << "host", "NewtonCam server address", "host name or IP", "127.0.0.1"); QString str; str.setNum(NETPROTOCOL_DEFAULT_PORT); QCommandLineOption portOption(QStringList() << "p" << "port", "NewtonCam server port", "numeric value", str); str.setNum(SERVERGUI_DEFAULT_FONTSIZE); QCommandLineOption fontOption(QStringList() << "f" << "fontsize", "GUI font size", "numeric value", str); str.setNum(SERVERGUI_DEFAULT_FONTSIZE-2); QCommandLineOption statusfontOption(QStringList() << "s" << "statusfontsize", "GUI status font size", "numeric value", str); str.setNum(SERVERGUI_DEFAULT_FONTSIZE); QCommandLineOption logfontOption(QStringList() << "l" << "logfontsize", "GUI log window font size", "numeric value", str); QCommandLineOption xcoordOption(QStringList() << "x" << "xpos", "GUI window x-coordinate position", "numeric vlue", str); QCommandLineOption ycoordOption(QStringList() << "y" << "ypos", "GUI window x-coordinate position", "numeric vlue", str); cmdline_parser.addOption(portOption); cmdline_parser.addOption(fontOption); cmdline_parser.addOption(statusfontOption); cmdline_parser.addOption(logfontOption); cmdline_parser.addOption(xcoordOption); cmdline_parser.addOption(ycoordOption); cmdline_parser.addPositionalArgument("IP-address", "NewtonCam server address (default 127.0.0.1)"); cmdline_parser.process(a); quint16 port; bool ok; port = cmdline_parser.value(portOption).toUInt(&ok); if ( !ok ) { // QMessageBox::StandardButton bt = QMessageBox::critical(0,"Error","Invalid port value!"); exit(NEWTONGUI_ERROR_INVALID_PORT); } int fontsize = cmdline_parser.value(fontOption).toInt(&ok); if ( !ok ) { // QMessageBox::StandardButton bt = QMessageBox::critical(0,"Error","Invalid GUI fontsize value!"); exit(NEWTONGUI_ERROR_INVALID_FONTSIZE); } int statusFontsize = cmdline_parser.value(statusfontOption).toInt(&ok); if ( !ok ) { QMessageBox::critical(0,"Error","Invalid GUI status fontsize value!"); exit(NEWTONGUI_ERROR_INVALID_FONTSIZE); } int logFontsize = cmdline_parser.value(logfontOption).toInt(&ok); if ( !ok ) { QMessageBox::critical(0,"Error","Invalid GUI log window fontsize value!"); exit(NEWTONGUI_ERROR_INVALID_FONTSIZE); } int xcoord; bool isX = false; if ( !cmdline_parser.value(xcoordOption).isEmpty() ) { xcoord = cmdline_parser.value(xcoordOption).toInt(&ok); if ( !ok ) { QMessageBox::critical(0,"Error","Invalid x-coordinate of GUI window!"); exit(NEWTONGUI_ERROR_INVALID_COORDINATE); } isX = true; } int ycoord; bool isY = false; if ( !cmdline_parser.value(ycoordOption).isEmpty() ) { ycoord = cmdline_parser.value(ycoordOption).toInt(&ok); if ( !ok ) { QMessageBox::critical(0,"Error","Invalid y-coordinate of GUI window!"); exit(NEWTONGUI_ERROR_INVALID_COORDINATE); } isY = true; } QHostAddress addr; QStringList pos_arg = cmdline_parser.positionalArguments(); if ( pos_arg.length() == 0 ) { str = "127.0.0.1"; addr.setAddress(str); } else { str = pos_arg[0]; QRegExp rx("\\s*\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\s*"); if ( !rx.exactMatch(str) ) { // do DNS look-up QHostInfo info = QHostInfo::fromName(str.trimmed()); if ( info.addresses().isEmpty() ) { QMessageBox::critical(0,"Error","Invalid server hostname!"); exit(NEWTONGUI_ERROR_INVALID_HOSTNAME); } addr = info.addresses().first(); } else { addr.setAddress(str); } } NewtonGui ng(fontsize); ng.SetFonts(fontsize,statusFontsize,logFontsize); QPoint gui_pos = ng.pos(); if ( isX ) gui_pos.setX(xcoord); if ( isY ) gui_pos.setY(ycoord); if ( isX || isY ) ng.move(gui_pos); ng.show(); // QObject::connect(&ng,&NewtonGui::Error,[=](int err){exit(err);}); str = QDateTime::currentDateTime().toString(" dd-MM-yyyy hh:mm:ss"); ng.LogMessage("<b> " + str + ":</b> Trying to connect to NewtonCam server at " + addr.toString() + " ..."); a.processEvents(); // to draw the main window and show start message ng.Connect(addr,port); return a.exec(); }
void SendDefaultMenu_paradox(Player *player, Creature *_Creature, uint32 action ) // Teleport { /*if(!player->getAttackers().empty()) { _Creature->MonsterSay("Du befindest dich im Kampf!", LANG_COMMON, NULL); return; }*///getAttackers gibt es nicht mehr ... if( player->getLevel() < 8 ) //sollte noch funktionieren { _Creature->MonsterSay("Du benoetigst 8+", LANG_COMMON, NULL); return; } if(action>1300 && action < 1399) { std::string q2("SELECT `map`, `x`, `y`, `z`, `r` FROM `teleguy` WHERE `gossipNR` = "); std::stringstream ac_str; ac_str << action; q2 += ac_str.str(); QueryResult *result__ = CharacterDatabase.Query( q2.c_str() ); if(result__) { Field *fieldss = result__->Fetch(); //_player->TeleportTo(mapid, x, y, z, ort);ort??? vielleicht ORienTation player->TeleportTo(fieldss[0].GetUInt32(), fieldss[1].GetFloat(), fieldss[2].GetFloat(), fieldss[3].GetFloat(), fieldss[4].GetFloat()); } else { _Creature->MonsterSay("Fehler: teleguy:X001 -> bitte melde es einem GM bzw Admin", LANG_COMMON, NULL); } } if(action==1300) { if ( player->GetTeam() == ALLIANCE ) { std::string q1("SELECT `name`, `gossipNR`, `lvl` from `teleguy` where `fraktion` = 'a' or `fraktion` = 'b'"); QueryResult *result_ = CharacterDatabase.Query( q1.c_str() ); if(result_) { do { Field *fields = result_->Fetch(); if(player->getLevel() >= fields[2].GetUInt32()) { //sLog.outString(fields[0].GetString()); player->ADD_GOSSIP_ITEM( 5, fields[0].GetString(), GOSSIP_SENDER_MAIN, fields[1].GetUInt32()); } } while(result_->NextRow()); } } else { std::string q1("SELECT `name`, `gossipNR`, `lvl` from `teleguy` where `fraktion` = 'h' or `fraktion` = 'b'"); QueryResult *result_ = CharacterDatabase.Query( q1.c_str() ); if(result_) { do { Field *fields = result_->Fetch(); if(player->getLevel() >= fields[2].GetUInt32()) { player->ADD_GOSSIP_ITEM( 5, fields[0].GetString(), GOSSIP_SENDER_MAIN, fields[1].GetUInt32()); } } while(result_->NextRow()); } } player->ADD_GOSSIP_ITEM( 5, "Ende", GOSSIP_SENDER_MAIN, 1600); player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE,_Creature->GetGUID()); } // Event Port if(action>1400 && action<1500) { std::string q2("SELECT `map`, `x`, `y`, `z`, `r` FROM `eventguy` WHERE `gossipNR` = "); std::stringstream ac_str; ac_str << action; q2 += ac_str.str(); QueryResult *result__ = CharacterDatabase.Query( q2.c_str() ); if(result__) { Field *fieldss = result__->Fetch(); player->TeleportTo(fieldss[0].GetUInt32(), fieldss[1].GetFloat(), fieldss[2].GetFloat(), fieldss[3].GetFloat(), fieldss[4].GetFloat()); } else { _Creature->MonsterSay("Fehler: teleguy:X001 -> bitte melde es einem GM bzw Admin", LANG_COMMON, NULL); } } if(action==1400) { if ( player->GetTeam() == ALLIANCE ) { std::string q1("SELECT `name`, `gossipNR`, `lvl` from `eventguy` where `fraktion` = 'a' or `fraktion` = 'b'"); QueryResult *result_ = CharacterDatabase.Query( q1.c_str() ); if(result_) { do { Field *fields = result_->Fetch(); if(player->getLevel() >= fields[2].GetUInt32()) { //sLog.outString(fields[0].GetString()); player->ADD_GOSSIP_ITEM( 5, fields[0].GetString(), GOSSIP_SENDER_MAIN, fields[1].GetUInt32()); } } while(result_->NextRow()); } } else { std::string q1("SELECT `name`, `gossipNR`, `lvl` from `eventguy` where `fraktion` = 'h' or `fraktion` = 'b'"); QueryResult *result_ = CharacterDatabase.Query( q1.c_str() ); if(result_) { do { Field *fields = result_->Fetch(); if(player->getLevel() >= fields[2].GetUInt32()) { player->ADD_GOSSIP_ITEM( 5, fields[0].GetString(), GOSSIP_SENDER_MAIN, fields[1].GetUInt32()); } } while(result_->NextRow()); } } player->ADD_GOSSIP_ITEM( 5, "Ende", GOSSIP_SENDER_MAIN, 1600); player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE,_Creature->GetGUID()); } // Gildenhaus if(action== 1500) { player->ADD_GOSSIP_ITEM( 5, "Zum Gildenhaus", GOSSIP_SENDER_MAIN, 1501); player->ADD_GOSSIP_ITEM( 5, "Ende", GOSSIP_SENDER_MAIN, 1600); player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE,_Creature->GetGUID()); } if(action== 1501) { //Test //Query vorbereiten std::string q1("SELECT `guid` FROM `character` where `name` = '"); q1 += player->GetName(); q1 += "'"; //ID des Players //sLog.outString(q1.c_str()); QueryResult *result_ = CharacterDatabase.Query( q1.c_str() ); if(result_) { do { Field *fields = result_->Fetch(); //Query std::string q2("SELECT `guildid` FROM `guild_member` where `guid` = '"); q2 += fields[0].GetString(); q2 += "'"; //GildenID des Players QueryResult *result__ = CharacterDatabase.Query( q2.c_str() ); if(result__) { Field *fieldss = result__->Fetch(); if(fieldss[0].GetString()!=""){ std::string q3("SELECT `map`,`x`,`y`,`z`,`r` FROM `guildmeister` where `id` = '"); q3 += fieldss[0].GetString(); q3 += "'"; QueryResult *result___ = CharacterDatabase.Query( q3.c_str() ); if(result___) { Field *fieldsss = result___->Fetch(); player->TeleportTo(fieldsss[0].GetUInt32(), fieldsss[1].GetFloat(), fieldsss[2].GetFloat(), fieldsss[3].GetFloat(), fieldsss[4].GetFloat()); } else { std::string ngh(player->GetName()); ngh += " Deine Gilde hat noch kein Gildenhaus!"; _Creature->MonsterSay(ngh.c_str(),LANG_COMMON,NULL); } } } else { std::string ng(player->GetName()); ng += " Du bist in keiner Gilde!"; _Creature->MonsterSay(ng.c_str(),LANG_COMMON,NULL); } } while( result_->NextRow() ); delete result_; } } }
int shiftbeta::discount(ngram ng_,int size,double& fstar,double& lambda, int cv) { ngram ng(dict); ng.trans(ng_); if (size > 1) { ngram history=ng; if (ng.ckhisto(size) && get(history,size,size-1) && (history.freq>cv) && ((size < 3) || ((history.freq-cv) > prunethresh ))) { // apply history pruning on trigrams only if (get(ng,size,size) && (!prunesingletons() || ng.freq >1 || size<3)) { cv=(cv>ng.freq)?ng.freq:cv; if (ng.freq>cv) { fstar=(double)((double)(ng.freq - cv) - beta[size])/(double)(history.freq-cv); lambda=beta[size]*((double)history.succ/(double)(history.freq-cv)); if (size>=3 && prunesingletons()) // correction due to frequency pruning lambda+=(1.0-beta[size]) * (double)succ1(history.link)/(double)(history.freq-cv); // succ1(history.link) is not affected if ng.freq > cv } else { // ng.freq == cv fstar=0.0; lambda=beta[size]*((double)(history.succ-1)/ //e` sparito il successore (double)(history.freq-cv)); if (size>=3 && prunesingletons()) //take into acccount single event pruning lambda+=(1.0-beta[size]) * (double)(succ1(history.link)-(cv==1 && ng.freq==1?1:0)) /(double)(history.freq-cv); } } else { fstar=0.0; lambda=beta[size]*(double)history.succ/(double)history.freq; if (size>=3 && prunesingletons()) // correction due to frequency pruning lambda+=(1.0-beta[size]) * (double)succ1(history.link)/(double)history.freq; } //cerr << "ngram :" << ng << "\n"; if (*ng.wordp(1)==dict->oovcode()) { lambda+=fstar; fstar=0.0; } else { *ng.wordp(1)=dict->oovcode(); if (get(ng,size,size) && (!prunesingletons() || ng.freq >1 || size<3)) lambda+=(double)((double)ng.freq - beta[size])/(double)(history.freq-cv); } } else { fstar=0; lambda=1; } } else { fstar=unigr(ng); lambda=0.0; } return 1; }