LCOV - code coverage report
Current view: top level - home/blackburn/Work/tapkee/include/tapkee - embed.hpp (source / functions) Hit Total Coverage
Test: clean.info Lines: 13 13 100.0 %
Date: 2013-05-24 Functions: 10 10 100.0 %
Branches: 269 576 46.7 %

           Branch data     Line data    Source code
       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                 :            : {
      16                 :            : /** Constructs a dense embedding with specified 
      17                 :            :  * dimensionality using provided data represented by random access iterators 
      18                 :            :  * and provided callbacks. Returns ReturnType that is essentially a pair of 
      19                 :            :  * @ref DenseMatrix (embedding of provided data) and a ProjectingFunction with 
      20                 :            :  * corresponding ProjectionImplementation used to project 
      21                 :            :  * data out of the sample.
      22                 :            :  *
      23                 :            :  * @tparam RandomAccessIterator random access iterator with no 
      24                 :            :  *         specific capabilities that points to some RandomAccessIterator::value_type 
      25                 :            :  *         (the simplest case is RandomAccessIterator::value_type being int).
      26                 :            :  *
      27                 :            :  * @tparam KernelCallback a callback that defines 
      28                 :            :  * @code ScalarType kernel(const RandomAccessIterator::value_type&, const RandomAccessIterator::value_type&) @endcode 
      29                 :            :  * function of two iterators. This method should return value of Mercer kernel function 
      30                 :            :  * between vectors/objects iterators pointing to. 
      31                 :            :  *
      32                 :            :  * @tparam DistanceCallback a callback that defines 
      33                 :            :  * @code ScalarType distance(const RandomAccessIterator::value_type&, const RandomAccessIterator::value_type&) @endcode 
      34                 :            :  * function of two iterators. 
      35                 :            :  *
      36                 :            :  * @tparam FeaturesCallback a callback that defines 
      37                 :            :  * @code void vector(const RandomAccessIterator::value_type&, DenseVector&) @endcode function
      38                 :            :  * used to access feature vector pointed by iterator. The callback should put the feature vector 
      39                 :            :  * pointed by the iterator to the provided vector.
      40                 :            :  *
      41                 :            :  * Parameters required by the chosen algorithm are obtained from the parameter map. It gracefully 
      42                 :            :  * fails during runtime and throws an exception if some of required 
      43                 :            :  * parameters are not specified or have improper values.
      44                 :            :  *
      45                 :            :  * @param begin begin iterator of data
      46                 :            :  * @param end end iterator of data
      47                 :            :  * @param kernel_callback the kernel callback implementing
      48                 :            :  * @code ScalarType kernel(const RandomAccessIterator::value_type&, const RandomAccessIterator::value_type&) @endcode 
      49                 :            :  * Used by the following methods: 
      50                 :            :  * - @ref tapkee::KernelLocallyLinearEmbedding
      51                 :            :  * - @ref tapkee::NeighborhoodPreservingEmbedding
      52                 :            :  * - @ref tapkee::KernelLocalTangentSpaceAlignment
      53                 :            :  * - @ref tapkee::LinearLocalTangentSpaceAlignment
      54                 :            :  * - @ref tapkee::HessianLocallyLinearEmbedding
      55                 :            :  * - @ref tapkee::KernelPCA
      56                 :            :  *
      57                 :            :  * @param distance_callback the distance callback implementing
      58                 :            :  * @code ScalarType distance(const RandomAccessIterator::value_type&, const RandomAccessIterator::value_type&) @endcode 
      59                 :            :  * Used by the following methods: 
      60                 :            :  * - @ref tapkee::LaplacianEigenmaps
      61                 :            :  * - @ref tapkee::LocalityPreservingProjections
      62                 :            :  * - @ref tapkee::DiffusionMap
      63                 :            :  * - @ref tapkee::Isomap
      64                 :            :  * - @ref tapkee::LandmarkIsomap
      65                 :            :  * - @ref tapkee::MultidimensionalScaling
      66                 :            :  * - @ref tapkee::LandmarkMultidimensionalScaling
      67                 :            :  * - @ref tapkee::StochasticProximityEmbedding
      68                 :            :  * - @ref tapkee::tDistributedStochasticNeighborEmbedding
      69                 :            :  *
      70                 :            :  * @param feature_vector_callback the feature vector callback implementing
      71                 :            :  * @code void vector(const RandomAccessIterator::value_type&, DenseVector&) @endcode
      72                 :            :  * Used by the following methods:
      73                 :            :  * - @ref tapkee::NeighborhoodPreservingEmbedding
      74                 :            :  * - @ref tapkee::LinearLocalTangentSpaceAlignment
      75                 :            :  * - @ref tapkee::LocalityPreservingProjections
      76                 :            :  * - @ref tapkee::PCA
      77                 :            :  * - @ref tapkee::RandomProjection
      78                 :            :  * - @ref tapkee::FactorAnalysis
      79                 :            :  * - @ref tapkee::tDistributedStochasticNeighborEmbedding
      80                 :            :  * - @ref tapkee::PassThru
      81                 :            :  *
      82                 :            :  * @param parameters a set of parameters formed with 
      83                 :            :  *        keywords expression.
      84                 :            :  *
      85                 :            :  * @throw tapkee::wrong_parameter_error if wrong parameter value is passed
      86                 :            :  * @throw tapkee::missed_parameter_error if some required parameter is missed
      87                 :            :  * @throw tapkee::multiple_parameter_error if some parameter is provided more than once
      88                 :            :  * @throw tapkee::unsupported_method_error if some method or combination of methods is unsupported 
      89                 :            :  * @throw tapkee::not_enough_memory_error if there is not enough memory to perform the computations
      90                 :            :  * @throw tapkee::cancelled_exception if computations were cancelled due to cancel_function returned true
      91                 :            :  * @throw tapkee::eigendecomposition_error if eigendecomposition has failed
      92                 :            :  *
      93                 :            :  */
      94                 :            : template <class RandomAccessIterator, class KernelCallback, class DistanceCallback, class FeaturesCallback>
      95                 :         40 : 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                 :         40 :         Eigen::initParallel();
     101                 :            : #endif
     102                 :         40 :         TapkeeOutput output;
     103                 :            : 
     104   [ +  -  +  -  :         40 :         parameters.merge(tapkee_internal::defaults);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  +  - ]
     105                 :            : 
     106 [ +  - ][ +  - ]:         40 :         DimensionReductionMethod selected_method = parameters(keywords::method);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  + ]
         [ +  - ][ +  - ]
                 [ +  - ]
     107                 :            :         
     108 [ +  - ][ +  - ]:         39 :         void (*progress_function)(double) = parameters(keywords::progress_function);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     109 [ +  - ][ +  - ]:         39 :         bool (*cancel_function)() = parameters(keywords::cancel_function);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     110                 :            : 
     111                 :         39 :         tapkee_internal::Context context(progress_function,cancel_function);
     112                 :            : 
     113                 :            :         try 
     114                 :            :         {
     115 [ +  - ][ +  - ]:         39 :                 LoggingSingleton::instance().message_info("Using the " + get_method_name(selected_method) + " method.");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     116                 :            :                 
     117 [ +  - ][ +  - ]:         39 :                 output = tapkee_internal::initialize(begin,end,kernel_callback,distance_callback,features_callback,parameters,context)
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  + ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ +  - ]
         [ +  + ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  + ]
         [ +  - ][ +  - ]
                 [ +  - ]
     118                 :            :                                          .embedUsing(selected_method);
     119                 :            :         }
     120 [ #  # ][ #  # ]:          6 :         catch (const std::bad_alloc&)
         [ #  # ][ #  # ]
         [ #  # ][ +  + ]
         [ +  - ][ +  - ]
                 [ +  - ]
     121                 :            :         {
     122 [ #  # ][ #  # ]:          1 :                 throw not_enough_memory_error("Not enough memory");
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     123                 :            :         }
     124                 :            : 
     125                 :         40 :         return output;
     126                 :            : }
     127                 :            : }
     128                 :            : #endif

Generated by: LCOV version 1.9