libDAI
Private Attributes | Related Functions | List of all members
dai::TFactorSp< T, spvector_type > Class Template Reference

Represents a (probability) factor. More...

#include <dai/factorsp.h>

Public Member Functions

Constructors and destructors
 TFactorSp (T p=1)
 Constructs factor depending on no variables with value p.
 TFactorSp (const Var &v)
 Constructs factor depending on the variable v with uniform distribution.
 TFactorSp (const VarSet &vars)
 Constructs factor depending on variables in vars with uniform distribution.
 TFactorSp (const VarSet &vars, T p)
 Constructs factor depending on variables in vars with all values set to p.
template<typename S >
 TFactorSp (const VarSet &vars, const std::vector< S > &x)
 Constructs factor depending on variables in vars, copying the values from a std::vector<>
 TFactorSp (const VarSet &vars, const T *p)
 Constructs factor depending on variables in vars, copying the values from an array.
 TFactorSp (const VarSet &vars, const TProbSp< T, spvector_type > &p)
 Constructs factor depending on variables in vars, copying the values from p.
 TFactorSp (const std::vector< Var > &vars, const std::vector< T > &p)
 Constructs factor depending on variables in vars, permuting the values given in p accordingly.
Get/set individual entries
void set (size_t i, T val)
 Sets i 'th entry to val.
get (size_t i) const
 Gets i 'th entry.
Queries
const TProbSp< T, spvector_type > & p () const
 Returns constant reference to value vector.
TProbSp< T, spvector_type > & p ()
 Returns reference to value vector.
operator[] (size_t i) const
 Returns a copy of the i 'th entry of the value vector.
const VarSetvars () const
 Returns constant reference to variable set (i.e., the variables on which the factor depends)
VarSetvars ()
 Returns reference to variable set (i.e., the variables on which the factor depends)
size_t nrStates () const
 Returns the number of possible joint states of the variables on which the factor depends, $\prod_{l\in L} S_l$.
entropy () const
 Returns the Shannon entropy of *this, $-\sum_i p_i \log p_i$.
max () const
 Returns maximum of all values.
min () const
 Returns minimum of all values.
sum () const
 Returns sum of all values.
sumAbs () const
 Returns sum of absolute values.
maxAbs () const
 Returns maximum absolute value of all values.
bool hasNaNs () const
 Returns true if one or more values are NaN.
bool hasNegatives () const
 Returns true if one or more values are negative.
strength (const Var &i, const Var &j) const
 Returns strength of this factor (between variables i and j), as defined in eq. (52) of [MoK07b].
bool operator== (const TFactorSp< T, spvector_type > &y) const
 Comparison.
Unary transformations
TFactorSp< T, spvector_type > operator- () const
 Returns negative of *this.
TFactorSp< T, spvector_type > abs () const
 Returns pointwise absolute value.
TFactorSp< T, spvector_type > exp () const
 Returns pointwise exponent.
TFactorSp< T, spvector_type > log (bool zero=false) const
 Returns pointwise logarithm.
TFactorSp< T, spvector_type > inverse (bool zero=true) const
 Returns pointwise inverse.
TFactorSp< T, spvector_type > normalized (ProbNormType norm=NORMPROB) const
 Returns normalized copy of *this, using the specified norm.
Unary operations
TFactorSp< T, spvector_type > & randomize ()
 Draws all values i.i.d. from a uniform distribution on [0,1)
TFactorSp< T, spvector_type > & setUniform ()
 Sets all values to $1/n$ where n is the number of states.
TFactorSp< T, spvector_type > & takeAbs ()
 Applies absolute value pointwise.
TFactorSp< T, spvector_type > & takeExp ()
 Applies exponent pointwise.
TFactorSp< T, spvector_type > & takeLog (bool zero=false)
 Applies logarithm pointwise.
normalize (ProbNormType norm=NORMPROB)
 Normalizes factor using the specified norm.
Operations with scalars
TFactorSp< T, spvector_type > & fill (T x)
 Sets all values to x.
TFactorSp< T, spvector_type > & operator+= (T x)
 Adds scalar x to each value.
TFactorSp< T, spvector_type > & operator-= (T x)
 Subtracts scalar x from each value.
