SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MultidimensionalScaling.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) 2011-2013 Sergey Lisitsyn
8  * Copyright (C) 2011-2013 Berlin Institute of Technology and Max-Planck-Society
9  */
10 
12 #ifdef HAVE_EIGEN3
16 #include <shogun/lib/common.h>
19 #include <shogun/io/SGIO.h>
21 #include <shogun/lib/tapkee/tapkee_shogun.hpp>
22 
23 using namespace shogun;
24 
26 {
29  m_landmark = false;
30 
31  init();
32 }
33 
35 {
36  SG_ADD(&m_eigenvalues, "eigenvalues", "eigenvalues of last embedding",
38  SG_ADD(&m_landmark, "landmark",
39  "indicates if landmark approximation should be used", MS_NOT_AVAILABLE);
40  SG_ADD(&m_landmark_number, "landmark_number",
41  "the number of landmarks for approximation", MS_AVAILABLE);
42 }
43 
45 {
46 }
47 
49 {
50  return m_eigenvalues;
51 }
52 
54 {
55  if (num<3)
56  SG_ERROR("Number of landmarks should be greater than 3 to make triangulation possible while %d given.",
57  num);
58  m_landmark_number = num;
59 }
60 
62 {
63  return m_landmark_number;
64 }
65 
67 {
68  m_landmark = landmark;
69 }
70 
72 {
73  return m_landmark;
74 }
75 
77 {
78  return "MultidimensionalScaling";
79 };
80 
82 {
83  TAPKEE_PARAMETERS_FOR_SHOGUN parameters;
84  if (m_landmark)
85  {
86  parameters.method = SHOGUN_LANDMARK_MULTIDIMENSIONAL_SCALING;
87  parameters.landmark_ratio = float64_t(m_landmark_number)/distance->get_num_vec_lhs();
88  if (parameters.landmark_ratio > 1.0) {
89  SG_WARNING("Number of landmarks (%d) exceeds number of feature vectors (%d)",m_landmark_number,distance->get_num_vec_lhs());
90  parameters.landmark_ratio = 1.0;
91  }
92  }
93  else
94  {
95  parameters.method = SHOGUN_MULTIDIMENSIONAL_SCALING;
96  }
97  parameters.target_dimension = m_target_dim;
98  parameters.distance = distance;
99  CDenseFeatures<float64_t>* embedding = tapkee_embed(parameters);
100  return embedding;
101 }
102 
104 {
105  SG_REF(features);
107 
108  m_distance->init(features,features);
111 
112  SG_UNREF(features);
113  return (CFeatures*)embedding;
114 }
115 
116 #endif /* HAVE_EIGEN3 */

SHOGUN Machine Learning Toolbox - Documentation