libDAI
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
include
dai
trwbp.h
Go to the documentation of this file.
1
/* This file is part of libDAI - http://www.libdai.org/
2
*
3
* Copyright (c) 2006-2011, The libDAI authors. All rights reserved.
4
*
5
* Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
6
*/
7
8
11
12
13
#ifndef __defined_libdai_trwbp_h
14
#define __defined_libdai_trwbp_h
15
16
17
#include <string>
18
#include <
dai/daialg.h
>
19
#include <
dai/factorgraph.h
>
20
#include <
dai/properties.h
>
21
#include <
dai/enum.h
>
22
#include <
dai/bp.h
>
23
24
25
namespace
dai {
26
27
29
48
class
TRWBP
:
public
BP
{
49
protected
:
51
56
std::vector<Real>
_weight
;
57
58
public
:
60
64
size_t
nrtrees
;
65
66
public
:
68
69
70
TRWBP
() :
BP
(),
_weight
() {}
71
73
78
TRWBP
(
const
FactorGraph
&
fg
,
const
PropertySet
&opts ) :
BP
(fg, opts),
_weight
() {
79
setProperties
( opts );
80
construct
();
81
}
83
85
86
virtual
TRWBP
*
clone
()
const
{
return
new
TRWBP
(*
this
); }
87
virtual
TRWBP
*
construct
(
const
FactorGraph
&
fg
,
const
PropertySet
&opts )
const
{
return
new
TRWBP
( fg, opts ); }
88
virtual
std::string
name
()
const
{
return
"TRWBP"
; }
89
virtual
Real
logZ
()
const
;
90
virtual
void
setProperties
(
const
PropertySet
&opts );
91
virtual
PropertySet
getProperties
()
const
;
92
virtual
std::string
printProperties
()
const
;
94
96
97
98
Real
Weight
(
size_t
I )
const
{
return
_weight
[I]; }
99
101
const
std::vector<Real>&
Weights
()
const
{
return
_weight
; }
102
104
void
setWeight
(
size_t
I,
Real
c ) {
_weight
[I] = c; }
105
107
109
void
setWeights
(
const
std::vector<Real> &c ) {
_weight
= c; }
110
112
void
addTreeToWeights
(
const
RootedTree
&tree );
113
115
void
sampleWeights
(
size_t
nrTrees );
116
117
protected
:
119
122
virtual
Prob
calcIncomingMessageProduct
(
size_t
I,
bool
without_i,
size_t
i )
const
;
123
125
virtual
void
calcBeliefV
(
size_t
i,
Prob
&p )
const
;
126
127
// Calculates unnormalized belief of factor \a I
128
virtual
void
calcBeliefF
(
size_t
I,
Prob
&p )
const
{
129
p =
calcIncomingMessageProduct
( I,
false
, 0 );
130
}
131
132
// Helper function for constructors
133
virtual
void
construct
();
134
};
135
136
137
}
// end of namespace dai
138
139
140
#endif
Generated on Mon Sep 17 2012 12:30:35 for libDAI by
1.8.1.2