SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LatentSVM.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 
11 #include <typeinfo>
12 
15 
16 using namespace shogun;
17 
20 {
21 }
22 
24  : CLinearLatentMachine(model, C)
25 {
26 }
27 
29 {
30 }
31 
33 {
34  if (!m_model)
35  SG_ERROR("LatentModel is not set!\n");
36 
37  if (!features)
38  return NULL;
39 
40  index_t num_examples = m_model->get_num_vectors();
41  CLatentLabels* hs = new CLatentLabels(num_examples);
42  CBinaryLabels* ys = new CBinaryLabels(num_examples);
43  hs->set_labels(ys);
44  m_model->set_labels(hs);
45 
46  for (index_t i = 0; i < num_examples; ++i)
47  {
48  /* find h for the example */
50  hs->add_latent_label(h);
51  }
52 
53  /* compute the y labels */
55  x->dense_dot_range(ys->get_labels().vector, 0, num_examples, NULL, w.vector, w.vlen, 0.0);
56 
57  return hs;
58 }
59 
61 {
63  CSVMOcas svm(m_C, features, ys);
64  svm.set_epsilon(cooling_eps);
65  svm.train();
66  SG_UNREF(ys);
67 
68  /* copy the resulting w */
69  SGVector<float64_t> cur_w = svm.get_w();
70  memcpy(w.vector, cur_w.vector, cur_w.vlen*sizeof(float64_t));
71 
72  return svm.compute_primal_objective();
73 }
74 

SHOGUN Machine Learning Toolbox - Documentation