openModeller
Version 1.4.0
|
00001 00035 #ifndef ENFA_H 00036 #define ENFA_H 00037 00038 #include <openmodeller/om.hh> 00039 #include <openmodeller/Exceptions.hh> 00040 #include <gsl/gsl_matrix.h> 00041 00049 00051 00123 00125 00215 class Enfa : public AlgorithmImpl 00216 { 00217 public: 00219 Enfa(); 00221 ~Enfa(); 00222 00223 // 00224 // Methods used to build the model 00225 // 00226 00232 virtual int initialize(); 00233 00238 int iterate(); 00239 00246 int done() const; 00247 00248 // 00249 // Methods used to project the model 00250 // 00251 00252 00259 Scalar getValue( const Sample& x ) const; 00260 00267 int getConvergence( Scalar * const val ) const; 00268 00269 00270 00271 private: 00272 00273 protected: 00277 int SamplerToMatrix(); 00278 00282 int BackgroundToMatrix(); 00283 00286 bool enfa1(); 00287 00292 int calculateMeanAndSd( gsl_matrix * theMatrix, 00293 gsl_vector * theMeanVector, 00294 gsl_vector * theStdDevVector); 00295 00302 int center(gsl_matrix * theMatrix, 00303 int spCount); 00304 00307 gsl_matrix* sqrtm(gsl_matrix* original_matrix) const; 00308 00311 gsl_matrix* inverse(gsl_matrix* _m) const; 00312 00316 double getGeomean(gsl_vector* v) const; 00317 00326 int discardComponents() const; 00327 00333 void displayVector(const gsl_vector * v, const char * name,const bool roundFlag=true) const; 00334 00340 void displayMatrix(const gsl_matrix * m, const char * name, const bool roundFlag=true) const; 00341 00347 void displayLoadings(const gsl_matrix * m, const int f) const; 00348 00353 gsl_matrix * autoCovariance(gsl_matrix * m); 00354 00358 virtual void _getConfiguration( ConfigurationPtr& ) const; 00359 00363 virtual void _setConfiguration( const ConstConfigurationPtr& ); 00364 00365 00367 int _initialized; 00370 int _done; 00374 gsl_matrix * _gsl_environment_matrix; 00375 /* Pointer to gsl matrix with environmental data for each locality 00376 converted to factors using the enfa score matrix */ 00377 gsl_matrix * _gsl_environment_factor_matrix; 00378 00382 gsl_matrix * _gsl_background_matrix; 00383 00386 gsl_matrix * _gsl_covariance_matrix; 00387 00390 gsl_matrix * _gsl_covariance_background_matrix; 00391 00394 gsl_vector * _gsl_avg_vector; 00396 gsl_vector * _gsl_stddev_vector; 00397 00400 gsl_vector * _gsl_avg_background_vector; 00401 00404 gsl_vector * _gsl_stddev_background_vector; 00405 00407 gsl_vector * _gsl_eigenvalue_vector; 00409 gsl_matrix * _gsl_eigenvector_matrix; 00412 gsl_matrix * _gsl_score_matrix ; 00415 gsl_matrix * _gsl_covariance_matrix_root_inverse; 00417 gsl_matrix * _gsl_workspace_H; 00419 gsl_matrix * _gsl_workspace_W; 00421 gsl_matrix * _gsl_workspace_y; 00423 gsl_vector * _gsl_workspace_z; 00425 gsl_vector* _gsl_factor_weights_all_components; 00427 gsl_vector* _gsl_factor_weights; 00430 gsl_vector* _gsl_geomean_vector; 00431 00432 int _layer_count; 00434 int _retained_components_count; 00436 int _localityCount; 00437 00439 int _backgroundCount; 00440 00442 int _backgroundProvided; 00443 00445 int _discardMethod; 00446 00448 int _retainComponents; 00449 00451 double _retainVariation; 00452 00454 int minComponentsInt; 00455 00457 int _verboseDebug; 00458 00460 int _displayLoadings; 00461 00463 int _gsl_vector_min; 00464 00466 double _marginality; 00467 00469 double _specialisation; 00470 00472 int _numRetries; 00473 00475 int _retryCount; 00476 00477 00478 }; 00479 00480 /* catch the case that generating an inverse fails 00481 gsl doesnt do this well, and we want to catch, 00482 ignore and retry when this happens */ 00483 class InverseFailedException : public OmException { 00484 public: 00485 InverseFailedException( const std::string& msg ) : 00486 OmException( msg ) 00487 {} 00488 }; 00489 00490 #endif