IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
IMP::example::ExampleSubsetFilterTable Class Reference

#include <IMP/example/ExampleSubsetFilterTable.h>

Inheritance diagram for IMP::example::ExampleSubsetFilterTable:

Detailed Description

Filter a set of particles based on the maximum difference in state indexes between them (a completely silly criteria). The thing to note is how the filter table determines when it should be applied and how it sets up the filters.

/**
* \file IMP/example/ExampleSubsetFilterTable.h
* \brief A Score on the distance between a pair of particles.
*
* Copyright 2007-2022 IMP Inventors. All rights reserved.
*/
#ifndef IMPEXAMPLE_EXAMPLE_SUBSET_FILTER_TABLE_H
#define IMPEXAMPLE_EXAMPLE_SUBSET_FILTER_TABLE_H
#include <IMP/example/example_config.h>
IMPEXAMPLE_BEGIN_NAMESPACE
/** Filter a set of particles based on the maximum difference
in state indexes between them (a completely silly criteria).
The thing to note is how the filter table determines when
it should be applied and how it sets up the filters.
\include ExampleSubsetFilterTable.h
\include ExampleSubsetFilterTable.cpp
*/
class IMPEXAMPLEEXPORT ExampleSubsetFilterTable
int max_diff_;
const Particles ps_;
Ints get_indexes(const domino::Subset &s,
const domino::Subsets &prior_subsets) const;
public:
ExampleSubsetFilterTable(unsigned int max_diff,
const ParticlesTemp &pt);
const IMP::domino::Subset &s, const IMP::domino::Subsets &excluded) const
override;
virtual double get_strength(const IMP::domino::Subset &s,
const IMP::domino::Subsets &excluded) const
override;
IMP_OBJECT_METHODS(ExampleSubsetFilterTable);
};
IMPEXAMPLE_END_NAMESPACE
#endif /* IMPEXAMPLE_EXAMPLE_SUBSET_FILTER_TABLE_H */
Represent a subset of the particles being optimized.
Definition Subset.h:34
virtual IMP::domino::SubsetFilter * get_subset_filter(const IMP::domino::Subset &s, const IMP::domino::Subsets &excluded) const override
virtual double get_strength(const IMP::domino::Subset &s, const IMP::domino::Subsets &excluded) const override
The strength is a rough metric of how this filter restricts the subset.
Various important macros for implementing decorators.
IMP::Vector< Subset > Subsets
Definition Subset.h:76
Vector< Pointer< Particle > > Particles
A list of reference-counted Particle objects.
Definition base_types.h:138
IMP::Vector< Int > Ints
Standard way to pass a bunch of Int values.
Definition types.h:48
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
A Bayesian inference-based sampler.
/**
* \file ExampleSubsetFilterTable.cpp
* \brief A Score on the distance between a pair of particles.
*
* Copyright 2007-2022 IMP Inventors. All rights reserved.
*/
#include <iterator>
IMPEXAMPLE_BEGIN_NAMESPACE
namespace {
class ExampleSubsetFilter : public domino::SubsetFilter {
Ints indices_;
int max_;
public:
ExampleSubsetFilter(const Ints& indices, unsigned int max)
: domino::SubsetFilter("ExampleSubsetFilter%1%"),
indices_(indices),
max_(max) {}
virtual bool get_is_ok(const IMP::domino::Assignment& assignment) const
override;
IMP_OBJECT_METHODS(ExampleSubsetFilter);
};
bool ExampleSubsetFilter::get_is_ok(const domino::Assignment& a) const {
for (unsigned int i = 0; i < indices_.size(); ++i) {
if (indices_[i] == -1) continue; // for the non-all case
for (unsigned int j = 0; j < i; ++j) {
if (indices_[j] == -1) continue; // for the non-all case
if (std::abs(a[indices_[i - 1]] - a[indices_[i]]) > max_) return false;
}
}
return true;
}
}
ExampleSubsetFilterTable::ExampleSubsetFilterTable(
unsigned int max_diff, const ParticlesTemp& ps)
: domino::SubsetFilterTable("ExampleSubsetFilterTable%1%"),
max_diff_(max_diff),
ps_(ps.begin(), ps.end()) {}
Ints ExampleSubsetFilterTable::get_indexes(
const domino::Subset& s, const domino::Subsets& prior_subsets) const {
// this method is only called from setup code, so it doesn't
// have to be too fast
Ints ret(ps_.size(), -1);
for (unsigned int i = 0; i < s.size(); ++i) {
for (unsigned int j = 0; j < ps_.size(); ++j) {
if (s[i] == ps_[j]) {
ret[j] = i;
break;
}
}
}
for (unsigned int i = 0; i < ret.size(); ++i) {
if (ret[i] == -1) return Ints();
}
// check if we have seen them already).
for (unsigned int i = 0; i < prior_subsets.size(); ++i) {
unsigned int count = 0;
for (unsigned j = 0; j < prior_subsets[i].size(); ++j) {
for (unsigned int k = 0; k < ps_.size(); ++k) {
if (prior_subsets[i][j] == ps_[k]) {
++count;
break;
}
}
}
if (count == ps_.size()) {
return Ints();
}
}
return ret;
}
double ExampleSubsetFilterTable::get_strength(
const domino::Subset& cur_subset,
const domino::Subsets& prior_subsets) const {
if (get_indexes(cur_subset, prior_subsets).size() != ps_.size()) {
return 0;
} else {
// pick some number
return .5;
}
}
domino::SubsetFilter* ExampleSubsetFilterTable::get_subset_filter(
const domino::Subset& cur_subset,
const domino::Subsets& prior_subsets) const {
Ints its = get_indexes(cur_subset, prior_subsets);
if (its.size() != ps_.size()) {
// either the subset doesn't contain the needed particles or the prior does
return nullptr;
} else {
IMP_NEW(ExampleSubsetFilter, ret, (its, max_diff_));
// remember to release
return ret.release();
}
}
IMPEXAMPLE_END_NAMESPACE
A Score on the distance between a pair of particles.
Store a configuration of a subset.
Definition Assignment.h:35
#define IMP_OBJECT_LOG
Set the log level to the object's log level.
Definition log_macros.h:284
Divide-and-conquer inferential optimization in discrete space.
ParticleIndexes get_indexes(const ParticlesTemp &ps)
Get the indexes from a list of particles.
#define IMP_NEW(Typename, varname, args)
Declare a ref counted pointer to a new object.

