SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LatentModel.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2012 Viktor Gal
8  * Copyright (C) 2012 Viktor Gal
9  */
10 
13 
14 using namespace shogun;
15 
17  : m_features(NULL), m_labels(NULL)
18 {
19  register_parameters();
20 }
21 
23  : m_features(feats), m_labels(labels)
24 {
25  register_parameters();
28 }
29 
31 {
34 }
35 
37 {
38  return m_features->get_num_vectors();
39 }
40 
42 {
44  SG_REF(labs);
45  m_labels = labs;
46 }
47 
49 {
51  return m_labels;
52 }
53 
55 {
57  SG_REF(feats);
58  m_features = feats;
59 }
60 
62 {
63  int32_t num = get_num_vectors();
65  ASSERT(num > 0);
66  ASSERT(num == m_labels->get_num_labels());
67 
68 
69  // argmax_h only for positive examples
70  for (int32_t i = 0; i < num; ++i)
71  {
72  if (y->get_label(i) == 1)
73  {
74  // infer h and set it for the argmax_h <w,psi(x,h)>
75  CData* latent_data = infer_latent_variable(w, i);
76  m_labels->set_latent_label(i, latent_data);
77  }
78  }
79 }
80 
81 void CLatentModel::register_parameters()
82 {
83  m_parameters->add((CSGObject**) &m_features, "features", "Latent features");
84  m_parameters->add((CSGObject**) &m_labels, "labels", "Latent labels");
85 }
86 

SHOGUN Machine Learning Toolbox - Documentation