Skip to content

Commit

Permalink
modified constructor of CResultSet; added checks in HashedMultilabelM…
Browse files Browse the repository at this point in the history
…odel::argmax() method
  • Loading branch information
pandaabinash committed Jun 18, 2014
1 parent ebb952f commit 44f064b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/shogun/structure/HashedMultilabelModel.cpp
Expand Up @@ -262,6 +262,7 @@ CResultSet * CHashedMultilabelModel::argmax(SGVector<float64_t> w,

SGVector<float64_t> y_pred_dense(m_num_classes);
y_pred_dense.zero();
int32_t count = 0;

for (int32_t c = 0; c < m_num_classes; c++)
{
Expand All @@ -278,11 +279,13 @@ CResultSet * CHashedMultilabelModel::argmax(SGVector<float64_t> w,
{
y_pred_dense[c] = 1;
total_score += score;
count++;
}

}

SGVector<int32_t> y_pred_sparse = to_sparse(y_pred_dense, 1, 0);
ASSERT(count == y_pred_sparse.vlen);

CResultSet * ret = new CResultSet();
SG_REF(ret);
Expand Down
10 changes: 9 additions & 1 deletion src/shogun/structure/StructuredModel.cpp
Expand Up @@ -14,7 +14,15 @@
using namespace shogun;

CResultSet::CResultSet()
: CSGObject(), argmax(NULL), score(0), delta(0)
: CSGObject(), argmax(NULL),
psi_computed_sparse(false),
psi_computed(false),
psi_truth(SGVector<float64_t>(0)),
psi_pred(SGVector<float64_t>(0)),
psi_truth_sparse(SGSparseVector<float64_t>(0)),
psi_pred_sparse(SGSparseVector<float64_t>(0)),
score(0),
delta(0)
{
}

Expand Down
12 changes: 6 additions & 6 deletions src/shogun/structure/StructuredModel.h
Expand Up @@ -63,22 +63,22 @@ struct CResultSet : public CSGObject
CStructuredData* argmax;

/** whether joint feature vector is sparse or not */
bool psi_computed_sparse = false;
bool psi_computed_sparse;

/** whether joint feature vector is dense or not */
bool psi_computed = false;
bool psi_computed;

/** joint feature vector for the given truth */
SGVector< float64_t > psi_truth = SGVector<float64_t>(0);
SGVector< float64_t > psi_truth;

/** joint feature vector for the prediction */
SGVector< float64_t > psi_pred = SGVector<float64_t>(0);
SGVector< float64_t > psi_pred;

/** joint feature vector for the given truth */
SGSparseVector< float64_t > psi_truth_sparse = SGSparseVector<float64_t>(0);
SGSparseVector< float64_t > psi_truth_sparse;

/** joint feature vector for the prediction */
SGSparseVector< float64_t > psi_pred_sparse = SGSparseVector<float64_t>(0);
SGSparseVector< float64_t > psi_pred_sparse;

/** \f$ \Delta(y_{pred}, y_{truth}) + \langle w,
* \Psi(x_{truth}, y_{pred}) - \Psi(x_{truth}, y_{truth}) \rangle \f$ */
Expand Down

0 comments on commit 44f064b

Please sign in to comment.