9 #ifndef IMPDOMINO_SUBSET_SCORES_H
10 #define IMPDOMINO_SUBSET_SCORES_H
22 #include <boost/unordered_map.hpp>
24 #ifdef IMP_DOMINO_USE_IMP_RMF
25 # include <RMF/config.h>
26 # if RMF_HAS_DEPRECATED_BACKENDS
27 # include <RMF/HDF5/Group.h>
32 IMPDOMINO_BEGIN_NAMESPACE
46 Subset, subset,
double, max, );
54 typedef boost::unordered_map<Restraint *, RestraintData> RMap;
56 typedef boost::unordered_map<Restraint *, SetData> SMap;
62 typedef double result_type;
63 typedef Key argument_type;
64 template <
class Cache>
65 result_type operator()(
const argument_type &k,
const Cache &cache)
const {
66 RMap::const_iterator it = rmap_.find(k.get_restraint());
67 if (it != rmap_.end()) {
68 Subset s = rmap_.find(k.get_restraint())->second.get_subset();
73 e = it->second.get_scoring_function()->evaluate_if_below(
74 false, it->second.get_max());
77 <<
" evaluated to " << e <<
" on "
78 << k.get_assignment() <<
" vs "
79 << it->second.get_max() << std::endl);
81 if (e > it->second.get_max()) e = std::numeric_limits<double>::max();
84 SMap::const_iterator it = sets_.find(k.get_restraint());
89 for (
unsigned int i = 0; i < it->second.get_members().size(); ++i) {
90 Assignment cur = it->second.get_members()[i].get_slice().get_sliced(
92 double score = cache.get(
93 argument_type(it->second.get_members()[i].get_restraint(), cur));
94 total += score * k.get_restraint()->get_weight();
95 if (total >= it->second.get_max()) {
100 <<
" evaluated to " << total <<
" on "
101 << k.get_assignment() <<
" with max "
102 << it->second.get_max() << std::endl);
103 if (total >= it->second.get_max()) {
104 return std::numeric_limits<double>::max();
113 "don't pass restraint sets here as second arg");
114 sets_[rs].access_members().push_back(RestraintSetData(slice, r));
115 sets_[rs].set_max(max);
119 "don't pass restraint sets here");
120 if (rmap_.find(e) == rmap_.end()) {
124 "Subsets don't match on restraint update");
125 rmap_[e].set_max(std::min(rmap_[e].get_max(), max));
129 void show_restraint_information(std::ostream &out)
const;
131 #endif // IMP_DOXYGEN
133 struct ApproximatelyEqual {
134 bool operator()(
double a,
double b)
const {
135 return std::abs(a - b) < .1 * (a + b) + .1;
138 typedef boost::unordered_map<Particle *, ParticlesTemp>
140 void add_restraint_internal(
Restraint *r,
unsigned int index,
142 Subset parent_subset,
const DepMap &dependencies);
143 void add_restraint_set_child_internal(
Restraint *r,
148 void add_restraint_set_internal(
RestraintSet *rs,
unsigned int index,
149 const Subset &cur_subset,
double cur_max,
150 const DepMap &dependencies);
157 typedef boost::unordered_map<Pointer<Restraint>,
Subset>
159 KnownRestraints known_restraints_;
161 typedef boost::unordered_map<Pointer<Restraint>,
int>
163 RestraintIndex restraint_index_;
164 unsigned int next_index_;
168 unsigned int size = std::numeric_limits<unsigned int>::max());
182 double s = cache_.get(Key(r, a));
200 const Subsets &exclusions)
const;
204 #if RMF_HAS_DEPRECATED_BACKENDS || defined(IMP_DOXYGEN)
215 RMF::HDF5::Group group,
unsigned int max_entries);
216 void load_cache(
const ParticlesTemp &ps, RMF::HDF5::ConstGroup group);
226 void validate()
const;
229 void show_restraint_information(std::ostream &out = std::cout)
const;
230 double get_hit_rate()
const {
return cache_.get_hit_rate(); }
234 IMPDOMINO_END_NAMESPACE
Smart pointer to Object-derived classes that does not refcount.
A Bayesian inference-based sampler.
RestraintsTemp get_restraints(const Subset &s, const ParticleStatesTable *pst, const DependencyGraph &dg, RestraintSet *rs)
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
virtual ScoringFunction * create_scoring_function(double weight=1.0, double max=NO_MAX) const
Create a scoring function with only this restraint.
Represent a subset of the particles being optimized.
#define IMP_LOG_TERSE(expr)
Object used to hold a set of restraints.
Store a subset of a subset or assignment.
void add_restraint(RMF::FileHandle fh, Restraint *hs)
Common base class for heavy weight IMP objects.
Helper classes for various types of caching.
A class to change and restore log state.
Provide a consistent interface for things that take Restraints as arguments.
Implement a simple least recently used cache.
void add_restraints(RMF::FileHandle fh, const Restraints &hs)
A smart pointer to a ref-counted Object that is a class member.
A Bayesian inference-based sampler.
double get_score(Restraint *r, const Assignment &a) const
Get the score of a set or restraint.
A Bayesian inference-based sampler.
Functions for helping optimize and understand DOMINO-based sampling.
A shared base class to help in debugging and things.
Store a configuration of a subset.
unsigned int get_number_of_entries() const
Return the number of entries currently in the cache.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Abstract base class for all restraints.
Logging and error reporting support.
void load_particle_states(const Subset &s, const Assignment &ss, const ParticleStatesTable *pst)
Load the appropriate state for each particle in a Subset.
A Bayesian inference-based sampler.
Helper class to aid in output of IMP classes to streams.
void set_was_used(bool tf) const
A restraint is a term in an IMP ScoringFunction.
Slice get_slice(Subset outer, Subset inner, const Subsets &excluded)