1#ifndef FSTDATAINTERVALLER_H
2#define FSTDATAINTERVALLER_H
87template<
typename IDXTYPE>
93template <
class CONTAINER,
typename IDXTYPE>
96template <
class CONTAINER,
typename IDXTYPE>
100template<
class CONTAINER,
typename IDXTYPE>
102class Data_Intervaller :
public CONTAINER {
104 Data_Intervaller() {
notify(
"Data_Intervaller constructor.");};
109 virtual ~Data_Intervaller() {
notify(
"Data_Intervaller destructor.");};
131 void reduce(
const std::shared_ptr<Data_Intervaller<CONTAINER,IDXTYPE> > reducer, std::shared_ptr<Data_Intervaller<CONTAINER,IDXTYPE> > target);
133 friend std::ostream& operator<< <>(std::ostream& os,
const Data_Intervaller<CONTAINER,IDXTYPE>& ia);
135 typedef typename Data_Intervaller<CONTAINER,IDXTYPE>::iterator
TCI;
139template<
class CONTAINER,
typename IDXTYPE>
140Data_Intervaller<CONTAINER,IDXTYPE>::Data_Intervaller(
const Data_Intervaller& tin)
142 notify(
"Data_Intervaller copy constructor.");
144 for(
typename Data_Intervaller<CONTAINER,IDXTYPE>::const_iterator iter=tin.begin();iter!=tin.end();iter++) this->push_back(*iter);
151template<
class CONTAINER,
typename IDXTYPE>
152std::ostream&
operator<<(std::ostream& os,
const Data_Intervaller<CONTAINER,IDXTYPE>& ia) {
153 for(
typename Data_Intervaller<CONTAINER,IDXTYPE>::const_iterator iter=ia.begin();iter!=ia.end();iter++) os <<
"si:" << iter->startidx <<
", c:" << iter->count << std::endl;
157template<
class CONTAINER,
typename IDXTYPE>
166template<
class CONTAINER,
typename IDXTYPE>
176template<
class CONTAINER,
typename IDXTYPE>
179 if(this->empty()) {{std::ostringstream sos; sos <<
"Data_Intervaller is empty" << std::endl;
syncout::print(std::cerr,sos);}
return false;}
180 TCI iter=this->begin();
181 IDXTYPE pivot=iter->startidx+iter->count;
182 if(iter->startidx<0 || (maxidx>0 && (pivot>maxidx)) ) {{std::ostringstream sos; sos <<
"first is wrong"<<std::endl;
syncout::print(std::cerr,sos);}
return false;}
184 while(iter!=this->end())
186 if(iter->startidx<pivot) {{std::ostringstream sos; sos <<
"iter->startidx="<<iter->startidx<<
", pivot="<<pivot<<std::endl;
syncout::print(std::cerr,sos);}
return false;}
187 pivot=iter->startidx+iter->count;
188 if(maxidx>0 && (pivot>maxidx)) {{std::ostringstream sos; sos <<
"startidx+count>maxidx"<<std::endl;
syncout::print(std::cerr,sos);}
return false;}
194template<
class CONTAINER,
typename IDXTYPE>
198 for(
TCI iter=this->begin();iter!=this->end();iter++) cnt+=iter->count;
202template<
class CONTAINER,
typename IDXTYPE>
206 for(
TCI iter=this->begin();iter!=this->end();iter++)
if(iter->count>0 && iter->startidx+iter->count-1>mx) mx=iter->startidx+iter->count-1;
210template<
class CONTAINER,
typename IDXTYPE>
214 assert(
sum()>reducer->max_idx());
216 typename Data_Intervaller<CONTAINER,IDXTYPE>::const_iterator rediter=reducer->begin();
218 for(
TCI iter=this->begin();iter!=this->end();iter++) {
219 if((*iter).count==0)
continue;
221 while((!stop) && (rediter!=reducer->end())) {
222 if((*rediter).count==0) {rediter++;
continue;}
223 IDXTYPE Rbottom=(*rediter).startidx;
224 IDXTYPE Rtop=Rbottom+(*rediter).count-1;
225 IDXTYPE MTRUEbottom=(*iter).startidx;
226 IDXTYPE Mtop=Mbottom+(*iter).count-1;
227 if(!(Rtop<Mbottom || Rbottom>Mtop)) {
228 IDXTYPE ISCbottom=Rbottom;
if(Rbottom<Mbottom) ISCbottom=Mbottom;
229 IDXTYPE ISCtop=Rtop;
if(Rtop>Mtop) ISCtop=Mtop;
231 target->push_back(I);
233 if(Rtop>=Mtop) stop=
true;
234 if(Rtop<=Mtop) rediter++;
236 Mbottom+=(*iter).count;
240 throw fst_error(
"Data_Intervaller::reduce() error.");
Container to hold list of Data_Interval; implements nested interval reduction.
Definition data_intervaller.hpp:102
Data_Interval< IDXTYPE > * getNextBlock(const unsigned int loopdepth=0)
Definition data_intervaller.hpp:167
IDXTYPE max_idx()
returns the largest sample index any interval covers, i.e. the maximum of startidx+count-1 over non-e...
Definition data_intervaller.hpp:203
Data_Interval< IDXTYPE > * getFirstBlock(const unsigned int loopdepth=0)
positions loop loopdepth at the first interval and returns it, or nullptr if there are none
Definition data_intervaller.hpp:158
Data_Intervaller(const Data_Intervaller &tin)
Definition data_intervaller.hpp:140
std::vector< TCI > blockiter
Definition data_intervaller.hpp:136
bool check_validity(const IDXTYPE maxidx)
checks whether all intervals are non-overlapping, ordered ascending, and all fit to <0,...
Definition data_intervaller.hpp:177
void reduce(const std::shared_ptr< Data_Intervaller< CONTAINER, IDXTYPE > > reducer, std::shared_ptr< Data_Intervaller< CONTAINER, IDXTYPE > > target)
Translates reducer's RELATIVE index intervals into absolute ones and stores them in target.
Definition data_intervaller.hpp:211
Data_Intervaller< std::vector< FST::Data_Interval< IDXTYPE > >, IDXTYPE >::iterator TCI
Definition data_intervaller.hpp:135
IDXTYPE sum()
sums the sizes of all contained intervals, i.e. the total number of samples they cover
Definition data_intervaller.hpp:195
FST4 specific error passing class.
Definition error.hpp:61
static void print(std::ostream &os, std::ostringstream &sos)
Writes sos's buffered content to os, serializing concurrent writers under FST_THREADED via a shared m...
Definition global.hpp:86
FST4 specific error passing class.
The Feature Selection Toolbox 4 library: every library component – data access, criteria and classifi...
Definition data_accessor.hpp:80
void notify(const std::string msg)
Prints msg followed by a newline via syncout::print(); a no-op unless the preprocessor macro DEBUG is...
Definition global.hpp:112
std::ostream & operator<<(std::ostream &os, const Data_Intervaller< CONTAINER, IDXTYPE > &ia)
Streams every contained interval as "si:<startidx>, c:<count>" lines to os.
Definition data_intervaller.hpp:152
Support structure to hold data interval (referring into data held by data accessor).
Definition data_intervaller.hpp:88
IDXTYPE startidx
index of the interval's first sample
Definition data_intervaller.hpp:89
IDXTYPE count
number of samples in the interval
Definition data_intervaller.hpp:90