void LoopOperator::forwardEstimation( boost::ptr_vector<MeshContext>& contextStack , FitobCalculator* calc , int& stackIndex , double& timeStamp ){ // see if the expression in the condition constant is // we use the context on the top of the stack MeshContext& actualContext = contextStack[stackIndex]; FITOB_OUT_LEVEL3(verb(),"LoopOperator::forwardEstimation Test if it is constant"); bool constCondition_ = loopCondition_->isConstantExpression(actualContext); nrLoop_ = 0; if (constCondition_) { // expression is constant, we calculate the LOOP count nrLoop_ = (int)(loopCondition_->eval(actualContext.minGlobCoord())); } else{ FITOB_ERROR_EXIT(" Expression in the LOOP operator must be a constant (invariant) expression "); } // call the body N times for (int ind = 0; ind < nrLoop_ ; ind++){ FITOB_OUT_LEVEL3(verb(),"LoopOperator::forwardEstimation bef. :" << stackIndex << " contextStack.size():" << contextStack.size() << " ind:"<<ind << " nrLoop:" << nrLoop_); loopBody_->forwardEstimation( contextStack , calc , stackIndex , timeStamp ); FITOB_OUT_LEVEL3(verb(),"LoopOperator::forwardEstimation aft. :" << stackIndex << " contextStack.size():" << contextStack.size() << " ind:"<<ind << " nrLoop:" << nrLoop_); } }
void llvm_model::set_prediction(const ObsId & obs_id, boost::ptr_vector<theta::Function> & coeffs_, boost::ptr_vector<HistogramFunction> & histos_){ observables.insert(obs_id); const size_t n = coeffs_.size(); if(n!=coeffs_.size()) throw invalid_argument("Model::setPrediction: number of histograms and coefficients do not match"); if(histos[obs_id].size()>0 || coeffs[obs_id].size()>0) throw invalid_argument("Model::setPrediction: prediction already set for this observable"); coeffs[obs_id].transfer(coeffs[obs_id].end(), coeffs_.begin(), coeffs_.end(), coeffs_); histos[obs_id].transfer(histos[obs_id].end(), histos_.begin(), histos_.end(), histos_); for(boost::ptr_vector<theta::Function>::const_iterator it=coeffs[obs_id].begin(); it!=coeffs[obs_id].end(); ++it){ ParIds pids = (*it).get_parameters(); parameters.insert(pids.begin(), pids.end()); } size_t nbins = 0; double xmin = NAN, xmax = NAN; bool first = true; for(boost::ptr_vector<HistogramFunction>::const_iterator it=histos[obs_id].begin(); it!=histos[obs_id].end(); ++it){ if(first){ it->get_histogram_dimensions(nbins, xmin, xmax); first = false; } else{ size_t nbins_tmp = 0; double xmin_tmp = NAN, xmax_tmp = NAN; it->get_histogram_dimensions(nbins_tmp, xmin_tmp, xmax_tmp); if(nbins!=nbins_tmp || xmin!=xmin_tmp || xmax!=xmax_tmp){ throw invalid_argument("llvm_model::set_prediction: histogram dimensions mismatch"); } } const ParIds & pids = (*it).get_parameters(); parameters.insert(pids.begin(), pids.end()); } }
void renderScene() { FrameTimeCounter counter; int avgFps = 0; int iterations = 0; while (!complete) { counter.BeginCounting(); physicsWorld->Simulate(1.0f / 10.0f); contextPtr->BeginScene(); contextPtr->ApplyCamera(*cameraPtr); //contextPtr->RenderLine(vec2(0.0f, 0.0f), vec2(100.0f, 100.0f)); for (int i = 0; i < physicsBodies.size(); ++i) { physicsBodies[i].DebugRender(debugRenderer); } for (int i = 0; i < physicsJoints.size(); ++i) { physicsJoints[i].DebugRender(debugRenderer); } contextPtr->EndScene(); counter.EndCounting(); avgFps += counter.GetFps(); iterations++; if (iterations > 10) { SetWindowTextA(hWnd, formatString("fps: %d", avgFps / iterations).c_str()); iterations = 0; avgFps = 0; } } }
bool geometry_utils::from_wkb(boost::ptr_vector<geometry_type>& paths, const char* wkb, unsigned size, wkbFormat format) { std::size_t geom_count = paths.size(); wkb_reader reader(wkb, size, format); reader.read(paths); if (paths.size() > geom_count) return true; return false; }
inline bool command::fetch(std::vector<variant>& row) { if (0 == m_hnd.stmt) return false; if (m_cols.empty()) columns(); const sword r(lib::singleton().p_OCIStmtFetch2(m_hnd.stmt, m_hnd.err, 1, OCI_FETCH_NEXT, 1, OCI_DEFAULT)); if (OCI_NO_DATA == r) return false; m_hnd.check(r); row.resize(m_cols.size()); for (size_t i(0); i < m_cols.size(); ++i) m_cols[i](row[i]); return true; }
inline bool command::fetch(std::vector<variant>& row) { if (!m_stmt) return false; if (m_cols.empty()) columns(); const int r(lib::singleton().p_mysql_stmt_fetch(m_stmt)); if (MYSQL_NO_DATA == r) return false; check(1 != r); row.resize(m_cols.size()); for (size_t i(0); i < m_cols.size(); ++i) check(m_cols[i](m_stmt, (unsigned int)i, row[i]) == 0); return true; }
inline bool command::fetch(std::vector<variant>& row) { if (lib::error(m_req)) return false; if (m_cols.empty()) columns(); const int r(lib::singleton().p_cci_cursor(m_req, 1, CCI_CURSOR_CURRENT, &m_err)); if (CCI_ER_NO_MORE_DATA == r) return false; check(r); check(lib::singleton().p_cci_fetch(m_req, &m_err)); row.resize(m_cols.size()); for (size_t i(0); i < m_cols.size(); ++i) if (lib::error(m_cols[i](m_req, i, row[i]))) throw std::runtime_error("CUBRID error"); return true; }
const Value MessageSelectorEnv::specialValue(const string& id) const { Value v; // TODO: Just use a simple if chain for now - improve this later if ( id=="delivery_mode" ) { v = msg.getEncoding().isPersistent() ? PERSISTENT : NON_PERSISTENT; } else if ( id=="redelivered" ) { v = msg.getDeliveryCount()>0 ? true : false; } else if ( id=="priority" ) { v = int64_t(msg.getPriority()); } else if ( id=="correlation_id" ) { MessageId cId = msg.getEncoding().getCorrelationId(); if (cId) { returnedStrings.push_back(new string(cId.str())); v = returnedStrings[returnedStrings.size()-1]; } } else if ( id=="message_id" ) { MessageId mId = msg.getEncoding().getMessageId(); if (mId) { returnedStrings.push_back(new string(mId.str())); v = returnedStrings[returnedStrings.size()-1]; } } else if ( id=="to" ) { v = EMPTY; // Hard to get this correct for both 1.0 and 0-10 } else if ( id=="reply_to" ) { v = EMPTY; // Hard to get this correct for both 1.0 and 0-10 } else if ( id=="absolute_expiry_time" ) { qpid::sys::AbsTime expiry = msg.getExpiration(); // Java property has value of 0 for no expiry v = (expiry==qpid::sys::FAR_FUTURE) ? 0 : qpid::sys::Duration(qpid::sys::AbsTime::Epoch(), expiry) / qpid::sys::TIME_MSEC; } else if ( id=="creation_time" ) { // Use the time put on queue (if it is enabled) as 0-10 has no standard way to get message // creation time and we're not paying attention to the 1.0 creation time yet. v = int64_t(msg.getTimestamp() * 1000); // getTimestamp() returns time in seconds we need milliseconds } else if ( id=="jms_type" ) { // Currently we can't distinguish between an empty JMSType and no JMSType // We'll assume for now that setting an empty JMSType doesn't make a lot of sense const string jmsType = msg.getAnnotation("jms-type").asString(); if ( !jmsType.empty() ) { returnedStrings.push_back(new string(jmsType)); v = returnedStrings[returnedStrings.size()-1]; } } else { v = Value(); } return v; }
double distance::getEuclidean2(boost::ptr_vector<double>& v1, boost::ptr_vector<double>& v2) { double euclidean = 0; int n = v1.size() == v2.size() ? v1.size() : 0; if (n > 0) { for (boost::ptr_vector<double>::iterator it1 = v1.begin(), it2 = v2.begin(); it1 != v1.end(), it2 != v2.end(); it1++, it2++) { euclidean += (*it1 - *it2)*(*it1 - *it2); } euclidean = sqrt(euclidean); return euclidean; } else return (double)-1; }
void set(const string& id, const qb::Value& value) { if (value.type==qb::Value::T_STRING) { strings.push_back(new string(*value.s)); values[id] = strings[strings.size()-1]; } else { values[id] = value; } }
/** function for diffusion axis size (enlargement) estimation */ void LoopOperator::forwardEstimation_DiffusionEnlarement( boost::ptr_vector<MeshContext>& contextStack , FitobCalculator* calc , DVector& gradValues, int globalVariableIndex, int& stackIndex , double timeStamp ) const { // if the index already below the index then nothing to do // this is the exit condition for instructions below "timeStamp" if ( stackIndex >= (int)contextStack.size() ) return; // EXIT IF NEEDED // call the body N times for (int ind = 0; ind < nrLoop_ ; ind++){ loopBody_->forwardEstimation_DiffusionEnlarement( contextStack , calc , gradValues , globalVariableIndex , stackIndex , timeStamp); FITOB_OUT_LEVEL3(verb(),"LoopOperator::forwardEstimation:" << stackIndex << " contextStack.size():" << contextStack.size() << " ind:"<<ind << " nrLoop:" << nrLoop_); } }
typename Argc_T<CON>::type Argc_T<CON>:: getData(RLMachine& machine, const boost::ptr_vector<libReallive::ExpressionPiece>& p, unsigned int& position) { type return_vector; for (; position < p.size(); ) return_vector.push_back(CON::getData(machine, p, position)); return return_vector; }
void set_target(engine::pointer z){ //cooltime(); if (cooldown < 1){ for(short i = 0; i < ammo.size(); i++){ if (!ammo[i].fired){ ammo[i].fired = true; break; } } } }
void init(unsigned int thread_count) { voxel_data.resize(thread_count); for (unsigned int index = 0; index < thread_count; ++index) { voxel_data[index].space.resize(q_count); voxel_data[index].odf.resize(ti.half_vertices_count); voxel_data[index].fa.resize(max_fiber_number); voxel_data[index].dir_index.resize(max_fiber_number); voxel_data[index].dir.resize(max_fiber_number); } for (unsigned int index = 0; index < process_list.size(); ++index) process_list[index].init(*this); }
void ThetaOperator::forwardEstimation_DiffusionEnlarement( boost::ptr_vector<MeshContext>& contextStack , FitobCalculator* calc , DVector& gradValues, int globalVariableIndex, int& stackIndex , double timeStamp ) const { // if the index already below the index then nothing to do // this is the exit condition for instructions below "timeStamp" if ( stackIndex >= (int)contextStack.size() ) return; // EXIT IF NEEDED // here we only increase the stack index stackIndex = stackIndex + 1; }
/// compute the resulting force of all force field objects. d_vector getObjForce(vrpn_float64 *pos, vrpn_float64 *vel) { int i; for (i=0; i<3; ++i) { m_curforce[i]=0.0; m_curpos[i]=pos[i]; m_curvel[i]=vel[i]; } // force field objects int nobj = m_FFEffects.size(); for (i=0; i<nobj; ++i) { m_curforce = m_curforce + m_FFEffects[i].calcForce (m_curpos); } return m_curforce; };
void thread_run(unsigned char thread_index,unsigned char thread_count, const std::vector<unsigned char>& mask) { unsigned int sum_mask = std::accumulate(mask.begin(),mask.end(),(unsigned int)0)/thread_count; unsigned int cur = 0; for(unsigned int voxel_index = thread_index; voxel_index < dim.size() && (thread_index != 0 || check_prog(cur,sum_mask));voxel_index += thread_count) { if (!mask[voxel_index]) continue; cur += mask[voxel_index]; voxel_data[thread_index].init(); voxel_data[thread_index].voxel_index = voxel_index; for (int index = 0; index < process_list.size(); ++index) process_list[index].run(*this,voxel_data[thread_index]); if(prog_aborted()) break; } }
void ThetaOperator::forwardEstimation( boost::ptr_vector<MeshContext>& contextStack , FitobCalculator* calc , int& stackIndex , double& timeStamp ){ FITOB_OUT_LEVEL3(verb(),"ThetaOperator::forwardEstimation stackIndex:" << stackIndex << "timeStamp" << timeStamp << " contextStack.size():" << contextStack.size()); MeshContext& actualContext = contextStack[stackIndex]; if (thetaExpression_->isConstantExpression(actualContext) == false){ FITOB_ERROR_EXIT(" ThetaOperator, theta expression is not constant "); } // evaluate the the expression (theta time) and store it thetaTime_ = thetaExpression_->eval(actualContext.minGlobCoord()); // todo: these values now are not taken in consideration, // This might be a future feature, to split up one Theta operator in small theta operators // in case of too large macro time step // 19.09.2010 -> at todays knowledge this is not necessary, this would only make things worse maxThetaTime_ = 10.0; //calc->getXMLConfiguration().get()->getDoubleConfiguration("thetaconfigurations.solver.maxThetaStep.<xmlattr>.value" ); nr_Theta_ = ceil(thetaTime_/maxThetaTime_); const boost::shared_ptr<ModelCollection>& factorModels = calc->getModelCollection(); const boost::shared_ptr<ScriptModel>& scriptModel = calc->getScriptModel(); const OperatorSequence& scriptBody = scriptModel->bodyOpSeq(); const Domain& actDom = actualContext.getDom(); int nrFactors = factorModels->nrFactors(); Domain newDom(actDom); FITOB_OUT_LEVEL3(verb(),"ThetaOperator::forwardEstimation nrFactors:" << factorModels->nrFactors() << " thetaTime:" << thetaTime_ ); for (int factorIndex = 0 ; factorIndex < nrFactors ; factorIndex++) { const FactorModelBase& model = factorModels->getModel(factorIndex); int globalIndex = model.getGlobalIndex(); const DVector& startVal = calc->getStartDomain()->getGradedAxis(globalIndex); // get the points of the normal distribution DVector stdPoints; returnScaledNormalDistribution( actDom.getMaximalLevel() , factorModels->stdFactor(factorIndex) , 1 , stdPoints ); FITOB_OUT_LEVEL3(verb(),"ThetaOperator::forwardEstimation factorIndex:" << factorIndex << " P.size():" << stdPoints.size()); // here we calculate the scaling if (startVal.size() > 1){ for (unsigned int pointI = 0; pointI < stdPoints.size() ; pointI++ ){ double endVal = 0.0; model.forwardEstimation(startVal[pointI] , timeStamp + thetaTime_ , stdPoints[pointI] , actDom.getAverage() , endVal ); if (verb()>3){ std::cout << endVal << ","; } stdPoints[pointI] = endVal; } if (verb()>3) std::cout << std::endl; } else { for (unsigned int pointI = 0; pointI < stdPoints.size() ; pointI++ ){ double endVal = 0.0; model.forwardEstimation(startVal[0] , timeStamp + thetaTime_ , stdPoints[pointI] , actDom.getAverage() , endVal ); if (verb()>3){ std::cout << endVal << ","; } stdPoints[pointI] = endVal; } if (verb()>3) std::cout << std::endl; } //and call forwardEstimation_DiffusionEnlarement int stackIndex_tmp = 0; scriptBody.forwardEstimation_DiffusionEnlarement( contextStack , calc ,stdPoints , globalIndex , stackIndex_tmp , timeStamp ); // sort stdPoints vector - not necessary (even in mean reversion case) // - this is not necessary since we estimate the values from 0 till T and not for dT std::sort( stdPoints.begin(),stdPoints.end() ); // set the axis in the new domain newDom.setAxis(stdPoints,globalIndex); } // add new context, extend contextStack contextStack.push_back(new MeshContext(newDom,timeStamp)); FITOB_OUT_LEVEL3(verb(),"ThetaOperator::forwardEstimation New Domain:" << newDom.toString() ); timeStamp = timeStamp + thetaTime_; stackIndex = stackIndex + 1; }
void end(MatFile& writer) { for (unsigned int index = 0; index < process_list.size(); ++index) process_list[index].end(*this,writer); }
std::pair<size_t, size_t> tune_params( const double* divs, size_t num_bags, const std::vector<label_type> &labels, const boost::ptr_vector<Kernel> &kernels, const std::vector<double> &c_vals, const svm_parameter &svm_params, size_t folds, size_t num_threads) { typedef std::pair<size_t, size_t> config; size_t num_kernels = kernels.size(); if (num_kernels == 0) { BOOST_THROW_EXCEPTION(std::domain_error( "no kernels in the kernel group")); } else if (num_kernels == 1 && c_vals.size() == 1) { // only one option, we already know what's best return config(0, 0); } // want to be able to take sub-lists of kernels. // this is like c_array(), but constness is slightly different and // it works in old, old boosts. const Kernel * const * kern_array = reinterpret_cast<const Kernel* const*>(&kernels.begin().base()[0]); // how many threads are we using? num_threads = npdivs::get_num_threads(num_threads); if (num_threads > num_kernels) num_threads = num_kernels; if (num_threads == 1) { // don't actually make a new thread if it's just 1-threaded double score; return pick_rand(tune_params_single(divs, num_bags, labels, kern_array, num_kernels, c_vals, svm_params, folds, &score)); } // grunt work to set up multithreading boost::ptr_vector< tune_params_worker<label_type> > workers; std::vector<boost::exception_ptr> errors(num_threads); boost::thread_group worker_threads; std::vector< std::vector<config> > results(num_threads); std::vector<double> scores(num_threads, 0); size_t kerns_per_thread = (size_t) std::ceil(double(num_kernels) / num_threads); size_t kern_start = 0; // give each thread a few kernels and get their most-accurate configs // TODO: better allocation algo for (size_t i = 0; i < num_threads; i++) { int n_kerns = (int)(std::min(kern_start+kerns_per_thread, num_kernels)) - (int)(kern_start); if (n_kerns <= 0) break; workers.push_back(new tune_params_worker<label_type>( divs, num_bags, labels, kern_array + kern_start, n_kerns, c_vals, svm_params, folds, &results[i], &scores[i], errors[i] )); worker_threads.create_thread(boost::ref(workers[i])); kern_start += kerns_per_thread; } worker_threads.join_all(); for (size_t i = 0; i < num_threads; i++) if (errors[i]) boost::rethrow_exception(errors[i]); // get all the best configs into one vector double best_score = *std::max_element( scores.begin(), scores.end()); std::vector<config> best_configs; if (best_score == -std::numeric_limits<double>::infinity()) { FILE_LOG(logERROR) << "all kernels were terrible"; BOOST_THROW_EXCEPTION(std::domain_error("all kernels were terrible")); } kern_start = 0; for (size_t i = 0; i < num_threads; i++) { if (scores[i] == best_score) { for (size_t j = 0; j < results[i].size(); j++) { config cfg = results[i][j]; best_configs.push_back( config(cfg.first + kern_start, cfg.second)); } } kern_start += kerns_per_thread; } return pick_rand(best_configs); }
void SnpEstimation::result(const boost::ptr_vector<Snp> &snpList, const boost::ptr_vector<Region> ®ionList){ bool sign = !(snpList.front().getSign()==0); double i2 = (m_bt)? usefulTools::dnorm(usefulTools::qnorm(m_prevalence))/(m_prevalence): 0; i2 = i2*i2; double adjust = 0.0; size_t countNum = 0; double sampleSize = 0.0; std::vector<double> heritability; std::vector<double> variance; std::vector<double> effective; for(size_t i = 0; i < regionList.size(); ++i){ // add stuff heritability.push_back(0.0); variance.push_back(regionList[i].getVariance()); effective.push_back(0.0); } std::ofstream fullOutput; bool requireFullOut = false; if(!m_output.empty()) requireFullOut = true; if(requireFullOut){ std::string fullOutName = m_output; fullOutName.append(".res"); fullOutput.open(fullOutName.c_str()); if(!fullOutput.is_open()){ requireFullOut = false; fprintf(stderr, "Cannot access output file: %s\n", fullOutName.c_str()); fprintf(stderr, "Will only provide basic output\n"); } else{ fullOutput << "Chr\tLoc\trsID\tZ\tF\tH\tStatus" << std::endl; } } for(size_t i = 0; i < snpList.size(); ++i){ if(requireFullOut){ fullOutput << snpList[i].getChr() << "\t" << snpList[i].getLoc() << "\t" << snpList[i].getRs() << "\t" << snpList[i].getTStat() << "\t"<< snpList[i].getFStat() << "\t" << snpList[i].getHeritability() << "\t" << snpList[i].getStatus() << std::endl; } for(size_t j = 0; j < regionList.size(); ++j){ // if(j ==0) std::cerr << snpList[i].flag(j) << std::endl; if(snpList[i].flag(j)) heritability[j]+=snpList[i].getHeritability(); if(snpList[i].flag(j)) effective[j] += snpList[i].getEffective(); } sampleSize +=(double)(snpList[i].getSampleSize()); countNum++; if(m_bt){ double portionCase = (double)(snpList[i].getNCase()) / (double)(snpList[i].getSampleSize()); adjust+= ((1.0-m_prevalence)*(1.0-m_prevalence))/(i2*portionCase*(1-portionCase)); } } if(requireFullOut) fullOutput.close(); double adjustment = adjust/(double)countNum; // we use the average adjustment value here if(!m_bt) adjustment = m_extreme; double averageSampleSize = sampleSize/(double)countNum; if(!m_output.empty()) requireFullOut =true; std::ofstream sumOut; if(requireFullOut){ std::string sumOutName = m_output; sumOutName.append(".sum"); sumOut.open(sumOutName.c_str()); if(!sumOut.is_open()){ fprintf(stderr, "Cannot access output file %s\n", sumOutName.c_str()); fprintf(stderr, "Will output to stdout instead\n"); requireFullOut=false; } } // We separate it, because it is possible for the previous if to change the requireFullOut flag if(!requireFullOut){ // Only output to the stdout std::cout << "Region\tHeritability\tVariance" << std::endl; for(size_t i = 0; i < regionList.size(); ++i){ std::cout << regionList[i].getName() << "\t" << adjustment*heritability[i] << "\t"; if(!sign) std::cout << adjustment*(2.0*(effective[i]*adjustment*adjustment+2.0*adjustment*heritability[i]*averageSampleSize)/(averageSampleSize*averageSampleSize)) << std::endl; else std::cout << adjustment*adjustment*variance[i] << std::endl; } } else{ sumOut << "Region\tHeritability\tVariance" << std::endl; std::cout << "Region\tHeritability\tVariance" << std::endl; for(size_t i = 0; i < regionList.size(); ++i){ sumOut << regionList[i].getName() << "\t" << adjustment*heritability[i] << "\t"; std::cout << regionList[i].getName() << "\t" << heritability[i] << "\t"; if(!sign){ // We use effective number sumOut << adjustment*(2.0*(effective[i]*adjustment*adjustment+2.0*adjustment*heritability[i]*averageSampleSize)/(averageSampleSize*averageSampleSize)) << std::endl; std::cout << adjustment*(2.0*(effective[i]*adjustment*adjustment+2.0*adjustment*heritability[i]*averageSampleSize)/(averageSampleSize*averageSampleSize)) << std::endl; } else{ sumOut << adjustment*adjustment*variance[i] << std::endl; std::cout << adjustment*adjustment*variance[i] << std::endl; } } sumOut.close(); } }
void set(const string& id, const char* value) { strings.push_back(new string(value)); values[id] = strings[strings.size()-1]; }
unsigned num_geometries() const { return geom_cont_.size(); }
void SnpEstimation::estimate(GenotypeFileHandler &genotypeFileHandler, boost::ptr_vector<Snp> &snpList, boost::ptr_vector<Region> ®ionList){ // This contains the genotypes from the reference panel, the main container for this function boost::ptr_deque<Genotype> genotype; // This contains the index of the SNPs included in the genotype std::deque<size_t> snpLoc; // This should be invoked when we came to the end of chromosome / region bool windowEnd = false; // Initialize the linkage and decompose Linkage linkage(m_thread); Decomposition decompose(m_thread); fprintf(stderr, "Estimate SNP heritability\n\n"); size_t doneItems = 0; size_t totalSnp = snpList.size(); std::string chr = ""; // This is use for indicating whether if the whole genome is read bool completed = false; std::vector<size_t> boundary; bool starting = true; size_t checking = 0; //DEBUG while(!completed){ // Keep doing this until the whole genome is read progress(doneItems, totalSnp, chr); // only used when the finalizeBuff is true, this indicate whether if the last block is coming from somewhere new bool retainLastBlock=false; while(boundary.size() < 5 && !completed && !windowEnd){ genotypeFileHandler.getBlock(snpList, genotype, snpLoc, windowEnd, completed,boundary, false); bool boundChange = false; linkage.construct(genotype, snpLoc, boundary, snpList, m_ldCorrection, boundChange); if(boundChange && boundary.back()==snpLoc.size()){ windowEnd=true; boundary.pop_back(); } else if(boundChange&&snpList.at(snpLoc[boundary.back()]).getLoc()- snpList.at(snpLoc[boundary.back()-1]).getLoc() > m_blockSize){ retainLastBlock = true; windowEnd=true; } genotypeFileHandler.getBlock(snpList, genotype, snpLoc, windowEnd, completed,boundary, true); linkage.construct(genotype, snpLoc, boundary, snpList, m_ldCorrection, boundChange); } if(windowEnd && !retainLastBlock && boundary.size() > 2){ //Check whether if we need to merge the two blocks size_t indexOfLastSnpOfSecondLastBlock = snpLoc.at(boundary.back()-1); // just in case size_t lastSnp = snpLoc.back(); if(snpList.at(lastSnp).getLoc()-snpList.at(indexOfLastSnpOfSecondLastBlock).getLoc() <= m_blockSize){ boundary.pop_back(); bool boundChange=false; linkage.construct(genotype, snpLoc, boundary, snpList, m_ldCorrection, boundChange); } } if(retainLastBlock && !windowEnd) throw std::runtime_error("Impossible combination of windowEnd and retain last block!"); decompose.run(linkage, snpLoc, boundary, snpList, windowEnd, !retainLastBlock, starting, regionList); doneItems= snpLoc.at(boundary.back()); chr = snpList[snpLoc[boundary.back()]].getChr(); if(retainLastBlock){ // Then we must remove everything except the last block // because finalizeBuff must be true here size_t update = boundary.back(); genotype.erase(genotype.begin(), genotype.begin()+update); snpLoc.erase(snpLoc.begin(), snpLoc.begin()+update); boundary.clear(); boundary.push_back(0); linkage.clear(update); starting = true; windowEnd = false; retainLastBlock = false; } else if(windowEnd){ snpLoc.clear(); boundary.clear(); genotype.clear(); linkage.clear(); starting = true; windowEnd = false; retainLastBlock = false; } else{ starting = false; size_t update=boundary[1]; genotype.erase(genotype.begin(), genotype.begin()+update); snpLoc.erase(snpLoc.begin(), snpLoc.begin()+update); linkage.clear(update); for(size_t i = 0; i < boundary.size()-1; ++i) boundary[i] = boundary[i+1]-update; boundary.pop_back(); } } progress(totalSnp, totalSnp, ""); fprintf(stderr, "\n\nEstimated the SNP Heritability, now proceed to output\n"); }
void MeshAssigmentOperator::backwardCalculation( boost::ptr_vector<MeshContext>& contextStack , FitobCalculator* calc , int& stackIndex , double& timeStamp ){ FITOB_OUT_LEVEL3(verb(),"MeshAssigmentOperator::backwardCalculation stackIndex:" << stackIndex << " contextStack.size():" << contextStack.size() << " timeStamp:" << timeStamp ); FITOB_OUT_LEVEL3(verb(),"MeshAssigmentOperator::backwardCalculation Domain:" << contextStack[stackIndex].getDom().toString() ); // if we get here then we just have a simple mesh assignment , no if condition will be considered here contextStack[stackIndex].getMesh()->setValues( assignExpression_ , contextStack[stackIndex].minGlobCoord()); //apply constraints DVector globCoord = contextStack[stackIndex].getDom().getAverage(); contextStack[stackIndex].getMesh()->applyConstraints( &(calc->getScriptModel().get()->constrainOpSeq()) , globCoord ); // do eventually plotting calc->getPlotter()->plot( &(contextStack[stackIndex]) , calc->getScriptModel()->getModelName() ); }