BALL  1.4.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Model.h
Go to the documentation of this file.
1 /* Model.h
2  *
3  * Copyright (C) 2009 Marcel Schumann
4  *
5  * This file is part of QuEasy -- A Toolbox for Automated QSAR Model
6  * Construction and Validation.
7  * QuEasy is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or (at
10  * your option) any later version.
11  *
12  * QuEasy is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 // -*- Mode: C++; tab-width: 2; -*-
22 // vi: set ts=2:
23 //
24 //
25 #ifndef MODEL
26 #define MODEL
27 
28 #include <vector>
29 #include <set>
30 
32 
33 #ifndef VALIDATION
34 #include <BALL/QSAR/validation.h>
35 #endif
36 
37 #ifndef QSARH
38 #include <BALL/QSAR/QSARData.h>
39 #endif
40 
41 #ifndef QSAR_EXCEPTION
42 #include <BALL/QSAR/exception.h>
43 #endif
44 
46 
47 namespace BALL
48 {
49 
50  namespace QSAR
51  {
53  {
54  public:
60  Model(const QSARData& q);
61 
62  virtual ~Model();
63 
66  virtual void operator=(const Model& m);
68 
69 
74  void copyData(const Model& m);
75 
77  void copyDescriptorIDs(const Model& m);
78 
79 
83  void readTrainingData();
84 
85 
92  virtual Vector<double> predict(const vector<double>& substance, bool transform) =0;
93 
95  void deleteDescriptorIDs();
96 
98  virtual void train() =0;
99 
100 
105  virtual bool optimizeParameters(int /*k*/, int /*no_steps*/){return 0;};
106 
107  bool optimizeParameters(int k);
108 
109  virtual double calculateStdErr()
110  {return -1.0;};
111 
113  virtual void setParameters(vector<double>& /*v*/){};
114 
115  virtual vector<double> getParameters() const;
116 
118  std::multiset<unsigned int>* getDescriptorIDs();
119 
120  void setDataSource(const QSARData* q);
121 
123  virtual void saveToFile(string filename) = 0;
124 
126  virtual void readFromFile(string filename) = 0;
127 
129  const Matrix<double>* getDescriptorMatrix();
130 
132  const vector<string>* getSubstanceNames();
133 
135  const vector<string>* getDescriptorNames();
136 
138  const Matrix<double>* getY();
139 
141  void setDescriptorIDs(const std::multiset<unsigned int>& sl);
142 
144  const string* getType();
145 
147  void getUnnormalizedFeatureValue(int compound, int feature, double& return_value);
148 
150  void getUnnormalizedResponseValue(int compound, int response, double& return_value);
152 
153 
158  const QSARData* data;
159 
163 
164 
165  protected:
166 
171 
177  Vector<double> getSubstanceVector(const vector<double>& substance, bool transform);
178 
179  Vector<double> getSubstanceVector(const Vector<double>& substance, bool transform);
180 
182  void backTransformPrediction(Vector<double>& pred);
183 
185  void addLambda(Matrix<double>& matrix, double& lambda);
186 
188  void readDescriptorInformation();
190 
191 
196  void readMatrix(Matrix<double>& mat, std::ifstream& in, uint lines, uint col);
197 
198  void readVector(Vector<double>& vec, std::ifstream& in, uint no_cells, bool column_vector);
199 
200  void readModelParametersFromFile(std::ifstream& in);
201  void saveModelParametersToFile(std::ofstream& out);
202 
203 
205  virtual void saveDescriptorInformationToFile(std::ofstream& out);
206  virtual void readDescriptorInformationFromFile(std::ifstream& in, int no_descriptors, bool transformation);
207 
208  void readResponseTransformationFromFile(std::ifstream& in, int no_y);
209  void saveResponseTransformationToFile(std::ofstream& out);
211 
212 
218 
220  vector<string> substance_names_;
221 
223  vector<string> descriptor_names_;
224 
228 
232 
236 
239 
243  std::multiset<unsigned int> descriptor_IDs_;
245 
246  friend class Validation;
247  friend class RegressionValidation;
249 #ifdef BALL_HAS_LAPACK
250  friend class PCRModel;
251  friend class KPCRModel;
252  friend class FeatureSelection;
253 #endif //BALL_HAS_LAPACK
254  };
255 
257  Model* createNewModelFromFile(String model_file, const QSARData& q);
258  }
259 }
260 
261 #endif // MODEL