[opengm] 14/386: add dumydataset - untested

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Wed Aug 31 08:34:59 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 bde49c1f7c1da7ca51a19080283745dd0f87bd16
Author: joergkappes <kappes at math.uni-heidelberg.de>
Date:   Mon May 19 10:01:44 2014 +0200

    add dumydataset - untested
---
 include/opengm/learning/dataset/testdataset.hxx | 90 +++++++++++++++++++++++++
 1 file changed, 90 insertions(+)

diff --git a/include/opengm/learning/dataset/testdataset.hxx b/include/opengm/learning/dataset/testdataset.hxx
new file mode 100644
index 0000000..5e18647
--- /dev/null
+++ b/include/opengm/learning/dataset/testdataset.hxx
@@ -0,0 +1,90 @@
+#pragma once
+#ifndef OPENGM_TESTDATASET_HXX
+#define OPENGM_TESTDATASET_HXX
+
+#include <vector>
+#include <cstdlib>
+
+
+namespace opengm {
+   namespace datasets{
+
+      template<class GM>
+      class TestDatset<GM>{
+      public:
+         typename typedef GM::ValueType ValueType;
+         typename typedef GM::IndexType IndexType;
+         typename typedef GM::LabelType LabelType; 
+         typename opengm::Parameters<ValueType,IndexType> ModelParameter;
+
+         const GM&                     getModel(const size_t i)  { return gms_[i]; }
+         const std::vector<LabelType>& getGT(const size_t i)     { return gt_; }
+         ModelParameters&              getModelParameters()      { return modelParameters_; }
+         size_t                        getNumberOfParameters()   { return 1; }
+         size_t                        getNumberOfModels()       { return gms_.size(); } 
+         
+         TestDatset();
+         TestDatset(size_t); 
+
+      private:
+         std::vector<GM> gms_; 
+         std::vector<LabelType> gt_; 
+         opengm::Parameters<ValueType,IndexType> modelParameter_;
+      };
+      
+       template<class GM>
+       TestDatset<GM>::TestDataset():TestDataset(3){};
+
+      template<class GM>
+       TestDatset<GM>::TestDataset(size_t numModels)
+          : modelParameter_(ModelParameter(1));
+      {
+         LabelType numberOfLabels = 2;
+         gt_.resize(64*64,0);
+         for(size_t i=32*64; i<64*64; ++i){
+            ft[i] = 1;
+         }
+         gms_.resize(numModels);
+         for(size_t m=0; m<numModels; ++m){
+            std::srand(m);
+            gms_[m].addVariables(64*64,2);
+            for(size_t y = 0; y < 64; ++y){ 
+               for(size_t x = 0; x < 64; ++x) {
+                  // function
+                  const size_t shape[] = {numberOfLabels};
+                  ExplicitFunction<double> f(shape, shape + 1);
+                  ValueType val = double(gt_[y*64+x]) + (double) std::rand() / (double) (std::RAND_MAX) * 0.75 ;
+                  f(0) = sta::fabs(val-0);
+                  f(1) = sta::fabs(val-1);
+                  typename GM::FunctionIdentifier fid = gm.addFunction(f);
+
+                  // factor
+                  size_t variableIndices[] = {y*64+x};
+                  gm.addFactor(fid, variableIndices, variableIndices + 1);
+               }
+            }
+          
+            opengm::functions::learnable::LPotts<ValueType,IndexType,LabelType> f(modelParameter_,2,std::vector<size_t>(1,0),std::vector<double>(1,1));
+            typename GM::FunctionIdentifier fid = gm.addFunction(f);      
+            for(size_t y = 0; y < 64; ++y){ 
+               for(size_t x = 0; x < 64; ++x) {
+                  if(x + 1 < 64) { // (x, y) -- (x + 1, y)
+                     size_t variableIndices[] = {y*64+x, y*64+x+1};
+                     sort(variableIndices, variableIndices + 2);
+                     gm.addFactor(fid, variableIndices, variableIndices + 2);
+                  }
+                  if(y + 1 < 64) { // (x, y) -- (x, y + 1)
+                     size_t variableIndices[] = {y*64+x, (y+1)*64+x};
+                     sort(variableIndices, variableIndices + 2);
+                     gm.addFactor(fid, variableIndices, variableIndices + 2);
+                  }
+               }    
+            }
+         }
+         
+      };
+
+   }
+} // namespace opengm
+
+#endif 

-- 
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