Definition at line 24 of file ExampleSubsetFilterTable.h.

Public Member Functions

 ExampleSubsetFilterTable (unsigned int max_diff, const ParticlesTemp &pt)
virtual double get_strength (const IMP::domino::Subset &s, const IMP::domino::Subsets &excluded) const override
 The strength is a rough metric of how this filter restricts the subset.
virtual IMP::domino::SubsetFilter * get_subset_filter (const IMP::domino::Subset &s, const IMP::domino::Subsets &excluded) const override
virtual std::string get_type_name () const override
virtual ::IMP::VersionInfo get_version_info () const override
 Get information about the module and version of the object.
Public Member Functions inherited from IMP::domino::SubsetFilterTable
 SubsetFilterTable (std::string name="SubsetFilterTable%1%")
Public Member Functions inherited from IMP::Object
CheckLevel get_check_level () const
 get_derived_object (self)
 Return this object cast to the most derived subclass.
LogLevel get_log_level () const
void set_check_level (CheckLevel l)
void set_log_level (LogLevel l)
 Set the logging level used in this object.
const std::string & get_name () const
 Get the (not necessarily unique) name of this object.
void set_name (std::string name)
void set_was_used (bool tf) const
void show (std::ostream &out=std::cout) const
virtual void clear_caches ()

Additional Inherited Members

Protected Member Functions inherited from IMP::Object
 Object (std::string name)
 Construct an object with the given name.
virtual void do_destroy ()

Constructor & Destructor Documentation

◆ ~ExampleSubsetFilterTable()

virtual IMP::example::ExampleSubsetFilterTable::~ExampleSubsetFilterTable ( )
virtual

Definition at line 41 of file ExampleSubsetFilterTable.h.

Member Function Documentation

◆ get_strength()

virtual double IMP::example::ExampleSubsetFilterTable::get_strength ( const IMP::domino::Subset & s,
const IMP::domino::Subsets & prior_subsets ) const
overridevirtual

The strength is a rough metric of how this filter restricts the subset.

It is still kind of nebulous, but as a rough guide, it should be the fraction of the states that are eliminated by the filter.

Implements IMP::domino::SubsetFilterTable.

◆ get_subset_filter()

virtual IMP::domino::SubsetFilter * IMP::example::ExampleSubsetFilterTable::get_subset_filter ( const IMP::domino::Subset & s,
const IMP::domino::Subsets & prior_subsets ) const
overridevirtual

Return a SubsetFilter which acts on the Subset s, given that all the prior_subsets have already been filtered. This should return nullptr if there is no filtering to be done.

Implements IMP::domino::SubsetFilterTable.

◆ get_type_name()

virtual std::string IMP::example::ExampleSubsetFilterTable::get_type_name ( ) const
overridevirtual

Reimplemented from IMP::Object.

Definition at line 41 of file ExampleSubsetFilterTable.h.

◆ get_version_info()

virtual ::IMP::VersionInfo IMP::example::ExampleSubsetFilterTable::get_version_info ( ) const
overridevirtual

Get information about the module and version of the object.

Reimplemented from IMP::Object.

Definition at line 41 of file ExampleSubsetFilterTable.h.


The documentation for this class was generated from the following file: