IMP  2.0.0
The Integrative Modeling Platform
DominoSampler.h
Go to the documentation of this file.
1 /**
2  * \file IMP/domino/DominoSampler.h
3  * \brief A beyesian infererence-based sampler.
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPDOMINO_DOMINO_SAMPLER_H
10 #define IMPDOMINO_DOMINO_SAMPLER_H
11 
12 #include <IMP/domino/domino_config.h>
13 //#include "Evaluator.h"
14 #include "DiscreteSampler.h"
15 #include "subset_graphs.h"
16 #include "internal/inference_utility.h"
17 #include <IMP/Sampler.h>
18 #include <IMP/macros.h>
19 #include <IMP/internal/OwnerPointer.h>
20 
21 IMPDOMINO_BEGIN_NAMESPACE
22 #ifdef SWIG
23 class SubsetGraph;
24 #endif
25 
26 //! Sample best solutions using Domino
27 /** Note that if there are many solutions, the ConfigurationSet returned
28  by get_sample() might be huge (in terms of memory usage) and slow to
29  generate. The Assignments returned by get_sample_assignments() can be
30  a lot smaller and faster.
31  */
32 class IMPDOMINOEXPORT DominoSampler : public DiscreteSampler
33 {
34  Pointer<AssignmentsTable> sst_;
35  SubsetGraph sg_;
36  MergeTree mt_;
37  bool has_sg_, has_mt_;
38  bool csf_;
39  mutable internal::InferenceStatistics stats_;
40 
41  public:
42  DominoSampler(Model *m, std::string name= "DominoSampler %1%");
44  std::string name= "DominoSampler %1%");
46  public:
47  /** \name Advanced
48  Default values are provided, you only need to replace these
49  if you want to do something special. See the overview of
50  the module for a general description.
51  @{
52  */
53  //! Use "loopy" inference on a subset graph
54  void set_subset_graph(const SubsetGraph &sg);
55  //! Specify the merge tree directly
56  void set_merge_tree(const MergeTree &mt);
57  /** @} */
58 
59  /** perform filtering between subsets based by eliminating states
60  that cannot be realized in a subset.
61  */
63  csf_=tf;
64  }
65 
66  /** \name Statistics
67  If you specify the merge tree explicitly, you can query
68  for statistics about particular nodes in the merge tree.
69  @{
70  */
71  //! Get the number of states found for the merge at that vertex of the tree
72  unsigned int
73  get_number_of_assignments_for_vertex(unsigned int tree_vertex) const;
74  //! Return a few subset states from that merge
76  get_sample_assignments_for_vertex(unsigned int tree_vertex) const;
77  /** @} */
78 
79  /** \name Interactive mode
80  Once a merge tree is specified, one can interactively perform the
81  sampling by requesting that domino fill in the Assignments for a
82  given node of the merge tree from the assignments for the children.
83  This can be useful for debugging Domino as well as for providing
84  a distributed implementation.
85 
86  For each method, you can pass max_states to limit how many states are
87  generated.
88 
89  You might want to just use load_leaf_assignments() and
90  load_merged_assignments() instead.
91  @{
92  */
93  //! Fill in assignments for a leaf
94  Assignments get_vertex_assignments(unsigned int node_index,
95  unsigned int max_states
96  =std::numeric_limits<int>::max()) const;
97  //! Fill in assignments for an internal node
98  /** The passed assignments, the ordering for the children is
99  the node index for the children.
100  */
101  Assignments get_vertex_assignments(unsigned int node_index,
102  const Assignments &first,
103  const Assignments &second,
104  unsigned int max_states
105  =std::numeric_limits<int>::max()) const;
106 
107 
108  //! Fill in assignments for a leaf
109  void load_vertex_assignments(unsigned int node_index,
111  unsigned int max_states
112  =std::numeric_limits<int>::max()) const;
113  //! Fill in assignments for an internal node
114  /** The passed assignments, the ordering for the children is that of
115  the node indexes for the children.
116  */
117  void load_vertex_assignments(unsigned int node_index,
118  AssignmentContainer *first,
119  AssignmentContainer *second,
121  unsigned int max_states
122  =std::numeric_limits<int>::max()) const;
123 
124  /** @} */
125 };
126 
127 
129 
130 
131 IMPDOMINO_END_NAMESPACE
132 
133 #endif /* IMPDOMINO_DOMINO_SAMPLER_H */