[opengm] 07/386: add LPotts IO-test and do bugfixes

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Wed Aug 31 08:34:58 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch debian/master
in repository opengm.

commit 69771798d72e4fcd52a93c9b2d3a76d710bd78b3
Author: joergkappes <kappes at math.uni-heidelberg.de>
Date:   Fri May 16 15:46:57 2014 +0200

     add LPotts IO-test and do bugfixes
---
 include/opengm/functions/learnable/lpotts.hxx | 33 +++++++++++++++++----------
 src/unittest/test_learnable_functions.cxx     | 32 +++++++++++++++++++++++---
 2 files changed, 50 insertions(+), 15 deletions(-)

diff --git a/include/opengm/functions/learnable/lpotts.hxx b/include/opengm/functions/learnable/lpotts.hxx
index b923788..6ef360a 100644
--- a/include/opengm/functions/learnable/lpotts.hxx
+++ b/include/opengm/functions/learnable/lpotts.hxx
@@ -27,13 +27,14 @@ namespace learnable {
 /// \ingroup functions
 template<class T, class I = size_t, class L = size_t>
 class LPotts
-: public FunctionBase<LearnableFeatureFunction<T, I, L>, T, I, L>
+   : public opengm::FunctionBase<opengm::functions::learnable::LPotts<T, I, L>, T, I, L>
 {
 public:
    typedef T ValueType;
    typedef L LabelType;
    typedef I IndexType;
-
+ 
+   LPotts();
    LPotts(
       const Parameters<T,I>& parameters,
       const L numLabels,
@@ -62,12 +63,12 @@ public:
 
 protected:
    const Parameters<T,I> * parameters_;
-   const L numLabels_;
-   const std::vector<size_t> parameterIDs_;
-   const std::vector<T> feat_;
+   L numLabels_;
+   std::vector<size_t> parameterIDs_;
+   std::vector<T> feat_;
 
 
-    friend class opengm::FunctionSerialization<opengm::functions::learnable::LPotts<T, I, L> > ;
+    friend class opengm::FunctionSerialization<opengm::functions::learnable::LPotts<T, I, L> >;
 };
 
 
@@ -98,6 +99,15 @@ LPotts<T, I, L>::LPotts
   OPENGM_ASSERT( parameterIDs_.size()==feat_.size() );
 }
 
+template <class T, class I, class L>
+inline
+LPotts<T, I, L>::LPotts
+( )
+   : numLabels_(0), parameterIDs_(std::vector<size_t>(0)), feat_(std::vector<T>(0))
+{
+  OPENGM_ASSERT( parameterIDs_.size()==feat_.size() );
+}
+
 
 template <class T, class I, class L>
 template <class ITERATOR>
@@ -224,18 +234,17 @@ FunctionSerialization<opengm::functions::learnable::LPotts<T, I, L> >::deseriali
    VALUE_INPUT_ITERATOR valueInIterator,
    opengm::functions::learnable::LPotts<T, I, L> & dst
 ) { 
-   const size_t numL=*indexInIterator;
+   dst.numLabels_=*indexInIterator;
    ++ indexInIterator;
    const size_t numW=*indexInIterator;
-   std::vector<T> feat(numW);
-   std::vector<size_t> id(numW);
+   dst.feat_.resize(numW);
+   dst.parameterIDs_.resize(numW);
    for(size_t i=0; i<numW;++i){
-     feat[i]=*valueInIterator;
-     id[i]=*indexInIterator;
+     dst.feat_[i]=*valueInIterator;
+     dst.parameterIDs_[i]=*indexInIterator;
      ++indexInIterator;
      ++valueInIterator;
    }
-   dst=opengm::functions::learnable::LPotts<T, I, L>(numL,id,feat);
 }
 
 } // namespace opengm
diff --git a/src/unittest/test_learnable_functions.cxx b/src/unittest/test_learnable_functions.cxx
index 90ec460..b2c63cd 100644
--- a/src/unittest/test_learnable_functions.cxx
+++ b/src/unittest/test_learnable_functions.cxx
@@ -43,18 +43,44 @@ struct LearnableFunctionsTest {
     std::vector<size_t> pIds(1,0);
     std::vector<ValueType> feat(1,1);
     // function
-    opengm::functions::learnable::LPotts<ValueType,IndexType,LabelType> lfunc(param,numL,pIds,feat);
+    opengm::functions::learnable::LPotts<ValueType,IndexType,LabelType> f(param,numL,pIds,feat);
 
     LabelType l[] ={0,0};
     for(l[0]=0;l[0]<numL;++l[0]){
       for(l[1]=0;l[1]<numL;++l[1]){
 	if(l[0]==l[1]){
-	  OPENGM_TEST_EQUAL_TOLERANCE(lfunc(l),0, 0.0001);
+	  OPENGM_TEST_EQUAL_TOLERANCE(f(l),0, 0.0001);
 	}else{
-	  OPENGM_TEST_EQUAL_TOLERANCE(lfunc(l),5.0, 0.0001);
+	  OPENGM_TEST_EQUAL_TOLERANCE(f(l),5.0, 0.0001);
 	}
       }
     }
+    {
+       typedef  opengm::functions::learnable::LPotts<ValueType,IndexType,LabelType> FUNCTION;
+       const size_t sizeIndices=opengm::FunctionSerialization<FUNCTION>::indexSequenceSize(f);
+       const size_t sizeValues=opengm::FunctionSerialization<FUNCTION>::valueSequenceSize(f);
+       std::vector<long long unsigned> indices(sizeIndices);
+       std::vector<T> values(sizeValues);
+      
+       opengm::FunctionSerialization<FUNCTION>::serialize(f,indices.begin(),values.begin());
+       FUNCTION f2;
+       opengm::FunctionSerialization<FUNCTION>::deserialize(indices.begin(),values.begin(),f2);
+       f2.setParameters(param);
+
+       OPENGM_TEST(f.dimension()==f2.dimension());
+       OPENGM_TEST(f.size() == f2.size());
+       std::vector<size_t> shape(f.dimension());
+       for(size_t i=0;i<f.dimension();++i) {
+          shape[i]=f.shape(i);
+          OPENGM_TEST(f.shape(i)==f2.shape(i));
+       }
+       opengm::ShapeWalker<std::vector<size_t>::const_iterator > walker(shape.begin(),f.dimension());
+       for(size_t i=0;i<f.size();++i) {
+          OPENGM_TEST(walker.coordinateTuple().size()==f.dimension());
+          OPENGM_TEST(f(walker.coordinateTuple().begin())==f2(walker.coordinateTuple().begin()) );
+          ++walker;
+       }
+    }
     std::cout << "OK" << std::endl; 
   }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/opengm.git



More information about the debian-science-commits mailing list