10 #ifndef __RD_MAXMINPICKER_H__ 11 #define __RD_MAXMINPICKER_H__ 20 #include <boost/random.hpp> 25 class distmatFunctor {
27 distmatFunctor(
const double *distMat) : dp_distMat(distMat){};
28 double operator()(
unsigned int i,
unsigned int j) {
33 const double *dp_distMat;
71 unsigned int pickSize,
111 int seed = -1)
const {
113 if (poolSize < pickSize)
115 distmatFunctor functor(distMat);
116 return this->lazyPick(functor, poolSize, pickSize, firstPicks, seed);
121 unsigned int pickSize)
const {
123 return pick(distMat, poolSize, pickSize, iv);
128 template <
typename T>
130 unsigned int pickSize,
133 if (poolSize < pickSize)
139 picks.reserve(pickSize);
140 unsigned int pick = 0;
143 for (
unsigned int i = 0; i < poolSize; i++) {
149 typedef boost::uniform_int<> distrib_type;
150 typedef boost::variate_generator<rng_type &, distrib_type> source_type;
151 rng_type generator(42u);
152 distrib_type dist(0, poolSize);
153 source_type randomSource(generator, dist);
154 if (seed > 0) generator.seed(static_cast<rng_type::result_type>(seed));
157 if (!firstPicks.size()) {
158 pick = randomSource();
160 picks.push_back(pick);
164 for (RDKit::INT_VECT::const_iterator pIdx = firstPicks.begin();
165 pIdx != firstPicks.end(); ++pIdx) {
166 pick =
static_cast<unsigned int>(*pIdx);
167 if (pick >= poolSize)
169 picks.push_back(pick);
174 while (picks.size() < pickSize) {
175 double maxOFmin = -1.0;
178 unsigned int poolIdx = (*pli);
181 unsigned int pickIdx = (*pi);
183 double dist = func(poolIdx, pickIdx);
184 if (dist <= minTOi) {
188 if (minTOi > maxOFmin ||
189 (
RDKit::feq(minTOi, maxOFmin) && poolIdx < pick)) {
197 picks.push_back(pick);
std::list< int > INT_LIST
boost::minstd_rand rng_type
#define CHECK_INVARIANT(expr, mess)
INT_LIST::iterator INT_LIST_I
RDKit::INT_VECT lazyPick(T &func, unsigned int poolSize, unsigned int pickSize, RDKit::INT_VECT firstPicks=RDKit::INT_VECT(), int seed=-1) const
Contains the implementation for a lazy MaxMin diversity picker.
double getDistFromLTM(const double *distMat, unsigned int i, unsigned int j)
function to lookup distance from 1D lower triangular distance matrix
std::vector< int > INT_VECT
RDKit::INT_VECT pick(const double *distMat, unsigned int poolSize, unsigned int pickSize) const
Implements the MaxMin algorithm for picking a subset of item from a pool.
INT_VECT::const_iterator INT_VECT_CI
RDKit::INT_VECT pick(const double *distMat, unsigned int poolSize, unsigned int pickSize, RDKit::INT_VECT firstPicks, int seed=-1) const
Contains the implementation for the MaxMin diversity picker.
MaxMinPicker()
Default Constructor.
Class to allow us to throw a ValueError from C++ and have it make it back to Python.
Abstract base class to do perform item picking (typically molecules) using a distance matrix...
bool feq(double v1, double v2, double tol=1e-4)
floating point comparison with a tolerance