yat
0.14.5pre
|
Most functionality in yat come in two versions: one optimized for speed and one weighted version allowing for missing value (see Weighted Statistics). For example, weighted containers such as theplu::yat::utility::MatrixWeighted and theplu::yat::classifier::MatrixLookupWeighted allow an easy way to handle missing values. Iterators that iterate over such weighted containers are by definition Weighted Iterator. This concept is orthogonal against other iterator concepts such as Random Access Iterator.
When implementing a new iterator that may be a Weighted Iterator, there are a few things to concider.
To decide whether an iterator is weighted, there exists a meta-function theplu::yat::utility::weighted_iterator_traits<Iterator>::type that will return either theplu::yat::utility::weighted_iterator_tag or theplu::yat::utility::unweighted_iterator_tag. The default implementation of this meta-function works in most cases, including on all std::iterators, but if you implement a new iterator make sure it behaves as you desire, or you need to create a specialization.
Sometimes it is useful to have unweighted iterators behaving as though they were weighted. For instance, theplu::yat::statistics::EuclideanDistance calculates the distance between two ranges. If both ranges are unweighted the unweighted version is used, and when any of the two ranges is weighted the weighted version kicks in. In order to make this work also when comparing weighted and unweighted ranges, there must a mechanism to let the unweighted iterator behave as though it were weighted.
This can be accomplished through theplu::yat::utility::iterator_traits, which enables access to data value as well as to weight value. For unweighted iterators the weight value is always equal to 1.0 and is not mutable. The default implementation works for most iterators including all unweighted, but if you implement a new weighted iterator you need to check that the default implementation will work for you (see class documentation). Otherwise, you will need to implement a specialization. Note that the default implementation requires that, if iterator
is a weighted iterator, its reference
must have member functions data() and weight(). This should not be a problem as long as reference
is theplu::yat::utility::DataWeight or theplu::yat::utility::DataWeightProxy, but could potentially be a problem when creating weighted iterators with other reference
.