[opengm] 295/386: verbose=false implemented in more detail

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Wed Aug 31 08:38:14 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 7bc0d74a056e1b3a231c25ca86f98f00dfb83941
Author: Janez Ales <janez.ales at iwr.uni-heidelberg.de>
Date:   Mon Nov 23 17:07:19 2015 +0100

    verbose=false implemented in more detail
---
 include/opengm/learning/bundle-optimizer.hxx  | 72 ++++++++++++++++-----------
 include/opengm/learning/solver/CplexBackend.h |  7 ++-
 include/opengm/learning/struct-max-margin.hxx | 10 +++-
 3 files changed, 57 insertions(+), 32 deletions(-)

diff --git a/include/opengm/learning/bundle-optimizer.hxx b/include/opengm/learning/bundle-optimizer.hxx
index 4642d71..e8e5a7e 100644
--- a/include/opengm/learning/bundle-optimizer.hxx
+++ b/include/opengm/learning/bundle-optimizer.hxx
@@ -12,14 +12,14 @@ namespace learning {
 //template <typename T>
 //std::ostream& operator<<(std::ostream& out, Weights<T>& w) {
 
-	//out << "[";
-	//for (int i = 0; i < w.numberOfWeights(); i++) {
-
-		//if (i > 0)
-			//out << ", ";
-		//out << w[i];
-	//}
-	//out << "]";
+//    out << "[";
+//    for (int i = 0; i < w.numberOfWeights(); i++) {
+
+//        if (i > 0)
+//            out << ", ";
+//        out << w[i];
+//    }
+//    out << "]";
 //}
 
 enum OptimizerResult {
@@ -157,14 +157,17 @@ BundleOptimizer<T>::optimize(Oracle& oracle, Weights& w) {
 
 		t++;
 
-        std::cout << std::endl << "----------------- iteration      " << t << std::endl;
+        if(oracle.getInfParam().verbose_ )
+            std::cout << std::endl << "----------------- iteration      " << t << std::endl;
 
         Weights w_tm1 = w;
 
-        std::cout << "w: ";
-        for(size_t i=0; i<w_tm1.size(); ++i)
-            std::cout << w_tm1[i] << " ";
-        std::cout << std::endl;
+        if(oracle.getInfParam().verbose_ ){
+            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;
@@ -175,24 +178,29 @@ BundleOptimizer<T>::optimize(Oracle& oracle, Weights& w) {
 		// get current value and gradient
 		oracle(w_tm1, L_w_tm1, a_t);
 
-		std::cout << "       L(w)              is: " << L_w_tm1 << 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;
+        if(oracle.getInfParam().verbose_ ){
+            std::cout << "       L(w)              is: " << L_w_tm1 << 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));
 
-		std::cout << " min_i L(w_i) + ½λ|w_i|² is: " << minValue << std::endl;
+        if(oracle.getInfParam().verbose_ )
+            std::cout << " min_i L(w_i) + ½λ|w_i|² is: " << minValue << std::endl;
 
 		// compute hyperplane offset
 		T b_t = L_w_tm1 - dot(w_tm1, a_t);
 
-        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;
+        if(oracle.getInfParam().verbose_ ){
+            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);
@@ -209,11 +217,16 @@ BundleOptimizer<T>::optimize(Oracle& oracle, Weights& w) {
             norm += w[i]*w[i];
         norm = std::sqrt(norm);
 
-        std::cout << " min_w ℒ(w)   + ½λ|w|²   is: " << minLower << 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;
+        if(oracle.getInfParam().verbose_ ){
+            std::cout << " min_w ℒ(w)   + ½λ|w|²   is: " << minLower << std::endl;
+            std::cout << " w* of ℒ(w)   + ½λ|w|²   is: (";
+            for(size_t i=0; i<w.size(); ++i)
+                std::cout << w[i] << " ";
+            std::cout << ")              normalized: (";
+            for(size_t i=0; i<w.size(); ++i)
+                std::cout << w[i]/norm << " ";
+            std::cout << ")" << std::endl;
+        }
 
 		// compute gap
 		T eps_t;
@@ -224,7 +237,8 @@ BundleOptimizer<T>::optimize(Oracle& oracle, Weights& w) {
 
 		lastMinLower = minLower;
 
-		std::cout  << "          ε   is: " << eps_t << std::endl;
+        if(oracle.getInfParam().verbose_ )
+            std::cout  << "          ε   is: " << eps_t << std::endl;
 
 		// converged?
 		if (eps_t <= _parameter.min_eps)
diff --git a/include/opengm/learning/solver/CplexBackend.h b/include/opengm/learning/solver/CplexBackend.h
index b4819e5..feda3f4 100644
--- a/include/opengm/learning/solver/CplexBackend.h
+++ b/include/opengm/learning/solver/CplexBackend.h
@@ -336,7 +336,8 @@ CplexBackend::solve(Solution& x, double& value, std::string& msg) {
            return false;
         }
         else
-            msg = "Optimal solution found";
+            if(_parameter.verbose == true)
+                msg = "Optimal solution found";
 
         // extract solution
         cplex_.getValues(sol_, x_);
@@ -412,12 +413,16 @@ CplexBackend::setVerbose(bool verbose) {
         cplex_.setParam(IloCplex::MIPDisplay, 1);
         cplex_.setParam(IloCplex::SimDisplay, 1);
         cplex_.setParam(IloCplex::SiftDisplay, 1);
+        cplex_.setParam(IloCplex::BarDisplay, 1);
+        cplex_.setParam(IloCplex::NetDisplay, 1);
     }
     else
     {
         cplex_.setParam(IloCplex::MIPDisplay, 0);
         cplex_.setParam(IloCplex::SimDisplay, 0);
         cplex_.setParam(IloCplex::SiftDisplay, 0);
+        cplex_.setParam(IloCplex::BarDisplay, 0);
+        cplex_.setParam(IloCplex::NetDisplay, 0);
     }
 }
 
diff --git a/include/opengm/learning/struct-max-margin.hxx b/include/opengm/learning/struct-max-margin.hxx
index 6ff2685..815c0aa 100644
--- a/include/opengm/learning/struct-max-margin.hxx
+++ b/include/opengm/learning/struct-max-margin.hxx
@@ -103,7 +103,9 @@ private:
 
 				// set the weights w in E(x,y) and F(x,y)
 				_dataset.getWeights() = w;
-                std::cout << std::endl << " MODEL : ";
+
+                if(_infParam.verbose_ )
+                    std::cout << std::endl << " MODEL : ";
 
                 #ifdef WITH_OPENMP
                 omp_lock_t modelLock;
@@ -111,7 +113,8 @@ private:
                 #pragma omp parallel for
                 #endif
                 for (int i = 0; i < _dataset.getNumberOfModels(); i++) {
-                    std::cout << i;
+                    if(_infParam.verbose_ )
+                        std::cout << i;
 
                     // lock the model
                     #ifdef WITH_OPENMP
@@ -163,6 +166,9 @@ private:
                 } // end for model
 			}
 
+            const typename InferenceType::Parameter& getInfParam(){
+                return _infParam;
+            }
 
 		private:
 

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