BALL  1.4.79
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Model.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 
5 #ifndef BALL_QSAR_MODEL_H
6 #define BALL_QSAR_MODEL_H
7 
8 
9 #ifndef BALL_QSAR_VALIDATION_H
10 #include <BALL/QSAR/validation.h>
11 #endif
12 
13 #ifndef BALL_QSAR_QSARDATA_H
14 #include <BALL/QSAR/QSARData.h>
15 #endif
16 
17 #ifndef BALL_QSAR_EXCEPTION_H
18 #include <BALL/QSAR/exception.h>
19 #endif
20 
21 #ifndef BALL_MATHS_PARSEDFUNCTION_H
23 #endif
24 
25 #include <vector>
26 #include <set>
27 
28 #include <Eigen/Core>
29 
30 namespace BALL
31 {
32  namespace QSAR
33  {
35  {
36  public:
42  Model(const QSARData& q);
43 
44  virtual ~Model();
45 
48  virtual void operator=(const Model& m);
49 
50  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
52 
53 
58  void copyData(const Model& m);
59 
61  void copyDescriptorIDs(const Model& m);
62 
63 
67  void readTrainingData();
68 
69 
76  virtual Eigen::VectorXd predict(const vector<double>& substance, bool transform) =0;
77 
79  void deleteDescriptorIDs();
80 
82  virtual void train() =0;
83 
84 
89  virtual bool optimizeParameters(int /*k*/, int /*no_steps*/){return 0;};
90 
91  bool optimizeParameters(int k);
92 
93  virtual double calculateStdErr()
94  {return -1.0;};
95 
97  virtual void setParameters(vector<double>& /*v*/){};
98 
99  virtual vector<double> getParameters() const;
100 
102  std::multiset<unsigned int>* getDescriptorIDs();
103 
104  void setDataSource(const QSARData* q);
105 
107  virtual void saveToFile(string filename) = 0;
108 
110  virtual void readFromFile(string filename) = 0;
111 
113  const Eigen::MatrixXd* getDescriptorMatrix();
114 
116  const vector<string>* getSubstanceNames();
117 
119  const vector<string>* getDescriptorNames();
120 
122  const Eigen::MatrixXd getDescriptorTransformations();
123 
124  const Eigen::MatrixXd getYTransformations();
125 
127  const Eigen::MatrixXd* getY();
128 
130  void setDescriptorIDs(const std::multiset<unsigned int>& sl);
131 
133  const string* getType();
134 
136  void getUnnormalizedFeatureValue(int compound, int feature, double& return_value);
137 
139  void getUnnormalizedResponseValue(int compound, int response, double& return_value);
141 
142 
147  const QSARData* data;
148 
152 
153 
154  protected:
155 
160 
166  Eigen::VectorXd getSubstanceVector(const vector<double>& substance, bool transform);
167 
168  Eigen::VectorXd getSubstanceVector(const Eigen::VectorXd& substance, bool transform);
169 
171  void backTransformPrediction(Eigen::VectorXd& pred);
172 
174  void addLambda(Eigen::MatrixXd& matrix, double& lambda);
175 
177  void readDescriptorInformation();
179 
180 
185  void readMatrix(Eigen::MatrixXd& mat, std::ifstream& in, unsigned int lines, unsigned int col);
186 
187  void readVector(Eigen::RowVectorXd& vec, std::ifstream& in, unsigned int no_cells, bool column_vector);
188 
189  void readModelParametersFromFile(std::ifstream& in);
190  void saveModelParametersToFile(std::ofstream& out);
191 
192 
194  virtual void saveDescriptorInformationToFile(std::ofstream& out);
195  virtual void readDescriptorInformationFromFile(std::ifstream& in, int no_descriptors, bool transformation);
196 
197  void readResponseTransformationFromFile(std::ifstream& in, int no_y);
198  void saveResponseTransformationToFile(std::ofstream& out);
200 
201 
206  Eigen::MatrixXd descriptor_matrix_;
207 
209  vector<string> substance_names_;
210 
212  vector<string> descriptor_names_;
213 
217 
220  Eigen::MatrixXd y_transformations_;
221 
224  Eigen::MatrixXd Y_;
225 
228 
232  std::multiset<unsigned int> descriptor_IDs_;
234 
235  friend class Validation;
236  friend class RegressionValidation;
238  friend class PCRModel;
239  friend class KPCRModel;
240  friend class FeatureSelection;
241  };
242 
244  BALL_EXPORT Model* createNewModelFromFile(String model_file, const QSARData& q);
245  }
246 }
247 
248 #endif // BALL_QSAR_MODEL_H
int default_no_opt_steps_
Definition: Model.h:159
virtual void setParameters(vector< double > &)
Definition: Model.h:97
const QSARData * data
Definition: Model.h:147
virtual double calculateStdErr()
Definition: Model.h:93
virtual bool optimizeParameters(int, int)
Definition: Model.h:89
Eigen::MatrixXd descriptor_transformations_
Definition: Model.h:216
BALL_EXTERN_VARIABLE const double k
Definition: constants.h:93
vector< string > substance_names_
Definition: Model.h:209
Eigen::MatrixXd y_transformations_
Definition: Model.h:220
BALL_EXPORT Model * createNewModelFromFile(String model_file, const QSARData &q)
String type_
Definition: Model.h:227
std::multiset< unsigned int > descriptor_IDs_
Definition: Model.h:232
Eigen::MatrixXd descriptor_matrix_
Definition: Model.h:206
Eigen::MatrixXd Y_
Definition: Model.h:224
#define BALL_EXPORT
Definition: COMMON/global.h:50
vector< string > descriptor_names_
Definition: Model.h:212
Validation * model_val
Definition: Model.h:150