ToPS
ProbabilisticModelParameter.hpp
00001 /*
00002  *       ProbabilisticModelParameter.hpp
00003  *
00004  *       Copyright 2011 Andre Yoshiaki Kashiwabara <akashiwabara@usp.br>
00005  *                      Ígor Bonádio <ibonadio@ime.usp.br>
00006  *                      Vitor Onuchic <vitoronuchic@gmail.com>
00007  *                      Alan Mitchell Durham <aland@usp.br>
00008  *
00009  *       This program is free software; you can redistribute it and/or modify
00010  *       it under the terms of the GNU  General Public License as published by
00011  *       the Free Software Foundation; either version 3 of the License, or
00012  *       (at your option) any later version.
00013  *
00014  *       This program is distributed in the hope that it will be useful,
00015  *       but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *       GNU General Public License for more details.
00018  *
00019  *       You should have received a copy of the GNU General Public License
00020  *       along with this program; if not, write to the Free Software
00021  *       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00022  *       MA 02110-1301, USA.
00023  */
00024 
00025 #ifndef CONFIGURATION_PARAMETER_VALUE_HPP
00026 #define CONFIGURATION_PARAMETER_VALUE_HPP
00027 
00028 #include "crossplatform.hpp"
00029 
00030 #include <boost/numeric/ublas/vector.hpp>
00031 #include <boost/numeric/ublas/matrix.hpp>
00032 
00033 #include <boost/shared_ptr.hpp>
00034 #include <map>
00035 #include <vector>
00036 #include <iostream>
00037 
00038 #include "SequenceEntry.hpp"
00039 #include "Sequence.hpp"
00040 
00041 namespace tops {
00042 
00043   typedef std::vector <double> DoubleVector;
00044   typedef std::vector <int> IntVector;
00045   typedef boost::numeric::ublas::matrix<double> Matrix;
00046   typedef std::vector <std::string> StringVector;
00047   typedef std::map <std::string, std::string> StringMap;
00048   class DLLEXPORT ProbabilisticModelParameterValue;
00049   typedef boost::shared_ptr <ProbabilisticModelParameterValue> ProbabilisticModelParameterValuePtr;
00051   class DLLEXPORT ProbabilisticModelParameters  {
00052     std::map <std::string, ProbabilisticModelParameterValuePtr> _parameters;
00053   public:
00054     ProbabilisticModelParameters(){}
00055     void add(const char * name, ProbabilisticModelParameterValuePtr value);
00056 
00058     void add(std::string name, ProbabilisticModelParameterValuePtr value);
00059 
00061     void set(std::string name, ProbabilisticModelParameterValuePtr value);
00062 
00064     ProbabilisticModelParameterValuePtr getMandatoryParameterValue(const std::string & name) const;
00065 
00067     ProbabilisticModelParameterValuePtr getOptionalParameterValue(const std::string & name) const;
00068 
00069     std::map <std::string, ProbabilisticModelParameterValuePtr>  parameters() const;
00070 
00071   };
00072 
00073 
00074 
00076   class DLLEXPORT ProbabilisticModelParameterValue {
00077   private:
00078     StringVector s;
00079     DoubleVector d;
00080     IntVector i;
00081     std::vector <DoubleVector> m;
00082     std::map<std::string,double> p;
00083     std::map<std::string,std::string> str_map;
00084     std::string _str;
00085     ProbabilisticModelParameters  _parameters;
00086   public:
00087     virtual void setIsRoot(bool root);
00088     ProbabilisticModelParameterValue(){}
00089     virtual    ~ProbabilisticModelParameterValue() {}
00090     virtual std::string parameter_type () const;
00091     virtual std::map<std::string,double> & getDoubleMap();
00092     virtual StringVector & getStringVector();
00093     virtual DoubleVector & getDoubleVector();
00094     virtual IntVector & getIntVector();
00095     virtual ProbabilisticModelParameters & getParameters();
00096     virtual std::string getString() const;
00097     virtual std::map<std::string,std::string> &  getStringMap();
00098     virtual int getInt() const;
00099     virtual double getDouble()  const;
00100     virtual std::string str() const;
00101   };
00102 
00103   class DLLEXPORT ProbabilisticModelParameterListValue : public ProbabilisticModelParameterValue {
00104   public:
00105     ProbabilisticModelParameterListValue(){_root = false;}
00106     ProbabilisticModelParameterListValue ( ProbabilisticModelParameters p) : _parameters(p) {
00107       _root =false;
00108     };
00109     virtual void initialize(ProbabilisticModelParameters p);
00110     virtual ProbabilisticModelParameters & getParameters() ;
00111     virtual std::string parameter_type () const;
00112     virtual void setIsRoot(bool root);
00113     virtual std::string getString() const;
00114     virtual std::string str () const;
00115   private:
00116     ProbabilisticModelParameters  _parameters;
00117     bool _root;
00118   };
00119   typedef boost::shared_ptr<ProbabilisticModelParameterListValue> ProbabilisticModelParameterListValuePtr;
00120 
00122   class DLLEXPORT DoubleParameterValue: public ProbabilisticModelParameterValue {
00123   private:
00124     double _d;
00125   public:
00126     DoubleParameterValue(){}
00127     virtual void initialize(double d);
00128     DoubleParameterValue(double d) {
00129       _d = d;
00130     }
00131     virtual std::string parameter_type () const;
00132     virtual ~DoubleParameterValue(){}
00133     virtual double getDouble() const;
00134     virtual int getInt() const;
00135     virtual std::string str() const;
00136   };
00137 
00139   class DLLEXPORT IntParameterValue: public ProbabilisticModelParameterValue {
00140   private:
00141     int _v;
00142   public:
00143     IntParameterValue() {};
00144     virtual std::string parameter_type () const;
00145     IntParameterValue(int v){ _v = v;}
00146     virtual void initialize(int v);
00147     virtual ~IntParameterValue() {}
00148     virtual int getInt() const;
00149     virtual double getDouble() const;
00150     virtual std::string str() const ;
00151   };
00152 
00154   class DLLEXPORT StringParameterValue: public ProbabilisticModelParameterValue {
00155   private:
00156     std::string _v;
00157   public:
00158     StringParameterValue() {}
00159     StringParameterValue(std::string  v) {
00160       _v = v;
00161     }
00162     virtual std::string parameter_type () const;
00163     virtual void initialize(std::string v);
00164     virtual ~StringParameterValue(){}
00165     virtual std::string getString() const;
00166     virtual std::string str() const ;
00167   };
00168 
00170   class DLLEXPORT IntVectorParameterValue: public ProbabilisticModelParameterValue {
00171   private:
00172     IntVector _v;
00173   public:
00174     IntVectorParameterValue() {}
00175     virtual std::string parameter_type () const;
00176     virtual void initialize(IntVector v);
00177     IntVectorParameterValue(IntVector v) ;
00178     virtual ~IntVectorParameterValue(){}
00179     virtual IntVector & getIntVector()  ;
00180     virtual std::string str() const;
00181   };
00183   class DLLEXPORT DoubleMapParameterValue: public ProbabilisticModelParameterValue {
00184   private:
00185     std::map <std::string,double> _v;
00186   public:
00187     DoubleMapParameterValue() {
00188     }
00189     DoubleMapParameterValue(const std::map<std::string, double> & values) {
00190       _v = values;
00191     }
00192     virtual void initialize(const std::map<std::string, double > & values);
00193     virtual std::string parameter_type () const;
00194     DoubleMapParameterValue(std::vector<std::string> keys, std::vector<double> value) {
00195       for(int i = 0; i < (int)value.size(); i++)
00196         _v[keys[i]] = value[i];
00197     }
00198     virtual ~DoubleMapParameterValue(){}
00199     virtual std::map<std::string, double> & getDoubleMap() ;
00200     virtual std::string str() const;
00201 
00202   };
00204   class DLLEXPORT DoubleVectorParameterValue: public ProbabilisticModelParameterValue {
00205   private:
00206     DoubleVector _v;
00207   public:
00208     DoubleVectorParameterValue() {
00209     }
00210     DoubleVectorParameterValue(DoubleVector v) {
00211       _v = v;
00212     }
00213     virtual void initialize(DoubleVector v);
00214     ~DoubleVectorParameterValue(){}
00215     virtual DoubleVector & getDoubleVector() ;
00216     virtual std::string parameter_type () const ;
00217     virtual std::string str() const ;
00218 
00219   };
00220 
00222   class DLLEXPORT StringMapParameterValue: public ProbabilisticModelParameterValue {
00223   private:
00224     std::map<std::string,std::string> _str_map;
00225   public:
00226 
00227     StringMapParameterValue(std::vector<std::string> keys,std::vector<std::string> values)
00228     {
00229       for(int i = 0; (i  < (int)keys.size()) && (i < (int)values.size()); i++)
00230         _str_map[keys[i]] = values[i];
00231     }
00232     StringMapParameterValue(std::map<std::string,std::string> m)
00233     {
00234       _str_map = m;
00235     }
00236     virtual void initialize(std::map<std::string,std::string> m) ;
00237     StringMapParameterValue() {
00238     }
00239     ~StringMapParameterValue(){}
00240     virtual StringMap & getStringMap();
00241     virtual std::string parameter_type () const;
00242     virtual std::string str() const;
00243   };
00244 
00246   class DLLEXPORT StringVectorParameterValue: public ProbabilisticModelParameterValue {
00247   private:
00248     StringVector _v;
00249   public:
00250     StringVectorParameterValue(){}
00251     StringVectorParameterValue(StringVector v) {
00252       _v = v;
00253     }
00254     ~StringVectorParameterValue(){}
00255     virtual StringVector &  getStringVector() ;
00256     virtual void initialize(StringVector v);
00257     virtual std::string parameter_type () const ;
00258     virtual std::string str() const;
00259   };
00260 
00261 
00262   typedef boost::shared_ptr <IntParameterValue> IntParameterValuePtr;
00263   typedef boost::shared_ptr <DoubleParameterValue> DoubleParameterValuePtr;
00264   typedef boost::shared_ptr <StringParameterValue> StringParameterValuePtr;
00265   typedef boost::shared_ptr <StringMapParameterValue> StringMapParameterValuePtr;
00266 
00267   typedef boost::shared_ptr <IntVectorParameterValue> IntVectorParameterValuePtr;
00268   typedef boost::shared_ptr <DoubleVectorParameterValue> DoubleVectorParameterValuePtr;
00269   typedef boost::shared_ptr <StringVectorParameterValue> StringVectorParameterValuePtr;
00270   typedef boost::shared_ptr <DoubleMapParameterValue> DoubleMapParameterValuePtr;
00271 }
00272 
00273 
00274 
00275 #endif
00276