Changeset 2338


Ignore:
Timestamp:
Oct 16, 2010, 7:00:12 AM (13 years ago)
Author:
Peter
Message:

adding an archetype class for distance concept and use that class in KNN and NCC. Adding CopyConstructible? to requirement for Distance concept

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/concepts.doxygen

    r2312 r2338  
    297297\section Requirements
    298298
    299 Classes modelling the concept \ref concept_distance should implement
    300 the following public function:
     299Classes modelling the concept \ref concept_distance should have a copy
     300constructor
     301
     302\verbatim
     303Distance(const Distance& d);
     304\endverbatim
     305
     306and also implement the following public function:
    301307
    302308\verbatim
  • trunk/test/Suite.h

    r2260 r2338  
    2323  along with yat. If not, see <http://www.gnu.org/licenses/>.
    2424*/
     25
     26#include <boost/concept_archetype.hpp>
    2527
    2628#include <iosfwd>
     
    219221    reference operator()(size_t row, size_t column)
    220222    { return this->element_; }
     223  };
     224
     225  /*
     226    class to test (at compile time) that a function (or class) works
     227    with a Distance. Do not run any test using this class because
     228    the class is not really functional at run time.
     229
     230    \see boost/concept_archetype.hpp
     231   */
     232  class distance_archetype
     233  {
     234  public:
     235    /// class must be constructible somehow, but we don't wanna assume
     236    /// void constructor or any other common constructor so we use the
     237    /// signature to allow construction without assuming too much.
     238    distance_archetype(const boost::detail::dummy_constructor&) {};
     239    distance_archetype(const distance_archetype&) {};
     240    template<typename T1, typename T2>
     241    double operator()(T1 first1, T1 last1, T2 first2) const { return 0.0; }
     242  private:
     243    distance_archetype(void);
     244    distance_archetype& operator=(const distance_archetype&);
    221245  };
    222246
  • trunk/test/knn_test.cc

    r2119 r2338  
    4343using namespace theplu::yat;
    4444
     45void compile_test(test::Suite&);
    4546utility::Matrix data(void);
    4647utility::MatrixWeighted data_weighted(void);
     
    5556std::vector<std::string> vec_target(void);
    5657
     58
    5759int main(int argc, char* argv[])
    5860
     
    6668  test_no_samples(suite);
    6769  test_no_features(suite);
     70  compile_test(suite);
    6871  return suite.return_value();
    6972}
     73
     74
     75void compile_test(test::Suite& suite)
     76{
     77  if (false) {
     78    boost::detail::dummy_constructor dummy;
     79    test::distance_archetype distance(dummy);
     80    classifier::KNN<test::distance_archetype> knn(distance);
     81    knn.k(3);
     82    knn.k();
     83    classifier::SupervisedClassifier* knn2 = knn.make_classifier();
     84    delete knn2;
     85    utility::Matrix result;
     86    knn.train(classifier::MatrixLookup(data()), classifier::Target());
     87    knn.train(classifier::MatrixLookupWeighted(data_weighted()),
     88              classifier::Target());
     89    knn.predict(classifier::MatrixLookup(data()), result);
     90    knn.predict(classifier::MatrixLookupWeighted(data_weighted()), result);
     91  }
     92}
    7093
    7194
  • trunk/test/ncc_test.cc

    r2119 r2338  
    4747
    4848void predict_nan_data_unweighted_data(test::Suite& suite);
     49void compile_test(test::Suite& suite);
    4950
    5051int main(int argc,char* argv[])
     
    259260    suite.err() << "Difference to stored prediction too large\n";
    260261  }
     262  compile_test(suite);
    261263
    262264  return suite.return_value();
    263265}
     266
     267
     268void compile_test(test::Suite& suite)
     269{
     270  if (false) {
     271    boost::detail::dummy_constructor dummy;
     272    test::distance_archetype distance(dummy);
     273    classifier::NCC<test::distance_archetype> ncc(distance);
     274  }
     275}
     276
    264277
    265278void predict_nan_data_unweighted_data(test::Suite& suite)
  • trunk/yat/utility/concept_check.h

    r2334 r2338  
    261261  */
    262262  template <class T>
    263   class DistanceConcept
     263  class DistanceConcept : boost::CopyConstructible<T>
    264264  {
    265265  public:
Note: See TracChangeset for help on using the changeset viewer.