TFactorSp< T, spvector_type > & operator*= (T x)
 Multiplies each value with scalar x.
TFactorSp< T, spvector_type > & operator/= (T x)
 Divides each entry by scalar x.
TFactorSp< T, spvector_type > & operator^= (T x)
 Raises values to the power x.
Transformations with scalars
TFactorSp< T, spvector_type > operator+ (T x) const
 Returns sum of *this and scalar x.
TFactorSp< T, spvector_type > operator- (T x) const
 Returns difference of *this and scalar x.
TFactorSp< T, spvector_type > operator* (T x) const
 Returns product of *this with scalar x.
TFactorSp< T, spvector_type > operator/ (T x) const
 Returns quotient of *this with scalar x.
TFactorSp< T, spvector_type > operator^ (T x) const
 Returns *this raised to the power x.
Operations with other factors
template<typename binOp >
TFactorSp< T, spvector_type > & binaryOp (const TFactorSp< T, spvector_type > &g, binOp op)
 Applies binary operation op on two factors, *this and g.
TFactorSp< T, spvector_type > & operator+= (const TFactorSp< T, spvector_type > &g)
 Adds g to *this.
TFactorSp< T, spvector_type > & operator-= (const TFactorSp< T, spvector_type > &g)
 Subtracts g from *this.
TFactorSp< T, spvector_type > & operator*= (const TFactorSp< T, spvector_type > &g)
 Multiplies *this with g.
TFactorSp< T, spvector_type > & operator/= (const TFactorSp< T, spvector_type > &g)
 Divides *this by g (where division by zero yields zero)
Transformations with other factors
template<typename binOp >
TFactorSp< T, spvector_type > binaryTr (const TFactorSp< T, spvector_type > &g, binOp op) const
 Returns result of applying binary operation op on two factors, *this and g.
TFactorSp< T, spvector_type > operator+ (const TFactorSp< T, spvector_type > &g) const
 Returns sum of *this and g.
TFactorSp< T, spvector_type > operator- (const TFactorSp< T, spvector_type > &g) const
 Returns *this minus g.
TFactorSp< T, spvector_type > operator* (const TFactorSp< T, spvector_type > &g) const
 Returns product of *this with g.
TFactorSp< T, spvector_type > operator/ (const TFactorSp< T, spvector_type > &g) const
 Returns quotient of *this by f (where division by zero yields zero)
Miscellaneous operations
TFactorSp< T, spvector_type > slice (const VarSet &vars, size_t varsState) const
 Returns a slice of *this, where the subset vars is in state varsState.
TFactorSp< T, spvector_type > embed (const VarSet &vars) const
 Embeds this factor in a larger VarSet.
TFactorSp< T, spvector_type > marginal (const VarSet &vars, bool normed=true) const
 Returns marginal on vars, obtained by summing out all variables except those in vars, and normalizing the result if normed == true.
TFactorSp< T, spvector_type > maxMarginal (const VarSet &vars, bool normed=true) const
 Returns max-marginal on vars, obtained by maximizing all variables except those in vars, and normalizing the result if normed == true.

Private Attributes

VarSet _vs
 Stores the variables on which the factor depends.
TProbSp< T, spvector_type > _p
 Stores the factor values.

Related Functions

(Note that these are not member functions.)

template<typename T , typename spvector_type , typename binaryOp >
TFactorSp< T, spvector_type > pointwiseOp (const TFactorSp< T, spvector_type > &f, const TFactorSp< T, spvector_type > &g, binaryOp op, bool fast=false)
 Apply binary operator pointwise on two factors.
template<typename T , typename spvector_type >
std::ostream & operator<< (std::ostream &os, const TFactorSp< T, spvector_type > &f)
 Writes a factor to an output stream.
template<typename T , typename spvector_type >
dist (const TFactorSp< T, spvector_type > &f, const TFactorSp< T, spvector_type > &g, ProbDistType dt)
 Returns distance between two factors f and g, according to the distance measure dt.
template<typename T , typename spvector_type >
TFactorSp< T, spvector_type > max (const TFactorSp< T, spvector_type > &f, const TFactorSp< T, spvector_type > &g)
 Returns the pointwise maximum of two factors.
