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 {
120 if (poolSize < pickSize) {
123 distmatFunctor functor(distMat);
124 return this->lazyPick(functor, poolSize, pickSize, firstPicks,
seed);
129 unsigned int pickSize)
const override {
131 return pick(distMat, poolSize, pickSize, iv);
143 template <
typename T>
145 unsigned int pickSize,
147 int seed,
double &threshold)
const {
152 if (poolSize < pickSize) {
158 unsigned int memsize = (
unsigned int)(poolSize *
sizeof(
MaxMinPickInfo));
160 memset(pinfo, 0, memsize);
162 picks.reserve(pickSize);
163 unsigned int picked = 0;
164 unsigned int pick = 0;
167 if (firstPicks.empty()) {
170 typedef boost::uniform_int<> distrib_type;
171 typedef boost::variate_generator<rng_type &, distrib_type> source_type;
173 distrib_type dist(0, poolSize - 1);
175 generator.seed(
static_cast<rng_type::result_type
>(
seed));
177 generator.seed(std::random_device()());
179 source_type randomSource(generator, dist);
180 pick = randomSource();
182 picks.push_back(
pick);
188 for (RDKit::INT_VECT::const_iterator pIdx = firstPicks.begin();
189 pIdx != firstPicks.end(); ++pIdx) {
190 pick =
static_cast<unsigned int>(*pIdx);
191 if (
pick >= poolSize) {
195 picks.push_back(
pick);
201 if (picked >= pickSize) {
207 unsigned int pool_list = 0;
208 unsigned int *prev = &pool_list;
210 for (
unsigned int i = 0; i < poolSize; i++) {
211 if (pinfo[i].picks == 0) {
213 prev = &pinfo[i].
next;
218 unsigned int poolIdx;
219 unsigned int pickIdx;
226 pinfo[poolIdx].
dist_bound = func(poolIdx, pickIdx);
227 pinfo[poolIdx].
picks = 1;
228 prev = &pinfo[poolIdx].
next;
229 }
while (*prev != 0);
232 double maxOFmin = -1.0;
233 double tmpThreshold = -1.0;
234 while (picked < pickSize) {
235 unsigned int *pick_prev =
nullptr;
241 if (minTOi > maxOFmin) {
242 unsigned int pi = pinfo[poolIdx].
picks;
243 while (pi < picked) {
244 unsigned int picki = picks[pi];
246 double dist = func(poolIdx, picki);
248 if (dist <= minTOi) {
250 if (minTOi <= maxOFmin) {
256 pinfo[poolIdx].
picks = pi;
257 if (minTOi > maxOFmin) {
263 prev = &pinfo[poolIdx].
next;
264 }
while (*prev != 0);
267 if (maxOFmin <= threshold && threshold >= 0.0) {
270 tmpThreshold = maxOFmin;
273 picks.push_back(
pick);
277 threshold = tmpThreshold;
282 template <
typename T>
284 unsigned int pickSize,
287 double threshold = -1.0;
292 template <
typename T>
294 unsigned int pickSize)
const {
296 double threshold = -1.0;
#define CHECK_INVARIANT(expr, mess)
Abstract base class to do perform item picking (typically molecules) using a distance matrix.
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.
RDKit::INT_VECT lazyPick(T &func, unsigned int poolSize, unsigned int pickSize) const
Contains the implementation for a lazy MaxMin diversity picker.
MaxMinPicker()
Default Constructor.
RDKit::INT_VECT pick(const double *distMat, unsigned int poolSize, unsigned int pickSize) const override
Class to allow us to throw a ValueError from C++ and have it make it back to Python.
#define RDKIT_SIMDIVPICKERS_EXPORT
std::vector< int > INT_VECT
boost::minstd_rand rng_type