Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
79605eb
Update lweightedsum_of_functions.hxx
joergkappes Jul 16, 2015
df11295
RebindGm added to LPCplex2
ilastikdev Sep 15, 2015
043e99a
Add RebindGM to LPCplex2 so that it can be used for structured learning
chaubold Sep 18, 2015
c7cbe6c
Fix an #elif statement to find the cplex backend for the struct-max-m…
chaubold Sep 18, 2015
7f0e04b
Merge pull request #374 from chaubold/fix-lpcplex2-rebindgm
joergkappes Sep 19, 2015
c34c57d
Merge pull request #375 from chaubold/fix-solver-check-SSVM
joergkappes Sep 21, 2015
6f4c408
Add LpGurobi2::RebindGm to allow learning with Gurobi solver
chaubold Sep 25, 2015
55666ae
Merge pull request #376 from chaubold/fix-lpgurobi-rebindgm
joergkappes Sep 27, 2015
c8990ba
Use IndexType instead of UInt16 in LearnableUnary, to allow large num…
chaubold Oct 7, 2015
ec66344
Merge pull request #378 from chaubold/fix-lunary-uint16
joergkappes Oct 10, 2015
b46caa6
lweighted sum of functions calls operator() on Marray with proper ind…
ilastikdev Oct 15, 2015
db4e221
corrects indexing call from a learnable function.weightGradient to a …
ilastikdev Oct 21, 2015
695964c
add model print out in struct-max-margin iteration
ilastikdev Oct 24, 2015
e19025f
lweightedsum_of_functions OPENGM_ASSERT corrected
ilastikdev Oct 28, 2015
6fb9119
adding normalized weights print output (only for check of convergence…
ilastikdev Nov 2, 2015
b04442e
paralellization added to struct-max-margin (triggered by WITH_OPENMP)
ilastikdev Nov 3, 2015
b6a5d0d
removed redundant print info
ilastikdev Nov 5, 2015
f24715a
Update README.md
joergkappes Nov 6, 2015
f8efc9c
Update README.md
joergkappes Nov 6, 2015
298b409
Update README.md
joergkappes Nov 6, 2015
7c1b6f0
Update README.md
opengm Nov 6, 2015
adf58c8
Merge branch 'learning-experimental' of https://github.com/ilastikdev…
ilastikdev Nov 6, 2015
83d4f90
Merge pull request #399 from ilastikdev/structured_learning_2
opengm Nov 6, 2015
442228d
minor fix
DerThorsten Nov 9, 2015
7bc0d74
verbose=false implemented in more detail
ilastikdev Nov 23, 2015
a052283
Merge branch 'learning-experimental' of https://github.com/opengm/ope…
ilastikdev Nov 23, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
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=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)


-----------------------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions include/opengm/functions/learnable/lunary.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ protected:

mutable const opengm::learning::Weights<T> * weights_;

opengm::UInt16Type numberOfLabels_;
std::vector<opengm::UInt16Type> offsets_;
IndexType numberOfLabels_;
std::vector<IndexType> offsets_;
std::vector<size_t> weightIds_;
std::vector<ValueType> features_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ LWeightedSumOfFunctions<T, I, L>::LWeightedSumOfFunctions
: shape_(shape), weights_(&weights), weightIDs_(weightIDs),feat_(feat)
{
OPENGM_ASSERT( weightIDs_.size() == feat_.size() );
for(size_t i=0 i<weightIDs_.size();++1)
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>
Expand All @@ -99,7 +102,7 @@ LWeightedSumOfFunctions<T, I, L>::weightGradient
ITERATOR begin
) const {
OPENGM_ASSERT(weightNumber< numberOfWeights());
return feat_[weightNumber](*begin);
return feat_[weightNumber](begin);
}

template <class T, class I, class L>
Expand Down
1 change: 0 additions & 1 deletion include/opengm/inference/lp_inference_base.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
15 changes: 8 additions & 7 deletions include/opengm/inference/lpcplex.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ LPCplex<GM, ACC>::infer
break;
}

