libeblearn
|
#include <datasource.h>
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 |
hierarchy_datasource A datasource associating samples with a discrete class which can are organized as a hierarchy.
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).
parents | The parent label associated with each label. A Nx2 matrix with N the number of classes and 2 the pair child/parent. |
lblstr | An optional vector of strings describing each class. |
name | An optional name for this dataset. |
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'.
parents | The parent label associated with each label. A Nx2 matrix with N the number of classes and 2 the pair child/parent. |
lblstr | An optional vector of strings describing each class. |
name | An optional name for this dataset. |
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'.
parents | The parent label associated with each label. A Nx2 matrix with N the number of classes and 2 the pair child/parent. |
classes | A vector of strings describing each class. |
name | An optional name for this dataset. |
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.
parents_name | The parent label associated with each label. A Nx2 matrix with N the number of classes and 2 the pair child/parent. |
name | An optional name for this dataset. |
max_size | If > 0, limit the number of samples to this value. |
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 >.
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 >.
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.
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 >.
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'.
index | If -1, return current sample's, otherwise sample's at 'index' position. |
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.
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.
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 >.
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 >.
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.
vector<vector<class_node<Tlabel>*>*> ebl::hierarchy_datasource< Tnet, Tdata, Tlabel >::all_depths [protected] |
All nodes by depth.
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.