libeblearn
ebl::hierarchy_datasource< Tnet, Tdata, Tlabel > Class Template Reference

#include <datasource.h>

Inheritance diagram for ebl::hierarchy_datasource< Tnet, Tdata, Tlabel >:
ebl::class_datasource< Tnet, Tdata, Tlabel > ebl::labeled_datasource< Tnet, Tdata, Tlabel > ebl::datasource< Tnet, Tdata >

List of all members.

Public Member Functions

 hierarchy_datasource ()
 CAUTION: This empty constructor requires a subsequent call to init().
 hierarchy_datasource (midx< Tdata > &data, idx< Tlabel > &labels, idx< Tlabel > *parents=NULL, vector< string * > *lblstr=NULL, const char *name=NULL)
 hierarchy_datasource (idx< Tdata > &data, idx< Tlabel > &labels, idx< Tlabel > *parents=NULL, vector< string * > *lblstr=NULL, const char *name=NULL)
 hierarchy_datasource (idx< Tdata > &data, idx< Tlabel > &labels, idx< Tlabel > *parents=NULL, idx< ubyte > *classes=NULL, const char *name=NULL)
 hierarchy_datasource (const char *data_name, const char *labels_name, const char *parents_name=NULL, const char *jitters_name=NULL, const char *scales_name=NULL, const char *classes_name=NULL, const char *name=NULL, uint max_size=0)
virtual ~hierarchy_datasource ()
 Destructor.
void init_parents (idx< Tlabel > *parents=NULL)
 Initialize parents and check their validity.
virtual void init_class_labels ()
virtual Tlabel get_parent ()
virtual bool is_parent_of (Tlabel lab1, Tlabel lab2)
 Returns true if 'lab1' is a parent of 'lab2'.
virtual vector< class_node
< Tlabel > * > & 
get_nodes ()
 Returns a reference to all nodes of the hierarchy.
virtual vector< class_node
< Tlabel > * > & 
get_nodes_by_depth ()
virtual void fprop_label (fstate_idx< Tlabel > &s)
 Copy current sample's label into s.
virtual void fprop_label_net (fstate_idx< Tnet > &s)
virtual void fprop_label_net (bbstate_idx< Tnet > &s)
virtual Tlabel get_label ()
virtual Tlabel get_label (uint depth, intg index=-1)
idx< Tlabel > & get_depth_labels ()
uint get_nbrothers (class_node< Tlabel > &n)
 Returns the number of brothers of node 'n'.
void set_depth_balanced (bool bal)
 Balance samples selection by current depth if 'bal' is true.
virtual void set_current_depth (uint depth)
virtual uint get_current_depth ()
 Returns current depth.
virtual void incr_current_depth ()
 Increment current depth (see set_current_depth() for more details).
virtual bool next_train ()
virtual void pretty ()
 Print info about the datasource on the standard output.
virtual void print_path (Tlabel l)
 Print path reaching class 'l'.

Protected Attributes

vector< class_node< Tlabel > * > all_nodes
 All hierarchy nodes.
vector< class_node< Tlabel > * > all_nodes_by_depth
 All, ordered by depth.
vector< vector< class_node
< Tlabel > * > * > 
all_depths
vector< vector< class_node
< Tlabel > * > * > 
complete_depths
idx< Tlabel > * parents
 Parents matrix.
idx< Tlabel > depth_labels
 All labels given a certain depth.
uint current_depth
 Maximum depth at which labels are set.
vector< uint > it_depths
 Depths iterators.
bool depth_balance
 Balance samples by depth.

Friends

class class_datasource_gui

Detailed Description

template<typename Tnet, typename Tdata, typename Tlabel>
class ebl::hierarchy_datasource< Tnet, Tdata, Tlabel >

hierarchy_datasource A datasource associating samples with a discrete class which can are organized as a hierarchy.


Constructor & Destructor Documentation

template<typename Tnet , typename Tdata , typename Tlabel >
ebl::hierarchy_datasource< Tnet, Tdata, Tlabel >::hierarchy_datasource ( midx< Tdata > &  data,
idx< Tlabel > &  labels,
idx< Tlabel > *  parents = NULL,
vector< string * > *  lblstr = NULL,
const char *  name = NULL 
)

Construct dataset with 'data' and its corresponding 'labels', where data is a multi-matrix (useful for dynamic loading, avoiding the need to fit all data in memory).

Parameters:
parentsThe parent label associated with each label. A Nx2 matrix with N the number of classes and 2 the pair child/parent.
lblstrAn optional vector of strings describing each class.
nameAn optional name for this dataset.
template<typename Tnet , typename Tdata , typename Tlabel >
ebl::hierarchy_datasource< Tnet, Tdata, Tlabel >::hierarchy_datasource ( idx< Tdata > &  data,
idx< Tlabel > &  labels,
idx< Tlabel > *  parents = NULL,
vector< string * > *  lblstr = NULL,
const char *  name = NULL 
)

Construct dataset with 'data' and its corresponding 'labels'.

Parameters:
parentsThe parent label associated with each label. A Nx2 matrix with N the number of classes and 2 the pair child/parent.
lblstrAn optional vector of strings describing each class.
nameAn optional name for this dataset.
template<typename Tnet , typename Tdata , typename Tlabel >
ebl::hierarchy_datasource< Tnet, Tdata, Tlabel >::hierarchy_datasource ( idx< Tdata > &  data,
idx< Tlabel > &  labels,
idx< Tlabel > *  parents = NULL,
idx< ubyte > *  classes = NULL,
const char *  name = NULL 
)

Construct dataset with 'data' and its corresponding 'labels'.

Parameters:
parentsThe parent label associated with each label. A Nx2 matrix with N the number of classes and 2 the pair child/parent.
classesA vector of strings describing each class.
nameAn optional name for this dataset.
template<typename Tnet , typename Tdata , typename Tlabel >
ebl::hierarchy_datasource< Tnet, Tdata, Tlabel >::hierarchy_datasource ( const char *  data_name,
const char *  labels_name,
const char *  parents_name = NULL,
const char *  jitters_name = NULL,
const char *  scales_name = NULL,
const char *  classes_name = NULL,
const char *  name = NULL,
uint  max_size = 0 
)

Constructor from full names for each dataset file. Note: jitters and classes files are optional.

Parameters:
parents_nameThe parent label associated with each label. A Nx2 matrix with N the number of classes and 2 the pair child/parent.
nameAn optional name for this dataset.
max_sizeIf > 0, limit the number of samples to this value.

Member Function Documentation

template<typename Tnet , typename Tdata , typename Tlabel >
void ebl::hierarchy_datasource< Tnet, Tdata, Tlabel >::fprop_label_net ( fstate_idx< Tnet > &  s) [virtual]

Copy current sample's label into s (name has to be different than fprop_label in case Tnet == Tlabel).

Reimplemented from ebl::labeled_datasource< Tnet, Tdata, Tlabel >.

template<typename Tnet , typename Tdata , typename Tlabel >
void ebl::hierarchy_datasource< Tnet, Tdata, Tlabel >::fprop_label_net ( bbstate_idx< Tnet > &  s) [virtual]

Copy current sample's label into s (name has to be different than fprop_label in case Tnet == Tlabel).

Reimplemented from ebl::labeled_datasource< Tnet, Tdata, Tlabel >.

template<typename Tnet , typename Tdata , typename Tlabel >
idx< Tlabel > & ebl::hierarchy_datasource< Tnet, Tdata, Tlabel >::get_depth_labels ( )

Returns the matrix of all labels at current depth, i.e. labels deeper than current depth, are given their parent's label at current depth.

template<typename Tnet , typename Tdata , typename Tlabel >
Tlabel ebl::hierarchy_datasource< Tnet, Tdata, Tlabel >::get_label ( ) [virtual]

Returns the label corresponding to current iterator and current depth. If current sample has a deeper label, it will return its parent's label at depth 'current_depth' (see set_current_depth()).

Reimplemented from ebl::class_datasource< Tnet, Tdata, Tlabel >.

template<typename Tnet , typename Tdata , typename Tlabel >
Tlabel ebl::hierarchy_datasource< Tnet, Tdata, Tlabel >::get_label ( uint  depth,
intg  index = -1 
) [virtual]

Returns the label corresponding to current iterator and 'depth'. If current sample has a deeper label, it will return its parent's label at depth 'depth'.

Parameters:
indexIf -1, return current sample's, otherwise sample's at 'index' position.
template<typename Tnet , typename Tdata , typename Tlabel >
vector< class_node< Tlabel > * > & ebl::hierarchy_datasource< Tnet, Tdata, Tlabel >::get_nodes_by_depth ( ) [virtual]

Returns a reference to all nodes ordered by depth, i.e. the following node is guaranteed to be of equal or higher depth.

template<typename Tnet , typename Tdata , typename Tlabel >
Tlabel ebl::hierarchy_datasource< Tnet, Tdata, Tlabel >::get_parent ( ) [virtual]

Return the parent's label of current sample. This supposes a label is only constituted of 1 element and will produce and error otherwise.

template<typename Tnet , typename Tdata , typename Tlabel >
void ebl::hierarchy_datasource< Tnet, Tdata, Tlabel >::init_class_labels ( ) [virtual]

Fills 'clabels' and 'clblstr' which are the true class labels if labels are not consecutive values starting from 0. If they are, then 'clabels' is equivalent to 'labels', same for 'clblstr' and 'lblstr'.

Reimplemented from ebl::class_datasource< Tnet, Tdata, Tlabel >.

template<typename Tnet , typename Tdata , typename Tlabel >
bool ebl::hierarchy_datasource< Tnet, Tdata, Tlabel >::next_train ( ) [virtual]

Move to the next datum in a way suited for training (_not_ for testing, for testing see next()). If balance is activated (see set_balanced()) this will return samples in a class-balanced way, i.e. showing each class sequentially, with different probabilities based on sample's difficulty, or/and in a random order after each pass. Samples coming from children are also recursively balanced, so that even if a child has lot of samples compared to other children, others will be shown as many times. When all samples of a class have been shown, it loops back to the first sample of that class. This should be used during training only. If a sample was not selected because of a low probability, this will return false, if it was selected it returns true. In any case, internal iterators will always be set to the next sample, regardless if it was selected or not. It is up to the caller, to train on the sample if selected, or only test and update its energy if not selected.

Reimplemented from ebl::class_datasource< Tnet, Tdata, Tlabel >.

template<typename Tnet , typename Tdata , typename Tlabel >
void ebl::hierarchy_datasource< Tnet, Tdata, Tlabel >::set_current_depth ( uint  depth) [virtual]

Set the current depth to 'depth' (for testing or training), i.e. the training or testing will set samples to have this depth at most. The label will be set to this depth's node's label, even if the sample come from children.


Member Data Documentation

template<typename Tnet , typename Tdata , typename Tlabel >
vector<vector<class_node<Tlabel>*>*> ebl::hierarchy_datasource< Tnet, Tdata, Tlabel >::all_depths [protected]

All nodes by depth.

template<typename Tnet , typename Tdata , typename Tlabel >
vector<vector<class_node<Tlabel>*>*> ebl::hierarchy_datasource< Tnet, Tdata, Tlabel >::complete_depths [protected]

All nodes by depth, plus ones with lower depth that contain samples internally. When iterating at one depth ensures samples at lower depth are also used.


The documentation for this class was generated from the following files: