int main ( int argc, char * argv[] ) { double * rx, * ry, * rz; double * vx, * vy, * vz; double * fx, * fy, * fz; int * ix, * iy, * iz; int nl; double * xi, * vxi, * Q; int N=216,c,a; double L=0.0; double rho=0.5, Tb = 1.0, nu=1.0, rc2 = 1.e20; double vir, vir_sum, pcor, V; double PE, KE, TE, ecor, ecut, T0=0.0, TE0; double rr3,dt=0.001, dt2, dt_2, dt_4, dt_8, sigma; int tj_ts=-1; double tj_Tb=1.0; int i,j,s; int nSteps = 10, fSamp=100; int short_out=0; int use_e_corr=0; int unfold = 0; char fn[20]; FILE * out; char * wrt_code_str = "w"; char * init_cfg_file = NULL; gsl_rng * r = gsl_rng_alloc(gsl_rng_mt19937); unsigned long int Seed = 23410981; /* Allocate arrays for the NH Chain */ nl = 2; /* for now... */ xi = (double*)malloc(nl*sizeof(double)); vxi = (double*)malloc(nl*sizeof(double)); Q = (double*)malloc(nl*sizeof(double)); /* Default masses */ Q[0] = Q[1] = 0.1; /* Here we parse the command line arguments; If you add an option, document it in the usage() function! */ for (i=1;i<argc;i++) { if (!strcmp(argv[i],"-N")) N=atoi(argv[++i]); else if (!strcmp(argv[i],"-rho")) rho=atof(argv[++i]); else if (!strcmp(argv[i],"-nu")) nu=atof(argv[++i]); else if (!strcmp(argv[i],"-dt")) dt=atof(argv[++i]); else if (!strcmp(argv[i],"-rc")) rc2=atof(argv[++i]); else if (!strcmp(argv[i],"-ns")) nSteps = atoi(argv[++i]); else if (!strcmp(argv[i],"-so")) short_out=1; else if (!strcmp(argv[i],"-T0")) T0=atof(argv[++i]); else if (!strcmp(argv[i],"-Tb")) Tb=atof(argv[++i]); else if (!strcmp(argv[i],"-Q")) sscanf(argv[++i],"%lf,%lf", &Q[0],&Q[1]); else if (!strcmp(argv[i],"-Tjump")) sscanf(argv[++i],"%i,%lf", &tj_ts,&tj_Tb); else if (!strcmp(argv[i],"-fs")) fSamp=atoi(argv[++i]); else if (!strcmp(argv[i],"-sf")) wrt_code_str = argv[++i]; else if (!strcmp(argv[i],"-icf")) init_cfg_file = argv[++i]; else if (!strcmp(argv[i],"-ecorr")) use_e_corr = 1; else if (!strcmp(argv[i],"-seed")) Seed = (unsigned long)atoi(argv[++i]); else if (!strcmp(argv[i],"-uf")) unfold = 1; else if (!strcmp(argv[i],"-h")) { usage(); exit(0); } else { fprintf(stderr,"Error: Command-line argument '%s' not recognized.\n", argv[i]); exit(-1); } } /* Compute the side-length */ L = pow((V=N/rho),0.3333333); /* Compute the tail-corrections; assumes sigma and epsilon are both 1 */ rr3 = 1.0/(rc2*rc2*rc2); ecor = use_e_corr?8*M_PI*rho*(rr3*rr3*rr3/9.0-rr3/3.0):0.0; pcor = use_e_corr?16.0/3.0*M_PI*rho*rho*(2./3.*rr3*rr3*rr3-rr3):0.0; ecut = 4*(rr3*rr3*rr3*rr3-rr3*rr3); /* Compute the *squared* cutoff, reusing the variable rc2 */ rc2*=rc2; /* compute the squared time step */ dt2 = dt*dt; dt_2 = 0.5*dt; dt_4 = 0.5*dt_2; dt_8 = 0.5*dt_4; // thanks, [email protected] /* Compute sigma */ sigma = sqrt(Tb); /* Output some initial information */ fprintf(stdout,"# Nose-Hoover-Chain-Thermostat MD Simulation" " of a Lennard-Jones fluid\n"); fprintf(stdout,"# L = %.5lf; rho = %.5lf; N = %i; rc = %.5lf\n", L,rho,N,sqrt(rc2)); fprintf(stdout,"# nSteps %i, seed %d, dt %.5lf, " "Tb %.5lf, Q0 %.5lf Q1 %.5lf\n", nSteps,Seed,dt,Tb,Q[0],Q[1]); /* Seed the random number generator */ gsl_rng_set(r,Seed); /* Allocate the position arrays */ rx = (double*)malloc(N*sizeof(double)); ry = (double*)malloc(N*sizeof(double)); rz = (double*)malloc(N*sizeof(double)); /* Allocate the boundary crossing counter arrays */ ix = (int*)malloc(N*sizeof(int)); iy = (int*)malloc(N*sizeof(int)); iz = (int*)malloc(N*sizeof(int)); /* Allocate the velocity arrays */ vx = (double*)malloc(N*sizeof(double)); vy = (double*)malloc(N*sizeof(double)); vz = (double*)malloc(N*sizeof(double)); /* Allocate the force arrays */ fx = (double*)malloc(N*sizeof(double)); fy = (double*)malloc(N*sizeof(double)); fz = (double*)malloc(N*sizeof(double)); /* Generate initial positions on a cubic grid, and measure initial energy */ init(rx,ry,rz,vx,vy,vz,ix,iy,iz,N,xi,vxi,nl,L,r,T0,&KE,init_cfg_file); sprintf(fn,"%i.xyz",0); out=fopen(fn,"w"); xyz_out(out,rx,ry,rz, vx,vy,vz,ix,iy,iz, L,N, xi,vxi,Q,nl, 16,1,unfold); fclose(out); PE = total_e(rx,ry,rz,fx,fy,fz,N,L,rc2,ecor,ecut,&vir); TE0=PE+KE; fprintf(stdout,"# step PE KE TE drift T P\n"); /* Nose-Hoover-Chain (Algorithms 30, 31, 32) */ for (s=0;s<nSteps;s++) { /* do a temperature jump at the prescribed time */ if (s==tj_ts) Tb = tj_Tb; chain(&KE,dt,dt_2,dt_4,dt_8,Q,xi,vxi,vx,vy,vz,nl,N,Tb); /* First integration half-step */ KE = 0.0; for (i=0;i<N;i++) { rx[i]+=vx[i]*dt_2; ry[i]+=vy[i]*dt_2; rz[i]+=vz[i]*dt_2; /* Apply periodic boundary conditions */ if (rx[i]<0.0) { rx[i]+=L; ix[i]--; } if (rx[i]>L) { rx[i]-=L; ix[i]++; } if (ry[i]<0.0) { ry[i]+=L; iy[i]--; } if (ry[i]>L) { ry[i]-=L; iy[i]++; } if (rz[i]<0.0) { rz[i]+=L; iz[i]--; } if (rz[i]>L) { rz[i]-=L; iz[i]++; } } /* Calculate forces */ PE = total_e(rx,ry,rz,fx,fy,fz,N,L,rc2,ecor,ecut,&vir); /* Second integration half-step */ for (i=0;i<N;i++) { vx[i]+=dt*fx[i]; vy[i]+=dt*fy[i]; vz[i]+=dt*fz[i]; rx[i]+=vx[i]*dt_2; ry[i]+=vy[i]*dt_2; rz[i]+=vz[i]*dt_2; KE+=vx[i]*vx[i]+vy[i]*vy[i]+vz[i]*vz[i]; } KE*=0.5; chain(&KE,dt,dt_2,dt_4,dt_8,Q,xi,vxi,vx,vy,vz,nl,N,Tb); TE=PE+KE; fprintf(stdout,"%i %.5lf %.5lf %.5lf %.5lf %.5le %.5lf %.5lf\n", s,s*dt,PE,KE,TE,(TE-TE0)/TE0,KE*2/3./N,rho*KE*2./3./N+vir/3.0/V); if (!(s%fSamp)) { sprintf(fn,"%i.xyz",!strcmp(wrt_code_str,"a")?0:s); out=fopen(fn,wrt_code_str); xyz_out(out,rx,ry,rz,vx,vy,vz,ix,iy,iz,L,N,xi,vxi,Q,nl,16,1,unfold); fclose(out); } } }
void RunProof() { std::string filename = "/data/Phys/data/mcd02kpi_tracks9_merged.root"; bool fileNotFound = gSystem->AccessPathName(filename.c_str()); // if local file is not found use the EOS version if (fileNotFound) { filename = "root://eoslhcb.cern.ch//eos/lhcb/user/m/malexand/d2hh/secondariesTagging/mcd02kpi_tracks9_merged.root"; } TChain chain("TrackFilter/DecayTree"); chain.Add(filename.c_str()); TDSet dset(chain); auto p = TProof::Open(""); p->Process(&dset, "RadialSelector.C"); }
void ising_entries_jnorm(options opts, int *buffer_sequenze, RandMT &generatore) { int L = opts.seq_len; int runs = opts.n_seq; double beta = opts.beta[0]; vector<int> flipchain(L); vector<int> chain(L); vector<int> J(L); vector<double> prob(L); for (int i = 0; i < L; i++) { double r; //probabilita di trovare un flip, ovvero -1 //J gaussiano (positivo) //r = generatore.semi_norm(); //J uniforme [0,1] (positivo) //r = generatore.rand(); //J uniforme [0,0.5] (positivo) r = generatore.get_double()/2; //J cost //r=1; prob[i] = exp(-2 * beta * r); prob[i] /= (1 + prob[i]); // J +- 1 //J[i] = 2 * (generatore() > .5) - 1; // J positivi J[i] = 1; } for (int i = 0; i < runs; i++) { chain[0] = 2 * (generatore.get_double() > .5) - 1; for (int k = 0; k < L; k++) flipchain[k] = (prob[k] > generatore.get_double()) ? -1 : 1; for (int k = 1; k < L; k++) chain[k] = flipchain[k] * chain[k - 1] * J[k]; for (int k = 0; k < L; k++) { buffer_sequenze[i * L + k] = chain[k]; } } }
std::vector<Chain> Board::getAllEmptyChains () { LOG_FUNCTION(cout, "Board::getAllEmptyChains"); std::vector<Chain> emptyChains; // A set of points that we've already examined. This helps prevents some // bad recursion and keeps a chain from being "found" once for each stone // in the chain. // ConstPointSet alreadyVisited; for (size_t row = 0; row < m_points.size(); ++row) { for (size_t column = 0; column < m_points[row].size(); ++column) { const Point & point = m_points[row][column]; // We are only looking for points without a stone, so get out // of here if there is a stone on this point // if (point.getStoneColor() != StoneColor::NONE) continue; // If the point we are considering has already been visited, // then Chain's ctor will throw a PointVisitedAlreadyException // object. We can safely swallow that exception and move on // to the next point. // try { // TODO: figure out why this didn't work... emptyChains.emplace_back(StoneColor::NONE, point, *this, &alreadyVisited); Chain chain(StoneColor::NONE, point, *this, &alreadyVisited); emptyChains.push_back(chain); gLogger.log(LogLevel::kMedium, cout, "Discovered empty chain"); // " : ", chain); } catch (const Chain::PointVisitedAlreadyException & ex) { gLogger.log(LogLevel::kFirehose, cout, "Skipping ", point); } } } return emptyChains; }
vector<DisambiguatedData> Disambiguator::disambiguate( const vector<PredisambiguatedData>& predisambiguated) { // Create chain size_t size = predisambiguated.size(); vector<wstring> words(size); vector<vector<wstring> > features(size); vector<wstring> labels(size); for (size_t chainIndex = 0; chainIndex < size; ++chainIndex) { words[chainIndex] = predisambiguated[chainIndex].content; features[chainIndex] = predisambiguated[chainIndex].features; } LinearCRF::Chain chain( std::move(words) , std::move(features) , std::move(labels) , vector<vector<wstring> >()); vector<wstring> bestSequence; vector<double> bestSequenceWeights; this->Apply(chain, &bestSequence, &bestSequenceWeights); // Create disambiguated data vector<DisambiguatedData> disambiguatedData; for (size_t tokenIndex = 0; tokenIndex < size; ++tokenIndex) { wstring& label = bestSequence[tokenIndex]; shared_ptr<Morphology> grammInfo = getBestGrammInfo( predisambiguated[tokenIndex], label); applyPostprocessRules(&label, grammInfo); const wstring& lemma = dictionary == 0 ? DICT_IS_NULL : *(grammInfo->lemma) == NOT_FOUND_LEMMA ? Tools::ToLower(predisambiguated[tokenIndex].content) : *(grammInfo->lemma); disambiguatedData.emplace_back( predisambiguated[tokenIndex].content , predisambiguated[tokenIndex].punctuation , predisambiguated[tokenIndex].source , predisambiguated[tokenIndex].isNextSpace , lemma , label , bestSequenceWeights[tokenIndex] , grammInfo->lemma_id); } return disambiguatedData; }
static void input2form(TInput *v, Tform **t) { TGrid *from, *to; TTex *tex; if (Grid) { from = &v->f; to = &v->t; grid_log(from); grid_log(to); tform_grid2grid(from->lo, from->hi, from->n, to->lo, to->hi, to->n, /**/ *t); } else if (Tex) { tex = &v->tex; tex2sdf_ini(coords, tex->T, tex->N, tex->M, /**/ *t); } else { UC(tform_vector(v->v.a0, v->v.a1, v->v.b0, v->v.b1, /**/ *t)); if (Chain) chain(v, t); } }
void main() { int i,q,n; clrscr(); printf("\n Number Of Matrix :"); scanf("%d",&q); for(i=1;i<=q+1;i++) { printf("r[%d] :",i); scanf("%d",&r[i]); } chain(q); printf("\n\n Total Computation : %5d",c[1][5]); printf("\n\n Kay Value : %5d",kay[1][q]); traceback(1,q); getch(); }
int chain(uint64_t x) { uint64_t y, z; if (found[x/8] & (1 << (x%8))) return result[x/8] & (1 << (x%8)); y = 0; z = x; while (z) { y += (z % 10) * (z % 10); z /= 10; } z = chain(y); found[x/8] |= (1 << (x%8)); if (z) result[x/8] |= (1 << (x%8)); return z; }
void checkIn( const boost::program_options::variables_map & options ) { BACKTRACE_BEGIN boost::filesystem::path reportFile = options[ "reportFile" ].as< std::string >(); unsigned reportIntervalSeconds = options[ "reportIntervalSeconds" ].as< unsigned >(); boost::filesystem::path workDir = stripTrailingSlash( options[ "arg1" ].as< std::string >() ); std::string label = options[ "arg2" ].as< std::string >(); Osmosis::Chain::Chain chain( options[ "objectStores" ].as< std::string >(), false, false ); if ( chain.count() > 1 ) THROW( Error, "--objectStores must contain one object store in a checkin operation" ); bool md5 = options.count( "MD5" ) > 0; boost::filesystem::path draftsPath = workDir / Osmosis::ObjectStore::DirectoryNames::DRAFTS; if ( boost::filesystem::exists( draftsPath ) ) THROW( Error, "workDir must not contain " << draftsPath ); Osmosis::Client::CheckIn instance( workDir, label, chain.single(), md5, reportFile, reportIntervalSeconds ); instance.go(); BACKTRACE_END }
int main(){ int ceiling = 1000000; int curStart = 1; long max = 0; long value = 1; long count = 0; while (curStart <= ceiling){ value = curStart; count = 0; while (value != 1){ value = chain(value); count++; } if (count > max){ max = count; printf("%d has a chain of %ld\n", curStart, max);} curStart++; } return 0; }
void univht_traverse(univht *ht, univht_visitor visitor, void *state) { int slot; /* Traverse every key in the table */ for (slot = 0; ht->entries; slot++) { void *entry; /* Traverse the chain */ for (entry = ht->table[slot]; entry != NULL; entry = chain(ht, entry)) { /* Invoke visitor on entry, propagating state changes */ state = visitor(entry, state); } } }
Hierarchy create_simplified_along_backbone(Hierarchy in, int num_res, bool keep_detailed) { Hierarchies chains= get_by_type(in, CHAIN_TYPE); if (chains.size() > 1) { Hierarchy root= Hierarchy::setup_particle(new Particle(in->get_model(), in->get_name())); for (unsigned int i=0; i< chains.size(); ++i) { Chain chain(chains[i].get_particle()); root.add_child(create_simplified_along_backbone(chain, num_res)); } return root; } else if (chains.size()==1) { // make sure to cast it to chain to get the right overload return create_simplified_along_backbone(Chain(chains[0]), num_res, keep_detailed); } else { IMP_THROW("No chains to simplify", ValueException); } }
int run_sample_osx(const long num_events = -1) { // load relevant libaries gSystem->Load("$CMSSW_BASE/lib/$SCRAM_ARCH/libPackagesLooperTools.dylib"); gSystem->Load("$CMSSW_BASE/lib/$SCRAM_ARCH/libAnalysisExampleCMS2Looper.dylib"); // simple style gROOT->SetStyle("Plain"); gStyle->SetOptStat(111111); LoadFWLite(); TChain chain("Events"); chain.Add("/nfs-7/userdata/rwkelley/cms2/dyjets_ntuple_slim_10k_53X_v2.root"); CMS2Looper looper("output/dy_plots.root"); looper.SetRunList("json/Merged_190456-208686_8TeV_PromptReReco_Collisions12_goodruns.txt"); std::cout << "running cms2 looper..." << std::endl; looper.ScanChain(chain, num_events); return 0; }
int main( void ) { // init time_t seed = time(NULL); printf("seed: %ld\n", seed); srand((unsigned int)seed); // might break in 2038 aa_test_ulimit(); for( size_t i = 0; i < 1000; i++ ) { /* Random Data */ static const size_t k=2; double E[2][7], S[2][8], T[2][12], dx[2][6]; for( size_t j = 0; j < k; j ++ ) { rand_tf(E[j], S[j], T[j]); aa_vrand(6,dx[j]); } //printf("%d\n",i); /* Run Tests */ rotvec(E[0]); euler(dx[0]); euler1(dx[0]); eulerzyx(E[0]); chain(E,S,T); quat(E); duqu(); rel_q(); rel_d(); slerp(); theta2quat(); rotmat(E[0]); tfmat(); tfmat_inv(T[0]); mzlook(dx[0]+0, dx[0]+3, dx[1]+0); integrate(E[0], S[0], T[0], dx[0]); tf_conj(E, S); qdiff(E,dx); } return 0; }
void PlanRep::insertEdgePathEmbedded( edge eOrig, CombinatorialEmbedding &E, const SList<adjEntry> &crossedEdges) { GraphCopy::insertEdgePathEmbedded(eOrig,E,crossedEdges); Graph::EdgeType edgeType = m_pGraphAttributes ? m_pGraphAttributes->type(eOrig) : Graph::association; long et = m_oriEdgeTypes[eOrig]; for(edge e : chain(eOrig)) { m_eType[e] = edgeType; m_edgeTypes[e] = et; if (!original(e->target())) { OGDF_ASSERT(e->target()->degree() == 4); setCrossingType(e->target()); } } }
void univht_destroy(univht *ht) { int slot; /* Print statistical information about database */ printf("Statistics:\n"); printf("\tNumber of entries: %lu\n", ht->entries); printf("\tNumber of occupied slots: %lu\n", ht->stat_chains); printf("\tLength of longest chain: %lu\n", ht->stat_max_chain_length); printf("\tAverage chain length: %f\n", ht->stat_avg_chain_length); printf("\tTotal memory occupied: %lu bytes\n", ht->slots * sizeof(void *) + ht->entries * ht->stat_entry_size); printf("\tMemory occupied by entries: %lu bytes\n", ht->entries * ht->stat_entry_size); for (slot = 0; ht->entries; slot++) { /* Traverse the chain */ while (ht->table[slot]) { void *entry = ht->table[slot]; /* Link the slot to chain of object moved */ ht->table[slot] = chain(ht, entry); /* Invoke entry object destructor */ ht->destructor(entry); /* Decrement number of entries in hash table */ ht->entries--; } } /* Free slots of hash table */ free(ht->table); /* Free actual hash table */ free(ht); }
int run_loadfile(u_long *marks, int howto) { char bootline[512]; /* Should check size? */ u_int32_t entry; char *cp; void *ssym, *esym; strlcpy(bootline, opened_name, sizeof bootline); cp = bootline + strlen(bootline); *cp++ = ' '; *cp = '-'; if (howto & RB_ASKNAME) *++cp = 'a'; if (howto & RB_CONFIG) *++cp = 'c'; if (howto & RB_SINGLE) *++cp = 's'; if (howto & RB_KDB) *++cp = 'd'; if (*cp == '-') *--cp = 0; else *++cp = 0; entry = marks[MARK_ENTRY]; ssym = (void *)marks[MARK_SYM]; esym = (void *)marks[MARK_END]; { u_int32_t lastpage; lastpage = roundup(marks[MARK_END], NBPG); OF_release((void*)lastpage, CLAIM_LIMIT - lastpage); } chain((void *)entry, bootline, ssym, esym); _rtt(); return 0; }
unsigned long NTriSolidTorus::areAnnuliLinkedAxis(int otherAnnulus) const { int right = (otherAnnulus + 1) % 3; int left = (otherAnnulus + 2) % 3; NTetrahedron* adj = tet[right]->adjacentTetrahedron( vertexRoles_[right][1]); if (adj != tet[otherAnnulus]->adjacentTetrahedron( vertexRoles_[otherAnnulus][2])) return 0; if (adj == tet[0] || adj == tet[1] || adj == tet[2] || adj == 0) return 0; NPerm4 roles = tet[right]->adjacentGluing( vertexRoles_[right][1]) * vertexRoles_[right] * NPerm4(2, 1, 0, 3); if (roles != tet[otherAnnulus]->adjacentGluing( vertexRoles_[otherAnnulus][2]) * vertexRoles_[otherAnnulus] * NPerm4(0, 3, 2, 1)) return 0; // We've successfully identified the first tetrahedron of the // layered chain. NLayeredChain chain(adj, roles); chain.extendMaximal(); NTetrahedron* top = chain.top(); NPerm4 topRoles(chain.topVertexRoles()); if (top->adjacentTetrahedron(topRoles[3]) != tet[left]) return 0; if (top->adjacentTetrahedron(topRoles[0]) != tet[otherAnnulus]) return 0; if (topRoles != tet[left]->adjacentGluing( vertexRoles_[left][2]) * vertexRoles_[left] * NPerm4(3, 0, 1, 2)) return 0; if (topRoles != tet[otherAnnulus]->adjacentGluing( vertexRoles_[otherAnnulus][1]) * vertexRoles_[otherAnnulus] * NPerm4(1, 2, 3, 0)) return 0; // Success! return chain.index(); }
void PARTICLE::update(DISPLAY& disp, bool is_draw) { // update if (data.particle_type == 3 || data.particle_type == 2) life -= 1; else if (data.type != 2) life -= data.speed; if (data.particle_type == 0 || (data.particle_type == 1 && life < starting_life/2)) { x += data.speed * cos(theta); y += data.speed * sin(theta); } // update frame frame_index += data.frame_rate; if (frame_index >= data.num_frames) { if (data.type == 0) { frame_index -= data.num_frames; } else if (data.type) { frame_index = data.num_frames-1; if (data.type == 2) life = 0; } } // update expansion (zoom type) if (data.particle_type == 1) { if (life < starting_life/2) { expansion = life / starting_life; if (!done_damage) do_damage(); if (chain_factor) chain(); } else expansion = (starting_life - life) / starting_life; } else if (data.particle_type == 2) { // update expansion (solid type) expansion = 1.0; } // draw if (is_draw && is_on_screen(disp)) draw(disp); }
void Module::menu_cb ( const Fl_Menu_ *m ) { char picked[256]; if ( ! m->mvalue() || m->mvalue()->flags & FL_SUBMENU_POINTER || m->mvalue()->flags & FL_SUBMENU ) return; strncpy( picked, m->mvalue()->label(), sizeof( picked ) ); // m->item_pathname( picked, sizeof( picked ) ); DMESSAGE( "%s", picked ); Logger log( this ); if ( ! strcmp( picked, "Edit Parameters" ) ) command_open_parameter_editor(); else if ( ! strcmp( picked, "Bypass" ) ) bypass( ! ( m->mvalue()->flags & FL_MENU_VALUE ) ); else if ( ! strcmp( picked, "Cut" ) ) { copy(); chain()->remove( this ); Fl::delete_widget( this ); } else if ( ! strcmp( picked, "Copy" ) ) { copy(); } else if ( ! strcmp( picked, "Paste" ) ) { paste_before(); } else if ( ! strcmp( picked, "Remove" ) ) command_remove(); }
double Disambiguator::GetPartitionFunction( const vector<Token>& tokens) { vector<PredisambiguatedData> predisambiguated = featureCalculator->CalculateFeatures(tokens); // Create chain size_t size = predisambiguated.size(); vector<wstring> words(size); vector<vector<wstring> > features(size); vector<wstring> labels(size); for (size_t chainIndex = 0; chainIndex < size; ++chainIndex) { words[chainIndex] = predisambiguated[chainIndex].content; features[chainIndex] = predisambiguated[chainIndex].features; } LinearCRF::Chain chain( std::move(words) , std::move(features) , std::move(labels) , vector<vector<wstring> >()); return this->GetPartFunction(chain); }
void* alloc_new_chunk(size_t size) { head_t* p = alloc_head(HeadSize + size); if (p == nullptr) return nullptr; head_t* list = chain(); if (size > BufferSize && list != nullptr) { p->next_ = list->next_; list->next_ = p; char* head = reinterpret_cast<char*>(p + 1); char* tail = head + p->free_ - size; p->free_ = tail - head; return tail; } else { p->next_ = list; head_ = reinterpret_cast<char*>(p + 1); tail_ = head_ + p->free_ - size; p->free_ = remain(); return tail_; } }
int main(int argc, char *argv[]) { std::string root = "mh"; int nChains = 4; int burnin = 1000; // Read the resulting chain(s) with thinning const unsigned int thin = 1; MarkovChain chain(nChains, root.c_str(), burnin, thin); // Get the one dimensional marginalized posterior distributions, Gaussian smoothed with a scale of 0.3 Posterior1D* px = chain.posterior(0, Posterior1D::GAUSSIAN_SMOOTHING); Posterior1D* py = chain.posterior(1, Posterior1D::GAUSSIAN_SMOOTHING); // Get the two dimensional posterior distribution, gaussian smoothed with a scale of 0.25 Posterior2D* pxy = chain.posterior(0, 1); // Write the distributions into text files output_screen("Writing the distributions into text files..." << std::endl); px->writeIntoFile("mh_px.txt"); py->writeIntoFile("mh_py.txt"); pxy->writeIntoFile("mh_pxy.txt"); output_screen("OK" << std::endl); // Write the contour levels for the 2D distribution into a text file. This can be used later to make contour plots std::ofstream out("mh_contour_levels.txt"); out << pxy->get1SigmaLevel() << std::endl; //out << pxy->get2SigmaLevel() << std::endl; out.close(); // Delete the posterior distributions delete px; delete py; delete pxy; return 0; }
void run_h1analysis(int type = 0, const char * h1dir = 0) { std::cout << "Run h1 analysis " << std::endl; // create first the chain with all the files TChain chain("h42"); if (h1dir) { gSystem->Setenv("H1",h1dir); } else gSystem->Setenv("H1","http://root.cern.ch/files/h1/"); std::cout << "Creating the chain" << std::endl; chain.SetCacheSize(20*1024*1024); chain.Add("$H1/dstarmb.root"); chain.Add("$H1/dstarp1a.root"); chain.Add("$H1/dstarp1b.root"); chain.Add("$H1/dstarp2.root"); TString selectionMacro = TString(gSystem->DirName(__FILE__) ) + "/h1analysis.C"; if (type == 0) chain.Process(selectionMacro); else if (type == 1) { // use AClic ( add a + at the end selectionMacro += "+"; chain.Process(selectionMacro); } else if (type == 2) { chain.Process(selectionMacro,"fillList"); chain.Process(selectionMacro,"useList"); } }
void checkOut( const boost::program_options::variables_map & options ) { BACKTRACE_BEGIN boost::filesystem::path reportFile = options[ "reportFile" ].as< std::string >(); unsigned reportIntervalSeconds = options[ "reportIntervalSeconds" ].as< unsigned >(); boost::filesystem::path workDir = stripTrailingSlash( options[ "arg1" ].as< std::string >() ); std::string label = options[ "arg2" ].as< std::string >(); bool putIfMissing = options.count( "putIfMissing" ) > 0; bool chainTouch = options.count( "noChainTouch" ) == 0; Osmosis::Chain::Chain chain( options[ "objectStores" ].as< std::string >(), putIfMissing, chainTouch ); bool md5 = options.count( "MD5" ) > 0; bool removeUnknownFiles = options.count( "removeUnknownFiles" ) > 0; bool myUIDandGIDcheckout = options.count( "myUIDandGIDcheckout" ) > 0; std::vector< std::string > ignores; if ( options.count( "ignore" ) > 0 ) boost::split( ignores, options[ "ignore" ].as< std::string >(), boost::is_any_of( ":" ) ); workDir = boost::filesystem::absolute( workDir ); std::string workDirString = workDir.string(); for ( auto & ignore : ignores ) { ignore = std::move( boost::filesystem::absolute( ignore ).string() ); if ( ignore.size() < workDirString.size() or ignore.substr( 0, workDirString.size() ) != workDirString ) THROW( Error, "ignore '" << ignore << "' is not under checkout path '" << workDirString << "'" ); TRACE_INFO( "will ignore '" << ignore << "'" ); } boost::filesystem::path draftsPath = workDir / Osmosis::ObjectStore::DirectoryNames::DRAFTS; boost::filesystem::remove_all( draftsPath ); Osmosis::FilesystemUtils::clearUMask(); Osmosis::Client::Ignores ignoresInstance( ignores ); ignoresInstance.append( draftsPath.string() ); Osmosis::Client::CheckOut instance( workDir, label, chain, md5, removeUnknownFiles, myUIDandGIDcheckout, ignoresInstance, reportFile, reportIntervalSeconds, chainTouch ); instance.go(); BACKTRACE_END }
void* alloc(size_t size, size_t alignment) { CAPO_ASSERT_(!(alignment & (alignment - 1)))(alignment); if (remain() < size) { return alloc_new_chunk(size, alignment); } char* buff = tail_ - size; size_t x = reinterpret_cast<size_t>(buff); x &= ~(x - 1); // calculate the alignment of buffer if (x < alignment) { buff = adjust_alignment(buff, alignment - 1); if (buff < head_) { return alloc_new_chunk(size, alignment); } } tail_ = buff; chain()->free_ = remain(); return tail_; }
void gc_sweep(void) { object *obj = active_list; object *next, *prev; fprintf(stderr, "sweeping objects...\n"); dump_active_list(); while (obj != NULL && obj == active_list) { next = chain(obj); if (gc_active(obj)) { gc_clear(obj); } else if (gc_free(obj)) { dump_object(obj); active_list = chain(obj); chain(obj) = free_list; free_list = obj; } else { error("illegal state while gc"); } obj = next; } prev = active_list; while (obj != NULL) { next = chain(obj); if (gc_active(obj)) { gc_clear(obj); prev = obj; } else if (gc_free(obj)) { dump_object(obj); chain(prev) = next; chain(obj) = free_list; free_list = obj; } else { error("illegal state while gc"); } obj = next; } dump_active_list(); fprintf(stderr, "finished sweep\n"); }
void Controller_Module::mode ( Mode m ) { if( mode() != CV && m == CV ) { if ( control_output[0].connected() ) { chain()->engine()->lock(); Port *p = control_output[0].connected_port(); JACK::Port po( chain()->engine(), JACK::Port::Input, p->name(), 0, "CV" ); if ( ! po.activate() ) { fl_alert( "Could not activate JACK port \"%s\"", po.name() ); chain()->engine()->unlock(); return; } if ( po.valid() ) { jack_input.push_back( po ); } chain()->engine()->unlock(); } } else if ( mode() == CV && m != CV ) { chain()->engine()->lock(); jack_input.back().shutdown(); jack_input.pop_back(); chain()->engine()->unlock(); } _mode = m ; }
QString KisImportExportManager::importDocument(const QString& url, const QString& documentMimeType, KisImportExportFilter::ConversionStatus& status) { // Find the mime type for the file to be imported. QString typeName(documentMimeType); QUrl u(url); QMimeType t; if (documentMimeType.isEmpty()) { QMimeDatabase db; db.mimeTypeForFile(u.path(), QMimeDatabase::MatchExtension); if (t.isValid()) typeName = t.name(); } m_graph.setSourceMimeType(typeName.toLatin1()); // .latin1() is okay here (Werner) if (!m_graph.isValid()) { bool userCancelled = false; warnFile << "Can't open " << typeName << ", trying filter chooser"; if (m_document) { if (!m_document->isAutoErrorHandlingEnabled()) { status = KisImportExportFilter::BadConversionGraph; return QString(); } QByteArray nativeFormat = m_document->nativeFormatMimeType(); QApplication::setOverrideCursor(Qt::ArrowCursor); KisFilterChooser chooser(0, KisImportExportManager::mimeFilter(nativeFormat, KisImportExportManager::Import, m_document->extraNativeMimeTypes()), nativeFormat, u); if (chooser.exec()) { QByteArray f = chooser.filterSelected().toLatin1(); if (f == nativeFormat) { status = KisImportExportFilter::OK; QApplication::restoreOverrideCursor(); return url; } m_graph.setSourceMimeType(f); } else userCancelled = true; QApplication::restoreOverrideCursor(); } if (!m_graph.isValid()) { errFile << "Couldn't create a valid graph for this source mimetype: " << typeName; importErrorHelper(typeName, userCancelled); status = KisImportExportFilter::BadConversionGraph; return QString(); } } KisFilterChain::Ptr chain(0); // Are we owned by a KisDocument? if (m_document) { QByteArray mimeType = m_document->nativeFormatMimeType(); QStringList extraMimes = m_document->extraNativeMimeTypes(); int i = 0; int n = extraMimes.count(); chain = m_graph.chain(this, mimeType); while (i < n) { QByteArray extraMime = extraMimes[i].toUtf8(); // TODO check if its the same target mime then continue KisFilterChain::Ptr newChain(0); newChain = m_graph.chain(this, extraMime); if (!chain || (newChain && newChain->weight() < chain->weight())) chain = newChain; ++i; } } else if (!d->importMimeType.isEmpty()) { chain = m_graph.chain(this, d->importMimeType); } else { errFile << "You aren't supposed to use import() from a filter!" << endl; status = KisImportExportFilter::UsageError; return QString(); } if (!chain) { errFile << "Couldn't create a valid filter chain!" << endl; importErrorHelper(typeName); status = KisImportExportFilter::BadConversionGraph; return QString(); } // Okay, let's invoke the filters one after the other m_direction = Import; // vital information! m_importUrl = url; // We want to load that file m_exportUrl.clear(); // This is null for sure, as embedded stuff isn't // allowed to use that method status = chain->invokeChain(); m_importUrl.clear(); // Reset the import URL if (status == KisImportExportFilter::OK) return chain->chainOutput(); return QString(); }
void Example_tags(TString topDir = "/star/rcf/GC/daq/tags") { ////////////////////////////////////////////////////////////////////////// // // // Example_tags.C // // // // shows how to use the STAR tags files // // Input: top level directory // // // // what it does: // // 1. creates TChain from all tags files down from the topDir // // 2. loops over all events in the chain // // // // owner: Alexandre V. Vaniachine <*****@*****.**> // ////////////////////////////////////////////////////////////////////////// gSystem->Load("libTable"); gSystem->Load("St_base"); // start benchmarks gBenchmark = new TBenchmark(); gBenchmark->Start("total"); // set loop optimization level gROOT->ProcessLine(".O4"); // gather all files from the same top directory into one chain // topDir must end with "/" topDir +='/'; St_FileSet dirs(topDir); St_DataSetIter next(&dirs,0); St_DataSet *set = 0; TChain chain("Tag"); while ( (set = next()) ) { if (strcmp(set->GetTitle(),"file") || !(strstr(set->GetName(),".tags.root"))) continue; chain.Add(gSystem->ConcatFileName(topDir,set->Path())); } UInt_t nEvents = chain->GetEntries(); cout<<"chained "<<nEvents<<" events "<<endl; TObjArray *files = chain.GetListOfFiles(); UInt_t nFiles = files->GetEntriesFast(); cout << "chained " << nFiles << " files from " << topDir << endl; TObjArray *leaves = chain.GetListOfLeaves(); Int_t nleaves = leaves->GetEntriesFast(); TString tableName = " "; TObjArray *tagTable = new TObjArray; Int_t tableCount = 0; Int_t *tableIndex = new Int_t[nleaves]; Int_t tagCount = 0; // decode tag table names for (Int_t l=0;l<nleaves;l++) { TLeaf *leaf = (TLeaf*)leaves->UncheckedAt(l); tagCount+=leaf->GetNdata(); TBranch *branch = leaf->GetBranch(); // new tag table name if ( strstr(branch->GetName(), tableName.Data()) == 0 ) { tableName = branch->GetName(); // the tableName is encoded in the branch Name before the "." tableName.Resize(tableName->Last('.')); tagTable->AddLast(new TObjString(tableName.Data())); tableCount++; } tableIndex[l]=tableCount-1; } cout << " tot num tables, tags = " << tableCount << " " << tagCount << endl << endl; //EXAMPLE 1: how to print out names of all tags and values for first event for (l=0;l<nleaves;l++) { leaf = (TLeaf*)leaves->UncheckedAt(l); branch = leaf->GetBranch(); branch->GetEntry(); // tag comment is in the title TString Title = leaf->GetTitle(); Int_t dim = leaf->GetNdata(); if (dim==1) { Title.ReplaceAll('['," '"); Title.ReplaceAll(']',"'"); } cout << "\n Table: "; cout.width(10); cout << ((TObjString*)tagTable->UncheckedAt(tableIndex[l]))->GetString() <<" -- has tag: " << Title << endl; for (Int_t i=0;i<dim;i++) { cout <<" "<< leaf->GetName(); if (dim>1) cout << '['<<i<<']'; cout << " = " << leaf->GetValue(i) << endl; } } // EXAMPLE 2: how to make a plot c1 = new TCanvas("c1","Beam-Gas Rejection",600,1000); gStyle->SetMarkerStyle(8); chain->Draw("n_trk_tpc[0]:n_trk_tpc[1]"); // EXAMPLE 3: how to make a selection (write selected event numbers on the plot) Int_t ncoll=0; char aevent[10]; TText t(0,0,"a"); t.SetTextFont(52); t.SetTextSize(0.02); Float_t cut = 0.35; cout <<"\n Events with ntrk>400 and |asim|<"<<cut<<endl; //loop over all events: READ ONLY n_trk_tpc AND mEventNumber BRANCHES! gBenchmark->Start("loop"); for (Int_t i=0;i<nFiles;i++) { chain.LoadTree(*(chain.GetTreeOffset()+i)); TTree *T = chain.GetTree(); //must renew leaf pointer for each tree TLeaf *ntrk = T->GetLeaf("n_trk_tpc"); TLeaf *run = T->GetLeaf("mRunNumber"); TLeaf *event = T->GetLeaf("mEventNumber"); for (Int_t j=0; j<T->GetEntries(); j++){ ntrk->GetBranch()->GetEntry(j); event->GetBranch()->GetEntry(j); run->GetBranch()->GetEntry(j); Int_t Nm=ntrk->GetValue(0); Int_t Np=ntrk->GetValue(1); Int_t Ntrk = Np+Nm; // avoid division by 0 Float_t asim = Np-Nm; if (Ntrk>0) asim /= Ntrk; if (-cut < asim&&asim < cut && Ntrk>400) { cout<<" Run "<<(UInt_t)run->GetValue() <<", Event "<<event->GetValue() <<endl; ncoll++; sprintf(aevent,"%d",event->GetValue()); t.DrawText(Np+10,Nm+10,aevent); } } } gBenchmark->Stop("loop"); t.SetTextSize(0.05); t.DrawText(50,2550,"ntrk>400 and |(Np-Nm)/(Np+Nm)| < 0.35 "); t.DrawText(500,-300,"Ntrk with tanl<0 "); cout << " Selected " << ncoll << " collision candidates out of " << nEvents << " events" << endl; // stop timer and print benchmarks gBenchmark->Print("loop"); gBenchmark->Stop("total"); gBenchmark->Print("total"); }