example-selector.h

Go to the documentation of this file.
00001 // Copyright 2006, Massachusetts Institute of Technology.
00002 // The use of this code is permitted for research only. There is
00003 // absolutely no warranty for this software.
00004 //
00005 // Author: John Lee (jjl@mit.edu)
00006 //
00007 
00008 #ifndef EXPERIMENT_EXAMPLE_SELECTOR_H
00009 #define EXPERIMENT_EXAMPLE_SELECTOR_H
00010 
00011 #include <vector>
00012 #include "util/labeled-index.h"
00013 
00014 using namespace std;
00015 using namespace libpmk;
00016 
00017 namespace libpmk_util {
00018 
00020 
00032 class ExampleSelector {
00033  public:
00034    ExampleSelector(const vector<int>& labels);
00035    virtual ~ExampleSelector() { }
00036 
00039    vector<LabeledIndex> GetTrainingExamples();
00040 
00043    vector<LabeledIndex> GetTestingExamples();
00044 
00047    vector<int> GetUniqueLabels();
00048 
00050    int GetNumExamples() const;
00051 
00052  protected:
00055    const vector<LabeledIndex>& GetExamples() const;
00056 
00058 
00062    vector<LabeledIndex>
00063       InvertSelection(const vector<LabeledIndex>& selection) const;
00064 
00066 
00070    vector<LabeledIndex>
00071       InvertSelection(const vector<LabeledIndex>& selection,
00072                       const vector<LabeledIndex>& superset) const;
00073 
00074 
00076 
00081    vector<LabeledIndex>
00082       RandomSample(int n, const vector<LabeledIndex>& selection) const;
00083 
00085 
00088    vector<LabeledIndex>
00089       GetInstancesWithLabel(int label,
00090                             const vector<LabeledIndex>& selection) const;
00091 
00093    void AddTrainingExample(LabeledIndex index);
00094 
00096    void AddTestingExample(LabeledIndex index);
00097 
00100    virtual void SelectExamples() = 0;
00101 
00102  private:
00103    // The internal function that manages the state of whether SelectExamples
00104    // has already been called and sorts the vectors.
00105    void LoadExamples();
00106    vector<LabeledIndex> labels_;
00107    vector<LabeledIndex> training_;
00108    vector<LabeledIndex> testing_;
00109    vector<int> unique_labels_;
00110    bool selected_;
00111 };
00112 }  // namespace libpmk_util
00113 #endif  // EXPERIMENT_EXAMPLE_SELECTOR_H

Generated on Wed May 2 11:17:12 2007 for libpmk by  doxygen 1.5.1