00001 // ---------------------------------------------------------------------------- 00002 // 00003 // $Id$ 00004 // 00005 // Copyright 2008, 2009, 2010, 2011, 2012 Antonio Franchi and Paolo Stegagno 00006 // 00007 // This file is part of MIP. 00008 // 00009 // MIP 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 // MIP 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 MIP. If not, see <http://www.gnu.org/licenses/>. 00021 // 00022 // Contact info: antonio.franchi@tuebingen.mpg.de stegagno@diag.uniroma1.it 00023 // 00024 // ---------------------------------------------------------------------------- 00025 00030 00031 #ifndef __DISCRETE_H 00032 #define __DISCRETE_H 00033 00034 #include "PDF.h" 00035 00036 using namespace MipBaselib; 00037 00038 namespace MipBaselib{ 00039 00041 /* @{ */ 00042 00043 00044 00048 struct ProbabilityMass{ 00049 public: 00050 00052 int x; 00054 Decimal p; 00055 00057 ProbabilityMass(); 00058 00062 ProbabilityMass(int y, Decimal q); 00063 00066 ProbabilityMass(const ProbabilityMass &pm); 00067 00070 void operator=(const ProbabilityMass &pm); 00071 00074 string print(); 00075 }; 00076 00077 00078 00079 00080 00081 00085 class Discrete:public PDF, public vector<ProbabilityMass>{ 00086 protected: 00087 00088 00089 public: 00090 00092 Discrete(); 00093 00097 Discrete(DCol &x, DCol &p); 00098 00101 Discrete(const Discrete &g); 00102 00105 void operator=(const Discrete &g); 00106 00108 DCol expectedValue(); 00109 00113 Decimal covariance(int row, int col); 00114 00116 Decimal covariance(); 00117 00120 Decimal evaluate(DCol p); 00121 00124 void printCovInv(); 00125 00128 virtual string print(); 00129 00134 bool findValue(int v, Decimal &pr); 00135 00139 void addValue(int v, Decimal pr); 00140 00143 void addValue(ProbabilityMass a); 00144 00146 void normalize(); 00147 }; 00148 00149 /* @} */ 00150 } 00151 00152 00153 #endif 00154 00155 00156 00157 00158 00159 00160 00161