inline interp createInterp(const unsigned nx, const unsigned ny, const double scale, std::string path, std::string simFile = "sim_solution.out", std::string mtvFile = "mtv_solution.out") { // retrieve grid and data. std::vector<ublas::matrix<double, ublas::column_major> > simData = readSim(nx, ny, path + simFile); interp ret(simData[0], simData[1], scale, 100, .1); ret.optimizeScale(); return ret; }
inline interp createInterpH(const unsigned nx, const unsigned ny, const double scale, const std::string path, const std::string simFile = "sim_solution.out", const std::string mtvFile = "mtv_solution.out", const unsigned ppp = 50, const double overlap = .33, const std::vector<unsigned> slowVarInd=std::vector<unsigned>(), const bool useBump = false) { // retrieve grid and data. std::vector<ublas::matrix<double, ublas::column_major> > simData = readSim(nx, ny, path + simFile,slowVarInd); // retrieve mtvs std::vector<ublas::matrix<double, ublas::column_major> > mtvData = readMTV(nx, ny, path + mtvFile,slowVarInd); // construct interpolator and return, due to incompatible constructor interfaces // PU and normal interpolators have to be treated differently. interp ret(simData[0], simData[1], mtvData, scale, ppp, overlap,useBump); //interp ret(simData[0], simData[1], mtvData, scale); ret.optimizeScale(); return ret; }
/* * calculate depedency score * score = syn(A->B) / syn(B->A) (where syn>threshold, score>1) * input syntagmatic file {FID1, FID2, SIM} * output dependency score to file {FID1, FID2, Score} */ void SyntagCmp(string fin, string fout, double threshold, char delim) { vector<string> terms; map< string, map<string, double> >synFrom = readSim(terms, fin, 'f', threshold, delim); // output file ofstream fileout(fout.c_str()); if (!fileout) { cout << "Error: can't open " << fout << endl; exit (-1); } // calculate dependency score // write to file double synscore; map< string, map<string, double> > score; for (int i=0; i<terms.size(); i++) { string term1 = terms[i]; for(auto elem: synFrom[term1]) { cout << "... processing term " << term1 << endl; string term2 = elem.first; if (synFrom.find(term2) == synFrom.end()) continue; if (synFrom[term2].find(term1) == synFrom[term2].end()) continue; synscore = elem.second / synFrom[term2][term1]; if (synscore>1) { score[term1][term2] = synscore; fileout << term1 << "\t" << term2 << "\t" << synscore << endl; } } } fileout.close(); return; }
void getDependency(string fin, string fout_to, string fout_eq, char delim) { vector<string> terms; map< string, map<string, double> >synTo = readSim(terms, fin, 't', 0, delim); // output file ofstream out_to(fout_to.c_str()); if (!out_to) { cout << "Error: can't open " << fout_to << endl; exit (-1); } ofstream out_eq(fout_eq.c_str()); if (!out_eq) { cout << "Error: can't open " << fout_eq << endl; exit (-1); } // parameters double threshold = 1.5; double syn_threshold = 0.001; // get dependency probability for (int i=0; i<terms.size(); i++) { cout << "... dependency of term " << i << endl; // variables string term1 = terms[i]; // to double syn12, syn21, score; vector<string> fromTerm, eqTerm; vector<double> fromSyn, eqSyn; double sum = 0, eqSum = 0; // calcultion for (auto elem: synTo[term1]) { string term2 = elem.first; // from syn21 = elem.second; if (synTo.find(term2) != synTo.end() && synTo[term2].find(term1) != synTo[term2].end()) { syn12 = synTo[term2][term1]; if (syn12 > syn_threshold && syn21/syn12 > threshold) { score = syn21 * syn21/(syn12+syn21); fromTerm.push_back(term2); fromSyn.push_back(score); sum += score; } else if ((syn21/syn12<=threshold && syn21/syn12>=1) || (syn12/syn21<=threshold && syn12/syn21>=1)) { score = syn12 * syn21 / (syn12+syn21); eqTerm.push_back(term2); eqSyn.push_back(score); eqSum += score; sum += score; } } else { score = syn21; fromTerm.push_back(term2); fromSyn.push_back(score); sum += score; } } // output // {fromTerm, toTerm, normalized_syntag} for (int k=0; k<fromTerm.size(); k++) { if (sum!=0) { out_to << fromTerm[k] << delim << term1 << delim << fromSyn[k]/sum << endl; cout << fromTerm[k] << delim << term1 << delim << fromSyn[k]/sum << endl; } } for (int k=0; k<eqTerm.size(); k++) if (sum!=0) out_eq << eqTerm[k] << delim << term1 << delim << eqSyn[k]/sum << endl; } out_eq.close(); out_to.close(); return; }