template<typename T , typename spvector_type >
TFactorSp< T, spvector_type > min (const TFactorSp< T, spvector_type > &f, const TFactorSp< T, spvector_type > &g)
 Returns the pointwise minimum of two factors.
template<typename T , typename spvector_type >
MutualInfo (const TFactorSp< T, spvector_type > &f)
 Calculates the mutual information between the two variables that f depends on, under the distribution given by f.

Detailed Description

template<typename T, typename spvector_type>
class dai::TFactorSp< T, spvector_type >

Represents a (probability) factor.

Mathematically, a factor is a function mapping joint states of some variables to the nonnegative real numbers. More formally, denoting a discrete variable with label $l$ by $x_l$ and its state space by $X_l = \{0,1,\dots,S_l-1\}$, a factor depending on the variables $\{x_l\}_{l\in L}$ is a function $f_L : \prod_{l\in L} X_l \to [0,\infty)$.

In libDAI, a sparse factor is represented by a TFactorSp<T,spvector_type> object, which has two components:

The factor values are stored in the entries of the TProbSp in a particular ordering, which is defined by the one-to-one correspondence of a joint state in $\prod_{l\in L} X_l$ with a linear index in $\{0,1,\dots,\prod_{l\in L} S_l-1\}$ according to the mapping $\sigma$ induced by dai::calcLinearState().

Template Parameters
TShould be a scalar that is castable from and to double and should support elementary arithmetic operations.
Todo:

Define a better fileformat for .fg files (maybe using XML)?

Add support for sparse factors.

Constructor & Destructor Documentation

template<typename T, typename spvector_type>
dai::TFactorSp< T, spvector_type >::TFactorSp ( p = 1)
inline

Constructs factor depending on no variables with value p.

template<typename T, typename spvector_type>
dai::TFactorSp< T, spvector_type >::TFactorSp ( const Var v)
inline

Constructs factor depending on the variable v with uniform distribution.

template<typename T, typename spvector_type>
dai::TFactorSp< T, spvector_type >::TFactorSp ( const VarSet vars)
inline

Constructs factor depending on variables in vars with uniform distribution.

template<typename T, typename spvector_type>
dai::TFactorSp< T, spvector_type >::TFactorSp ( const VarSet vars,
p 
)
inline

Constructs factor depending on variables in vars with all values set to p.

template<typename T, typename spvector_type>
template<typename S >
dai::TFactorSp< T, spvector_type >::TFactorSp ( const VarSet vars,
const std::vector< S > &  x 
)
inline

Constructs factor depending on variables in vars, copying the values from a std::vector<>

Template Parameters
SType of values of x
Parameters
varscontains the variables that the new factor should depend on.
xVector with values to be copied.
template<typename T, typename spvector_type>
dai::TFactorSp< T, spvector_type >::TFactorSp ( const VarSet vars,
const T *  p 
)
inline

Constructs factor depending on variables in vars, copying the values from an array.

Parameters
varscontains the variables that the new factor should depend on.
pPoints to array of values to be added.
template<typename T, typename spvector_type>
dai::TFactorSp< T, spvector_type >::TFactorSp ( const VarSet vars,
const TProbSp< T, spvector_type > &  p 
)
inline

Constructs factor depending on variables in vars, copying the values from p.

template<typename T, typename spvector_type>
dai::TFactorSp< T, spvector_type >::TFactorSp ( const std::vector< Var > &  vars,
const std::vector< T > &  p 
)
inline

Constructs factor depending on variables in vars, permuting the values given in p accordingly.

Member Function Documentation

template<typename T, typename spvector_type>
void dai::TFactorSp< T, spvector_type >::set ( size_t  i,
val 
)
inline

Sets i 'th entry to val.

template<typename T, typename spvector_type>
T dai::TFactorSp< T, spvector_type >::get ( size_t  i) const
inline

Gets i 'th entry.

template<typename T, typename spvector_type>
const TProbSp<T,spvector_type>& dai::TFactorSp< T, spvector_type >::p ( ) const
inline

Returns constant reference to value vector.

template<typename T, typename spvector_type>
TProbSp<T,spvector_type>& dai::TFactorSp< T, spvector_type >::p ( )
inline

Returns reference to value vector.

template<typename T, typename spvector_type>
T dai::TFactorSp< T, spvector_type >::operator[] ( size_t  i) const
inline

Returns a copy of the i 'th entry of the value vector.

template<typename T, typename spvector_type>
const VarSet& dai::TFactorSp< T, spvector_type >::vars ( ) const
inline

Returns constant reference to variable set (i.e., the variables on which the factor depends)

template<typename T, typename spvector_type>
VarSet& dai::TFactorSp< T, spvector_type >::vars ( )
inline

Returns reference to variable set (i.e., the variables on which the factor depends)

template<typename T, typename spvector_type>
size_t dai::TFactorSp< T, spvector_type >::nrStates ( ) const
inline

Returns the number of possible joint states of the variables on which the factor depends, $\prod_{l\in L} S_l$.

Note
This is equal to the length of the value vector.
template<typename T, typename spvector_type>
T dai::TFactorSp< T, spvector_type >::entropy ( ) const
inline

Returns the Shannon entropy of *this, $-\sum_i p_i \log p_i$.

template<typename T, typename spvector_type>
T dai::TFactorSp< T, spvector_type >::max ( ) const
inline

Returns maximum of all values.

template<typename T, typename spvector_type>
T dai::TFactorSp< T, spvector_type >::min ( ) const
inline

Returns minimum of all values.

template<typename T, typename spvector_type>
T dai::TFactorSp< T, spvector_type >::sum ( ) const
inline

Returns sum of all values.

template<typename T, typename spvector_type>
T dai::TFactorSp< T, spvector_type >::sumAbs ( ) const
inline

Returns sum of absolute values.

template<typename T, typename spvector_type>
T dai::TFactorSp< T, spvector_type >::maxAbs ( ) const
inline

Returns maximum absolute value of all values.

template<typename T, typename spvector_type>
bool dai::TFactorSp< T, spvector_type >::hasNaNs ( ) const
inline

Returns true if one or more values are NaN.

template<typename T, typename spvector_type>
bool dai::TFactorSp< T, spvector_type >::hasNegatives ( ) const
inline

Returns true if one or more values are negative.

template<typename T , typename spvector_type >
T dai::TFactorSp< T, spvector_type >::strength ( const Var i,
const Var j 
) const

Returns strength of this factor (between variables i and j), as defined in eq. (52) of [MoK07b].

template<typename T, typename spvector_type>
bool dai::TFactorSp< T, spvector_type >::operator== ( const TFactorSp< T, spvector_type > &  y) const
inline

Comparison.

template<typename T, typename spvector_type>
TFactorSp<T,spvector_type> dai::TFactorSp< T, spvector_type >::operator- ( ) const
inline

Returns negative of *this.

template<typename T, typename spvector_type>
TFactorSp<T,spvector_type> dai::TFactorSp< T, spvector_type >::abs ( ) const
inline

Returns pointwise absolute value.

template<typename T, typename spvector_type>
TFactorSp<T,spvector_type> dai::TFactorSp< T, spvector_type >::exp ( ) const
inline

Returns pointwise exponent.

template<typename T, typename spvector_type>
TFactorSp<T,spvector_type> dai::TFactorSp< T, spvector_type >::log ( bool  zero = false) const
inline

Returns pointwise logarithm.

If zero == true, uses log(0)==0; otherwise, log(0)==-Inf.

template<typename T, typename spvector_type>
TFactorSp<T,spvector_type> dai::TFactorSp< T, spvector_type >::inverse ( bool  zero = true) const
inline

Returns pointwise inverse.

If zero == true, uses 1/0==0; otherwise, 1/0==Inf.

template<typename T, typename spvector_type>
TFactorSp<T,spvector_type> dai::TFactorSp< T, spvector_type >::normalized ( ProbNormType  norm = NORMPROB) const
inline

Returns normalized copy of *this, using the specified norm.

Exceptions
NOT_NORMALIZABLEif the norm is zero
template<typename T, typename spvector_type>
TFactorSp<T,spvector_type>& dai::TFactorSp< T, spvector_type >::randomize ( )
inline

Draws all values i.i.d. from a uniform distribution on [0,1)

template<typename T, typename spvector_type>
TFactorSp<T,spvector_type>& dai::TFactorSp< T, spvector_type >::setUniform ( )
inline

Sets all values to $1/n$ where n is the number of states.

