From 79605eb9897d694079c0942c12bf365ef8a61b87 Mon Sep 17 00:00:00 2001 From: Joerg Kappes Date: Thu, 16 Jul 2015 09:53:41 +0200 Subject: [PATCH 01/19] Update lweightedsum_of_functions.hxx fix typo in assert-loop --- .../opengm/functions/learnable/lweightedsum_of_functions.hxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/opengm/functions/learnable/lweightedsum_of_functions.hxx b/include/opengm/functions/learnable/lweightedsum_of_functions.hxx index f831329..7180164 100644 --- a/include/opengm/functions/learnable/lweightedsum_of_functions.hxx +++ b/include/opengm/functions/learnable/lweightedsum_of_functions.hxx @@ -77,7 +77,7 @@ LWeightedSumOfFunctions::LWeightedSumOfFunctions : shape_(shape), weights_(&weights), weightIDs_(weightIDs),feat_(feat) { OPENGM_ASSERT( weightIDs_.size() == feat_.size() ); - for(size_t i=0 i Date: Tue, 15 Sep 2015 15:11:00 +0200 Subject: [PATCH 02/19] RebindGm added to LPCplex2 --- include/opengm/inference/lpcplex.hxx | 15 ++++++++------- include/opengm/inference/lpcplex2.hxx | 9 +++++++++ include/opengm/learning/bundle-optimizer.hxx | 2 +- include/opengm/learning/solver/CplexBackend.h | 1 - src/unittest/test_gm_learning_functions.cxx | 4 ++-- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/include/opengm/inference/lpcplex.hxx b/include/opengm/inference/lpcplex.hxx index 52712c8..07c77f4 100644 --- a/include/opengm/inference/lpcplex.hxx +++ b/include/opengm/inference/lpcplex.hxx @@ -482,7 +482,7 @@ LPCplex::infer break; } - // MIP EMPHASIS + // MIP EMPHASIS switch(parameter_.mipEmphasis_) { case MIP_EMPHASIS_BALANCED: cplex_.setParam(IloCplex::MIPEmphasis, 0); @@ -503,11 +503,11 @@ LPCplex::infer // verbose options if(parameter_.verbose_ == false) { - cplex_.setParam(IloCplex::MIPDisplay, 0); - cplex_.setParam(IloCplex::BarDisplay, 0); - cplex_.setParam(IloCplex::SimDisplay, 0); - cplex_.setParam(IloCplex::NetDisplay, 0); - cplex_.setParam(IloCplex::SiftDisplay, 0); + cplex_.setParam(IloCplex::MIPDisplay, 0); + cplex_.setParam(IloCplex::BarDisplay, 0); + cplex_.setParam(IloCplex::SimDisplay, 0); + cplex_.setParam(IloCplex::NetDisplay, 0); + cplex_.setParam(IloCplex::SiftDisplay, 0); } // tolarance settings @@ -555,11 +555,12 @@ LPCplex::infer //cplex_.setParam(IloCplex::MIRCuts, parameter_.MIRCutLevel_); // solve problem + if(!cplex_.solve()) { std::cout << "failed to optimize. " < + struct RebindGm{ + typedef LPCplex2<_GM, ACC_TYPE> type; + }; + + template + struct RebindGmAndAcc{ + typedef LPCplex2<_GM, _ACC > type; + }; }; template diff --git a/include/opengm/learning/bundle-optimizer.hxx b/include/opengm/learning/bundle-optimizer.hxx index 7b020c6..aebe248 100644 --- a/include/opengm/learning/bundle-optimizer.hxx +++ b/include/opengm/learning/bundle-optimizer.hxx @@ -161,7 +161,7 @@ BundleOptimizer::optimize(Oracle& oracle, Weights& w) { Weights w_tm1 = w; - //std::cout << "current w is " << w_tm1 << std::endl; + //std::cout << "current w is " << w_tm1 << std::endl; // value of L at current w T L_w_tm1 = 0.0; diff --git a/include/opengm/learning/solver/CplexBackend.h b/include/opengm/learning/solver/CplexBackend.h index d330917..b4819e5 100644 --- a/include/opengm/learning/solver/CplexBackend.h +++ b/include/opengm/learning/solver/CplexBackend.h @@ -330,7 +330,6 @@ CplexBackend::solve(Solution& x, double& value, std::string& msg) { std::cerr << "Invalid value for MIP focus!" << std::endl; setNumThreads(_parameter.numThreads); - if(!cplex_.solve()) { std::cout << "failed to optimize. " << cplex_.getStatus() << std::endl; msg = "Optimal solution *NOT* found"; diff --git a/src/unittest/test_gm_learning_functions.cxx b/src/unittest/test_gm_learning_functions.cxx index 653e0d6..b797175 100644 --- a/src/unittest/test_gm_learning_functions.cxx +++ b/src/unittest/test_gm_learning_functions.cxx @@ -40,8 +40,8 @@ struct GraphicalModelTest { ValueType, //value type (should be float double or long double) opengm::Multiplier, //operator (something like Adder or Multiplier) typename opengm::meta::TypeListGenerator< - opengm::ExplicitFunction, - opengm::PottsNFunction + opengm::ExplicitFunction, + opengm::PottsNFunction >::type, //implicit function functor opengm::DiscreteSpace > GraphicalModelType; From 043e99a3766e4dd2e0af30e9f45dec7ef6cd47df Mon Sep 17 00:00:00 2001 From: Carsten Haubold Date: Fri, 18 Sep 2015 16:19:45 +0200 Subject: [PATCH 03/19] Add RebindGM to LPCplex2 so that it can be used for structured learning --- include/opengm/inference/lpcplex2.hxx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/opengm/inference/lpcplex2.hxx b/include/opengm/inference/lpcplex2.hxx index 8769055..b2a5d20 100644 --- a/include/opengm/inference/lpcplex2.hxx +++ b/include/opengm/inference/lpcplex2.hxx @@ -25,6 +25,16 @@ public: // public member functions virtual std::string name() const; + + template + struct RebindGm{ + typedef LPCplex2<_GM, ACC_TYPE> type; + }; + + template + struct RebindGmAndAcc{ + typedef LPCplex2<_GM, _ACC > type; + }; }; template From c7cbe6cb368133cc8c91cf5b572eca85163fe3f5 Mon Sep 17 00:00:00 2001 From: Carsten Haubold Date: Fri, 18 Sep 2015 17:29:15 +0200 Subject: [PATCH 04/19] Fix an #elif statement to find the cplex backend for the struct-max-margin solver --- include/opengm/learning/solver/QuadraticSolverFactory.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/opengm/learning/solver/QuadraticSolverFactory.h b/include/opengm/learning/solver/QuadraticSolverFactory.h index 43ca5bc..e986630 100644 --- a/include/opengm/learning/solver/QuadraticSolverFactory.h +++ b/include/opengm/learning/solver/QuadraticSolverFactory.h @@ -3,7 +3,7 @@ #ifdef WITH_GUROBI #include "GurobiBackend.h" -#elif WITH_CPLEX +#elif defined(WITH_CPLEX) #include "CplexBackend.h" #endif @@ -19,7 +19,7 @@ class QuadraticSolverFactory { #ifdef WITH_GUROBI return new GurobiBackend(); -#elif WITH_CPLEX +#elif defined(WITH_CPLEX) return new CplexBackend(); #endif From 6f4c40805d007c8b336c29cdaa001f9a98be4884 Mon Sep 17 00:00:00 2001 From: Carsten Haubold Date: Fri, 25 Sep 2015 21:03:21 +0200 Subject: [PATCH 05/19] Add LpGurobi2::RebindGm to allow learning with Gurobi solver --- include/opengm/inference/lpgurobi2.hxx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/opengm/inference/lpgurobi2.hxx b/include/opengm/inference/lpgurobi2.hxx index a9c1a9c..192b038 100644 --- a/include/opengm/inference/lpgurobi2.hxx +++ b/include/opengm/inference/lpgurobi2.hxx @@ -25,6 +25,16 @@ public: // public member functions virtual std::string name() const; + + template + struct RebindGm{ + typedef LPGurobi2<_GM, ACC_TYPE> type; + }; + + template + struct RebindGmAndAcc{ + typedef LPGurobi2<_GM, _ACC > type; + }; }; template From c8990ba17fe8f98cca5e4e096ecd4bf48e6361d4 Mon Sep 17 00:00:00 2001 From: Carsten Haubold Date: Wed, 7 Oct 2015 15:31:43 +0200 Subject: [PATCH 06/19] Use IndexType instead of UInt16 in LearnableUnary, to allow large numbers of features --- include/opengm/functions/learnable/lunary.hxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/opengm/functions/learnable/lunary.hxx b/include/opengm/functions/learnable/lunary.hxx index c4cc08a..cc1b930 100644 --- a/include/opengm/functions/learnable/lunary.hxx +++ b/include/opengm/functions/learnable/lunary.hxx @@ -101,8 +101,8 @@ protected: mutable const opengm::learning::Weights * weights_; - opengm::UInt16Type numberOfLabels_; - std::vector offsets_; + IndexType numberOfLabels_; + std::vector offsets_; std::vector weightIds_; std::vector features_; From b46caa64078682222cb2a06e28aea4e6c29ca599 Mon Sep 17 00:00:00 2001 From: Janez Ales Date: Thu, 15 Oct 2015 20:15:53 +0200 Subject: [PATCH 07/19] lweighted sum of functions calls operator() on Marray with proper indices for dimension =2 (and 1) --- .../functions/learnable/lweightedsum_of_functions.hxx | 10 +++++++++- include/opengm/learning/bundle-optimizer.hxx | 8 ++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/opengm/functions/learnable/lweightedsum_of_functions.hxx b/include/opengm/functions/learnable/lweightedsum_of_functions.hxx index 7180164..eaa7d28 100644 --- a/include/opengm/functions/learnable/lweightedsum_of_functions.hxx +++ b/include/opengm/functions/learnable/lweightedsum_of_functions.hxx @@ -99,7 +99,15 @@ LWeightedSumOfFunctions::weightGradient ITERATOR begin ) const { OPENGM_ASSERT(weightNumber< numberOfWeights()); - return feat_[weightNumber](*begin); + + if(dimension()==1){ + return feat_[weightNumber](*begin); + } + else if(dimension()==2){ + return feat_[weightNumber](*begin, *(begin+1)); + } + else + OPENGM_ASSERT(dimension()<=2); } template diff --git a/include/opengm/learning/bundle-optimizer.hxx b/include/opengm/learning/bundle-optimizer.hxx index aebe248..1135b0b 100644 --- a/include/opengm/learning/bundle-optimizer.hxx +++ b/include/opengm/learning/bundle-optimizer.hxx @@ -157,7 +157,7 @@ BundleOptimizer::optimize(Oracle& oracle, Weights& w) { t++; - std::cout << std::endl << "----------------- iteration " << t << std::endl; + std::cout << std::endl << "----------------- iteration " << t << std::endl; Weights w_tm1 = w; @@ -173,7 +173,7 @@ BundleOptimizer::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)/∂ is: " << a_t << 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 +183,7 @@ BundleOptimizer::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 " << a_t << "*w + " << b_t << std::endl; // update lower bound _bundleCollector.addHyperplane(a_t, b_t); @@ -195,7 +195,7 @@ BundleOptimizer::optimize(Oracle& oracle, Weights& w) { 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: " << w << std::endl; // compute gap T eps_t; From db4e221c20b4733eaa32246ef31c95e7e5105884 Mon Sep 17 00:00:00 2001 From: Janez Ales Date: Wed, 21 Oct 2015 14:53:47 +0200 Subject: [PATCH 08/19] corrects indexing call from a learnable function.weightGradient to a multidimensional marray (*begin ---> begin) (this was working correctly only for 1-dim marrays) --- .../opengm/datastructures/marray/marray.hxx | 1 + .../learnable/lweightedsum_of_functions.hxx | 12 ++----- .../opengm/inference/lp_inference_base.hxx | 1 - include/opengm/learning/bundle-optimizer.hxx | 31 +++++++++++++++---- .../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 // cout #include // allocator #include // accumulate +#include /// 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::LWeightedSumOfFunctions OPENGM_ASSERT( weightIDs_.size() == feat_.size() ); for(size_t i=0; i @@ -99,15 +101,7 @@ LWeightedSumOfFunctions::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 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::LPInferenceBase(const GraphicalModelT if(!opengm::meta::Compare::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::optimize(Oracle& oracle, Weights& w) { unsigned int t = 0; - while (true) { + while (true) { t++; @@ -161,7 +161,10 @@ BundleOptimizer::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::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::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::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::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 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 Accessor; typedef opengm::AccessorIterator AccessorIter; - // get the number of weights_ const size_t nWeights = f.numberOfWeights(); if(nWeights>0){ From 695964c3cfce7bb2ad06ba241085a2685af9f238 Mon Sep 17 00:00:00 2001 From: Janez Ales Date: Sat, 24 Oct 2015 19:30:26 +0200 Subject: [PATCH 09/19] add model print out in struct-max-margin iteration --- include/opengm/learning/bundle-optimizer.hxx | 4 +--- include/opengm/learning/struct-max-margin.hxx | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/include/opengm/learning/bundle-optimizer.hxx b/include/opengm/learning/bundle-optimizer.hxx index 7f99d5d..4be57e8 100644 --- a/include/opengm/learning/bundle-optimizer.hxx +++ b/include/opengm/learning/bundle-optimizer.hxx @@ -157,7 +157,7 @@ BundleOptimizer::optimize(Oracle& oracle, Weights& w) { t++; - std::cout << std::endl << "----------------- iteration " << t << std::endl; + std::cout << std::endl << "-----------------------------------------------------------------------------> iteration " << t << std::endl; Weights w_tm1 = w; @@ -286,8 +286,6 @@ BundleOptimizer::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 diff --git a/include/opengm/learning/struct-max-margin.hxx b/include/opengm/learning/struct-max-margin.hxx index 55b03a1..f3d0b72 100644 --- a/include/opengm/learning/struct-max-margin.hxx +++ b/include/opengm/learning/struct-max-margin.hxx @@ -99,10 +99,11 @@ private: // set the weights w in E(x,y) and F(x,y) _dataset.getWeights() = w; - + std::cout << std::endl << " MODEL : "; for (int i = 0; i < _dataset.getNumberOfModels(); i++) { + std::cout << i << " "; - // get E(x,y) and F(x,y) + // get E(x,y) and F(x,y) //std::cout << "locking model " << i << " of " << _dataset.getNumberOfModels() << std::endl; _dataset.lockModel(i); const GMType & gm = _dataset.getModel(i); @@ -117,24 +118,24 @@ private: // find the minimizer y* of F(y,w) ConfigurationType mostViolated; InferenceType inference(gml, _infParam); - inference.infer(); + inference.infer(); inference.arg(mostViolated); // the optimal value of (1) is now c - F(y*,w) - value += c - gml.evaluate(mostViolated); + value += c - gml.evaluate(mostViolated); // the gradients are typedef GradientAccumulator GA; - GA gaBestEffort(gradient, bestEffort, GA::Add); - GA gaMostViolated(gradient, mostViolated, GA::Subtract); - for (size_t j = 0; j < gm.numberOfFactors(); j++) { + GA gaBestEffort(gradient, bestEffort, GA::Add); + GA gaMostViolated(gradient, mostViolated, GA::Subtract); + for (size_t j = 0; j < gm.numberOfFactors(); j++) { gm[j].callViFunctor(gaBestEffort); gm[j].callViFunctor(gaMostViolated); } - - _dataset.unlockModel(i); + _dataset.unlockModel(i); } + std::cout << std::endl; } private: From e19025f6d4832ac92a6868d1f1b8a217528be309 Mon Sep 17 00:00:00 2001 From: Janez Ales Date: Wed, 28 Oct 2015 21:45:08 +0100 Subject: [PATCH 10/19] lweightedsum_of_functions OPENGM_ASSERT corrected --- .../functions/learnable/lweightedsum_of_functions.hxx | 5 +++-- include/opengm/learning/gradient-accumulator.hxx | 6 ------ include/opengm/learning/struct-max-margin.hxx | 6 +++--- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/include/opengm/functions/learnable/lweightedsum_of_functions.hxx b/include/opengm/functions/learnable/lweightedsum_of_functions.hxx index 5978c52..62314f4 100644 --- a/include/opengm/functions/learnable/lweightedsum_of_functions.hxx +++ b/include/opengm/functions/learnable/lweightedsum_of_functions.hxx @@ -77,10 +77,11 @@ LWeightedSumOfFunctions::LWeightedSumOfFunctions : shape_(shape), weights_(&weights), weightIDs_(weightIDs),feat_(feat) { OPENGM_ASSERT( weightIDs_.size() == feat_.size() ); - for(size_t i=0; i diff --git a/include/opengm/learning/gradient-accumulator.hxx b/include/opengm/learning/gradient-accumulator.hxx index 43c9cf8..a13473d 100644 --- a/include/opengm/learning/gradient-accumulator.hxx +++ b/include/opengm/learning/gradient-accumulator.hxx @@ -97,8 +97,6 @@ struct FeatureAccumulator{ } void resetWeights(){ - //accFeaturesGt_ = 0.0; - //accWeights_ = 0.0; for(size_t i=0; i Date: Mon, 2 Nov 2015 19:51:49 +0100 Subject: [PATCH 11/19] adding normalized weights print output (only for check of convergence - not to be used in calculation) --- include/opengm/learning/bundle-optimizer.hxx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/include/opengm/learning/bundle-optimizer.hxx b/include/opengm/learning/bundle-optimizer.hxx index 4be57e8..9f7c094 100644 --- a/include/opengm/learning/bundle-optimizer.hxx +++ b/include/opengm/learning/bundle-optimizer.hxx @@ -200,18 +200,22 @@ BundleOptimizer::optimize(Oracle& oracle, Weights& w) { // minimal value of lower bound T minLower; - std::cout << "w before findMinLowerBound: "; - for(size_t i=0; i Date: Tue, 3 Nov 2015 18:47:21 +0100 Subject: [PATCH 12/19] paralellization added to struct-max-margin (triggered by WITH_OPENMP) --- .../opengm/learning/gradient-accumulator.hxx | 2 +- include/opengm/learning/struct-max-margin.hxx | 38 ++++++++++++++++--- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/include/opengm/learning/gradient-accumulator.hxx b/include/opengm/learning/gradient-accumulator.hxx index a13473d..88e920a 100644 --- a/include/opengm/learning/gradient-accumulator.hxx +++ b/include/opengm/learning/gradient-accumulator.hxx @@ -124,7 +124,7 @@ struct FeatureAccumulator{ const Accessor accessorGt(begin, end, gtLabel_); const Accessor accessorMap(begin, end, mapLabel_); - + if(add_){ // for gt label accWeights_[gwi] += weight_*f.weightGradient(wi, AccessorIter(accessorGt, 0)); diff --git a/include/opengm/learning/struct-max-margin.hxx b/include/opengm/learning/struct-max-margin.hxx index 04f3ffd..6ff2685 100644 --- a/include/opengm/learning/struct-max-margin.hxx +++ b/include/opengm/learning/struct-max-margin.hxx @@ -5,6 +5,10 @@ #include "bundle-optimizer.hxx" #include "gradient-accumulator.hxx" +#ifdef WITH_OPENMP +#include +#endif + namespace opengm { namespace learning { @@ -100,12 +104,25 @@ private: // set the weights w in E(x,y) and F(x,y) _dataset.getWeights() = w; std::cout << std::endl << " MODEL : "; - for (int i = 0; i < _dataset.getNumberOfModels(); i++) { - std::cout << i << " "; - // get E(x,y) and F(x,y) + #ifdef WITH_OPENMP + omp_lock_t modelLock; + omp_init_lock(&modelLock); + #pragma omp parallel for + #endif + for (int i = 0; i < _dataset.getNumberOfModels(); i++) { + std::cout << i; + + // lock the model + #ifdef WITH_OPENMP + omp_set_lock(&modelLock); _dataset.lockModel(i); - const GMType & gm = _dataset.getModel(i); + omp_unset_lock(&modelLock); + #else + _dataset.lockModel(i); + #endif + // get E(x,y) and F(x,y) + const GMType & gm = _dataset.getModel(i); const GMWITHLOSS & gml = _dataset.getModelWithLoss(i); // get the best-effort solution y' @@ -122,6 +139,7 @@ private: inference.arg(mostViolated); // the optimal value of (1) is now c - F(y*,w) + #pragma omp atomic value += c - gml.evaluate(mostViolated); // the gradients are @@ -133,11 +151,19 @@ private: gm[j].callViFunctor(gaBestEffort); gm[j].callViFunctor(gaMostViolated); } + + // unlock the model + #ifdef WITH_OPENMP + omp_set_lock(&modelLock); + _dataset.unlockModel(i); + omp_unset_lock(&modelLock); + #else _dataset.unlockModel(i); - } - std::cout << std::endl; + #endif + } // end for model } + private: DatasetType& _dataset; From b6a5d0d3893598a43dbc30876d225455c5496e09 Mon Sep 17 00:00:00 2001 From: Janez Ales Date: Thu, 5 Nov 2015 15:37:49 +0100 Subject: [PATCH 13/19] removed redundant print info --- include/opengm/datastructures/marray/marray.hxx | 1 - include/opengm/learning/bundle-optimizer.hxx | 5 +---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/include/opengm/datastructures/marray/marray.hxx b/include/opengm/datastructures/marray/marray.hxx index 7871e7e..0c91d2f 100644 --- a/include/opengm/datastructures/marray/marray.hxx +++ b/include/opengm/datastructures/marray/marray.hxx @@ -15,7 +15,6 @@ #include // cout #include // allocator #include // accumulate -#include /// Runtime-flexible multi-dimensional views and arrays namespace marray { diff --git a/include/opengm/learning/bundle-optimizer.hxx b/include/opengm/learning/bundle-optimizer.hxx index 9f7c094..4642d71 100644 --- a/include/opengm/learning/bundle-optimizer.hxx +++ b/include/opengm/learning/bundle-optimizer.hxx @@ -157,7 +157,7 @@ BundleOptimizer::optimize(Oracle& oracle, Weights& w) { t++; - std::cout << std::endl << "-----------------------------------------------------------------------------> iteration " << t << std::endl; + std::cout << std::endl << "----------------- iteration " << t << std::endl; Weights w_tm1 = w; @@ -213,9 +213,6 @@ BundleOptimizer::optimize(Oracle& oracle, Weights& w) { std::cout << " w* of ℒ(w) + ½λ|w|² is: ("; for(size_t i=0; i Date: Fri, 6 Nov 2015 07:53:48 +0100 Subject: [PATCH 14/19] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 020f22b..9b54a74 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ OpenGM 2 [![Build Status](https://travis-ci.org/opengm/opengm.png?branch=master)](https://travis-ci.org/opengm/opengm) +[![Build Status](https://travis-ci.org/opengm/opengm.png?branch=learning-experimental)](https://travis-ci.org/opengm/opengm) + ----------------------------------------------------------------------------------------------- From f8efc9cfb46e45b0850580df38201022b7521c26 Mon Sep 17 00:00:00 2001 From: Joerg Kappes Date: Fri, 6 Nov 2015 07:54:23 +0100 Subject: [PATCH 15/19] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9b54a74..9c12007 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ OpenGM 2 ======== -[![Build Status](https://travis-ci.org/opengm/opengm.png?branch=master)](https://travis-ci.org/opengm/opengm) +master: [![Build Status](https://travis-ci.org/opengm/opengm.png?branch=master)](https://travis-ci.org/opengm/opengm) -[![Build Status](https://travis-ci.org/opengm/opengm.png?branch=learning-experimental)](https://travis-ci.org/opengm/opengm) +learning-experimental: [![Build Status](https://travis-ci.org/opengm/opengm.png?branch=learning-experimental)](https://travis-ci.org/opengm/opengm) ----------------------------------------------------------------------------------------------- From 298b409c56b3aa9162f431b4e2d89400edca88ac Mon Sep 17 00:00:00 2001 From: Joerg Kappes Date: Fri, 6 Nov 2015 07:55:15 +0100 Subject: [PATCH 16/19] Update README.md --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9c12007..d1709e1 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,8 @@ OpenGM 2 ======== -master: [![Build Status](https://travis-ci.org/opengm/opengm.png?branch=master)](https://travis-ci.org/opengm/opengm) - -learning-experimental: [![Build Status](https://travis-ci.org/opengm/opengm.png?branch=learning-experimental)](https://travis-ci.org/opengm/opengm) +master: [![Build Status](https://travis-ci.org/opengm/opengm.png?branch=master)](https://travis-ci.org/opengm/opengm) +learning-experimental: [![Build Status](https://travis-ci.org/opengm/opengm.png?branch=learning-experimental)](https://travis-ci.org/opengm/learning-experimental) ----------------------------------------------------------------------------------------------- From 7c1b6f0012983b841af0b3ac327f2d8dc7acaa16 Mon Sep 17 00:00:00 2001 From: opengm Date: Fri, 6 Nov 2015 08:03:03 +0100 Subject: [PATCH 17/19] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d1709e1..77e4d40 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ OpenGM 2 ======== -master: [![Build Status](https://travis-ci.org/opengm/opengm.png?branch=master)](https://travis-ci.org/opengm/opengm) -learning-experimental: [![Build Status](https://travis-ci.org/opengm/opengm.png?branch=learning-experimental)](https://travis-ci.org/opengm/learning-experimental) +[![Build Status](https://travis-ci.org/opengm/opengm.png?branch=master)](https://travis-ci.org/opengm/opengm) (master) + +[![Build Status](https://travis-ci.org/opengm/opengm.png?branch=learning-experimental)](https://travis-ci.org/opengm/opengm) (learning-experimental) ----------------------------------------------------------------------------------------------- From 442228dc4b9bba2df88bc128f74ce2fd34c27797 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Mon, 9 Nov 2015 09:08:21 +0100 Subject: [PATCH 18/19] minor fix --- src/interfaces/python/opengm/learning/CMakeLists.txt | 2 +- src/interfaces/python/opengm/learning/learning.cxx | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/interfaces/python/opengm/learning/CMakeLists.txt b/src/interfaces/python/opengm/learning/CMakeLists.txt index 05bc47c..a594ea4 100644 --- a/src/interfaces/python/opengm/learning/CMakeLists.txt +++ b/src/interfaces/python/opengm/learning/CMakeLists.txt @@ -24,7 +24,7 @@ set(PY_OPENGM_CORE_SOURCES pyDataset.cxx pyLoss.cxx pyGridSearchLearner.cxx - pyMaxLikelihoodLearner.cxx + #pyMaxLikelihoodLearner.cxx pyStructMaxMarginLearner.cxx pySubgradientSSVM.cxx pyStructPerceptron.cxx diff --git a/src/interfaces/python/opengm/learning/learning.cxx b/src/interfaces/python/opengm/learning/learning.cxx index a45d3a9..195b2ac 100644 --- a/src/interfaces/python/opengm/learning/learning.cxx +++ b/src/interfaces/python/opengm/learning/learning.cxx @@ -37,8 +37,8 @@ namespace opengm{ template void export_struct_max_margin_bundle_learner(const std::string & clsName); - template - void export_max_likelihood_learner(const std::string & clsName); + //template + //void export_max_likelihood_learner(const std::string & clsName); template void export_struct_perceptron_learner(const std::string & clsName); @@ -82,7 +82,7 @@ BOOST_PYTHON_MODULE_INIT(_learning) { opengm::export_grid_search_learner("GridSearch_FlexibleLoss"); opengm::export_struct_perceptron_learner("StructPerceptron_FlexibleLoss"); opengm::export_subgradient_ssvm_learner("SubgradientSSVM_FlexibleLoss"); - opengm::export_max_likelihood_learner("MaxLikelihood_FlexibleLoss"); + //opengm::export_max_likelihood_learner("MaxLikelihood_FlexibleLoss"); opengm::export_rws_learner("Rws_FlexibleLoss"); #if defined(WITH_CPLEX) || defined(WITH_GUROBI) From 7bc0d74a056e1b3a231c25ca86f98f00dfb83941 Mon Sep 17 00:00:00 2001 From: Janez Ales Date: Mon, 23 Nov 2015 17:07:19 +0100 Subject: [PATCH 19/19] 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 //std::ostream& operator<<(std::ostream& out, Weights& 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::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::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::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::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: