[opengm] 282/386: corrects indexing call from a learnable function.weightGradient to a multidimensional marray (*begin ---> begin) (this was working correctly only for 1-dim marrays)

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Wed Aug 31 08:38:11 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 db4e221c20b4733eaa32246ef31c95e7e5105884
Author: Janez Ales <janez.ales at iwr.uni-heidelberg.de>
Date:   Wed Oct 21 14:53:47 2015 +0200

    corrects indexing call from a learnable function.weightGradient to a multidimensional marray (*begin ---> begin)
    (this was working correctly only for 1-dim marrays)
---
 include/opengm/datastructures/marray/marray.hxx    |  1 +
 .../learnable/lweightedsum_of_functions.hxx        | 12 +++------
 include/opengm/inference/lp_inference_base.hxx     |  1 -
 include/opengm/learning/bundle-optimizer.hxx       | 31 +++++++++++++++++-----
 include/opengm/learning/gradient-accumulator.hxx   |  3 ---
 5 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/include/opengm/datastructures/marray/marray.hxx b/include/opengm/datastructures/marray/marray.hxx
index 0c91d2f..7871e7e 100644
--- a/include/opengm/datastructures/marray/marray.hxx
+++ b/include/opengm/datastructures/marray/marray.hxx
@@ -15,6 +15,7 @@
 #include <iostream> // cout
 #include <memory> // allocator
 #include <numeric> // accumulate
+#include <typeinfo>
 
 /// Runtime-flexible multi-dimensional views and arrays
 namespace marray {
diff --git a/include/opengm/functions/learnable/lweightedsum_of_functions.hxx b/include/opengm/functions/learnable/lweightedsum_of_functions.hxx
index eaa7d28..5978c52 100644
--- a/include/opengm/functions/learnable/lweightedsum_of_functions.hxx
+++ b/include/opengm/functions/learnable/lweightedsum_of_functions.hxx
@@ -79,6 +79,8 @@ LWeightedSumOfFunctions<T, I, L>::LWeightedSumOfFunctions
    OPENGM_ASSERT( weightIDs_.size() == feat_.size() );
    for(size_t i=0; i<weightIDs_.size(); ++i)
       OPENGM_ASSERT( size() == feat_[i].size() );
+      for(size_t j=0; j<dimension(); ++j)
+          OPENGM_ASSERT( shape(j) == feat_[i].shape(j))
 }
 
 template <class T, class I, class L>
@@ -99,15 +101,7 @@ LWeightedSumOfFunctions<T, I, L>::weightGradient
    ITERATOR begin
 ) const {
   OPENGM_ASSERT(weightNumber< numberOfWeights());
-
-  if(dimension()==1){
-    return feat_[weightNumber](*begin);
-  }
-  else if(dimension()==2){
-    return feat_[weightNumber](*begin, *(begin+1));
-  }
-  else
-    OPENGM_ASSERT(dimension()<=2);
+  return feat_[weightNumber](begin);
 }
 
 template <class T, class I, class L>