template<typename T, typename spvector_type>
TFactorSp<T,spvector_type>& dai::TFactorSp< T, spvector_type >::takeAbs ( )
inline

Applies absolute value pointwise.

template<typename T, typename spvector_type>
TFactorSp<T,spvector_type>& dai::TFactorSp< T, spvector_type >::takeExp ( )
inline

Applies exponent pointwise.

template<typename T, typename spvector_type>
TFactorSp<T,spvector_type>& dai::TFactorSp< T, spvector_type >::takeLog ( bool  zero = false)
inline

Applies logarithm pointwise.

If zero == true, uses log(0)==0; otherwise, log(0)==-Inf.

template<typename T, typename spvector_type>
T dai::TFactorSp< T, spvector_type >::normalize ( ProbNormType  norm = NORMPROB)
inline

Normalizes factor using the specified norm.

Exceptions
NOT_NORMALIZABLEif the norm is zero
template<typename T, typename spvector_type>
TFactorSp<T,spvector_type>& dai::TFactorSp< T, spvector_type >::fill ( x)
inline

Sets all values to x.

template<typename T, typename spvector_type>
TFactorSp<T,spvector_type>& dai::TFactorSp< T, spvector_type >::operator+= ( x)
inline

Adds scalar x to each value.

template<typename T, typename spvector_type>
TFactorSp<T,spvector_type>& dai::TFactorSp< T, spvector_type >::operator-= ( x)
inline

Subtracts scalar x from each value.

template<typename T, typename spvector_type>
TFactorSp<T,spvector_type>& dai::TFactorSp< T, spvector_type >::operator*= ( x)
inline

Multiplies each value with scalar x.

template<typename T, typename spvector_type>
TFactorSp<T,spvector_type>& dai::TFactorSp< T, spvector_type >::operator/= ( x)
inline

Divides each entry by scalar x.

template<typename T, typename spvector_type>
TFactorSp<T,spvector_type>& dai::TFactorSp< T, spvector_type >::operator^= ( x)
inline

Raises values to the power x.

template<typename T, typename spvector_type>
TFactorSp<T,spvector_type> dai::TFactorSp< T, spvector_type >::operator+ ( x) const
inline

Returns sum of *this and scalar x.

template<typename T, typename spvector_type>
TFactorSp<T,spvector_type> dai::TFactorSp< T, spvector_type >::operator- ( x) const
inline

Returns difference of *this and scalar x.

template<typename T, typename spvector_type>
TFactorSp<T,spvector_type> dai::TFactorSp< T, spvector_type >::operator* ( x) const
inline

Returns product of *this with scalar x.

template<typename T, typename spvector_type>
TFactorSp<T,spvector_type> dai::TFactorSp< T, spvector_type >::operator/ ( x) const
inline

Returns quotient of *this with scalar x.

template<typename T, typename spvector_type>
TFactorSp<T,spvector_type> dai::TFactorSp< T, spvector_type >::operator^ ( x) const
inline

Returns *this raised to the power x.

template<typename T, typename spvector_type>
template<typename binOp >
TFactorSp<T,spvector_type>& dai::TFactorSp< T, spvector_type >::binaryOp ( const TFactorSp< T, spvector_type > &  g,
binOp  op 
)
inline

Applies binary operation op on two factors, *this and g.

Template Parameters
binOpType of function object that accepts two arguments of type T and outputs a type T
Parameters
gRight operand
opOperation of type binOp
template<typename T, typename spvector_type>
TFactorSp<T,spvector_type>& dai::TFactorSp< T, spvector_type >::operator+= ( const TFactorSp< T, spvector_type > &  g)
inline

Adds g to *this.

The sum of two factors is defined as follows: if $f : \prod_{l\in L} X_l \to [0,\infty)$ and $g : \prod_{m\in M} X_m \to [0,\infty)$, then

\[f+g : \prod_{l\in L\cup M} X_l \to [0,\infty) : x \mapsto f(x_L) + g(x_M).\]

template<typename T, typename spvector_type>
TFactorSp<T,spvector_type>& dai::TFactorSp< T, spvector_type >::operator-= ( const TFactorSp< T, spvector_type > &  g)
inline

Subtracts g from *this.

