void testSingleRateModel(Params ¶ms, NGSAlignment &aln, NGSTree &tree, string model, double *freq, DoubleVector &rate_info, StrVector &rate_name, bool write_info, const char *report_file) { char model_name[20]; NGSAlignment sum_aln(aln.num_states, 1, freq); ModelsBlock *models_block = new ModelsBlock; NGSTree sum_tree(params, &sum_aln); sum_aln.tree = &sum_tree; if (model == "") sprintf(model_name, "GTR+F1"); else sprintf(model_name, "%s+F1", model.c_str()); try { params.model_name = model_name; sum_tree.setModelFactory(new ModelFactory(params, &sum_tree, models_block)); sum_tree.setModel(sum_tree.getModelFactory()->model); sum_tree.setRate(sum_tree.getModelFactory()->site_rate); double bestTreeScore = sum_tree.getModelFactory()->optimizeParameters(false, write_info); cout << "LogL: " << bestTreeScore; cout << " / Rate: " << sum_tree.getRate()->getRate(0) << endl; } catch (...) { cout << "Skipped due to sparse matrix" << endl; //rate_info.push_back(MIN_SITE_RATE); rate_info.insert(rate_info.end(), rate_name.size(), MIN_SITE_RATE); return; } //return sum_tree.getRate()->getRate(0); rate_info.push_back(sum_tree.getRate()->getRate(0)); double *rate_mat = new double[aln.num_states*aln.num_states]; memset(rate_mat, 0, aln.num_states*aln.num_states*sizeof(double)); sum_tree.getModel()->getRateMatrix(rate_mat); rate_info.insert(rate_info.end(), rate_mat, rate_mat+sum_tree.getModel()->getNumRateEntries()); if (tree.getModel()->isReversible()) { sum_tree.getModel()->getStateFrequency(rate_mat); rate_info.insert(rate_info.end(), rate_mat, rate_mat+aln.num_states); } delete [] rate_mat; delete models_block; if (report_file) { DoubleMatrix tmp(1); tmp[0] = rate_info; reportNGSAnalysis(report_file, params, sum_aln, sum_tree, tmp, rate_name); } }
// must be mt-safe. don't use boost::python handles! double objectiveFunction(DoubleVector const &args) const { bpl::list args2; for (DoubleVector::const_iterator iter=args.begin(); iter != args.end(); iter++) { args2.append(*iter); } bpl::object result = m_CallbackFn(args2); return bpl::extract<double>(result); }
void RRSchedule::print_DoubleVector(DoubleVector _invect, std::ostream &stream = std::cout) { for (DoubleVector::const_iterator row = _invect.begin(); row != _invect.end(); ++row) { print_Vector(*row, stream); stream << '\n' << std::flush; } }
int RRSchedule::DVectMax(DoubleVector _invect) { int global_max = 0; for (DoubleVector::const_iterator tslot = _invect.begin(); tslot != _invect.end(); ++tslot) { global_max = std::max(VectMax(*tslot), global_max); } return global_max; }
int RRSchedule::DVectMin(DoubleVector _invect) { int global_min = max_per_time; for (DoubleVector::const_iterator tslot = _invect.begin(); tslot != _invect.end(); ++tslot) { global_min = std::min(VectMin(*tslot), global_min); } return global_min; }
void LowessSmoothing::smoothData(const DoubleVector& input_x, const DoubleVector& input_y, DoubleVector& smoothed_output) { if (input_x.size() != input_y.size()) { throw Exception::InvalidValue(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Sizes of x and y values not equal! Aborting... ", String(input_x.size())); } // unable to smooth over 2 or less data points (we need at least 3) if (input_x.size() <= 2) { smoothed_output = input_y; return; } Size input_size = input_y.size(); // const Size q = floor( input_size * alpha ); const Size q = (window_size_ < input_size) ? static_cast<Size>(window_size_) : input_size - 1; DoubleVector distances(input_size, 0.0); DoubleVector sortedDistances(input_size, 0.0); for (Size outer_idx = 0; outer_idx < input_size; ++outer_idx) { // Compute distances. // Size inner_idx = 0; for (Size inner_idx = 0; inner_idx < input_size; ++inner_idx) { distances[inner_idx] = std::fabs(input_x[outer_idx] - input_x[inner_idx]); sortedDistances[inner_idx] = distances[inner_idx]; } // Sort distances in order from smallest to largest. std::sort(sortedDistances.begin(), sortedDistances.end()); // Compute weigths. std::vector<double> weigths(input_size, 0); for (Size inner_idx = 0; inner_idx < input_size; ++inner_idx) { weigths.at(inner_idx) = tricube_(distances[inner_idx], sortedDistances[q]); } //calculate regression Math::QuadraticRegression qr; std::vector<double>::const_iterator w_begin = weigths.begin(); qr.computeRegressionWeighted(input_x.begin(), input_x.end(), input_y.begin(), w_begin); //smooth y-values double rt = input_x[outer_idx]; smoothed_output.push_back(qr.eval(rt)); } return; }
static void initialiseIndexScore () { int numEntries; char* info = getFileInfo ( MsparamsDir::instance ().getParamPath ( "indicies.txt" ), '>', 1, true, &numEntries ); for ( int i = 0 ; i < numEntries ; i++ ) { names.push_back ( ( i == 0 ) ? strtok ( info, "\n" ) : strtok ( NULL, "\n" ) ); DoubleVector dv (52); indexV.push_back ( dv ); fill ( dv.begin (), dv.end (), 0.0 ); for ( ; ; ) { char aa; double value; char* line = strtok ( NULL, "\n" ); if ( !strcmp ( line, ">" ) ) break; sscanf ( line, "%c %lf", &aa, &value ); indexV [i][aa-'A'] = value; } } initialised = true; }
Vector RRSchedule::compute_team_waits_for_week(DoubleVector _week) // Compute how long each team will wait in a week { DoubleVector team_played_counts; Vector team_wait; init2DEmpty(team_played_counts, max_teams, max_per_night); // First determine in which timeslot each team played int tslotNum = 0; for (DoubleVector::const_iterator _tslot = _week.begin(); _tslot != _week.end(); ++_tslot) { for (Vector::const_iterator team = _tslot->begin(); team != _tslot->end(); ++team) { team_played_counts[*team].push_back(tslotNum); } tslotNum ++; } // From that, determine how long a team will wait that week for (DoubleVector::const_iterator _team = team_played_counts.begin(); _team != team_played_counts.end(); ++_team) { if (_team->size() > 0) { team_wait.push_back(VectMax(*_team) - VectMin(*_team) - int(_team->size()) + 1); } else { team_wait.push_back(0); } } return team_wait; }
bool RandomNumberInputHandler::handleInput(const yarp::os::Bottle & input, const YarpString & senderChannel, yarp::os::ConnectionWriter * replyMechanism, const size_t numBytes) { #if (! defined(ODL_ENABLE_LOGGING_)) # if MAC_OR_LINUX_ # pragma unused(senderChannel,replyMechanism,numBytes) # endif // MAC_OR_LINUX_ #endif // ! defined(ODL_ENABLE_LOGGING_) ODL_OBJENTER(); //#### ODL_S2s("senderChannel = ", senderChannel, "got ", input.toString()); //#### ODL_P1("replyMechanism = ", replyMechanism); //#### ODL_I1("numBytes = ", numBytes); //#### bool result = true; try { if (0 < input.size()) { BaseChannel * theOutput = _shared.getOutput(); RandomNumberClient * theClient = (RandomNumberClient *) _shared.getClient(); if (theClient && theOutput) { int count; yarp::os::Value argValue(input.get(0)); if (argValue.isInt()) { count = argValue.asInt(); } else if (argValue.isDouble()) { count = static_cast<int>(argValue.asDouble()); } else { count = 1; } if (0 > count) { count = 1; } if (1 < count) { DoubleVector randResult; if (theClient->getRandomNumbers(count, randResult)) { yarp::os::Bottle message; if (0 < randResult.size()) { for (DoubleVector::const_iterator it(randResult.begin()); randResult.end() != it; ++it) { message.addDouble(*it); } } _shared.lock(); if (! theOutput->write(message)) { ODL_LOG("(! theOutput->write(message))"); //#### #if defined(MpM_StallOnSendProblem) Stall(); #endif // defined(MpM_StallOnSendProblem) } _shared.unlock(); } else { ODL_LOG("! (theClient->getRandomNumbers(count, randResult))"); //#### } } else if (0 < count) { double randResult; if (theClient->getOneRandomNumber(randResult)) { yarp::os::Bottle message; message.addDouble(randResult); _shared.lock(); if (! theOutput->write(message)) { ODL_LOG("(! theOutput->write(message))"); //#### #if defined(MpM_StallOnSendProblem) Stall(); #endif // defined(MpM_StallOnSendProblem) } _shared.unlock(); } else { ODL_LOG("! (theClient->getOneRandomNumber(randResult))"); //#### } } else { _shared.deactivate(); } } } } catch (...) { ODL_LOG("Exception caught"); //#### throw; } ODL_OBJEXIT_B(result); //#### return result; } // RandomNumberInputHandler::handleInput
void RateMeyerHaeseler::setRates(DoubleVector &rates) { clear(); insert(begin(), rates.begin(), rates.end()); }
bool RRSchedule::isPresent(DoubleVector _vect, Vector item) { return (std::find(_vect.begin(), _vect.end(), item) != _vect.end()); }