12 #ifndef RD_MAXMINPICKER_H 13 #define RD_MAXMINPICKER_H 22 #include <boost/random.hpp> 63 unsigned int pickSize)
const;
67 unsigned int pickSize,
73 unsigned int pickSize,
75 double &threshold)
const;
115 int seed = -1)
const {
118 if (poolSize < pickSize)
120 distmatFunctor functor(distMat);
121 return this->lazyPick(functor, poolSize, pickSize, firstPicks, seed);
126 unsigned int pickSize)
const {
128 return pick(distMat, poolSize, pickSize, iv);
140 template <
typename T>
142 unsigned int pickSize,
144 int seed,
double &threshold)
const {
147 if (poolSize < pickSize)
152 unsigned int memsize = (
unsigned int)(poolSize *
sizeof(
MaxMinPickInfo));
158 memset(pinfo, 0, memsize);
160 picks.reserve(pickSize);
161 unsigned int picked = 0;
162 unsigned int pick = 0;
165 if (firstPicks.empty()) {
168 typedef boost::uniform_int<> distrib_type;
169 typedef boost::variate_generator<rng_type &, distrib_type> source_type;
171 distrib_type dist(0, poolSize - 1);
173 generator.seed(static_cast<rng_type::result_type>(seed));
175 generator.seed(std::random_device()());
177 source_type randomSource(generator, dist);
178 pick = randomSource();
180 picks.push_back(pick);
182 pinfo[pick].
picks = 1;
186 for (RDKit::INT_VECT::const_iterator pIdx = firstPicks.begin();
187 pIdx != firstPicks.end(); ++pIdx) {
188 pick =
static_cast<unsigned int>(*pIdx);
189 if (pick >= poolSize) {
193 picks.push_back(pick);
194 pinfo[pick].
picks = 1;
199 if (picked >= pickSize) {
205 unsigned int pool_list = 0;
206 unsigned int *prev = &pool_list;
208 for (
unsigned int i = 0; i < poolSize; i++)
209 if (pinfo[i].picks == 0) {
211 prev = &pinfo[i].
next;
215 unsigned int poolIdx;
216 unsigned int pickIdx;
223 pinfo[poolIdx].
dist_bound = func(poolIdx, pickIdx);
224 pinfo[poolIdx].
picks = 1;
225 prev = &pinfo[poolIdx].
next;
226 }
while (*prev != 0);
229 double maxOFmin = -1.0;
230 double tmpThreshold = -1.0;
231 while (picked < pickSize) {
232 unsigned int *pick_prev = 0;
238 if (minTOi > maxOFmin) {
239 unsigned int pi = pinfo[poolIdx].
picks;
240 while (pi < picked) {
241 unsigned int picki = picks[pi];
243 double dist = func(poolIdx, picki);
245 if (dist <= minTOi) {
247 if (minTOi <= maxOFmin)
break;
251 pinfo[poolIdx].
picks = pi;
252 if (minTOi > maxOFmin) {
258 prev = &pinfo[poolIdx].
next;
259 }
while (*prev != 0);
262 if (maxOFmin <= threshold && threshold >= 0.0)
break;
263 tmpThreshold = maxOFmin;
265 *pick_prev = pinfo[pick].
next;
266 picks.push_back(pick);
270 threshold = tmpThreshold;
275 template <
typename T>
277 unsigned int pickSize,
280 double threshold = -1.0;
285 template <
typename T>
287 unsigned int pickSize)
const {
289 double threshold = -1.0;
boost::minstd_rand rng_type
#define CHECK_INVARIANT(expr, mess)
#define RDKIT_SIMDIVPICKERS_EXPORT
RDKit::INT_VECT lazyPick(T &func, unsigned int poolSize, unsigned int pickSize) const
Contains the implementation for a lazy 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.
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...