The difference of two factors is defined as follows: if $f : \prod_{l\in L} X_l \to [0,\infty)$ and $g : \prod_{m\in M} X_m \to [0,\infty)$, then

\[f-g : \prod_{l\in L\cup M} X_l \to [0,\infty) : x \mapsto f(x_L) - g(x_M).\]

template<typename T, typename spvector_type>
TFactorSp<T,spvector_type>& dai::TFactorSp< T, spvector_type >::operator*= ( const TFactorSp< T, spvector_type > &  g)
inline

Multiplies *this with g.

The product of two factors is defined as follows: if $f : \prod_{l\in L} X_l \to [0,\infty)$ and $g : \prod_{m\in M} X_m \to [0,\infty)$, then

\[fg : \prod_{l\in L\cup M} X_l \to [0,\infty) : x \mapsto f(x_L) g(x_M).\]

template<typename T, typename spvector_type>
TFactorSp<T,spvector_type>& dai::TFactorSp< T, spvector_type >::operator/= ( const TFactorSp< T, spvector_type > &  g)
inline

Divides *this by g (where division by zero yields zero)

The quotient of two factors is defined as follows: if $f : \prod_{l\in L} X_l \to [0,\infty)$ and $g : \prod_{m\in M} X_m \to [0,\infty)$, then

\[\frac{f}{g} : \prod_{l\in L\cup M} X_l \to [0,\infty) : x \mapsto \frac{f(x_L)}{g(x_M)}.\]

template<typename T, typename spvector_type>
template<typename binOp >
TFactorSp<T,spvector_type> dai::TFactorSp< T, spvector_type >::binaryTr ( const TFactorSp< T, spvector_type > &  g,
binOp  op 
) const
inline

Returns result of applying binary operation op on two factors, *this and g.

Template Parameters
binOpType of function object that accepts two arguments of type T and outputs a type T
Parameters
gRight operand
opOperation of type binOp
template<typename T, typename spvector_type>
TFactorSp<T,spvector_type> dai::TFactorSp< T, spvector_type >::operator+ ( const TFactorSp< T, spvector_type > &  g) const
inline

Returns sum of *this and g.

The sum of two factors is defined as follows: if $f : \prod_{l\in L} X_l \to [0,\infty)$ and $g : \prod_{m\in M} X_m \to [0,\infty)$, then

\[f+g : \prod_{l\in L\cup M} X_l \to [0,\infty) : x \mapsto f(x_L) + g(x_M).\]

template<typename T, typename spvector_type>
TFactorSp<T,spvector_type> dai::TFactorSp< T, spvector_type >::operator- ( const TFactorSp< T, spvector_type > &  g) const
inline

Returns *this minus g.

The difference of two factors is defined as follows: if $f : \prod_{l\in L} X_l \to [0,\infty)$ and $g : \prod_{m\in M} X_m \to [0,\infty)$, then

\[f-g : \prod_{l\in L\cup M} X_l \to [0,\infty) : x \mapsto f(x_L) - g(x_M).\]

template<typename T, typename spvector_type>
TFactorSp<T,spvector_type> dai::TFactorSp< T, spvector_type >::operator* ( const TFactorSp< T, spvector_type > &  g) const
inline

Returns product of *this with g.

The product of two factors is defined as follows: if $f : \prod_{l\in L} X_l \to [0,\infty)$ and $g : \prod_{m\in M} X_m \to [0,\infty)$, then

\[fg : \prod_{l\in L\cup M} X_l \to [0,\infty) : x \mapsto f(x_L) g(x_M).\]

template<typename T, typename spvector_type>
TFactorSp<T,spvector_type> dai::TFactorSp< T, spvector_type >::operator/ ( const TFactorSp< T, spvector_type > &  g) const
inline

Returns quotient of *this by f (where division by zero yields zero)

The quotient of two factors is defined as follows: if $f : \prod_{l\in L} X_l \to [0,\infty)$ and $g : \prod_{m\in M} X_m \to [0,\infty)$, then

\[\frac{f}{g} : \prod_{l\in L\cup M} X_l \to [0,\infty) : x \mapsto \frac{f(x_L)}{g(x_M)}.\]

template<typename T , typename spvector_type >
TFactorSp< T, spvector_type > dai::TFactorSp< T, spvector_type >::slice ( const VarSet vars,
size_t  varsState 
) const

