Bayesian Filtering Library Generated from SVN r
bfl_constants.h
1// $Id$
2// Copyright (C) 2003 Klaas Gadeyne <first dot last at gmail dot com>
3//
4// This program is free software; you can redistribute it and/or modify
5// it under the terms of the GNU Lesser General Public License as published by
6// the Free Software Foundation; either version 2.1 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU Lesser General Public License for more details.
13//
14// You should have received a copy of the GNU Lesser General Public License
15// along with this program; if not, write to the Free Software
16// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17//
18#ifndef __BFL_CONSTANTS_H__
19#define __BFL_CONSTANTS_H__
20
21#define NUMERIC_PRECISION 0.000000001
22
23#ifndef M_PI
24#define M_PI 3.141592653589793284626433832795
25#endif
26
27// Check if double is probability value (maybe this should be solved
28// by a type probability_t or something. Needs thinking.
29#include <iostream>
30#include <cmath>
31#include <cassert>
32
33namespace BFL
34{
35 using namespace std;
38 {
39 public:
40 Probability(){};
41 Probability(double p)
42 {
43 #ifndef _MSC_VER
44 assert(std::isfinite(p) != 0);
45 #endif
46 assert( p >= 0 );
47 _prob = p;
48 };
49 virtual ~Probability(){};
50/*
51 ostream & operator<< (ostream & stream)
52 {
53 stream << this->getValue() << endl;
54 return stream;
55 };
56
57 istream & operator>> (istream & stream)
58 {
59 double value;
60 stream >> value;
61 _prob = Probability(value);
62 return stream;
63 };
64*/
65 friend ostream & operator<< (ostream & stream,Probability& prob);
66
67 friend istream & operator>> (istream & stream,Probability& prob);
68
69 double getValue() const { return _prob;} ;
70 double& getValue() { return _prob;} ;
71
72 operator double(){return _prob;};
73 Probability operator *(Probability p)
74 { return ((Probability) (this->_prob * (double) p));};
75 Probability operator /(Probability p)
76 { return ((Probability) (this->_prob / (double) p));};
77
78
79 private:
80 double _prob;
81 };
82
83} // End namespace
84
99#endif
100
101
Class representing a probability (a double between 0 and 1)