Пример #1
0
Params::Params(const string &params_file, const long seed_from_command_line) {
  try {
    po::options_description eems_options("EEMS options from parameter file");
    eems_options.add_options()
      ("seed", po::value<long>(&seed)->default_value(seed_from_command_line), "Random seed")
      ("datapath", po::value<string>(&datapath)->required(), "Path to coord/sites/outer files")
      ("mcmcpath", po::value<string>(&mcmcpath)->required(), "Path to output directory")
      ("prevpath", po::value<string>(&prevpath)->default_value(""), "Path to previous output directory")
      ("gridpath", po::value<string>(&gridpath)->default_value(""), "Path to demes/edges/ipmap files")
      ("nIndiv", po::value<int>(&nIndiv)->required(), "nIndiv")
      ("nSites", po::value<int>(&nSites)->required(), "nSites")
      ("nDemes", po::value<int>(&nDemes)->default_value(1), "nDemes")
      ("diploid", po::value<bool>(&diploid)->default_value(true), "diploid")
      ("distance", po::value<string>(&distance)->default_value("euclidean"), "distance")
      ("numMCMCIter", po::value<int>(&numMCMCIter)->default_value(1), "numMCMCIter")
      ("numBurnIter", po::value<int>(&numBurnIter)->default_value(0), "numBurnIter")
      ("numThinIter", po::value<int>(&numThinIter)->default_value(0), "numThinIter")
      ("mSeedsProposalS2", po::value<double>(&mSeedsProposalS2)->default_value(0.01), "mSeedsProposalS2")
      ("qSeedsProposalS2", po::value<double>(&qSeedsProposalS2)->default_value(0.1), "qSeedsProposalS2")
      ("mEffctProposalS2", po::value<double>(&mEffctProposalS2)->default_value(0.1), "mEffctProposalS2")
      ("qEffctProposalS2", po::value<double>(&qEffctProposalS2)->default_value(0.001), "qEffctProposalS2")
      ("mrateMuProposalS2", po::value<double>(&mrateMuProposalS2)->default_value(0.01), "mrateMuProposalS2")
      ("qVoronoiPr", po::value<double>(&qVoronoiPr)->default_value(0.05), "qVoronoiPr")
      ("mrateShape", po::value<double>(&mrateShape_2)->default_value(0.001), "mrateShape")
      ("qrateShape", po::value<double>(&qrateShape_2)->default_value(0.001), "qrateShape")
      ("sigmaShape", po::value<double>(&sigmaShape_2)->default_value(0.001), "sigmaShape")
      ("qrateScale", po::value<double>(&qrateScale_2)->default_value(1.0), "qrateScale")
      ("mrateScale", po::value<double>(&mrateScale_2)->default_value(1.0), "mrateScale")
      ("sigmaScale", po::value<double>(&sigmaScale_2)->default_value(1.0), "sigmaScale")
      ("negBiProb", po::value<double>(&negBiProb)->default_value(0.67), "negBiProb")
      ("negBiSize", po::value<int>(&negBiSize)->default_value(10), "negBiSize") ;
    ifstream instrm(params_file.c_str());
    po::variables_map vm;
    po::store(po::parse_config_file(instrm,eems_options,true),vm);
    po::notify(vm);
    instrm.close();
  } catch(exception& e) {
    cerr << "[EEMS::Params] Error parsing input parameters in " << params_file << ": " << endl;
    cerr << e.what() << endl; exit(1);
  } 
  mrateShape_2 /= 2.0;
  qrateShape_2 /= 2.0;
  sigmaShape_2 /= 2.0;
  mrateScale_2 /= 2.0;
  qrateScale_2 /= 2.0;
  sigmaScale_2 /= 2.0;
  /*
    There are two functions for testing whether the prior and the likelihood are computed correctly:
    * test_prior(parameters) + test_likelihood(parameters)
    * eval_prior() + eval_likelihood(), which use the current parameter values
    If testing = true, then the function check_ll_computation() will be called after each MCMC iteration,
    and it will check that the current prior, nowpi, is the same as test_prior(current parameters)
    as well as that the currrent likelihood, nowll, is the same as test_likelihood(current parameters)
   */
  testing = false;
  mEffctHalfInterval = 2.0;
  qEffctHalfInterval = 0.1;
  mrateMuHalfInterval = 2.4771; // log10(300)
}
Пример #2
0
//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------
int FillEphemerisStore(const vector<string>& files, SP3EphemerisStore& PE,
                                                     GPSEphemerisStore& BCE)
{
   try
   {
      int nread = 0;
      Rinex3NavHeader rnh;
      Rinex3NavData rne;
      for(size_t nfile = 0; nfile < files.size(); nfile++) {
         if(files[nfile].empty()) {
            Exception e("File name is empty");
            GPSTK_THROW(e);
         }

         if(isRinex3NavFile(files[nfile]) || isRinexNavFile(files[nfile])) {
            Rinex3NavStream instrm(files[nfile].c_str());
            instrm.exceptions(fstream::failbit);
            try {
               instrm >> rnh;
               while (instrm >> rne) {
                  // check health...
                  if(rne.health == 0)
                     BCE.addEphemeris(rne);
               }
               nread++;
            }
            catch(Exception& e) {
               GPSTK_RETHROW(e);
            }
         }

         else if(isSP3File(files[nfile])) {
            try {
               PE.loadFile(files[nfile]);
               nread++;
            }
            catch(Exception& e) { GPSTK_RETHROW(e); }
         }
         else {
            Exception e("File " + files[nfile]
                  + " is neither Rinex Nav nor SP3 file.");
            GPSTK_THROW(e);
         }
      }
Пример #3
0
// Read a matrix, with unknown dimensions, from a text file
// Return an empty matrix (0 rows, 0 columns) if there is an error
MatrixXd readMatrixXd(const string &filename) {
  ifstream instrm(filename.c_str(), ios::in);
  if (!instrm.is_open( )) { return (MatrixXd::Zero(0,0)); }
  string line; getline(instrm,line);
  boost::algorithm::trim(line);
  // Split the first line into numbers
  VectorXd row = split(line);
  // This tells us the number of columns
  int cols = row.size();
  if (!cols) { return (MatrixXd::Zero(0,0)); }
  MatrixXd mat(1,cols); mat.row(0) = row;
  while (getline(instrm,line)) {
    boost::algorithm::trim(line);
    row = split(line);
    if (row.size()==cols) {
      // Resize the matrix to add each row (done once at the start of EEMS, so okay)
      insertRow(mat,row);
    } else {
      return (MatrixXd::Zero(0,0));
    }
  }
  instrm.close();
  return(mat);
}
Пример #4
0
void testGETAWAY() {
  std::cout << "=>start test GETAWAY\n";

  std::string pathName = getenv("RDBASE");
  std::string sdfName =
      pathName + "/Code/GraphMol/Descriptors/test_data/PBF_egfr.sdf";

  RDKit::SDMolSupplier reader(sdfName, true, false);
  std::string fName =
      pathName + "/Code/GraphMol/Descriptors/test_data/GETAWAY.new.out";

  std::ifstream instrm(fName.c_str());

  // std::string ofName =
  //     pathName + "/Code/GraphMol/Descriptors/test_data/GETAWAY.new.out";
  // std::ofstream outstrm(ofName.c_str());

  std::string line;
  std::vector<std::vector<std::string> > data;

  while (std::getline(instrm, line)) {
    std::string phrase;
    std::vector<std::string> row;
    std::stringstream ss(line);
    while (std::getline(ss, phrase, '\t')) {
      row.push_back(phrase);
    }

    data.push_back(row);
  }

  int nDone = 0;
  while (!reader.atEnd()) {
    // if (nDone > 10) {
    //   break;
    // }
    RDKit::ROMol *m = reader.next();
    TEST_ASSERT(m);
    std::string nm;
    m->getProp("_Name", nm);

    std::vector<double> dgetaway;

    RDKit::Descriptors::GETAWAY(*m, dgetaway);

    std::vector<std::string> myrow = data[nDone];
    std::string inm = myrow[0];
    TEST_ASSERT(inm == nm);
    // std::cout <<  "\n";
    // int numAtoms = m->getNumAtoms();
    // std::cout << "number of Atoms : " << numAtoms << "\n";

    // outstrm << nm << "\t";
    for (int i = 0; i < 273; i++) {
      double ref = atof(myrow[i + 1].c_str());

      if (fabs(ref) > 1) {
        if (fabs((ref - dgetaway[i]) / ref) > 0.01) {
          std::cerr << "value mismatch: pos" << i << " " << inm
                    << " dragon: " << ref << " rdkit: " << dgetaway[i]
                    << std::endl;
        }
      }
      if (fabs(ref) <= 1) {
        if (fabs(ref - dgetaway[i]) > 0.02) {
          std::cerr << "value mismatch: pos" << i << " " << inm
                    << " dragon: " << ref << " rdkit: " << dgetaway[i]
                    << std::endl;
        }
      }
      // if (i != 0) outstrm << "\t";
      // outstrm << dgetaway[i];
      TEST_ASSERT(fabs(ref - dgetaway[i]) < 0.05);
    }
    // outstrm << "\n";
    delete m;
    ++nDone;
    // if (nDone > 50) break;
  }

  BOOST_LOG(rdErrorLog) << "test on : " << nDone << " molecules done"
                        << std::endl;
}
Пример #5
0
void testMORSE() {
  std::cout << "=>start test MORSE\n";

  std::string pathName = getenv("RDBASE");
  std::string sdfName =
      pathName + "/Code/GraphMol/Descriptors/test_data/PBF_egfr.sdf";

  RDKit::SDMolSupplier reader(sdfName, true, false);

  std::string fName =
      pathName + "/Code/GraphMol/Descriptors/test_data/MORSE.out";

  std::ifstream instrm(fName.c_str());

  std::string line;
  std::vector<std::vector<std::string> > data;

  while (std::getline(instrm, line)) {
    std::string phrase;
    std::vector<std::string> row;
    std::stringstream ss(line);
    while (std::getline(ss, phrase, '\t')) {
      row.push_back(phrase);
    }

    data.push_back(row);
  }

  std::cout << "=>read file\n";

  int nDone = 0;
  while (!reader.atEnd()) {
    RDKit::ROMol *m = reader.next();
    TEST_ASSERT(m);
    std::string nm;
    m->getProp("_Name", nm);

    std::vector<double> dmorse;

    RDKit::Descriptors::MORSE(*m, dmorse, -1);

    std::vector<std::string> myrow = data[nDone];
    std::string inm = myrow[0];
    TEST_ASSERT(inm == nm);

    for (int i = 0; i < dmorse.size(); i++) {
      double ref = atof(myrow[i + 1].c_str());

      if (fabs(ref) > 0.01) {
        if (fabs((ref - dmorse[i]) / ref) > 1) {
          std::cout << "value mismatch: pos" << i << " " << inm << " " << ref
                    << " " << dmorse[i] << std::endl;
        }
      }

      if (fabs(ref) < 0.01) {
        if (fabs(ref - dmorse[i]) > 0.02) {
          std::cout << "value mismatch: pos" << i << " " << inm << " " << ref
                    << " " << dmorse[i] << std::endl;
        }
      }
      if (ref > 1 && fabs(ref - dmorse[i]) / ref > 0.02) {
        std::cout << "value mismatch: pos" << i << " " << inm << " " << ref
                  << " " << dmorse[i] << std::endl;
      }
      // we're testing reasonably sized values and want to be sure that we're
      // within 2% of the reference.
      TEST_ASSERT(ref < 1 || fabs(ref - dmorse[i]) / ref < 0.02);
    }

    delete m;
    ++nDone;
  }

  BOOST_LOG(rdErrorLog) << "test on : " << nDone << " molecules done"
                        << std::endl;
}