Returns a slice of *this, where the subset vars is in state varsState.

Precondition
vars sould be a subset of vars()
varsState < vars.nrStates()

The result is a factor that depends on the variables of *this except those in vars, obtained by setting the variables in vars to the joint state specified by the linear index varsState. Formally, if *this corresponds with the factor $f : \prod_{l\in L} X_l \to [0,\infty)$, $M \subset L$ corresponds with vars and varsState corresponds with a mapping $s$ that maps a variable $x_m$ with $m\in M$ to its state $s(x_m) \in X_m$, then the slice returned corresponds with the factor $g : \prod_{l \in L \setminus M} X_l \to [0,\infty)$ defined by $g(\{x_l\}_{l\in L \setminus M}) = f(\{x_l\}_{l\in L \setminus M}, \{s(x_m)\}_{m\in M})$.

template<typename T, typename spvector_type>
TFactorSp<T,spvector_type> dai::TFactorSp< T, spvector_type >::embed ( const VarSet vars) const
inline

Embeds this factor in a larger VarSet.

Precondition
vars() should be a subset of vars

If *this corresponds with $f : \prod_{l\in L} X_l \to [0,\infty)$ and $L \subset M$, then the embedded factor corresponds with $g : \prod_{m\in M} X_m \to [0,\infty) : x \mapsto f(x_L)$.

template<typename T , typename spvector_type >
TFactorSp< T, spvector_type > dai::TFactorSp< T, spvector_type >::marginal ( const VarSet vars,
bool  normed = true 
) const

Returns marginal on vars, obtained by summing out all variables except those in vars, and normalizing the result if normed == true.

template<typename T , typename spvector_type >
TFactorSp< T, spvector_type > dai::TFactorSp< T, spvector_type >::maxMarginal ( const VarSet vars,
bool  normed = true 
) const

Returns max-marginal on vars, obtained by maximizing all variables except those in vars, and normalizing the result if normed == true.

Friends And Related Function Documentation

template<typename T , typename spvector_type , typename binaryOp >
TFactorSp< T, spvector_type > pointwiseOp ( const TFactorSp< T, spvector_type > &  f,
const TFactorSp< T, spvector_type > &  g,
binaryOp  op,
bool  fast = false 
)
related

Apply binary operator pointwise on two factors.

Template Parameters
binaryOpType of function object that accepts two arguments of type T and outputs a type T
Parameters
fLeft operand
gRight operand
opOperation of type binaryOp
fastIf true, supposes that the default value of f always gives the same result in op, and similarly for the default value of g
template<typename T , typename spvector_type >
std::ostream & operator<< ( std::ostream &  os,
const TFactorSp< T, spvector_type > &  f 
)
related

Writes a factor to an output stream.

template<typename T , typename spvector_type >
T dist ( const TFactorSp< T, spvector_type > &  f,
const TFactorSp< T, spvector_type > &  g,
ProbDistType  dt 
)
related

Returns distance between two factors f and g, according to the distance measure dt.

Precondition
f.vars() == g.vars()
template<typename T , typename spvector_type >
TFactorSp< T, spvector_type > max ( const TFactorSp< T, spvector_type > &  f,
const TFactorSp< T, spvector_type > &  g 
)
related

Returns the pointwise maximum of two factors.

Precondition
f.vars() == g.vars()
template<typename T , typename spvector_type >
TFactorSp< T, spvector_type > min ( const TFactorSp< T, spvector_type > &  f,
const TFactorSp< T, spvector_type > &  g 
)
related

Returns the pointwise minimum of two factors.

Precondition
f.vars() == g.vars()
template<typename T , typename spvector_type >
T MutualInfo ( const TFactorSp< T, spvector_type > &  f)
related

Calculates the mutual information between the two variables that f depends on, under the distribution given by f.

Precondition
f.vars().size() == 2

Member Data Documentation

template<typename T, typename spvector_type>
VarSet dai::TFactorSp< T, spvector_type >::_vs
private

Stores the variables on which the factor depends.

template<typename T, typename spvector_type>
TProbSp<T,spvector_type> dai::TFactorSp< T, spvector_type >::_p
private

Stores the factor values.


The documentation for this class was generated from the following file: