mixmod  3.2.0
Mixture models for clustering and classification
 All Classes Namespaces Files Functions Variables Enumerations Friends
ModelOutput.h
1 /***************************************************************************
2  SRC/mixmod/Kernel/IO/ModelOutput.h description
3  copyright : (C) MIXMOD Team - 2001-2016
4  email : contact@mixmod.org
5  ***************************************************************************/
6 
7 /***************************************************************************
8  This file is part of MIXMOD
9 
10  MIXMOD is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MIXMOD is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with MIXMOD. If not, see <http://www.gnu.org/licenses/>.
22 
23  All informations available on : http://www.mixmod.org
24 ***************************************************************************/
25 #ifndef XEMMODELOUTPUT_H
26 #define XEMMODELOUTPUT_H
27 
28 #include "mixmod/Utilities/Util.h"
29 #include "mixmod/Kernel/Model/ModelType.h"
30 #include "mixmod/Kernel/Criterion/CriterionOutput.h"
31 #include "mixmod/Kernel/Parameter/Parameter.h"
32 #include "mixmod/Kernel/IO/ParameterDescription.h"
33 
34 namespace XEM {
35 
36 // pre-declaration
37 class ProbaDescription;
38 class LabelDescription;
39 
40 /* Note :
41 A XEMModelOutput object could be created :
42 - with an XEMEstimation (after calculation)
43 - or without XEMEstimation. In this case, XEMModelOutput is created from XML mixmod file which contains input and output information.
44  */
45 
52 class ModelOutput {
53 
54 public:
55 
57  ModelOutput();
58 
60  ModelOutput(const ModelOutput & modelOutput);
61 
63  ModelOutput(Model * estimation);
64 
66  ModelOutput(ModelType & modelType, int64_t nbCluster, std::vector<CriterionOutput*> & criterionOutput, double likelihood, ParameterDescription & parameterDescription, LabelDescription & labelDescription, ProbaDescription & probaDescription);
67 
69  ModelOutput(ModelType & modelType, int64_t nbCluster, Exception& error);
70 
72  virtual ~ModelOutput();
73 
75  bool operator ==(const ModelOutput & modelOutput) const;
76 
77  // --- get --- ///
78  //-------------//
79  ModelType getModelType() const;
80 
81  int64_t getNbCluster() const;
82 
83  ParameterDescription * getParameterDescription() const;
84 
85  LabelDescription * getLabelDescription() const;
86 
87  ProbaDescription * getProbaDescription() const;
88 
89  Exception & getStrategyRunError() const;
90 
91  Model * getModel() const;
92 
93  double getLikelihood() const;
94 
95  CriterionOutput const & getCriterionOutput(CriterionName criterionName) const;
96  CriterionOutput const & getCriterionOutput(const int index) const;
97  CriterionOutput & getCriterionOutput(CriterionName criterionName);
98 
99  // set criterion output
100  void setCriterionOutput(CriterionOutput const & criterionOutput);
101 
102 protected:
103 
104  // criterion output
105  CriterionOutput _criterionOutput[maxNbCriterion];
106 
107  // type of the model
108  ModelType _modelType;
109 
110  // the number of cluster
111  int64_t _nbCluster;
112 
113  // parameter description for that model
114  ParameterDescription * _parameterDescription;
115 
116  // labels for the model
117  LabelDescription * _labelDescription;
118 
119  // the probabilities of the model
120  ProbaDescription * _probaDescription;
121 
122  // the model likelihood
123  double _likelihood;
124 
125  // the error
126  Exception * _strategyRunError;
127 };
128 
129 inline ModelType ModelOutput::getModelType() const {
130  return _modelType;
131 }
132 
133 inline int64_t ModelOutput::getNbCluster() const {
134  return _nbCluster;
135 }
136 
137 inline ParameterDescription * ModelOutput::getParameterDescription() const {
138  return _parameterDescription;
139 }
140 
141 inline LabelDescription * ModelOutput::getLabelDescription() const {
142  return _labelDescription;
143 }
144 
145 inline ProbaDescription * ModelOutput::getProbaDescription() const {
146  return _probaDescription;
147 }
148 
149 inline Exception & ModelOutput::getStrategyRunError() const {
150  return *_strategyRunError;
151 }
152 
153 inline double ModelOutput::getLikelihood() const {
154  return _likelihood;
155 }
156 
157 inline CriterionOutput const & ModelOutput::getCriterionOutput(CriterionName criterionName) const {
158  return _criterionOutput[criterionName];
159 }
160 
161 inline CriterionOutput const & ModelOutput::getCriterionOutput(const int index) const {
162  return _criterionOutput[index];
163 }
164 
165 inline CriterionOutput & ModelOutput::getCriterionOutput(CriterionName criterionName) {
166  return _criterionOutput[criterionName];
167 }
168 
169 // Define structure to sort by criterion name
171 
172  // Constructor
173  SortByCriterion(CriterionName criterionName) : _criterionName(criterionName) {
174  }
175 
176  // Destructor
177  ~SortByCriterion() {
178  }
179 
180  // operator()
181  inline bool operator ()(const ModelOutput * m1, const ModelOutput * m2) const {
182  Exception& error1 = (m1->getCriterionOutput(_criterionName).getError());
183  Exception& error2 = (m2->getCriterionOutput(_criterionName).getError());
184  if (error1 != NOERROR && error2 != NOERROR) return false;
185  if (error1 != NOERROR) return false;
186  if (error2 != NOERROR) return true;
187  const double value1 = m1->getCriterionOutput(_criterionName).getValue();
188  const double value2 = m2->getCriterionOutput(_criterionName).getValue();
189  if (value1 == value2) {
190  return m1->getParameterDescription()->getParameter()->getFreeParameter() < m2->getParameterDescription()->getParameter()->getFreeParameter();
191  }
192  else {
193  return value1 < value2;
194  }
195  }
196 
197 private:
198 
199  // criterion name
200  CriterionName _criterionName;
201 };
202 
203 }
204 
205 #endif
Definition: ModelOutput.h:52
Definition: LabelDescription.h:43
Base class for ModelType(s)
Definition: ModelType.h:37
Definition: ProbaDescription.h:43
double const getValue() const
getValue
Definition: CriterionOutput.h:107
Definition: Exception.h:42
virtual int64_t getFreeParameter() const =0
Selector.
Definition: ModelOutput.h:170
Parameter * getParameter()
getParameter
Definition: ParameterDescription.h:174
bool operator==(const ModelOutput &modelOutput) const
Comparison operator.
Definition: ModelOutput.cpp:128
Definition: Model.h:50
Exception & getError() const
getError
Definition: CriterionOutput.h:111
ModelOutput()
Default Constructor.
Definition: ModelOutput.cpp:37
CriterionName
Enumeration of Criterion type.
Definition: Util.h:303
Constants definitions, various utilities to describe models, and others...
Definition: ParameterDescription.h:44
Base class for Label(s)
Definition: CriterionOutput.h:36
virtual ~ModelOutput()
Destructor.
Definition: ModelOutput.cpp:118