Public Member Functions |
|
| 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.
|
|
void | set (size_t i, T val) |
| Sets i 'th entry to val.
|
T | get (size_t i) const |
| Gets i 'th entry.
|
|
const TProbSp< T, spvector_type > & | p () const |
| Returns constant reference to value vector.
|
TProbSp< T, spvector_type > & | p () |
| Returns reference to value vector.
|
T | operator[] (size_t i) const |
| Returns a copy of the i 'th entry of the value vector.
|
const VarSet & | vars () const |
| Returns constant reference to variable set (i.e., the variables on which the factor depends)
|
VarSet & | vars () |
| 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, .
|
T | entropy () const |
| Returns the Shannon entropy of *this , .
|
T | max () const |
| Returns maximum of all values.
|
T | min () const |
| Returns minimum of all values.
|
T | sum () const |
| Returns sum of all values.
|
T | sumAbs () const |
| Returns sum of absolute values.
|
T | 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.
|
T | 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.
|
|
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.
|
|
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 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.
|
T | normalize (ProbNormType norm=NORMPROB) |
| Normalizes factor using the specified norm.
|
|
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.
|
|
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.
|
|
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)
|
|
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)
|
|
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 .
|
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 > |
T | 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 > |
T | 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.
|
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
by
and its state space by
, a factor depending on the variables
is a function
.
In libDAI, a sparse factor is represented by a TFactorSp<T,spvector_type> object, which has two components:
- a VarSet, corresponding with the set of variables
that the factor depends on;
- a TProbSp, a vector containing the value of the factor for each possible joint state of the variables.
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
with a linear index in
according to the mapping
induced by dai::calcLinearState().
- Template Parameters
-
T | Should 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.