SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 
15 #include <shogun/lib/common.h>
18 #include <shogun/io/SGIO.h>
20 #include <shogun/lib/tapkee/tapkee_shogun.hpp>
21 
22 using namespace shogun;
23 
25 {
28  m_landmark = false;
29 
30  init();
31 }
32 
34 {
35  SG_ADD(&m_eigenvalues, "eigenvalues", "eigenvalues of last embedding",
37  SG_ADD(&m_landmark, "landmark",
38  "indicates if landmark approximation should be used", MS_NOT_AVAILABLE);
39  SG_ADD(&m_landmark_number, "landmark_number",
40  "the number of landmarks for approximation", MS_AVAILABLE);
41 }
42 
44 {
45 }
46 
48 {
49  return m_eigenvalues;
50 }
51 
53 {
54  if (num<3)
55  SG_ERROR("Number of landmarks should be greater than 3 to make triangulation possible while %d given.",
56  num);
57  m_landmark_number = num;
58 }
59 
61 {
62  return m_landmark_number;
63 }
64 
66 {
67  m_landmark = landmark;
68 }
69 
71 {
72  return m_landmark;
73 }
74 
76 {
77  return "MultidimensionalScaling";
78 };
79 
81 {
82  TAPKEE_PARAMETERS_FOR_SHOGUN parameters;
83  if (m_landmark)
84  {
85  parameters.method = SHOGUN_LANDMARK_MULTIDIMENSIONAL_SCALING;
86  parameters.landmark_ratio = float64_t(m_landmark_number)/distance->get_num_vec_lhs();
87  if (parameters.landmark_ratio > 1.0) {
88  SG_WARNING("Number of landmarks (%d) exceeds number of feature vectors (%d)",m_landmark_number,distance->get_num_vec_lhs());
89  parameters.landmark_ratio = 1.0;
90  }
91  }
92  else
93  {
94  parameters.method = SHOGUN_MULTIDIMENSIONAL_SCALING;
95  }
96  parameters.target_dimension = m_target_dim;
97  parameters.distance = distance;
98  CDenseFeatures<float64_t>* embedding = tapkee_embed(parameters);
99  return embedding;
100 }
101 
103 {
104  SG_REF(features);
106 
107  m_distance->init(features,features);
110 
111  SG_UNREF(features);
112  return (CFeatures*)embedding;
113 }
114 
float distance(CJLCoverTreePoint p1, CJLCoverTreePoint p2, float64_t upper_bound)
Class Distance, a base class for all the distances used in the Shogun toolbox.
Definition: Distance.h:87
virtual int32_t get_num_vec_lhs()
Definition: Distance.h:312
class EmbeddingConverter (part of the Efficient Dimensionality Reduction Toolkit) used to construct e...
#define SG_ERROR(...)
Definition: SGIO.h:129
virtual CDenseFeatures< float64_t > * embed_distance(CDistance *distance)
#define SG_REF(x)
Definition: SGObject.h:51
#define ASSERT(x)
Definition: SGIO.h:201
virtual void remove_lhs_and_rhs()
Definition: Distance.cpp:119
double float64_t
Definition: common.h:50
virtual CFeatures * apply(CFeatures *features)
SGVector< float64_t > get_eigenvalues() const
#define SG_UNREF(x)
Definition: SGObject.h:52
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
The class Features is the base class of all feature objects.
Definition: Features.h:68
#define SG_WARNING(...)
Definition: SGIO.h:128
#define SG_ADD(...)
Definition: SGObject.h:81
virtual bool init(CFeatures *lhs, CFeatures *rhs)
Definition: Distance.cpp:78
SGVector< float64_t > m_eigenvalues
FIELDS.

SHOGUN Machine Learning Toolbox - Documentation