26 SG_ERROR(
"Expected StreamingDenseFeatures\n")
28 SG_ERROR(
"Expected float32_t feature type\n")
33 vector<int32_t> predicts;
35 m_feats->start_parser();
36 while (m_feats->get_next_example())
38 predicts.push_back(apply_multiclass_example(m_feats->get_vector()));
39 m_feats->release_example();
41 m_feats->end_parser();
44 for (
size_t i=0; i < predicts.size(); ++i)
51 compute_conditional_probabilities(ex);
53 for (map<int32_t,bnode_t*>::iterator it = m_leaves.begin(); it != m_leaves.end(); ++it)
55 probs[it->first] = accumulate_conditional_probability(it->second);
62 stack<bnode_t *> nodes;
65 while (!nodes.empty())
71 nodes.push(node->
left());
72 nodes.push(node->
right());
75 node->
data.p_right = predict_node(ex, node);
86 if (leaf == par->
left())
87 prob *= (1-par->
data.p_right);
89 prob *= par->
data.p_right;
103 SG_ERROR(
"Expected StreamingDenseFeatures\n")
105 SG_ERROR(
"Expected float32_t features\n")
111 SG_ERROR(
"No data features provided\n")
114 m_machines->reset_array();
120 m_feats->start_parser();
121 for (int32_t ipass=0; ipass < m_num_passes; ++ipass)
123 while (m_feats->get_next_example())
125 train_example(m_feats->get_vector(),
static_cast<int32_t
>(m_feats->get_label()));
126 m_feats->release_example();
129 if (ipass < m_num_passes-1)
130 m_feats->reset_stream();
132 m_feats->end_parser();
134 for (int32_t i=0; i < m_machines->get_num_elements(); ++i)
149 printf(
"Empty Tree\n");
157 m_root->data.label = label;
158 m_leaves.insert(make_pair(label, (
bnode_t*) m_root));
159 m_root->machine(create_machine(ex));
163 if (m_leaves.find(label) != m_leaves.end())
165 train_path(ex, m_leaves[label]);
170 while (node->
left() != NULL)
173 bool is_left = which_subtree(node, ex);
179 train_node(ex, node_label, node);
184 node = node->
right();
187 m_leaves.erase(node->
data.label);
190 left_node->
data.label = node->
data.label;
191 node->
data.label = -1;
196 m_machines->push_back(mch);
197 left_node->
machine(m_machines->get_num_elements()-1);
198 m_leaves.insert(make_pair(left_node->
data.label, left_node));
199 node->
left(left_node);
202 right_node->
data.label = label;
203 right_node->
machine(create_machine(ex));
204 m_leaves.insert(make_pair(label, right_node));
205 node->
right(right_node);
212 train_node(ex, node_label, node);
217 if (par->
left() == node)
222 train_node(ex, node_label, par);
230 REQUIRE(node,
"Node must not be NULL\n");
232 REQUIRE(mch,
"Instance of %s could not be casted to COnlineLibLinear\n", node->
get_name());
239 REQUIRE(node,
"Node must not be NULL\n");
241 REQUIRE(mch,
"Instance of %s could not be casted to COnlineLibLinear\n", node->
get_name());
253 m_machines->push_back(mch);
254 return m_machines->get_num_elements()-1;
float64_t accumulate_conditional_probability(bnode_t *leaf)
void parent(CTreeMachineNode *par)
The node of the tree structure forming a TreeMachine The node contains pointer to its parent and poin...
void machine(int32_t idx)
void train_example(SGVector< float32_t > ex, int32_t label)
static int32_t arg_max(T *vec, int32_t inc, int32_t len, T *maxv_ptr=NULL)
virtual CMulticlassLabels * apply_multiclass(CFeatures *data=NULL)
virtual void train_one(SGVector< float32_t > ex, float64_t label)
virtual void stop_train()
float64_t predict_node(SGVector< float32_t > ex, bnode_t *node)
Multiclass Labels for multi-class classification.
static void print_data(const ConditionalProbabilityTreeNodeData &data)
void right(CBinaryTreeMachineNode *r)
int32_t create_machine(SGVector< float32_t > ex)
virtual bool train_machine(CFeatures *data)
virtual float64_t apply_one(int32_t vec_idx)
get output for example "vec_idx"
virtual EFeatureClass get_feature_class() const =0
virtual const char * get_name() const
void train_path(SGVector< float32_t > ex, bnode_t *node)
void train_node(SGVector< float32_t > ex, float64_t label, bnode_t *node)
CBinaryTreeMachineNode< VwConditionalProbabilityTreeNodeData > bnode_t
all of classes and functions are contained in the shogun namespace
Class implementing a purely online version of CLibLinear, using the L2R_L1LOSS_SVC_DUAL solver only...
bool set_int_label(int32_t idx, int32_t label)
The class Features is the base class of all feature objects.
static float64_t exp(float64_t x)
void left(CBinaryTreeMachineNode *l)
void compute_conditional_probabilities(SGVector< float32_t > ex)
virtual void start_train()
virtual EFeatureType get_feature_type() const =0
virtual int32_t apply_multiclass_example(SGVector< float32_t > ex)