CEBL  2.1
DecisionConfig.cpp
Go to the documentation of this file.
1 #include <algorithm>
2 using namespace std;
3 
4 #include "DecisionConfig.hpp"
5 #include "../CEBLModel.hpp"
6 
7 
8 //----------------------------------------------------------------------
9 // CONSTRUCTORS / DESTRUCTORS
10 
11 
13 {
14  this->model = model;
15  this->plugin_loader = new PluginLoader<Decision>;
16  this->selected_decision = "";
17  std::vector<string> paths = model->preferencesGetPaths();
18  for(unsigned int i=0; i<paths.size();i++)
19  {
20  string path = paths[i]+"/plugins/decision/";
21  try
22  {
23  plugin_loader->loadDir(path.c_str());
24  } catch(FileException & e)
25  {
26  cerr << e.what() << "\n";
27  //if there were exceptions, just continue
28  continue;
29  }
30  }
31  if (plugin_loader->getNames().size() > 0)
32  {
33  this->selected_decision = this->getNameList().at(0);
34  }
35 }
36 
38 {
39  delete plugin_loader;
40 }
41 
42 //----------------------------------------------------------------------
43 //GETTING OPERATIONS
44 
45 //special sort to put MSPRT at the top
46 bool decisionSort(string i, string j)
47 {
48  if(i == "MSPRT")
49  return true;
50  else
51  return (i<j);
52 }
53 
54 std::vector<string> DecisionConfig::getNameList()
55 {
56  std::vector<string> names = plugin_loader->getNames();
57  sort(names.begin(),names.end(),decisionSort);
58  return names;
59 }
60 
61 std::vector<string> DecisionConfig::getPathList()
62 {
63  return plugin_loader->getPaths();
64 }
65 
67 {
68  return this->selected_decision;
69 }
70 
71 std::map<std::string, CEBL::Param> DecisionConfig::getParams(string decision)
72 {
73  if(decision=="")
74  decision = selected_decision;
75  try
76  {
77  return plugin_loader->getPlugin(selected_decision)->getParamsList();
78  }
79  catch(...)
80  {
81  throw PluginException("Failed to get parameter list for decision: "
82  + selected_decision);
83  }
84 }
85 
86 //----------------------------------------------------------------------
87  //SETTING OPERATIONS
88 
89 void DecisionConfig::setSelected(string decision)
90 {
91  this->selected_decision = decision;
92 }
93 
94 
95 void DecisionConfig::setParams(std::map<std::string, CEBL::Param> params, string decision)
96 {
97  if(decision=="")
98  decision = selected_decision;
99 
100  if(decision == "")
101  return;
102 
103  try
104  {
105  plugin_loader->getPlugin(decision)->setParamsList(params);
106  }
107  catch(...)
108  {
109  throw PluginException("Failed to set parameter list for decision: "
110  + decision);
111  }
112 }
113 
114 
115 
117 (std::vector<std::vector<double> >probs)
118 {
119  string decision = selected_decision;
120  plugin_loader->getPlugin(decision)->updateWithProbabilities(probs);
121 }
122 
123 void DecisionConfig::updateWithProbabilities(std::vector<double> probs)
124 {
125  string decision = selected_decision;
126  plugin_loader->getPlugin(decision)->updateWithProbabilities(probs);
127 }
128 
129 void DecisionConfig::updateWithClassification(ublas::vector<int> classes)
130 {
131  string decision = selected_decision;
132  plugin_loader->getPlugin(decision)->updateWithClassification(classes);
133 }
134 
136 {
137  string decision = selected_decision;
138  plugin_loader->getPlugin(decision)->updateWithClassification(cls);
139 }
140 
141 void DecisionConfig::init(int num_classes)
142 {
143  string decision = selected_decision;
144  plugin_loader->getPlugin(decision)->init(num_classes);
145 }
146 
147 std::vector<double> DecisionConfig::decideClasses()
148 {
149  string decision = selected_decision;
150  return plugin_loader->getPlugin(decision)->decideClasses();
151 }
152