Bayesian Filtering Library Generated from SVN r
conditionalpdf.h
1// $Id$
2// Copyright (C) 2002 Klaas Gadeyne <first dot last at gmail dot com>
3 /***************************************************************************
4 * This library is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU General Public *
6 * License as published by the Free Software Foundation; *
7 * version 2 of the License. *
8 * *
9 * As a special exception, you may use this file as part of a free *
10 * software library without restriction. Specifically, if other files *
11 * instantiate templates or use macros or inline functions from this *
12 * file, or you compile this file and link it with other files to *
13 * produce an executable, this file does not by itself cause the *
14 * resulting executable to be covered by the GNU General Public *
15 * License. This exception does not however invalidate any other *
16 * reasons why the executable file might be covered by the GNU General *
17 * Public License. *
18 * *
19 * This library is distributed in the hope that it will be useful, *
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Lesser General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
27 * Boston, MA 02110-1301 USA *
28 * *
29 ***************************************************************************/
30#ifndef __CONDITIONAL_PDF__
31#define __CONDITIONAL_PDF__
32
33#include "pdf.h"
34#include <vector>
35#include <cassert>
36namespace BFL
37{
38
40
49 template <typename Var, typename CondArg> class ConditionalPdf : public Pdf<Var>
50 {
51 public:
53
58 ConditionalPdf(int dimension=0, unsigned int num_conditional_arguments=0);
59
60 // Default copy constructor will do
61
63 virtual ~ConditionalPdf();
64
67
69
71 unsigned int NumConditionalArgumentsGet() const;
72
74
79 virtual void NumConditionalArgumentsSet(unsigned int numconditionalarguments);
80
82
85 const std::vector<CondArg>& ConditionalArgumentsGet() const;
86
88
91 virtual void ConditionalArgumentsSet(std::vector<CondArg> ConditionalArguments);
92
94
97 const CondArg& ConditionalArgumentGet(unsigned int n_argument) const;
98
100
104 virtual void ConditionalArgumentSet(unsigned int n_argument, const CondArg& argument);
105
106 private:
108 unsigned int _NumConditionalArguments;
110 std::vector<CondArg> _ConditionalArguments;
111 };
112
113
114 // constructor
115 template<typename Var, typename CondArg>
116 ConditionalPdf<Var,CondArg>::ConditionalPdf(int dim, unsigned int num_args)
117 : Pdf<Var>(dim)
118 , _NumConditionalArguments(num_args)
119 , _ConditionalArguments(num_args)
120 {}
121
122 // destructor
123 template<typename Var, typename CondArg>
126
127 //Clone function
128 template<typename Var, typename CondArg>
133
134 template<typename Var, typename CondArg> inline unsigned int
136 {
137 return _NumConditionalArguments;
138 }
139
140 template<typename Var, typename CondArg> inline void
142 {
143 if (numconditionalarguments != _NumConditionalArguments)
144 {
145 _NumConditionalArguments = numconditionalarguments;
146 this->_ConditionalArguments.resize(_NumConditionalArguments);
147 }
148 }
149
150
151 template<typename Var, typename CondArg> const std::vector<CondArg>&
153 {
154 return _ConditionalArguments;
155 }
156
157 template<typename Var, typename CondArg> void
159 {
160 assert (condargs.size() == _NumConditionalArguments);
161 this->_ConditionalArguments = condargs;
162 }
163
164 template<typename Var, typename CondArg> const CondArg&
166 {
167 assert( n_argument < _NumConditionalArguments );
168 // index of conditional arguments of ConditionalPdf out of range
169 return _ConditionalArguments[n_argument];
170 }
171
172 template<typename Var, typename CondArg> void
174 const CondArg& argument)
175 {
176 assert ( n_argument < _NumConditionalArguments );
177 // index of conditional arguments of ConditionalPdf out of range
178 this->_ConditionalArguments[n_argument]= argument;
179 }
180
181} // End namespace
182#endif // __CONDITIONAL_PDF__
Abstract Class representing conditional Pdfs P(x | ...)
virtual void ConditionalArgumentsSet(std::vector< CondArg > ConditionalArguments)
Set the whole list of conditional arguments.
const CondArg & ConditionalArgumentGet(unsigned int n_argument) const
Get the n-th argument of the list.
virtual ~ConditionalPdf()
Destructor.
virtual ConditionalPdf< Var, CondArg > * Clone() const
Clone function.
virtual void NumConditionalArgumentsSet(unsigned int numconditionalarguments)
Set the Number of conditional arguments.
virtual void ConditionalArgumentSet(unsigned int n_argument, const CondArg &argument)
Set the n-th argument of the list.
unsigned int NumConditionalArgumentsGet() const
Get the Number of conditional arguments.
const std::vector< CondArg > & ConditionalArgumentsGet() const
Get the whole list of conditional arguments.
ConditionalPdf(int dimension=0, unsigned int num_conditional_arguments=0)
Constructor.