Implements data access to data cached entirely in memory, concrete file type support is delegated to derived classes. More...
#include <data_accessor_splitting_mem.hpp>
Public Types | |
| typedef Data_Accessor_Splitting< DATATYPE, IDXTYPE, INTERVALCONTAINER > | DAS |
| the immediate base class, aliased for brevity in derived classes | |
| typedef std::shared_ptr< Data_Scaler< DATATYPE > > | PScaler |
| shared pointer to the scaler applied to loaded data | |
| typedef DAS::PPattern | PPattern |
| inherited from Data_Accessor: raw pointer to one read-only feature vector | |
| typedef DAS::PSplitters | PSplitters |
| Public Types inherited from FST::Data_Accessor_Splitting< DATATYPE, IDXTYPE, INTERVALCONTAINER > | |
| typedef std::shared_ptr< Data_Splitter< INTERVALCONTAINER, IDXTYPE > > | PSplitter |
| shared pointer to one Data_Splitter (one nested splitting level) | |
| typedef std::shared_ptr< std::vector< PSplitter > > | PSplitters |
| shared pointer to the ordered list of splitters, one per nested splitting depth (depth 0 = outermost) | |
| typedef const DATATYPE * | PPattern |
| Public Types inherited from FST::Data_Accessor< DATATYPE, IDXTYPE > | |
| typedef const DATATYPE * | PPattern |
| one data sample: a raw pointer to its (read-only) feature vector, getNoOfFeatures() entries long | |
Public Member Functions | |
| Data_Accessor_Splitting_Mem (const std::string _filename, const PSplitters _dsp, const PScaler _dsc) | |
| virtual void | initialize () |
| to be called after object creation (for initialization of data file access etc.) | |
| void | set_scaler_fit_train (const bool b) |
| Switches on per-split scaling: the scaler learns its transform on the current depth-0 split's TRAIN part only and applies it to ALL data, refreshed on every depth-0 split change. | |
| bool | get_scaler_fit_train () const |
| see set_scaler_fit_train() | |
| void | scale_sample_inplace (DATATYPE *sample) const |
Applies the learned per-feature transform to sample, a caller-owned vector of getNoOfFeatures() values, in place. | |
| virtual bool | getFirstSplit () override |
| data access iteration (to support, e.g., loops in cross-validation) | |
| virtual bool | getNextSplit () override |
| data access iteration (to support, e.g., loops in cross-validation) | |
| virtual bool | getFirstBlock (const DataPart ofwhat, PPattern &firstpattern, IDXTYPE &patterns, const unsigned int loopdepth=0) override |
| returns pointer to first consecutive block of data of requested DataPart type in the current split (access iteration) | |
| virtual bool | getNextBlock (const DataPart ofwhat, PPattern &firstpattern, IDXTYPE &patterns, const unsigned int loopdepth=0) override |
| returns pointer to next consecutive block of data of requested DataPart type in the current split (access iteration) | |
| Data_Accessor_Splitting_Mem * | clone () const override |
| Data_Accessor_Splitting_Mem * | sharing_clone () const override=0 |
| Data_Accessor_Splitting_Mem * | stateless_clone () const override |
| virtual std::ostream & | print (std::ostream &os) const override |
writes the splitter stack's print() output (or "Data_Accessor_Splitting()" if the stack is empty) to os | |
| Public Member Functions inherited from FST::Data_Accessor_Splitting< DATATYPE, IDXTYPE, INTERVALCONTAINER > | |
| Data_Accessor_Splitting (const PSplitters _dsp) | |
Constructs an (uninitialized) accessor bound to the splitter stack _dsp; concrete subclasses must still call initialize() once dimensionality/class sizes are known. | |
| virtual unsigned int | getNoOfClasses () const override |
| returns number of classes | |
| virtual unsigned int | getNoOfFeatures () const override |
| returns data dimensionality | |
| virtual IDXTYPE | getClassSize (const unsigned int c) const override |
| returns size (number of samples in) of class c | |
| virtual IDXTYPE | getClassSizeSum () const override |
| returns summed size (number of samples in) of all classes, i.e., no. of all patterns in data | |
| virtual void | setClass (const int c) override |
| sets active class -> from now on only data from class c will be considered | |
| virtual int | getClass () const override |
| returns active class | |
| void | setSplittingDepth (const unsigned int depth) |
| Selects the nested splitting level (0 = outermost/depth-0 splitter, 1 = the next-nested level, etc.) that subsequent getFirstSplit()/getNextSplit()/getFirstBlock()/getNextBlock() calls operate on. | |
| unsigned int | getSplittingDepth () const |
| the nested splitting level last set via setSplittingDepth() | |
| virtual unsigned int | getNoOfSplits () const override |
| data access iteration (to support, e.g., loops in cross-validation) | |
| virtual unsigned int | getSplitIndex () const override |
| data access iteration (to support, e.g., loops in cross-validation) | |
| virtual IDXTYPE | getNoOfBlocks (const DataPart ofwhat) const override |
| virtual IDXTYPE | getBlockIndex (const unsigned int loopdepth=0) const override |
| returns index of the current consecutive block of data of requested DataPart type in the current split (access iteration) | |
| virtual IDXTYPE | getNoOfPatterns (const DataPart ofwhat) const override |
| returns number of patterns in all consecutive blocks of data of requested DataPart type in the current split (access iteration) | |
| virtual void | substitute (const DataPart source, const DataPart target) override |
| enables change of meaning of DataPart types, for use in specialized data access scenarios like in bias predicting wrappers | |
| virtual void | resubstitute () override |
| resets standard DataPart types' meaning | |
| Public Member Functions inherited from FST::Data_Accessor< DATATYPE, IDXTYPE > | |
| Block_Range | blocks (const DataPart ofwhat) |
| RAII block range over the current split - prefer over the deprecated getFirstBlock()/getNextBlock() cursor. | |
| Public Member Functions inherited from FST::Clonable | |
| bool | is_clone () const |
| bool | is_sharing () const |
| true if this instance is a sharing_clone() result (referencing, not owning, the source's structures) | |
| bool | is_sharing_clone () const |
| true if this instance is BOTH a clone and sharing – i.e. specifically a sharing_clone() result, not a clone()/stateless_clone() one | |
Protected Member Functions | |
| Data_Accessor_Splitting_Mem (const Data_Accessor_Splitting_Mem &damt, int) | |
| weak (referencing) copy-constructor to be used in sharing_clone() | |
| virtual void | initial_data_read ()=0 |
| fills the already-allocated data array with the file's samples; called once by initialize() after the array is sized Must write exactly datasize values, laid out class by class, pattern by pattern, feature by feature (class c starts at _class_offset[c]), matching the counts the file_get*() queries report. | |
| virtual void | initial_file_prepare ()=0 |
| opens/prepares the underlying file for reading; called once by initialize() before initial_data_read() After it returns, the three file_get*() queries below must answer correctly. | |
| virtual unsigned int | file_getNoOfClasses () const =0 |
| number of classes as reported by the underlying file (valid only after initial_file_prepare()) | |
| virtual unsigned int | file_getNoOfFeatures () const =0 |
| data dimensionality as reported by the underlying file (valid only after initial_file_prepare()) | |
| virtual IDXTYPE | file_getClassSize (unsigned int cls) const =0 |
number of samples of class cls as reported by the underlying file (valid only after initial_file_prepare()) | |
| void | initial_data_scaling () |
| void | per_split_data_scaling () |
| re-learns the scaler transform on the current depth-0 TRAIN part and re-scales the whole working buffer from the pristine data (scaler_fit_train mode only) | |
| Protected Member Functions inherited from FST::Data_Accessor_Splitting< DATATYPE, IDXTYPE, INTERVALCONTAINER > | |
| Data_Accessor_Splitting (const Data_Accessor_Splitting &da) | |
| "Strong" (1:1, deep) copy constructor: stateless_clone()s every splitter and re-assign()s it to this instance's own (deep-copied via splits) interval lists. | |
| void | initialize (const unsigned int _features, const CLASSSIZES &_classes) |
| DataPart | mappedDataPart (const DataPart ofwhat) const |
looks up ofwhat's current remapping target (mappedTRAIN/mappedTEST/mappedTRAINTEST/mappedALL); NONE maps to itself | |
| virtual bool | getFirstBlock (const DataPart ofwhat, DATAINTERVAL &tmp, const unsigned int loopdepth=0) |
| returns Data_Interval record representing the first consecutive block of data of requested DataPart type in the current split (access iteration) | |
| virtual bool | getNextBlock (const DataPart ofwhat, DATAINTERVAL &tmp, const unsigned int loopdepth=0) |
| returns Data_Interval record representing the next consecutive block of data of requested DataPart type in the current split (access iteration) | |
| bool | is_initialized () const |
| void | assert_splits (const int splitting_check=-1) const |
| DEBUG-only: asserts the internal structures (dsp, splits, enum_split, enum_block, tt_phase, classes) are non-empty, consistently sized, and every splits entry has its train/test/reduced interval lists allocated; a no-op in release builds. | |
| Protected Member Functions inherited from FST::Clonable | |
| void | set_cloned (const bool cloned=true) |
| marks/unmarks this instance as a clone; call from clone()/stateless_clone() overrides (Clonable_Impl does this automatically) | |
| void | set_sharing (const bool sharing=true) |
| marks/unmarks this instance as sharing (see is_sharing()) | |
| void | set_sharing_cloned (const bool cloned=true, const bool sharing=true) |
| sets both flags at once; call from sharing_clone() overrides (Clonable_Impl does this automatically) | |
Protected Attributes | |
| PScaler | dsc |
| std::vector< PScaler > | feature_scalers |
| std::string | filename |
| IDXTYPE | datasize |
| total number of DATATYPE values held in data/data_raw (sum over classes of class size * features) | |
| std::shared_ptr< DATATYPE > | data |
| std::shared_ptr< DATATYPE > | data_raw |
| pristine (unscaled) data as loaded; allocated in scaler_fit_train mode only; shared across clones, never mutated after load | |
| bool | scaler_fit_train |
| per-split scaling mode switch (see set_scaler_fit_train()) | |
| std::vector< IDXTYPE > | _class_offset |
| class start indexes (offsets) in whatever random-access data representation | |
| Protected Attributes inherited from FST::Data_Accessor_Splitting< DATATYPE, IDXTYPE, INTERVALCONTAINER > | |
| CLASSSIZES | classes |
| pattern count per class, as passed to initialize() | |
| unsigned int | features |
| data dimensionality, as passed to initialize() | |
| DataPart | mappedTRAIN |
| current remapping target of TRAIN (see substitute()/resubstitute()); defaults to TRAIN | |
| DataPart | mappedTEST |
| current remapping target of TEST (see substitute()/resubstitute()); defaults to TEST | |
| DataPart | mappedTRAINTEST |
| current remapping target of TRAINTEST (see substitute()/resubstitute()); defaults to TRAINTEST | |
| DataPart | mappedALL |
| current remapping target of ALL (see substitute()/resubstitute()); defaults to ALL | |
| PSplitters | dsp |
| the splitter stack this accessor was constructed with, one Data_Splitter per nested splitting depth | |
| std::vector< std::vector< DataSplit > > | splits |
| one set of splitters per each splitting depth and class | |
| std::vector< IDXTYPE > | enum_split |
| current split.. 0~none | |
| std::vector< std::vector< IDXTYPE > > | enum_block |
| current block loop.. 0~none | |
| std::vector< std::vector< DataPart > > | tt_phase |
| in current block loop.. for DataPart==TRAINTEST indicates which half is being delivered: TRAIN, then TEST once the train blocks run out, NONE when the loop is finished | |
| unsigned int | splitting_depth |
| the nested splitting level the get*Split()/get*Block() calls currently refer to; set via setSplittingDepth() | |
| int | active_class |
| denotes from which class the get*Train* get*Validate* get*Test* methods return patterns, to be set using setClass() | |
| bool | _initialize_called |
| set true by initialize(); read by is_initialized() | |
Additional Inherited Members | |
| Protected Types inherited from FST::Data_Accessor_Splitting< DATATYPE, IDXTYPE, INTERVALCONTAINER > | |
| typedef std::vector< unsigned int > | CLASSSIZES |
| per-class pattern counts, indexed by class index; the format initialize() takes | |
| typedef const Data_Interval< IDXTYPE > * | DATAINTERVAL |
| typedef std::shared_ptr< INTERVALCONTAINER > | PIntervaller |
Implements data access to data cached entirely in memory, concrete file type support is delegated to derived classes.
The whole data set is read once into one contiguous DATATYPE array. Classes are stored one after another (class c starts at _class_offset[c]), each class holds its patterns consecutively, and each pattern holds its getNoOfFeatures() values consecutively. A block handed out by getFirstBlock()/getNextBlock() is therefore just a pointer into that array plus a pattern count; the array stays alive for the accessor's lifetime and is never handed over to the caller.
A derived class supplies the file format: it implements initial_file_prepare() (open and read the header), initial_data_read() (fill the array) and the three file_get*() queries that report dimensionality and class sizes. initialize() drives all of them, in that order, and must be called exactly once before any data access.
| typedef DAS::PSplitters FST::Data_Accessor_Splitting_Mem< DATATYPE, IDXTYPE, INTERVALCONTAINER >::PSplitters |
inherited: shared pointer to the per-depth splitter stack
|
inline |
Constructs the accessor for _filename (opened by a derived class's initial_file_prepare()), the splitter stack _dsp and the scaler _dsc; actual file reading happens in initialize().
|
inlineoverridevirtual |
create 1:1 independent clone of the current object. The caller owns the returned object. Families that cannot support a given clone kind implement it to throw fst_error; Clonable_Impl's CLONE_INHERIT slot defers to such a body.
Implements FST::Data_Accessor< DATATYPE, IDXTYPE >.
|
protectedpure virtual |
number of samples of class cls as reported by the underlying file (valid only after initial_file_prepare())
Implemented in FST::Data_Accessor_Splitting_MemARFF< DATATYPE, IDXTYPE, INTERVALCONTAINER >, FST::Data_Accessor_Splitting_MemCSV< DATATYPE, IDXTYPE, INTERVALCONTAINER >, FST::Data_Accessor_Splitting_MemTRN< DATATYPE, IDXTYPE, INTERVALCONTAINER >, and FST::Data_Accessor_Universe< DATATYPE, IDXTYPE, INTERVALCONTAINER >.
|
protectedpure virtual |
number of classes as reported by the underlying file (valid only after initial_file_prepare())
Implemented in FST::Data_Accessor_Splitting_MemARFF< DATATYPE, IDXTYPE, INTERVALCONTAINER >, FST::Data_Accessor_Splitting_MemCSV< DATATYPE, IDXTYPE, INTERVALCONTAINER >, FST::Data_Accessor_Splitting_MemTRN< DATATYPE, IDXTYPE, INTERVALCONTAINER >, and FST::Data_Accessor_Universe< DATATYPE, IDXTYPE, INTERVALCONTAINER >.
|
protectedpure virtual |
data dimensionality as reported by the underlying file (valid only after initial_file_prepare())
Implemented in FST::Data_Accessor_Splitting_MemARFF< DATATYPE, IDXTYPE, INTERVALCONTAINER >, FST::Data_Accessor_Splitting_MemCSV< DATATYPE, IDXTYPE, INTERVALCONTAINER >, FST::Data_Accessor_Splitting_MemTRN< DATATYPE, IDXTYPE, INTERVALCONTAINER >, and FST::Data_Accessor_Universe< DATATYPE, IDXTYPE, INTERVALCONTAINER >.
|
overridevirtual |
returns pointer to first consecutive block of data of requested DataPart type in the current split (access iteration)
Implements FST::Data_Accessor_Splitting< DATATYPE, IDXTYPE, INTERVALCONTAINER >.
|
overridevirtual |
data access iteration (to support, e.g., loops in cross-validation)
Reimplemented from FST::Data_Accessor_Splitting< DATATYPE, IDXTYPE, INTERVALCONTAINER >.
Reimplemented in FST::Data_Accessor_Universe< DATATYPE, IDXTYPE, INTERVALCONTAINER >.
|
overridevirtual |
returns pointer to next consecutive block of data of requested DataPart type in the current split (access iteration)
Implements FST::Data_Accessor_Splitting< DATATYPE, IDXTYPE, INTERVALCONTAINER >.
|
overridevirtual |
data access iteration (to support, e.g., loops in cross-validation)
Reimplemented from FST::Data_Accessor_Splitting< DATATYPE, IDXTYPE, INTERVALCONTAINER >.
Reimplemented in FST::Data_Accessor_Universe< DATATYPE, IDXTYPE, INTERVALCONTAINER >.
|
protectedpure virtual |
fills the already-allocated data array with the file's samples; called once by initialize() after the array is sized Must write exactly datasize values, laid out class by class, pattern by pattern, feature by feature (class c starts at _class_offset[c]), matching the counts the file_get*() queries report.
Implemented in FST::Data_Accessor_Splitting_MemARFF< DATATYPE, IDXTYPE, INTERVALCONTAINER >, FST::Data_Accessor_Splitting_MemCSV< DATATYPE, IDXTYPE, INTERVALCONTAINER >, FST::Data_Accessor_Splitting_MemTRN< DATATYPE, IDXTYPE, INTERVALCONTAINER >, and FST::Data_Accessor_Universe< DATATYPE, IDXTYPE, INTERVALCONTAINER >.
|
protected |
|
protectedpure virtual |
opens/prepares the underlying file for reading; called once by initialize() before initial_data_read() After it returns, the three file_get*() queries below must answer correctly.
Implemented in FST::Data_Accessor_Splitting_MemARFF< DATATYPE, IDXTYPE, INTERVALCONTAINER >, FST::Data_Accessor_Splitting_MemCSV< DATATYPE, IDXTYPE, INTERVALCONTAINER >, FST::Data_Accessor_Splitting_MemTRN< DATATYPE, IDXTYPE, INTERVALCONTAINER >, and FST::Data_Accessor_Universe< DATATYPE, IDXTYPE, INTERVALCONTAINER >.
|
virtual |
to be called after object creation (for initialization of data file access etc.)
Opens and reads the file through the derived class's hooks, allocates the in-memory data array and sets up the splitting structures. Call it exactly once, on the owning instance, before any other access; it throws fst_error (or an I/O or allocation exception) on failure. It also reports the file name, dimensionality, class sizes and splitting depth on standard output through syncout::print() – there is no quiet mode, so a caller that needs clean standard output must redirect it around this call.
Reimplemented in FST::Data_Accessor_Universe< DATATYPE, IDXTYPE, INTERVALCONTAINER >.
|
overridevirtual |
writes the splitter stack's print() output (or "Data_Accessor_Splitting()" if the stack is empty) to os
Reimplemented from FST::Data_Accessor_Splitting< DATATYPE, IDXTYPE, INTERVALCONTAINER >.
Reimplemented in FST::Data_Accessor_Splitting_MemARFF< DATATYPE, IDXTYPE, INTERVALCONTAINER >, FST::Data_Accessor_Splitting_MemCSV< DATATYPE, IDXTYPE, INTERVALCONTAINER >, FST::Data_Accessor_Splitting_MemTRN< DATATYPE, IDXTYPE, INTERVALCONTAINER >, and FST::Data_Accessor_Universe< DATATYPE, IDXTYPE, INTERVALCONTAINER >.
| void FST::Data_Accessor_Splitting_Mem< DATATYPE, IDXTYPE, INTERVALCONTAINER >::scale_sample_inplace | ( | DATATYPE * | sample | ) | const |
Applies the learned per-feature transform to sample, a caller-owned vector of getNoOfFeatures() values, in place.
Value i receives feature i's transform – min/max (to01), mean/stddev (white) or the missing-value substitution – exactly as the loaded data went through it, so a vector that is to be classified by a model trained on this accessor's data must pass through here first. In per-split mode (set_scaler_fit_train()) the transform is the one fitted on the CURRENT depth-0 split, i.e. the one the working buffer carries at the moment of the call. Throws fst_error before initialize(), or when the scaler does not implement duplicate().
|
inline |
Switches on per-split scaling: the scaler learns its transform on the current depth-0 split's TRAIN part only and applies it to ALL data, refreshed on every depth-0 split change.
This avoids the normalization leakage inherent in scaling at load time, where the test part contributes to the min/max or mean/stddev the transform is built from and so biases every later estimate of generalization performance. Must be called BEFORE initialize(). The default, false, scales once over the whole data set at load time.
|
overridepure virtual |
create equivalent clone of the current object, permitting read-only access to structures in the source object (allows referencing instead of copying of large memory structures). may be faster and save space but requires more caution with respect to concurrency Use example: Data_Accessor memory data representation cloning
Implements FST::Data_Accessor< DATATYPE, IDXTYPE >.
Implemented in FST::Clonable_Impl< Data_Accessor_Splitting_MemARFF< DATATYPE, IDXTYPE, INTERVALCONTAINER >, Data_Accessor_Splitting_Mem< DATATYPE, IDXTYPE, INTERVALCONTAINER >, CLONE_INHERIT, CLONE_WEAK_SHARING, CLONE_INHERIT >, FST::Clonable_Impl< Data_Accessor_Splitting_MemCSV< DATATYPE, IDXTYPE, INTERVALCONTAINER >, Data_Accessor_Splitting_Mem< DATATYPE, IDXTYPE, INTERVALCONTAINER >, CLONE_INHERIT, CLONE_WEAK_SHARING, CLONE_INHERIT >, FST::Clonable_Impl< Data_Accessor_Splitting_MemTRN< DATATYPE, IDXTYPE, INTERVALCONTAINER >, Data_Accessor_Splitting_Mem< DATATYPE, IDXTYPE, INTERVALCONTAINER >, CLONE_INHERIT, CLONE_WEAK_SHARING, CLONE_INHERIT >, and FST::Clonable_Impl< Data_Accessor_Universe< DATATYPE, IDXTYPE, INTERVALCONTAINER >, Data_Accessor_Splitting_Mem< DATATYPE, IDXTYPE, INTERVALCONTAINER >, CLONE_INHERIT, CLONE_WEAK_SHARING, CLONE_INHERIT >.
|
inlineoverridevirtual |
create clone of the current object, ignoring internal temporary structures to save speed. Does not replicate exact object state. The clone must be used carefully in a way that ensures internal structure re-initialization Use example: Data_Splitter cloning or Classifier_LIBSVM cloning due to inability to clone external structures defined in LibSVM
Implements FST::Data_Accessor< DATATYPE, IDXTYPE >.
|
protected |
class start indexes (offsets) in whatever random-access data representation
|
protected |
|
protected |
|
protected |
the learned per-feature transforms: one duplicate() of dsc per feature, taken right after that feature was learned, for scale_sample_inplace() – the single dsc object is re-learned feature after feature and so ends up holding only the LAST feature's statistics. Filled by initial_data_scaling() (load-time fit), or by per_split_data_scaling() in scaler_fit_train mode (then the current depth-0 split's transform); empty until then, or when the scaler does not implement duplicate(). The duplicates are never mutated, so sharing clones may share them.
|
protected |