double pickRandomDistMat(const BoundsMatrix &mmat, RDNumeric::SymmMatrix<double> &distMat, RDKit::double_source_type &rng) { // make sure the sizes match up unsigned int npt = mmat.numRows(); CHECK_INVARIANT(npt == distMat.numRows(), "Size mismatch"); double largestVal = -1.0; double *ddata = distMat.getData(); for (unsigned int i = 1; i < npt; i++) { unsigned int id = i * (i + 1) / 2; for (unsigned int j = 0; j < i; j++) { double ub = mmat.getUpperBound(i, j); double lb = mmat.getLowerBound(i, j); CHECK_INVARIANT(ub >= lb, ""); double rval = rng(); // std::cerr<<i<<"-"<<j<<": "<<rval<<std::endl; double d = lb + (rval) * (ub - lb); ddata[id + j] = d; if (d > largestVal) { largestVal = d; } } } return largestVal; }
double pickRandomDistMat(const BoundsMatrix &mmat, RDNumeric::SymmMatrix<double> &distMat, int seed) { // make sure the sizes match up unsigned int npt = mmat.numRows(); CHECK_INVARIANT(npt == distMat.numRows(), "Size mismatch"); RDKit::rng_type &generator = RDKit::getRandomGenerator(); if (seed > 0) { generator.seed(seed); } double largestVal=-1.0; double *ddata = distMat.getData(); for (unsigned int i = 1; i < npt; i++) { unsigned int id = i*(i+1)/2; for (unsigned int j = 0; j < i; j++) { double ub = mmat.getUpperBound(i,j); double lb = mmat.getLowerBound(i,j); CHECK_INVARIANT(ub >= lb, ""); double rval = RDKit::getRandomVal(); double d = lb + (rval)*(ub - lb); ddata[id+j] = d; if(d>largestVal){ largestVal=d; } } } return largestVal; }
void readFromFile(const std::ifstream& input_file) { std::vector<std::string> lines; std::string line; while(!input_file.eof()) { std::getline(input_file, line); lines.push_back(line); } matrix.setDimensions(line.length(), lines.size()); for (int i = 0; i < lines.size(); i++) { line = lines.at(i); for (int j = 0; j < line.length(); j++) { short value = (line.at(j) == 'o' ? 1 : 0); matrix.set(j, i, value); } } }
void test1() { // test triangle smoothing unsigned int npt = 5; double x = sqrt(3.0); BoundsMatrix *mmat = new BoundsMatrix(npt); mmat->setUpperBound(0, 1, 1.0); mmat->setLowerBound(0, 1, 1.0); mmat->setUpperBound(0, 2, x); mmat->setLowerBound(0, 2, x); mmat->setUpperBound(0, 3, 10.0); mmat->setLowerBound(0, 3, 0.0); mmat->setUpperBound(0, 4, 10.0); mmat->setLowerBound(0, 4, 0.0); mmat->setUpperBound(1, 2, 1.0); mmat->setLowerBound(1, 2, 1.0); mmat->setUpperBound(1, 3, x); mmat->setLowerBound(1, 3, x); mmat->setUpperBound(1, 4, 10.0); mmat->setLowerBound(1, 4, 0.0); mmat->setUpperBound(2, 3, 1.0); mmat->setLowerBound(2, 3, 1.0); mmat->setUpperBound(2, 4, x); mmat->setLowerBound(2, 4, x); mmat->setUpperBound(3, 4, 1.0); mmat->setLowerBound(3, 4, 1.0); BoundsMatPtr mptr(mmat); triangleSmoothBounds(mptr); CHECK_INVARIANT(RDKit::feq(mmat->getUpperBound(0, 1), 1.0, 0.001), ""); CHECK_INVARIANT(RDKit::feq(mmat->getLowerBound(0, 1), 1.0, 0.001), ""); CHECK_INVARIANT(RDKit::feq(mmat->getUpperBound(0, 2), 1.732, 0.001), ""); CHECK_INVARIANT(RDKit::feq(mmat->getLowerBound(0, 2), 1.732, 0.001), ""); CHECK_INVARIANT(RDKit::feq(mmat->getUpperBound(0, 3), 2.732, 0.001), ""); CHECK_INVARIANT(RDKit::feq(mmat->getLowerBound(0, 3), 0.732, 0.001), ""); CHECK_INVARIANT(RDKit::feq(mmat->getUpperBound(0, 4), 3.464, 0.001), ""); CHECK_INVARIANT(RDKit::feq(mmat->getLowerBound(0, 4), 0.0, 0.001), ""); CHECK_INVARIANT(RDKit::feq(mmat->getUpperBound(1, 2), 1.0, 0.001), ""); CHECK_INVARIANT(RDKit::feq(mmat->getLowerBound(1, 2), 1.0, 0.001), ""); CHECK_INVARIANT(RDKit::feq(mmat->getUpperBound(1, 3), 1.732, 0.001), ""); CHECK_INVARIANT(RDKit::feq(mmat->getLowerBound(1, 3), 1.732, 0.001), ""); CHECK_INVARIANT(RDKit::feq(mmat->getUpperBound(1, 4), 2.732, 0.001), ""); CHECK_INVARIANT(RDKit::feq(mmat->getLowerBound(1, 4), 0.732, 0.001), ""); CHECK_INVARIANT(RDKit::feq(mmat->getUpperBound(2, 3), 1.0, 0.001), ""); CHECK_INVARIANT(RDKit::feq(mmat->getLowerBound(2, 3), 1.0, 0.001), ""); CHECK_INVARIANT(RDKit::feq(mmat->getUpperBound(2, 4), 1.732, 0.001), ""); CHECK_INVARIANT(RDKit::feq(mmat->getLowerBound(2, 4), 1.732, 0.001), ""); CHECK_INVARIANT(RDKit::feq(mmat->getUpperBound(3, 4), 1.0, 0.001), ""); CHECK_INVARIANT(RDKit::feq(mmat->getLowerBound(3, 4), 1.0, 0.001), ""); DoubleSymmMatrix dmat(npt, 0.0); RDKit::rng_type generator(42u); generator.seed(100); RDKit::uniform_double distrib(0, 1.0); RDKit::double_source_type rng(generator, distrib); pickRandomDistMat(*mmat, dmat, rng); double sumElem = 0.0; for (unsigned int i = 0; i < dmat.getDataSize(); i++) { sumElem += dmat.getData()[i]; } CHECK_INVARIANT(RDKit::feq(sumElem, 14.3079, 0.001), ""); }
unsigned int dimy() { return matrix.dimy(); }
void markLand(unsigned int x, unsigned int y) { matrix.set(x, y, 100); }