diff --git a/include/opengm/inference/lp_inference_base.hxx b/include/opengm/inference/lp_inference_base.hxx
index 36fc750..cf47706 100644
--- a/include/opengm/inference/lp_inference_base.hxx
+++ b/include/opengm/inference/lp_inference_base.hxx
@@ -1842,7 +1842,6 @@ inline LPInferenceBase<LP_INFERENCE_TYPE>::LPInferenceBase(const GraphicalModelT
    if(!opengm::meta::Compare<OperatorType, opengm::Adder>::value) {
       throw RuntimeError("This implementation does only supports Min-Sum-Semiring and Max-Sum-Semiring.");
    }
-
    // sort factors
    sortFactors();
 
diff --git a/include/opengm/learning/bundle-optimizer.hxx b/include/opengm/learning/bundle-optimizer.hxx
index 1135b0b..7f99d5d 100644
--- a/include/opengm/learning/bundle-optimizer.hxx
+++ b/include/opengm/learning/bundle-optimizer.hxx
@@ -153,7 +153,7 @@ BundleOptimizer<T>::optimize(Oracle& oracle, Weights& w) {
 
 	unsigned int t = 0;
 
-	while (true) {
+    while (true) {
 
 		t++;
 
@@ -161,7 +161,10 @@ BundleOptimizer<T>::optimize(Oracle& oracle, Weights& w) {
 
         Weights w_tm1 = w;
 
-        //std::cout << "current w is " << w_tm1 << std::endl;
+        std::cout << "w: ";
+        for(size_t i=0; i<w_tm1.size(); ++i)
+            std::cout << w_tm1[i] << " ";
+        std::cout << std::endl;
 
 		// value of L at current w
 		T L_w_tm1 = 0.0;
@@ -173,7 +176,10 @@ BundleOptimizer<T>::optimize(Oracle& oracle, Weights& w) {
 		oracle(w_tm1, L_w_tm1, a_t);
 
 		std::cout << "       L(w)              is: " << L_w_tm1 << std::endl;
-        //std::cout << "      ∂L(w)/∂            is: " << a_t << std::endl;
+        std::cout << "∂L(w)/∂:  (";
+        for(size_t i=0; i<a_t.size(); ++i)
+            std::cout << a_t[i] << " ";
+        std::cout << ")" << std::endl;
 
 		// update smallest observed value of regularized L
 		minValue = std::min(minValue, L_w_tm1 + _parameter.lambda*0.5*dot(w_tm1, w_tm1));
@@ -183,7 +189,10 @@ BundleOptimizer<T>::optimize(Oracle& oracle, Weights& w) {
 		// compute hyperplane offset
 		T b_t = L_w_tm1 - dot(w_tm1, a_t);
 
-        //std::cout << "adding hyperplane " << a_t << "*w + " << b_t << std::endl;
+        std::cout << "adding hyperplane: ( ";
+        for(size_t i=0; i<a_t.size(); ++i)
+            std::cout << a_t[i] << " ";
+        std::cout << ")*w + " << b_t << std::endl;
 
 		// update lower bound
 		_bundleCollector.addHyperplane(a_t, b_t);
@@ -191,11 +200,19 @@ BundleOptimizer<T>::optimize(Oracle& oracle, Weights& w) {
 		// minimal value of lower bound
 		T minLower;
 
-		// update w and get minimal value
+        std::cout << "w before findMinLowerBound: ";
+        for(size_t i=0; i<w.size(); ++i)
+            std::cout << w[i] << " ";
+        std::cout << std::endl;
+
+        // update w and get minimal value
 		findMinLowerBound(w, minLower);
 
 		std::cout << " min_w ℒ(w)   + ½λ|w|²   is: " << minLower << std::endl;
-        //std::cout << " w* of ℒ(w)   + ½λ|w|²   is: "  << w << std::endl;
+        std::cout << " w* of ℒ(w)   + ½λ|w|²   is: (";
+        for(size_t i=0; i<w.size(); ++i)
+            std::cout << w[i] << " ";
+        std::cout << ")" << std::endl;
 
 		// compute gap
 		T eps_t;
@@ -269,6 +286,8 @@ BundleOptimizer<T>::findMinLowerBound(ModelWeights& w, T& value) {
 
 	for (size_t i = 0; i < w.numberOfWeights(); i++)
 		w[i] = x[i];
+    for (size_t i = 0; i < w.numberOfWeights(); i++)
+        std::cout << "x[" << i << "]=" << x[i] << std::endl;
 }
 
 template <typename T>
diff --git a/include/opengm/learning/gradient-accumulator.hxx b/include/opengm/learning/gradient-accumulator.hxx
index f605122..43c9cf8 100644
--- a/include/opengm/learning/gradient-accumulator.hxx
+++ b/include/opengm/learning/gradient-accumulator.hxx
@@ -53,9 +53,7 @@ public:
         for (int i = 0; i < function.numberOfWeights(); i++) {
 
             int index = function.weightIndex(i);
-
             double g = function.weightGradient(i, Iter(accessor, 0));
-
             if (_mode == Add)
                 _gradient[index] += g;
             else
@@ -117,7 +115,6 @@ struct FeatureAccumulator{
         typedef opengm::SubsetAccessor<Iter, LABEL_ITER> Accessor;
         typedef opengm::AccessorIterator<Accessor, true> AccessorIter;
 
-
         // get the number of weights_
         const size_t nWeights = f.numberOfWeights();
         if(nWeights>0){

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