25 bool leaf_nodes_mandatory)
28 init(taxonomy, leaf_nodes_mandatory);
43 bool leaf_nodes_mandatory)
45 SG_ADD(&m_num_classes,
"num_classes",
"Number of (binary) class assignment per label",
47 SG_ADD(&m_taxonomy,
"taxonomy",
"Taxonomy of the hierarchy of the labels",
49 SG_ADD(&m_leaf_nodes_mandatory,
"leaf_nodes_mandatory",
"Whether internal nodes belong"
53 m_leaf_nodes_mandatory = leaf_nodes_mandatory;
56 int32_t num_classes = 0;
63 REQUIRE(num_classes == taxonomy.
vlen,
"Number of classes must be equal to taxonomy vector = %d\n",
69 int32_t root_node_count = 0;
71 for (
index_t i = 0; i < num_classes; i++)
73 REQUIRE(taxonomy[i] < num_classes && taxonomy[i] >= -1,
"parent-id of node-id:%d is taxonomy[%d] = %d,"
74 " but must be within [-1; %d-1] (-1 for root node)\n", i, i,
75 taxonomy[i], num_classes);
76 m_taxonomy[i] = taxonomy[i];
78 if (m_taxonomy[i] == -1)
87 REQUIRE(m_root != -1 && root_node_count == 1,
"Single ROOT element must be defined "
88 "with parent-id = -1\n");
94 for (int32_t i = 0; i < num_classes; i++)
97 m_children[i] = child_id;
107 return num_classes * feats_dim;
120 int32_t node_id = sparse_label[i];
121 label_vector[node_id] = 1;
123 for (int32_t parent_id = m_taxonomy[node_id]; parent_id != -1;
124 parent_id = m_taxonomy[parent_id])
126 label_vector[parent_id] = 1;
150 int32_t label = label_vector[i];
154 int32_t offset = i * feats_dim;
156 for (
index_t j = 0; j < feats_dim; j++)
158 psi[offset + j] = x[j];
172 ASSERT(y1_slabel != NULL);
173 ASSERT(y2_slabel != NULL);
176 get_label_vector(y2_slabel->
get_data()));
182 REQUIRE(y1.
vlen == y2.
vlen,
"Size of both the vectors should be same\n");
196 return y1 != y2 ? 1 : 0;
213 int32_t feat_idx,
bool const training)
225 REQUIRE(m_num_classes > 0,
"The model needs to be trained before using "
226 "if for prediction\n");
234 SG_REF(nodes_to_traverse);
261 nodes_to_traverse->
push_back(child_id[i]);
264 if (m_leaf_nodes_mandatory)
267 if (child_id.
vlen == 0)
269 y_pred_sparse[count++] = node;
274 y_pred_sparse[count++] = node;
SGVector< float64_t > psi_truth
Base class of the labels used in Structured Output (SO) problems.
Class CMultilabelSOLabels used in the application of Structured Output (SO) learning to Multilabel Cl...
virtual float64_t dense_dot(int32_t vec_idx1, const float64_t *vec2, int32_t vec2_len)=0
virtual CStructuredLabels * structured_labels_factory(int32_t num_labels=0)
SGVector< float64_t > get_joint_feature_vector(int32_t feat_idx, int32_t lab_idx)
Features that support dot products among other operations.
virtual int32_t get_dim_feature_space() const =0
virtual SGVector< float64_t > get_joint_feature_vector(int32_t feat_idx, CStructuredData *y)
bool delete_element(int32_t idx)
virtual void init_primal_opt(float64_t regularization, SGMatrix< float64_t > &A, SGVector< float64_t > a, SGMatrix< float64_t > B, SGVector< float64_t > &b, SGVector< float64_t > &lb, SGVector< float64_t > &ub, SGMatrix< float64_t > &C)
virtual int32_t get_dim() const
CHierarchicalMultilabelModel()
float64_t delta_loss(int32_t ytrue_idx, CStructuredData *ypred)
Class CSparseMultilabel to be used in the application of Structured Output (SO) learning to Multilabe...
static float64_t dot(const bool *v1, const bool *v2, int32_t n)
Compute dot product between v1 and v2 (blas optimized)
Class CStructuredModel that represents the application specific model and contains most of the applic...
CStructuredLabels * m_labels
all of classes and functions are contained in the shogun namespace
virtual CResultSet * argmax(SGVector< float64_t > w, int32_t feat_idx, bool const training=true)
virtual float64_t delta_loss(CStructuredData *y1, CStructuredData *y2)
The class Features is the base class of all feature objects.
SGVector< float64_t > get_computed_dot_feature_vector(int32_t num)
int32_t get_num_elements() const
SGVector< float64_t > psi_pred
void resize_vector(int32_t n)
virtual int32_t get_num_classes() const
static SGMatrix< T > create_identity_matrix(index_t size, T scale)
SGVector< index_t > find(T elem)
Base class of the components of StructuredLabels.
const T & get_element(int32_t idx1, int32_t idx2=0, int32_t idx3=0) const
virtual ~CHierarchicalMultilabelModel()
static CSparseMultilabel * obtain_from_generic(CStructuredData *base_data)
SGVector< int32_t > get_data() const