Tapkee
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, stichwort::ParametersSet parameters)
98 {
99 #if EIGEN_VERSION_AT_LEAST(3,1,0)
100  Eigen::initParallel();
101 #endif
102  TapkeeOutput output;
103 
104  try
105  {
106  parameters.check();
107  parameters.merge(tapkee_internal::defaults);
108 
109  DimensionReductionMethod selected_method = parameters[method];
110 
111  void (*progress_function_ptr)(double) = parameters[progress_function];
112  bool (*cancel_function_ptr)() = parameters[cancel_function];
113 
114  tapkee_internal::Context context(progress_function_ptr,cancel_function_ptr);
115 
116  LoggingSingleton::instance().message_info(formatting::format("Using the {} method.", get_method_name(selected_method)));
117 
118  output = tapkee_internal::initialize(begin,end,kernel_callback,distance_callback,features_callback,parameters,context)
119  .embedUsing(selected_method);
120  }
121  catch (const std::bad_alloc&)
122  {
123  throw tapkee::not_enough_memory_error("Not enough memory");
124  }
125  catch (const stichwort::wrong_parameter_error& ex)
126  {
127  throw tapkee::wrong_parameter_error(ex.what());
128  }
129  catch (const stichwort::wrong_parameter_type_error& ex)
130  {
131  throw tapkee::wrong_parameter_type_error(ex.what());
132  }
133  catch (const stichwort::multiple_parameter_error& ex)
134  {
135  throw tapkee::multiple_parameter_error(ex.what());
136  }
137  catch (const stichwort::missed_parameter_error& ex)
138  {
139  throw tapkee::missed_parameter_error(ex.what());
140  }
141 
142  return output;
143 }
144 }
145 #endif
An exception type that is thrown in case if wrong parameter value is passed.
An exception type that is thrown in case of missed parameter, i.e. when some required parameter is no...
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.
An exception type that is thrown in case of missed parameter, i.e. when some required parameter is no...
std::string format(const std::string &fmt, const ValueWrapper a)
Definition: formatting.hpp:411
An exception type that is thrown when some parameter is passed more than once.
DimensionReductionMethod
Dimension reduction methods.
An exception type that is thrown when some parameter is passed more than once.
An exception type that is thrown in case if wrong parameter value is passed.
TapkeeOutput embed(RandomAccessIterator begin, RandomAccessIterator end, KernelCallback kernel_callback, DistanceCallback distance_callback, FeaturesCallback features_callback, stichwort::ParametersSet parameters)
Definition: embed.hpp:95
void message_info(const std::string &msg)
Definition: logging.hpp:115
Return result of the library - a pair of DenseMatrix (embedding) and ProjectingFunction.
Definition: defines.hpp:43
ImplementationBase< RandomAccessIterator, KernelCallback, DistanceCallback, FeaturesCallback > initialize(RandomAccessIterator begin, RandomAccessIterator end, KernelCallback kernel, DistanceCallback distance, FeaturesCallback features, stichwort::ParametersSet &pmap, const Context &ctx)
Definition: methods.hpp:560
static LoggingSingleton & instance()
Definition: logging.hpp:102
void merge(const ParametersSet &pg)
Definition: parameter.hpp:275
An exception type that is thrown in case if wrong parameter value is passed.
An exception type that is thrown in case if wrong parameter value is passed.