// MIP EMPHASIS
// MIP EMPHASIS
switch(parameter_.mipEmphasis_) {
case MIP_EMPHASIS_BALANCED:
cplex_.setParam(IloCplex::MIPEmphasis, 0);
Expand All @@ -503,11 +503,11 @@ LPCplex<GM, ACC>::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
Expand Down Expand Up @@ -555,11 +555,12 @@ LPCplex<GM, ACC>::infer
//cplex_.setParam(IloCplex::MIRCuts, parameter_.MIRCutLevel_);

// solve problem

if(!cplex_.solve()) {
std::cout << "failed to optimize. " <<cplex_.getStatus() << std::endl;
return UNKNOWN;
}
cplex_.getValues(sol_, x_);
cplex_.getValues(sol_, x_);
}
catch(IloCplex::Exception e) {
std::cout << "caught CPLEX exception: " << e << std::endl;
Expand Down
10 changes: 10 additions & 0 deletions include/opengm/inference/lpcplex2.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ public:

// public member functions
virtual std::string name() const;

template<class _GM>
struct RebindGm{
typedef LPCplex2<_GM, ACC_TYPE> type;
};

template<class _GM,class _ACC>
struct RebindGmAndAcc{
typedef LPCplex2<_GM, _ACC > type;
};
};

template<class GM_TYPE, class ACC_TYPE>
Expand Down
10 changes: 10 additions & 0 deletions include/opengm/inference/lpgurobi2.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ public:

// public member functions
virtual std::string name() const;

template<class _GM>
struct RebindGm{
typedef LPGurobi2<_GM, ACC_TYPE> type;
};

template<class _GM,class _ACC>
struct RebindGmAndAcc{
typedef LPGurobi2<_GM, _ACC > type;
};
};

template<class GM_TYPE, class ACC_TYPE>
Expand Down
70 changes: 51 additions & 19 deletions include/opengm/learning/bundle-optimizer.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -153,15 +153,21 @@ BundleOptimizer<T>::optimize(Oracle& oracle, Weights& w) {

unsigned int t = 0;

while (true) {
while (true) {

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 << "current w is " << w_tm1 << 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;
Expand All @@ -172,30 +178,55 @@ 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)/∂ is: " << a_t << 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 " << a_t << "*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);

// minimal value of lower bound
T minLower;

// update w and get minimal value
// 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;
// norm of w
double norm = 0.0;
for(size_t i=0; i<w.size(); ++i)
norm += w[i]*w[i];
norm = std::sqrt(norm);

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;
Expand All @@ -206,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)
Expand Down
9 changes: 0 additions & 9 deletions include/opengm/learning/gradient-accumulator.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -99,8 +97,6 @@ struct FeatureAccumulator{
}

void resetWeights(){
//accFeaturesGt_ = 0.0;
//accWeights_ = 0.0;
for(size_t i=0; i<accWeights_.size(); ++i){
accWeights_[i] = 0.0;
}
Expand All @@ -117,7 +113,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){
Expand All @@ -129,7 +124,6 @@ struct FeatureAccumulator{

const Accessor accessorGt(begin, end, gtLabel_);
const Accessor accessorMap(begin, end, mapLabel_);


if(add_){
// for gt label
Expand Down Expand Up @@ -175,9 +169,6 @@ struct FeatureAccumulator{
double weight_;
};




}} // namespace opengm::learning

#endif // OPENGM_LEARNING_GRADIENT_ACCUMULATOR_H__
Expand Down
8 changes: 6 additions & 2 deletions include/opengm/learning/solver/CplexBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,14 @@ 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";
return false;
}
else
msg = "Optimal solution found";
if(_parameter.verbose == true)
msg = "Optimal solution found";

// extract solution
cplex_.getValues(sol_, x_);
Expand Down Expand Up @@ -413,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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions include/opengm/learning/solver/QuadraticSolverFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#ifdef WITH_GUROBI
#include "GurobiBackend.h"
#elif WITH_CPLEX
#elif defined(WITH_CPLEX)
#include "CplexBackend.h"
#endif

Expand All @@ -19,7 +19,7 @@ class QuadraticSolverFactory {

#ifdef WITH_GUROBI
return new GurobiBackend();
#elif WITH_CPLEX
#elif defined(WITH_CPLEX)
return new CplexBackend();
#endif

Expand Down
Loading