IMP  2.1.0
The Integrative Modeling Platform
IMP::example::ExampleSubsetFilterTable Class Reference

#include <IMP/example/ExampleSubsetFilterTable.h>

+ Inheritance diagram for IMP::example::ExampleSubsetFilterTable:

Public Member Functions

 ExampleSubsetFilterTable (unsigned int max_diff, const kernel::ParticlesTemp &pt)
 
virtual double get_strength (const IMP::domino::Subset &s, const IMP::domino::Subsets &excluded) const
 The strength is a rough metric of how this filter restricts the subset. More...
 
virtual IMP::domino::SubsetFilterget_subset_filter (const IMP::domino::Subset &s, const IMP::domino::Subsets &excluded) const
 
virtual std::string get_type_name () const
 
virtual ::IMP::base::VersionInfo get_version_info () const
 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::base::Object
virtual void clear_caches ()
 
virtual void do_destroy ()
 
CheckLevel get_check_level () const
 
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. More...
 
void set_was_used (bool tf) const
 
void show (std::ostream &out=std::cout) const
 
const std::string & get_name () const
 
void set_name (std::string name)
 

Additional Inherited Members

- Protected Member Functions inherited from IMP::base::Object
 Object (std::string name)
 Construct an object with the given name. More...
 
 Object ()
 

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-2013 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
: public domino::SubsetFilterTable {
int max_diff_;
const kernel::Particles ps_;
Ints get_indexes(const domino::Subset &s,
const domino::Subsets &prior_subsets) const;
public:
ExampleSubsetFilterTable(unsigned int max_diff, const kernel::ParticlesTemp &pt);
const IMP::domino::Subsets &excluded) const IMP_OVERRIDE;
virtual double get_strength(
const IMP::domino::Subsets &excluded) const IMP_OVERRIDE;
IMP_OBJECT_METHODS(ExampleSubsetFilterTable);
};
IMPEXAMPLE_END_NAMESPACE
#endif /* IMPEXAMPLE_EXAMPLE_SUBSET_FILTER_TABLE_H */
/**
* \file ExampleSubsetFilterTable.cpp
* \brief A Score on the distance between a pair of particles.
*
* Copyright 2007-2013 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 IMP_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 kernel::ParticlesTemp& ps)
: domino::SubsetFilterTable("ExampleSubsetFilterTable%1%"),
max_diff_(max_diff),
ps_(ps.begin(), ps.end()) {}
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

Definition at line 24 of file ExampleSubsetFilterTable.h.

Member Function Documentation

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

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.

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

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.


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