3 #ifndef PROB_WEIGHT_ARRAY_H_
4 #define PROB_WEIGHT_ARRAY_H_
18 #include <boost/array.hpp>
19 #include <boost/bind.hpp>
45 typedef boost::array<bool, D>
Filter;
52 : values_(), total_mass_(0), modified_(true), normalized_(false)
64 template<
typename InputIter>
66 : values_(), total_mass_(0), modified_(true), normalized_(false)
68 std::copy(start, end, values_.begin());
144 template<
size_t M,
size_t K>
155 friend bool operator==<>(
const Self_t& left,
const Self_t& right);
159 friend bool operator!=<>(
const Self_t& left,
const Self_t& right);
165 void set_as_normalized()
174 mutable bool modified_;
182 const Weight_array<D>& left,
183 const Weight_array<D>& right
188 const Weight_array<D>& left,
189 const Weight_array<D>& right
194 const Weight_array<D>& left,
195 const Weight_array<D>& right
200 const Weight_array<D>& w,
201 const typename Weight_array<D>::Val_type& offset
206 const Weight_array<D>& w,
207 const typename Weight_array<D>::Val_type&
scale
212 const Weight_array<D>& w,
213 const typename Weight_array<D>::Val_type& right
216 template<
size_t D,
size_t K>
218 const Weight_array<K>& weights,
219 const boost::array<Weight_array<D>, K>& components
241 operator/=(total_mass());
252 begin(), end(), right.
begin(), begin(),
253 std::plus<Val_type>()
255 modified_ =
true; normalized_ =
false;
264 begin(), end(), right.
begin(), begin(),
265 std::multiplies<Val_type>()
267 modified_ =
true; normalized_ =
false;
276 begin(), end(), right.
begin(), begin(),
277 std::divides<Val_type>()
279 modified_ =
true; normalized_ =
false;
289 begin(), end(), begin(),
290 boost::bind(std::plus<Val_type>(), _1, offset)
292 if(modified_ ==
false) total_mass_ +=
D*offset;
299 const typename Weight_array<D>::Val_type&
scale
303 begin(), end(), begin(),
304 boost::bind(std::multiplies<Val_type>(), _1, scale)
306 if(modified_ ==
false) total_mass_ *=
scale;
313 const typename Weight_array<D>::Val_type& scale
317 begin(), end(), begin(),
318 boost::bind(std::divides<Val_type>(), _1, scale)
320 if(modified_ ==
false) total_mass_ /=
scale;
327 const typename Weight_array<D>::Filter& filter
331 begin(), end(), filter.begin(), begin(),
332 boost::bind(std::multiplies<Val_type>(), _1, _2)
341 const size_t& position
348 "Attempted to access nonexistent data position in "
352 return values_[position];
365 return abs(log(a) - log(b));
373 typedef typename Wt_arr::Val_type Val_t;
374 typedef typename Wt_arr::Data_type Data_t;
377 Wt_arr left_normed = left;
378 Wt_arr right_normed = right;
380 right_normed.normalize();
383 left_normed.begin(), left_normed.end(),
384 right_normed.begin(),
388 Val_t total_abs_diff =
390 diff_arr.begin(), diff_arr.end(),
static_cast<Val_t
>(0)
392 return total_abs_diff <
D * 0.0000000000000001;
398 return !(left == right);
463 result /= normalization;
467 template<
size_t D,
size_t K>
474 typedef typename WA::Val_type Val_t;
476 boost::array<WA, K> rescaled_components = components;
478 rescaled_components.begin(), rescaled_components.end(),
479 boost::bind(&WA::normalize, _1)
482 rescaled_components.begin(), rescaled_components.end(),
484 rescaled_components.begin(),
486 static_cast<WA& (WA::*)(
const Val_t&)
>(&WA::operator*=),
492 rescaled_components.begin(), rescaled_components.end(),
507 it != wa.
end(); ++it)
515 template<
typename T,
size_t D>
518 const boost::array<T, D>& arr
522 for(
typename boost::array<T,D>::const_iterator it = arr.begin();
523 it != arr.end(); ++it)
Weight_array(InputIter start, InputIter end)
Definition: prob_weight_array.h:65
friend std::ostream & operator<<(std::ostream &os, const Weight_array< M > &wa)
double accumulate(const Matrix_d< R, C, T > &mat, double init)
Definition: m_matrix_d.impl.h:432
Weight_array(const Data_type &values)
construct a Weight_array from a value array
Definition: prob_weight_array.h:57
Object thrown when an index argument exceeds the size of a container.
Definition: l_exception.h:399
boost::array< bool, D > Filter
Definition: prob_weight_array.h:45
const_iterator begin() const
get a const_iterator to the first value
Definition: prob_weight_array.h:83
Self_t & operator/=(const Self_t &right)
rescale the weights by division element-wise
Definition: prob_weight_array.h:272
boost::array< Val_type, D > Data_type
Definition: prob_weight_array.h:44
const_iterator cend() const
get a const_iterator to the last value
Definition: prob_weight_array.h:77
iterator begin()
get an iterator to the first value
Definition: prob_weight_array.h:95
Image operator+(const Image &op1, const Image &op2)
Add two images.
Definition: i_image.h:834
Self_t & operator*=(const Self_t &right)
rescale the weights element-wise
Definition: prob_weight_array.h:260
friend Weight_array< M > convex_combination(const Weight_array< K > &weights, const boost::array< Weight_array< M >, K > &components)
const_iterator end() const
get a const_iterator to the last value
Definition: prob_weight_array.h:89
iterator end()
get an iterator to the last value
Definition: prob_weight_array.h:101
Self_t & operator+=(const Self_t &right)
shift values
Definition: prob_weight_array.h:248
kjb_c::Pixel abs(const kjb_c::Pixel &p)
Take the channel-wise absolute value of a kjb_c::Pixel.
Definition: i_pixel.h:354
Weight_array< D > convex_combination(const Weight_array< K > &weights, const boost::array< Weight_array< D >, K > &components)
Definition: prob_weight_array.h:468
Data_type::const_iterator const_iterator
Definition: prob_weight_array.h:47
const_iterator cbegin() const
get a const_iterator to the first value
Definition: prob_weight_array.h:73
Data_type::iterator iterator
Definition: prob_weight_array.h:46
std::ofstream & operator<<(std::ofstream &out, const Quaternion &q)
Definition: turntable_camera.cpp:77
Image operator/(const Image &op1, double op2)
Scale an image in channel space, yielding a new image.
Definition: i_image.h:825
Filter class.
Definition: i_filter.h:36
Weight_array< D > Self_t
Definition: prob_weight_array.h:42
#define KJB_THROW_2(ex, msg)
Definition: l_exception.h:48
bool operator!=(const Int_matrix &op1, const Int_matrix::Impl_type &op2)
Test for any difference between two matrices.
Definition: l_int_matrix.h:1274
const Val_type & operator[](const size_t &position) const
access value in position position.
Definition: prob_weight_array.h:340
double Val_type
Definition: prob_weight_array.h:43
bool operator==(const Int_matrix &op1, const Int_matrix::Impl_type &op2)
Test for exact equality between two matrices.
Definition: l_int_matrix.cpp:218
Various utility functions for probabiliity-related stuff.
Weight_array()
construct an empty Weight_array
Definition: prob_weight_array.h:51
Forward declarations.
Definition: prob_weight_array.h:28
D
Definition: APPgetLargeConnectedEdges.m:106
Support for error handling exception classes in libKJB.
Self_t & normalize()
normalize the weights
Definition: prob_weight_array.h:237
void scale(kjb::Axis_aligned_rectangle_2d &box, const kjb::Vector &s)
Definition: gr_2D_bounding_box.cpp:108
Gsl_Vector operator*(double scalar, const Gsl_Vector &vector)
multiply scalar and vector, scalar written on the left side
Definition: gsl_vector.h:661
Val_type total_mass() const
get total mass
Definition: prob_weight_array.h:226