19 #ifndef MCMCDA_DATA_H_INCLUDED
20 #define MCMCDA_DATA_H_INCLUDED
33 #include <boost/function.hpp>
34 #include <boost/bind.hpp>
35 #include <boost/ref.hpp>
49 template<
class Element>
50 class Data :
private std::vector<std::set<Element> >
53 typedef boost::function1<Vector, const Element&>
Convert;
56 typedef std::set<Element> E_set;
57 typedef std::vector<E_set> Parent;
68 template<
class Iterator>
69 Data(Iterator first, Iterator last) : Parent(first, last) {}
78 using Parent::reserve;
79 using Parent::push_back;
80 using Parent::operator[];
81 using Parent::operator=;
88 void read(
const std::vector<std::string>& filenames)
91 "Read data from file: must have at least two time steps.");
94 resize(filenames.size());
95 std::transform(filenames.begin(), filenames.end(), begin(),
102 void write(
const std::vector<std::string>& filenames)
const;
121 "write_single_time: not defined in general");
137 not_equal_to<E_set>(),
139 boost::cref(empty_set)));
141 return eset_p == end();
180 template<
class Element>
210 template<
class Element>
213 const size_t sz = size();
215 "Write data to file: wrong number of files.");
217 for(
size_t t = 0; t < sz; t++)
225 template<
class Element>
237 std::set<const Element*> hood;
240 "neighborhood: t=%d cannot be negative.", (t));
242 if(t + d >= static_cast<int>(size()) || t + d < 1 ||
std::abs(d) > d_bar)
246 const E_set& Y_t = (*this)[t - 1 + d];
247 for(
typename E_set::const_iterator p = Y_t.begin();
251 if(
is_neighbor(y, *p, d, d_bar, v_bar, sg, to_vector))
262 template<
class Element>
277 "neighborhood: t=%d cannot be negative.", (t));
279 if(t + d >= static_cast<int>(size()) || t + d < 0 ||
std::abs(d) > d_bar)
284 const E_set& Y_t = (*this)[t - 1 + d];
285 for(
typename E_set::const_iterator p = Y_t.begin();
289 if(
is_neighbor(y, *p, d, d_bar, v_bar, sg, to_vector))
305 std::set<Vector> data_t;
320 const std::string& filename
323 std::ofstream ofs(filename.c_str());
329 std::copy(data_t.begin(), data_t.end(),
330 std::ostream_iterator<Vector>(ofs,
"\n"));
double vector_distance(const Int_vector &op1, const Int_vector &op2)
Compute the Euclidian distance between two vectors.
Definition: l_int_vector.h:1569
virtual E_set read_single_time(const std::string &) const
Read data elements from a single time-step, contained in a single file.
Definition: mcmcda_data.h:108
Definition for the Matrix class, a thin wrapper on the KJB Matrix struct and its related functionalit...
A class that holds data for the tracking problem.
Definition: mcmcda_data.h:50
int neighborhood_size(const Element &y, int t, int d, int d_bar, double v_bar, double sg, const Convert &to_vector) const
Computes the size of the neighborhood of a point. This should be faster than computing the neighborho...
Definition: mcmcda_data.h:264
Parent::iterator iterator
Definition: mcmcda_data.h:82
#define IFT(a, ex, msg)
Definition: l_exception.h:101
virtual void write_single_time(const E_set &, const std::string &) const
Read data elements from a single time-step, contained in a single file.
Definition: mcmcda_data.h:118
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
std::set< const Element * > neighborhood(const Element &y, int t, int d, int d_bar, double v_bar, double sg, const Convert &to_vector) const
Computes the neighborhood of a point. See MCMCDA paper for details.
Definition: mcmcda_data.h:227
boost::function1< Vector, const Element & > Convert
Definition: mcmcda_data.h:53
Data(Iterator first, Iterator last)
Constructor from sequence.
Definition: mcmcda_data.h:69
#define KJB_THROW_2(ex, msg)
Definition: l_exception.h:48
void read(const std::vector< std::string > &filenames)
Reads data from files with given names.
Definition: mcmcda_data.h:88
#define KJB_THROW_3(ex, fmt, params)
Definition: l_exception.h:56
Parent::const_iterator const_iterator
Definition: mcmcda_data.h:83
bool is_neighbor(const Element &y, const Element &y_p, int d, int d_bar, double v_bar, double sg, const typename Data< Element >::Convert &to_vector)
Returns true if given point is a neighbor of second given point.
Definition: mcmcda_data.h:182
Object thrown when an argument to a function is not acceptable.
Definition: l_exception.h:377
Object thrown when attempting to use unimplemented functionality.
Definition: l_exception.h:281
bool is_completely_empty() const
Checks whether this data set is completely empty.
Definition: mcmcda_data.h:128
Object thrown when input or output fails.
Definition: l_exception.h:496
This class implements matrices, in the linear-algebra sense, with real-valued elements.
Definition: m_matrix.h:94
Support for error handling exception classes in libKJB.
#define IFTD(a, ex, msg, params)
Definition: l_exception.h:112
OutputIterator get_all_rows(OutputIterator result) const
Return all rows of this matrix into the provided iterator.
Definition: m_matrix.h:1656
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...
void write(const std::vector< std::string > &filenames) const
Write data to files with given names.
Definition: mcmcda_data.h:211
Data()
Empty constructor.
Definition: mcmcda_data.h:61