Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef __LATENTSOMODEL_H__
- #define __LATENTSOMODEL_H__
- #include <shogun/latent/LatentModel.h>
- #include <shogun/structure/StructuredModel.h>
- namespace shogun
- {
- /** @brief TODO
- */
- class CLatentSOModel: public CLatentModel
- {
- public:
- /** default ctor */
- CLatentSOModel();
- /** ctor
- *
- * @param feats Latent features
- * @param labels Latent labels
- */
- CLatentSOModel(CLatentFeatures* feats, CLatentLabels* labels);
- virtual ~CLatentSOModel();
- /**
- * get the dimension of PSI
- *
- * @return dimension of features, i.e. psi vector
- */
- virtual int32_t get_dim() const=0;
- /**
- * Calculate the PSI vector for a given sample
- *
- * @param idx index of the sample
- *
- * @return PSI vector
- */
- virtual CDotFeatures* get_psi_feature_vectors()=0;
- virtual SGVector<float64_t> get_psi_feature_vector(index_t feat_idx, CStructuredData* ybar, CData* hbar)=0;
- virtual CData* infer_latent_variable(const SGVector<float64_t>& w, index_t idx)=0;
- /** Finds the most violated constraint
- * \f[
- * argmax_{(ybar,hbar)} [<w,psi(x,ybar,hbar)> + loss(y,ybar,hbar)]
- * \f]
- *
- * @param idx
- * @param
- */
- virtual void get_most_violated_constraint(const SGVector<float64_t>& w, index_t feat_idx, CStructuredData* ybar, CData* hbar)=0;
- virtual void argmax_h(const SGVector<float64_t>& w);
- virtual float64_t delta(CStructuredData* y1, CStructuredData* y2, CData* h) = 0;
- virtual const char* get_name() const { return "LatentModel"; }
- float64_t get_sum_argmax_h() const;
- private:
- void register_parameters();
- private:
- float64_t m_sum_argmax_h;
- };
- class CLSOModel: public CStructuredModel
- {
- public:
- CLSOModel();
- CLSOModel(CLatentSOModel* latent_model);
- virtual ~CLSOModel();
- virtual int32_t get_dim() const;
- virtual CResultSet* argmax(SGVector< float64_t > w, int32_t feat_idx, bool const training = true);
- virtual const char* get_name() const { return "LSOModel"; }
- /** Calculates the risk function for Latent Structural SVM
- *
- * \f[
- * \sum_{i=1}^n \left( \max_{(\hat{y},\hat{h}) \in YxH} \left[ \mathbf{w}
- * \cdot \Psi(x_i, \hat{y}, \hat{h})+\Delta(y_i, \hat{y}, \hat{h}) \right ] \right )
- * - \sum_{i=1}^n \mathbf{w} \cdot \Psi(x_i, y_i, h^*_i)
- * \f]
- *
- * For more details see [1]
- * [1] C.-N. J. Yu and T. Joachims,
- * "Learning structural SVMs with latent variables"
- * presented at the Proceedings of the 26th Annual International Conference on Machine Learning,
- * New York, NY, USA, 2009, pp. 1169-1176.
- * http://www.cs.cornell.edu/~cnyu/papers/icml09_latentssvm.pdf
- *
- */
- virtual float64_t risk(float64_t* subgrad, float64_t* W, TMultipleCPinfo* info=0);
- private:
- CLatentSOModel* m_latent_model;
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement