9 #ifndef IMPDOMINO_SUBSET_SCORES_H
10 #define IMPDOMINO_SUBSET_SCORES_H
22 #include <boost/unordered_map.hpp>
24 #if IMP_DOMINO_HAS_RMF
25 #include <RMF/HDF5/Group.h>
28 IMPDOMINO_BEGIN_NAMESPACE
42 Subset, subset,
double, max, );
50 typedef boost::unordered_map<Restraint *, RestraintData> RMap;
52 typedef boost::unordered_map<Restraint *, SetData> SMap;
58 typedef double result_type;
59 typedef Key argument_type;
60 template <
class Cache>
61 result_type operator()(
const argument_type &k,
const Cache &cache)
const {
62 RMap::const_iterator it = rmap_.find(k.get_restraint());
63 if (it != rmap_.end()) {
64 Subset s = rmap_.find(k.get_restraint())->second.get_subset();
69 e = it->second.get_scoring_function()->evaluate_if_below(
70 false, it->second.get_max());
73 <<
" evaluated to " << e <<
" on "
74 << k.get_assignment() <<
" vs "
75 << it->second.get_max() << std::endl);
77 if (e > it->second.get_max()) e = std::numeric_limits<double>::max();
80 SMap::const_iterator it = sets_.find(k.get_restraint());
85 for (
unsigned int i = 0; i < it->second.get_members().size(); ++i) {
86 Assignment cur = it->second.get_members()[i].get_slice().get_sliced(
88 double score = cache.get(
89 argument_type(it->second.get_members()[i].get_restraint(), cur));
90 total += score * k.get_restraint()->get_weight();
91 if (total >= it->second.get_max()) {
96 <<
" evaluated to " << total <<
" on "
97 << k.get_assignment() <<
" with max "
98 << it->second.get_max() << std::endl);
99 if (total >= it->second.get_max()) {
100 return std::numeric_limits<double>::max();
109 "don't pass restraint sets here as second arg");
110 sets_[rs].access_members().push_back(RestraintSetData(slice, r));
111 sets_[rs].set_max(max);
115 "don't pass restraint sets here");
116 if (rmap_.find(e) == rmap_.end()) {
120 "Subsets don't match on restraint update");
121 rmap_[e].set_max(std::min(rmap_[e].get_max(), max));
125 void show_restraint_information(std::ostream &out)
const;
127 #endif // IMP_DOXYGEN
129 struct ApproximatelyEqual {
130 bool operator()(
double a,
double b)
const {
131 return std::abs(a - b) < .1 * (a + b) + .1;
134 typedef boost::unordered_map<Particle *, ParticlesTemp>
136 void add_restraint_internal(
Restraint *r,
unsigned int index,
138 Subset parent_subset,
const DepMap &dependencies);
139 void add_restraint_set_child_internal(
Restraint *r,
144 void add_restraint_set_internal(
RestraintSet *rs,
unsigned int index,
145 const Subset &cur_subset,
double cur_max,
146 const DepMap &dependencies);
153 typedef boost::unordered_map<Pointer<Restraint>,
Subset>
155 KnownRestraints known_restraints_;
157 typedef boost::unordered_map<Pointer<Restraint>,
int>
159 RestraintIndex restraint_index_;
160 unsigned int next_index_;
164 unsigned int size = std::numeric_limits<unsigned int>::max());
178 double s = cache_.get(Key(r, a));
196 const Subsets &exclusions)
const;
200 #if IMP_DOMINO_HAS_RMF || defined(IMP_DOXYGEN)
211 RMF::HDF5::Group group,
unsigned int max_entries);
212 void load_cache(
const ParticlesTemp &ps, RMF::HDF5::ConstGroup group);
222 void validate()
const;
225 void show_restraint_information(std::ostream &out = std::cout)
const;
226 double get_hit_rate()
const {
return cache_.get_hit_rate(); }
230 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.
Various general useful functions for IMP.
A class to change and restore log state.
Provide a consistent interface for things that take Restraints as arguments.
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 to get report statistics about the used attributes.
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)
A Bayesian inference-based sampler.
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)