10 #ifndef __RD_MAXMINPICKER_H__ 11 #define __RD_MAXMINPICKER_H__ 20 #include <boost/random.hpp> 27 distmatFunctor(
const double *distMat) : dp_distMat(distMat) {};
28 double operator()(
unsigned int i,
unsigned int j) {
32 const double *dp_distMat;
63 unsigned int poolSize,
unsigned int pickSize,
98 unsigned int poolSize,
unsigned int pickSize,
102 if(poolSize<pickSize)
104 distmatFunctor functor(distMat);
105 return this->lazyPick(functor,poolSize,pickSize,firstPicks,seed);
110 unsigned int poolSize,
unsigned int pickSize)
const {
112 return pick(distMat,poolSize,pickSize,iv);
119 template <
typename T>
121 unsigned int poolSize,
unsigned int pickSize,
124 if(poolSize<pickSize)
130 picks.reserve(pickSize);
134 for (
unsigned int i = 0; i < poolSize; i++) {
141 typedef boost::uniform_int<> distrib_type;
142 typedef boost::variate_generator<rng_type &,distrib_type> source_type;
143 rng_type generator(42u);
144 distrib_type dist(0,poolSize);
145 source_type randomSource(generator,dist);
146 if(seed>0) generator.seed(static_cast<rng_type::result_type>(seed));
149 if(!firstPicks.size()){
150 pick = randomSource();
152 picks.push_back(pick);
156 for(RDKit::INT_VECT::const_iterator pIdx=firstPicks.begin();
157 pIdx!=firstPicks.end();++pIdx){
158 pick =
static_cast<unsigned int>(*pIdx);
161 picks.push_back(pick);
166 while (picks.size() < pickSize) {
167 double maxOFmin = -1.0;
170 pli!=pool.end(); ++pli){
171 unsigned int poolIdx = (*pli);
174 pi != picks.end(); ++pi) {
175 unsigned int pickIdx = (*pi);
177 double dist = func(poolIdx,pickIdx);
178 if (dist <= minTOi) {
182 if (minTOi > maxOFmin || (
RDKit::feq(minTOi,maxOFmin) && poolIdx<pick) ) {
190 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
double getDistFromLTM(const double *distMat, unsigned int i, unsigned int j)
function to lookup distance from 1D lower triangular distance matrix
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.
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
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...
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.
bool feq(double v1, double v2, double tol=1e-4)
floating point comparison with a tolerance