Tapkee
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
embed.hpp
Go to the documentation of this file.
1 /* This software is distributed under BSD 3-clause license (see LICENSE file).
2  *
3  * Copyright (c) 2012-2013 Sergey Lisitsyn
4  */
5 
6 #ifndef TAPKEE_EMBED_H_
7 #define TAPKEE_EMBED_H_
8 
9 /* Tapkee includes */
10 #include <tapkee/defines.hpp>
11 #include <tapkee/methods.hpp>
12 /* End of Tapkee includes */
13 
14 namespace tapkee
15 {
94 template <class RandomAccessIterator, class KernelCallback, class DistanceCallback, class FeaturesCallback>
95 TapkeeOutput embed(RandomAccessIterator begin, RandomAccessIterator end,
96  KernelCallback kernel_callback, DistanceCallback distance_callback,
97  FeaturesCallback features_callback, ParametersSet parameters)
98 {
99 #if EIGEN_VERSION_AT_LEAST(3,1,0)
100  Eigen::initParallel();
101 #endif
102  TapkeeOutput output;
103 
104  parameters.merge(tapkee_internal::defaults);
105 
106  DimensionReductionMethod selected_method = parameters(keywords::method);
107 
108  void (*progress_function)(double) = parameters(keywords::progress_function);
109  bool (*cancel_function)() = parameters(keywords::cancel_function);
110 
111  tapkee_internal::Context context(progress_function,cancel_function);
112 
113  try
114  {
115  LoggingSingleton::instance().message_info("Using the " + get_method_name(selected_method) + " method.");
116 
117  output = tapkee_internal::initialize(begin,end,kernel_callback,distance_callback,features_callback,parameters,context)
118  .embedUsing(selected_method);
119  }
120  catch (const std::bad_alloc&)
121  {
122  throw not_enough_memory_error("Not enough memory");
123  }
124 
125  return output;
126 }
127 }
128 #endif
std::string get_method_name(DimensionReductionMethod m)
Definition: naming.hpp:13
An exception type that is thrown when the library can&#39;t get enough memory.
Definition: exceptions.hpp:57
void merge(const ParametersSet &pg)
Definition: parameters.hpp:325
DimensionReductionMethod
Dimension reduction methods.
void message_info(const std::string &msg)
Definition: logging.hpp:113
Return result of the library - a pair of DenseMatrix (embedding) and ProjectingFunction.
Definition: defines.hpp:43
static LoggingSingleton & instance()
Definition: logging.hpp:100
ImplementationBase< RandomAccessIterator, KernelCallback, DistanceCallback, FeaturesCallback > initialize(RandomAccessIterator begin, RandomAccessIterator end, KernelCallback kernel, DistanceCallback distance, FeaturesCallback features, ParametersSet &pmap, const Context &ctx)
Definition: methods.hpp:518
TapkeeOutput embed(RandomAccessIterator begin, RandomAccessIterator end, KernelCallback kernel_callback, DistanceCallback distance_callback, FeaturesCallback features_callback, ParametersSet parameters)
Definition: embed.hpp:95