#include <probabilities.hpp>
Public Types | |
| typedef Domain | domain_type |
| Type of domain of operations. | |
| typedef Value | value_type |
| Type representing probability values. | |
| typedef Validator | validator_type |
| Type modeling ValidatorConcept for probability values. | |
Public Member Functions | |
| probability () | |
| Construct a probability of unity. | |
| template<typename T> | |
| probability (const T &t) | |
| Explicitly construct a probability. | |
| template<typename T, typename D> | |
| probability (const T &t, D) | |
| Explicitly construct a probability from another domain. | |
| template<typename D, typename V, typename VV> | |
| probability (const probability< D, V, VV > &p) | |
| Transform a probability from another domain. | |
| probability (const probability &p) | |
| probability & | operator= (const probability &p) |
| void | swap (probability &p) |
| probability | operator+ () const |
| Unary plus operator. | |
| template<typename D> | |
| probability< D, value_type, validator_type > | domain_cast (D) const |
| Cast to another domain. | |
| template<typename D> | |
| value_type | value_cast (D) const |
| Cast the internal value to another domain. | |
Mathematical assignment operators | |
The probability class is derived from the boost::operators classes. As a result, these mathematical assignment operators are the foundation for a complete set of natural mathematical operations. The probability class supports the full range of arithmetic operators. | |
| template<typename D, typename V, typename VV> | |
| probability & | operator+= (const probability< D, V, VV > &p) |
| Addition assignment operator. | |
| template<typename T> | |
| probability & | operator+= (const T &t) |
| Addition assignment operator. | |
| template<typename D, typename V, typename VV> | |
| probability & | operator-= (const probability< D, V, VV > &p) |
| Subtraction assignment operator. | |
| template<typename T> | |
| probability & | operator-= (const T &t) |
| Subtraction assignment operator. | |
| template<typename D, typename V, typename VV> | |
| probability & | operator *= (const probability< D, V, VV > &p) |
| Multiplication assignment operator. | |
| template<typename T> | |
| probability & | operator *= (const T &t) |
| Multiplication assignment operator. | |
| template<typename D, typename V, typename VV> | |
| probability & | operator/= (const probability< D, V, VV > &p) |
| Division assignment operator. | |
| template<typename T> | |
| probability & | operator/= (const T &t) |
| Division assignment operator. | |
This class encapsulates a probability quantity, represented as the value_type template argument. Probabilities and their logarithms are encapsulated by types differing in their domains (i.e., the linear_domain versus the log_domain). In both cases, however, the same semantics apply to the same operators. For example, the multiplication operator operator*() denotes multiplication of probabilities or addition of logarithms of probabilities. This helps make the fundamental operations clearer in the code while providing an explicit means of selecting the mode of operation, for example to avoid underflow of the value_type. The consistency of semantics also makes generic algorithms possible.
In addition to providing all the natural arithmetic operators, the probability class models the following concepts.
value_type must also model most of these. In addition, the value_type must provide the exponential functions exp(), log(), and log1p(). Finally, the class provides strong exception guarrantees. For example, although an assignment may throw an exception, it will do so only if the copy constructor does. If this occurs, the original lvalue object is guarranteed to be unchanged.
|
|||||
|
Type of domain of operations. The domain of operations is assumed to be one of linear_domain or log_domain. |
|
|||||
|
Type representing probability values. The value type should be a model of the real numbers within the closed interval [0,1]. |
|
|||||||||
|
Construct a probability of unity. In many contexts, the most common operation on probabilities is multiplication. To simplify the accumulation of a product of probabilities, the default constructed value is the multiplicative identity. |
|
||||||||||||||
|
Explicitly construct a probability.
value_type). |
|
||||||||||||||||||||
|
Explicitly construct a probability from another domain.
value_type). |
|
||||||||||||||
|
Multiplication assignment operator.
Multiply a probability by a value of type T. Note that the type T must be convertible to the |
|
||||||||||||||
|
Addition assignment operator.
Add a value of type T to a probability. Note that the type T must be convertible to the |
|
||||||||||||||
|
Subtraction assignment operator.
Subtract a value of type T from a probability. Note that the type T must be convertible to the |
|
||||||||||||||
|
Division assignment operator.
Divide a probability by a value of type T. Note that the type T must be convertible to the |
1.4.5