void CollectNucleotideFrequences(const string& col, int base_count[], int numBases) { // first, we record which bases occur and how often // this is computed in NCBI4na notation fill_n(base_count, numBases, 0); const char* i = col.c_str(); unsigned char c; while ((c = *i++)) { switch(c) { case 'A': ++base_count[0]; break; case 'C': ++base_count[1]; break; case 'M': ++base_count[1]; ++base_count[0]; break; case 'G': ++base_count[2]; break; case'R': ++base_count[2]; ++base_count[0]; break; case 'S': ++base_count[2]; ++base_count[1]; break; case 'V': ++base_count[2]; ++base_count[1]; ++base_count[0]; break; case 'T': ++base_count[3]; break; case 'W': ++base_count[3]; ++base_count[0]; break; case 'Y': ++base_count[3]; ++base_count[1]; break; case 'H': ++base_count[3]; ++base_count[1]; ++base_count[0]; break; case 'K': ++base_count[3]; ++base_count[2]; break; case 'D': ++base_count[3]; ++base_count[2]; ++base_count[0]; break; case 'B': ++base_count[3]; ++base_count[2]; ++base_count[1]; break; case 'N': ++base_count[3]; ++base_count[2]; ++base_count[1]; ++base_count[0]; break; default: break; } } }
void PSSinthesis::Sinthesis(double s) { hops[Qcolumn-1] = round(hopa*(pow(2,(s/12)))); //Some declaration int L; L = N; for (int i=0; i< Qcolumn-1; i++) L = L + hops[i]; double r; int n1; int n2; double n3; //Some inicialization ysaida2 = &ysaida[L-N]; // We can divide the code in two here Phi = PhiPrevious + (hops[Qcolumn-1])*omega_true_sobre_fs[0] ; for (int i=0; i<(N/2 + 1); i++) Xs(i) = ExponencialComplexa(Phi(i)); Xs = Xa_abs[0] % Xs; PhiPrevious = Phi; for (int i=0; i<(N/2 + 1); i++) { fXs[i][0] = real(Xs(i)); fXs[i][1] = imag(Xs(i)); } /*Synthesis*/ if (p2) fftwf_execute(p2); double norm = N*sqrt( N/(2.0*hops[Qcolumn-1]) ); for (int i=0; i<N; i++) q[i] = q[i]*w[0](i)/norm; if (first == true) { first = false; fill_n(ysaida,L-N,0); for (int i=L-N; i<L; i++) ysaida[i] = q[i-(L-N)]; } else { for (int i=L-N; i<L; i++) ysaida[i] = ysaida[i] + q[i-(L-N)]; } //Linear interpolation r = hops[Qcolumn-1]/(1.0*hopa); for (int n=0; n < hopa; n++) { n3 = n*r+1; n1 = floor(n3); n2 = ceil(n3); yshift[n] = ysaida2[n1] + (ysaida2[n2]-ysaida2[n1])*(n3 - n1); } //Shift ysaida hops[0] left for (int i=0; i<L-hops[0]; i++) ysaida[i] = ysaida[i+hops[0]]; for (int i=L-hops[0]; i<L; i++) ysaida[i] = 0; }
void SymbolicMX::propagateSparsity(DMatrixPtrV& input, DMatrixPtrV& output, bool fwd) { bvec_t *outputd = get_bvec_t(output[0]->data()); fill_n(outputd, output[0]->size(), 0); }
Trie::Trie() { this->leaf = false; this->idx = 0; fill_n(this->children, 26, nullptr); }
elf_reader_impl::elf_reader_impl() { ref_count_ = 1; initialized_ = false; fill_n( reinterpret_cast<char*>( &header_ ), sizeof( header_ ), '\0' ); }
static void TestAlgorithms (void) { static const int c_TestNumbers[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 11, 12, 13, 13, 14, 15, 16, 17, 18 }; const int* first = c_TestNumbers; const int* last = first + VectorSize(c_TestNumbers); intvec_t v, buf; v.assign (first, last); PrintVector (v); cout << "swap(1,2)\n"; swap (v[0], v[1]); PrintVector (v); v.assign (first, last); cout << "copy(0,8,9)\n"; copy (v.begin(), v.begin() + 8, v.begin() + 9); PrintVector (v); v.assign (first, last); cout << "copy with back_inserter\n"; v.clear(); copy (first, last, back_inserter(v)); PrintVector (v); v.assign (first, last); cout << "copy with inserter\n"; v.clear(); copy (first, first + 5, inserter(v, v.begin())); copy (first, first + 5, inserter(v, v.begin() + 3)); PrintVector (v); v.assign (first, last); cout << "copy_n(0,8,9)\n"; copy_n (v.begin(), 8, v.begin() + 9); PrintVector (v); v.assign (first, last); cout << "copy_if(is_even)\n"; intvec_t v_even; copy_if (v, back_inserter(v_even), &is_even); PrintVector (v_even); v.assign (first, last); cout << "for_each(printint)\n{ "; for_each (v, &printint); cout << "}\n"; cout << "for_each(reverse_iterator, printint)\n{ "; for_each (v.rbegin(), v.rend(), &printint); cout << "}\n"; cout << "find(10)\n"; cout.format ("10 found at offset %zd\n", abs_distance (v.begin(), find (v, 10))); cout << "count(13)\n"; cout.format ("%zu values of 13, %zu values of 18\n", count(v,13), count(v,18)); cout << "transform(sqr)\n"; transform (v, &sqr); PrintVector (v); v.assign (first, last); cout << "replace(13,666)\n"; replace (v, 13, 666); PrintVector (v); v.assign (first, last); cout << "fill(13)\n"; fill (v, 13); PrintVector (v); v.assign (first, last); cout << "fill_n(5, 13)\n"; fill_n (v.begin(), 5, 13); PrintVector (v); v.assign (first, last); cout << "fill 64083 uint8_t(0x41) "; TestBigFill<uint8_t> (64083, 0x41); cout << "fill 64083 uint16_t(0x4142) "; TestBigFill<uint16_t> (64083, 0x4142); cout << "fill 64083 uint32_t(0x41424344) "; TestBigFill<uint32_t> (64083, 0x41424344); cout << "fill 64083 float(0.4242) "; TestBigFill<float> (64083, 0x4242f); #if HAVE_INT64_T cout << "fill 64083 uint64_t(0x4142434445464748) "; TestBigFill<uint64_t> (64083, UINT64_C(0x4142434445464748)); #else cout << "No 64bit types available on this platform\n"; #endif cout << "copy 64083 uint8_t(0x41) "; TestBigCopy<uint8_t> (64083, 0x41); cout << "copy 64083 uint16_t(0x4142) "; TestBigCopy<uint16_t> (64083, 0x4142); cout << "copy 64083 uint32_t(0x41424344) "; TestBigCopy<uint32_t> (64083, 0x41424344); cout << "copy 64083 float(0.4242) "; TestBigCopy<float> (64083, 0.4242f); #if HAVE_INT64_T cout << "copy 64083 uint64_t(0x4142434445464748) "; TestBigCopy<uint64_t> (64083, UINT64_C(0x4142434445464748)); #else cout << "No 64bit types available on this platform\n"; #endif cout << "generate(genint)\n"; generate (v, &genint); PrintVector (v); v.assign (first, last); cout << "rotate(4)\n"; rotate (v, 7); rotate (v, -3); PrintVector (v); v.assign (first, last); cout << "merge with (3,5,10,11,11,14)\n"; const int c_MergeWith[] = { 3,5,10,11,11,14 }; intvec_t vmerged; merge (v.begin(), v.end(), VectorRange(c_MergeWith), back_inserter(vmerged)); PrintVector (vmerged); v.assign (first, last); cout << "inplace_merge with (3,5,10,11,11,14)\n"; v.insert (v.end(), VectorRange(c_MergeWith)); inplace_merge (v.begin(), v.end() - VectorSize(c_MergeWith), v.end()); PrintVector (v); v.assign (first, last); cout << "remove(13)\n"; remove (v, 13); PrintVector (v); v.assign (first, last); cout << "remove (elements 3, 4, 6, 15, and 45)\n"; vector<uoff_t> toRemove; toRemove.push_back (3); toRemove.push_back (4); toRemove.push_back (6); toRemove.push_back (15); toRemove.push_back (45); typedef index_iterate<intvec_t::iterator, vector<uoff_t>::iterator> riiter_t; riiter_t rfirst = index_iterator (v.begin(), toRemove.begin()); riiter_t rlast = index_iterator (v.begin(), toRemove.end()); remove (v, rfirst, rlast); PrintVector (v); v.assign (first, last); cout << "unique\n"; unique (v); PrintVector (v); v.assign (first, last); cout << "reverse\n"; reverse (v); PrintVector (v); v.assign (first, last); cout << "lower_bound(10)\n"; PrintVector (v); cout.format ("10 begins at position %zd\n", abs_distance (v.begin(), lower_bound (v, 10))); v.assign (first, last); cout << "upper_bound(10)\n"; PrintVector (v); cout.format ("10 ends at position %zd\n", abs_distance (v.begin(), upper_bound (v, 10))); v.assign (first, last); cout << "equal_range(10)\n"; PrintVector (v); TestEqualRange (v); v.assign (first, last); cout << "sort\n"; reverse (v); PrintVector (v); random_shuffle (v); sort (v); PrintVector (v); v.assign (first, last); cout << "stable_sort\n"; reverse (v); PrintVector (v); random_shuffle (v); stable_sort (v); PrintVector (v); v.assign (first, last); cout << "is_sorted\n"; random_shuffle (v); const bool bNotSorted = is_sorted (v.begin(), v.end()); sort (v); const bool bSorted = is_sorted (v.begin(), v.end()); cout << "unsorted=" << bNotSorted << ", sorted=" << bSorted << endl; v.assign (first, last); cout << "find_first_of\n"; static const int c_FFO[] = { 10000, -34, 14, 27 }; cout.format ("found 14 at position %zd\n", abs_distance (v.begin(), find_first_of (v.begin(), v.end(), VectorRange(c_FFO)))); v.assign (first, last); static const int LC1[] = { 3, 1, 4, 1, 5, 9, 3 }; static const int LC2[] = { 3, 1, 4, 2, 8, 5, 7 }; static const int LC3[] = { 1, 2, 3, 4 }; static const int LC4[] = { 1, 2, 3, 4, 5 }; cout << "lexicographical_compare"; cout << "\nLC1 < LC2 == " << lexicographical_compare (VectorRange(LC1), VectorRange(LC2)); cout << "\nLC2 < LC2 == " << lexicographical_compare (VectorRange(LC2), VectorRange(LC2)); cout << "\nLC3 < LC4 == " << lexicographical_compare (VectorRange(LC3), VectorRange(LC4)); cout << "\nLC4 < LC1 == " << lexicographical_compare (VectorRange(LC4), VectorRange(LC1)); cout << "\nLC1 < LC4 == " << lexicographical_compare (VectorRange(LC1), VectorRange(LC4)); cout << "\nmax_element\n"; cout.format ("max element is %d\n", *max_element (v.begin(), v.end())); v.assign (first, last); cout << "min_element\n"; cout.format ("min element is %d\n", *min_element (v.begin(), v.end())); v.assign (first, last); cout << "partial_sort\n"; reverse (v); partial_sort (v.begin(), v.iat(v.size() / 2), v.end()); PrintVector (v); v.assign (first, last); cout << "partial_sort_copy\n"; reverse (v); buf.resize (v.size()); partial_sort_copy (v.begin(), v.end(), buf.begin(), buf.end()); PrintVector (buf); v.assign (first, last); cout << "partition\n"; partition (v.begin(), v.end(), &is_even); PrintVector (v); v.assign (first, last); cout << "stable_partition\n"; stable_partition (v.begin(), v.end(), &is_even); PrintVector (v); v.assign (first, last); cout << "next_permutation\n"; buf.resize (3); iota (buf.begin(), buf.end(), 1); PrintVector (buf); while (next_permutation (buf.begin(), buf.end())) PrintVector (buf); cout << "prev_permutation\n"; reverse (buf); PrintVector (buf); while (prev_permutation (buf.begin(), buf.end())) PrintVector (buf); v.assign (first, last); cout << "reverse_copy\n"; buf.resize (v.size()); reverse_copy (v.begin(), v.end(), buf.begin()); PrintVector (buf); v.assign (first, last); cout << "rotate_copy\n"; buf.resize (v.size()); rotate_copy (v.begin(), v.iat (v.size() / 3), v.end(), buf.begin()); PrintVector (buf); v.assign (first, last); static const int c_Search1[] = { 5, 6, 7, 8, 9 }, c_Search2[] = { 10, 10, 11, 14 }; cout << "search\n"; cout.format ("{5,6,7,8,9} at %zd\n", abs_distance (v.begin(), search (v.begin(), v.end(), VectorRange(c_Search1)))); cout.format ("{10,10,11,14} at %zd\n", abs_distance (v.begin(), search (v.begin(), v.end(), VectorRange(c_Search2)))); cout << "find_end\n"; cout.format ("{5,6,7,8,9} at %zd\n", abs_distance (v.begin(), find_end (v.begin(), v.end(), VectorRange(c_Search1)))); cout.format ("{10,10,11,14} at %zd\n", abs_distance (v.begin(), find_end (v.begin(), v.end(), VectorRange(c_Search2)))); cout << "search_n\n"; cout.format ("{14} at %zd\n", abs_distance (v.begin(), search_n (v.begin(), v.end(), 1, 14))); cout.format ("{13,13} at %zd\n", abs_distance (v.begin(), search_n (v.begin(), v.end(), 2, 13))); cout.format ("{10,10,10} at %zd\n", abs_distance (v.begin(), search_n (v.begin(), v.end(), 3, 10))); v.assign (first, last); cout << "includes\n"; static const int c_Includes[] = { 5, 14, 15, 18, 20 }; cout << "includes=" << includes (v.begin(), v.end(), VectorRange(c_Includes)-1); cout << ", not includes=" << includes (v.begin(), v.end(), VectorRange(c_Includes)); cout << endl; static const int c_Set1[] = { 1, 2, 3, 4, 5, 6 }, c_Set2[] = { 4, 4, 6, 7, 8 }; intvec_t::iterator setEnd; cout << "set_difference\n"; v.resize (4); setEnd = set_difference (VectorRange(c_Set1), VectorRange(c_Set2), v.begin()); PrintVector (v); assert (setEnd == v.end()); cout << "set_symmetric_difference\n"; v.resize (7); setEnd = set_symmetric_difference (VectorRange(c_Set1), VectorRange(c_Set2), v.begin()); PrintVector (v); assert (setEnd == v.end()); cout << "set_intersection\n"; v.resize (2); setEnd = set_intersection (VectorRange(c_Set1), VectorRange(c_Set2), v.begin()); PrintVector (v); assert (setEnd == v.end()); cout << "set_union\n"; v.resize (9); setEnd = set_union (VectorRange(c_Set1), VectorRange(c_Set2), v.begin()); PrintVector (v); assert (setEnd == v.end()); v.assign (first, last); }
Classificador* TreinadorAdaboost::executarTreinamento( Corpus &corpus, int atributo ){ Classificador *cl; double beta, acertos, erros, sumdist; vector <double> alphas; vector<Classificador*> classificadores; unsigned i, atributoTemporario, c, e, nConjExemplos = corpus.pegarQtdTotalExemplos(), nExemplos; vector<double> dist(nConjExemplos, 1.0/nConjExemplos); vector<bool> errado(nConjExemplos); atributoTemporario = corpus.criarAtributo("adab"); for (i = 0; i < iterations; i++){ fill_n(errado.begin(), nConjExemplos, false); base.ajustarDistribuicao(dist); cl = base.executarTreinamento(corpus, atributo); cl->executarClassificacao(corpus, atributoTemporario); //calcula erro, generalizar para vários exemplos por conjunto de exemplo acertos = erros = 0; for (c=0;c<nConjExemplos;c++){ nExemplos = corpus.pegarQtdExemplos(c); for (e=0; e<nExemplos; e++){ if ((corpus.pegarValor(c,e,atributo)!=corpus.pegarValor(c,e,atributoTemporario))){ errado[c] = true; break; } } if (errado[c]) erros += dist[c]; else acertos += dist[c]; } beta = acertos/erros; //cout << i << "-" << beta << endl; sumdist = 0.0; for (c=0;c<nConjExemplos;c++){ if (errado[c]) dist[c] *= beta; sumdist += dist[c]; } for (c=0;c<nConjExemplos;c++) dist[c] /= sumdist; classificadores.push_back(cl); alphas.push_back(.5*log(beta)); if (alphas[i] < minalpha) break; } corpus.removerAtributo("adab"); return new ClassificadorAdaboost(classes,classificadores,alphas); }
int main(int argc, const char * argv[]) { if (argc < 2) { cout << "Usage: " << argv[0] << " assembly_file_name.asm" << endl; return 0; } SourceReader sourceReader(argv[1]); sourceReader.findLabelAddresses(); sourceReader.constructInstructionList(); vector<Instruction> originalInstructionList = sourceReader.getInstructionList(); vector<SimulatedInstruction> simulatedInstructionList = vector<SimulatedInstruction>(); cout << "-------------Start Simulation-------------" << endl; cout << "Original number of instructions : " << originalInstructionList.size() << endl; cout << string(OUTPUT_WIDTH, '-') << endl; for (Instruction instruction: originalInstructionList) { simulatedInstructionList.push_back(SimulatedInstruction(instruction)); } // Inserts an end instruction followed by 3 'NOPs' to terminate the instruction list // An end NOP instruction is used to indicate the end of the instruction list SimulatedInstruction end = SimulatedInstruction(); end.originalString = "end"; end.opcodeString = "end"; simulatedInstructionList.push_back(end); fill_n(back_inserter(simulatedInstructionList), 3, SimulatedInstruction()); for (int i = 0; i < simulatedInstructionList.size(); i++) { simulatedInstructionList[i].instructionLocation = i; } Simulator simulator(simulatedInstructionList); cout << "Press enter to run the entire simulation without pauses" << endl; cout << "Or press space to step through the simulation" << endl; BufferToggle bt; while (simulator.memoryStage.currentInstructionList.front().originalString != "end") { bt.off(); char input = getchar(); bt.on(); if (input == ' ') { cout << endl; simulator.stepProcess(); } else if (input == '\n' || input == '\r') { simulator.process(); } } simulator.printFinalOutput(); return 0; }
void SymbolicMX::spAdj(const pv_bvec_t& arg, const pv_bvec_t& res, int* itmp, bvec_t* rtmp) { fill_n(res[0], nnz(), 0); }
/** * returns the accuracy */ float LacSupervised::predict(Trainning &trainning, char *ftest, AssociationRule* associationRule){ ui ntransactions = 0; ui nhits = 0; ui totalRules = 0; FILE* file=fopen(ftest,"r"); if(file==NULL) { fprintf(stderr,"Test set %s not found.\n\n", ftest); exit(-1); } SymbolTable* featureTable = SymbolTable::FeaturesTable(); SymbolTable* classesTable = SymbolTable::ClassesTable(); vector<pair<string, ui> > classes; classesTable->getTableName(classes); unordered_set<ui> featureIds; const ui bufferSize = 200*1024; char line[bufferSize]; ui tid, classId; ui nclasses = trainning.getNumberOfClasses(); vector<float> scores(nclasses); ui defaultClass = trainning.getMostFrequentClass(); while(fgets(line, bufferSize, file)){ ++ntransactions; classId = 10000000; processLineInput(line, featureTable, classesTable, tid, classId, featureIds); if(classId == 10000000){ throw string("Class Id not found: ") + line ; } Projection* projection = trainning.geProjection(featureIds); fill_n(scores.begin(), scores.size(), 0.0f); float totalScore = 0.0f; ui nrules = 0; ui prediction = defaultClass; AssociationRule::RulesResult result = associationRule->induceRules(projection, minSupport, iminSupport, nclasses); for(ui classId = 0; classId < nclasses; ++classId){ nrules += result.classesNRules[classId]; float score = result.score(classId); totalScore += score; scores[classId] = score; if(cmp(scores[prediction], score) < 0){ prediction = classId; } } totalRules += nrules; nhits += prediction == classId;; printStatistics(trainning, tid, classesTable, classes, classId, prediction, scores, totalScore, nrules); delete projection; } fclose(file); //printf("%u\n", totalRules); return ntransactions == 0 ? 1.0 : static_cast<float>(nhits)/static_cast<float>(ntransactions); }
void SymbolicMX::sp_rev(bvec_t** arg, bvec_t** res, int* iw, bvec_t* w, int mem) const { fill_n(res[0], nnz(), 0); }
bool BonminInterface:: intermediate_callback(BonminMemory* m, const double* x, const double* z_L, const double* z_U, const double* g, const double* lambda, double obj_value, int iter, double inf_pr, double inf_du, double mu, double d_norm, double regularization_size, double alpha_du, double alpha_pr, int ls_trials, bool full_callback) const { m->n_iter += 1; try { log("intermediate_callback started"); m->inf_pr.push_back(inf_pr); m->inf_du.push_back(inf_du); m->mu.push_back(mu); m->d_norm.push_back(d_norm); m->regularization_size.push_back(regularization_size); m->alpha_pr.push_back(alpha_pr); m->alpha_du.push_back(alpha_du); m->ls_trials.push_back(ls_trials); m->obj.push_back(obj_value); if (!fcallback_.is_null()) { m->fstats.at("callback_fun").tic(); if (full_callback) { casadi_copy(x, nx_, m->xk); for (int i=0; i<nx_; ++i) { m->lam_xk[i] = z_U[i]-z_L[i]; } casadi_copy(lambda, ng_, m->lam_gk); casadi_copy(g, ng_, m->gk); } else { if (iter==0) { userOut<true, PL_WARN>() << "Warning: intermediate_callback is disfunctional in your installation. " "You will only be able to use stats(). " "See https://github.com/casadi/casadi/wiki/enableBonminCallback to enable it." << endl; } } // Inputs fill_n(m->arg, fcallback_.n_in(), nullptr); if (full_callback) { // The values used below are meaningless // when not doing a full_callback m->arg[NLPSOL_X] = x; m->arg[NLPSOL_F] = &obj_value; m->arg[NLPSOL_G] = g; m->arg[NLPSOL_LAM_P] = 0; m->arg[NLPSOL_LAM_X] = m->lam_xk; m->arg[NLPSOL_LAM_G] = m->lam_gk; } // Outputs fill_n(m->res, fcallback_.n_out(), nullptr); double ret_double; m->res[0] = &ret_double; fcallback_(m->arg, m->res, m->iw, m->w, 0); int ret = static_cast<int>(ret_double); m->fstats.at("callback_fun").toc(); return !ret; } else { return 1; } } catch(exception& ex) { if (iteration_callback_ignore_errors_) { userOut<true, PL_WARN>() << "intermediate_callback: " << ex.what() << endl; } else { throw ex; } return 1; } }
polynomial(const int n) : vals(std::make_shared<std::vector<T>>(n)) { fill_n(vals->data(),size(),T(0.0)); }
// 败者树建立函数 void LoserTree(int exnode[], int leaf[], int k) { fill_n(exnode, k, -1); for (int i = 0; i < k; ++i) { ajustLosers(exnode, leaf, k, i); } }
// Initialize your data structure here. TrieNode() { fill_n(next, 26, nullptr); isWord = false; }