[opengm] 215/386: remove code from mll
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Wed Aug 31 08:37:52 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 de15f6547831c5c1790b5abf84de20129d8aab53
Author: joergkappes <kappes at math.uni-heidelberg.de>
Date: Mon Jan 12 11:40:19 2015 +0100
remove code from mll
---
.../learning/maximum-likelihood-learning.hxx | 150 +++++++++++----------
.../learning/test_maximum_likelihood_learner.cxx | 5 +-
2 files changed, 79 insertions(+), 76 deletions(-)
diff --git a/include/opengm/learning/maximum-likelihood-learning.hxx b/include/opengm/learning/maximum-likelihood-learning.hxx
index d2d6718..c553a59 100644
--- a/include/opengm/learning/maximum-likelihood-learning.hxx
+++ b/include/opengm/learning/maximum-likelihood-learning.hxx
@@ -5,40 +5,40 @@
#include <vector>
#include <fstream>
#include <opengm/inference/messagepassing/messagepassing.hxx>
-#include <opengm/functions/explicit_function.hxx>
+//#include <opengm/functions/explicit_function.hxx>
#include <opengm/functions/view_convert_function.hxx>
-#include <opengm/functions/learnable/lpotts.hxx>
-#include <opengm/functions/learnable/lsum_of_experts.hxx>
+//#include <opengm/functions/learnable/lpotts.hxx>
+//#include <opengm/functions/learnable/lsum_of_experts.hxx>
#include <opengm/graphicalmodel/graphicalmodel.hxx>
-#include <opengm/inference/icm.hxx>
-
-typedef double ValueType;
-typedef size_t IndexType;
-typedef size_t LabelType;
-typedef opengm::meta::TypeListGenerator<
- opengm::ExplicitFunction<ValueType,IndexType,LabelType>,
- opengm::functions::learnable::LPotts<ValueType,IndexType,LabelType>,
- opengm::functions::learnable::LSumOfExperts<ValueType,IndexType,LabelType>
->::type FunctionListType;
-
-typedef opengm::GraphicalModel<
- ValueType,opengm::Adder,
- FunctionListType,
- opengm::DiscreteSpace<IndexType,LabelType>
-> GM;
-
-typedef opengm::ICM<GM,opengm::Minimizer> INF;
-typedef opengm::learning::Weights<ValueType> WeightType;
+//#include <opengm/inference/icm.hxx>
+//
+//typedef double ValueType;
+//typedef size_t IndexType;
+//typedef size_t LabelType;
+//typedef opengm::meta::TypeListGenerator<
+// opengm::ExplicitFunction<ValueType,IndexType,LabelType>,
+// opengm::functions::learnable::LPotts<ValueType,IndexType,LabelType>,
+// opengm::functions::learnable::LSumOfExperts<ValueType,IndexType,LabelType>
+//>::type FunctionListType;
+//
+//typedef opengm::GraphicalModel<
+// ValueType,opengm::Adder,
+// FunctionListType,
+// opengm::DiscreteSpace<IndexType,LabelType>
+//> GM;
+//
+//typedef opengm::ICM<GM,opengm::Minimizer> INF;
+//typedef opengm::learning::Weights<ValueType> WeightType;
struct WeightGradientFunctor{
- WeightGradientFunctor(IndexType weight, std::vector<LabelType>::iterator labelVectorBegin)
+ WeightGradientFunctor(size_t weight, std::vector<size_t>::iterator labelVectorBegin)
: weight_(weight),
labelVectorBegin_(labelVectorBegin){
}
template<class F>
void operator()(const F & function ){
- IndexType index=-1;
+ size_t index=-1;
for(size_t i=0; i<function.numberOfWeights();++i)
if(function.weightIndex(i)==weight_)
index=i;
@@ -48,9 +48,10 @@ struct WeightGradientFunctor{
result_ = 0;
}
- IndexType weight_;
- std::vector<LabelType>::iterator labelVectorBegin_;
- ValueType result_;
+ size_t weight_;
+ // std::vector<LabelType>::iterator labelVectorBegin_;
+ std::vector<size_t>::iterator labelVectorBegin_;
+ double result_;
};
namespace opengm {
@@ -66,18 +67,28 @@ public:
typedef typename GMType::IndexType IndexType;
typedef typename GMType::LabelType LabelType;
typedef typename GMType::FactorType FactorType;
-
+ typedef opengm::learning::Weights<ValueType> WeightType;
+
+ typedef typename opengm::ExplicitFunction<ValueType,IndexType,LabelType> FunctionType;
+ typedef typename opengm::ViewConvertFunction<GMType,Minimizer,ValueType> ViewFunctionType;
+ typedef typename GMType::FunctionIdentifier FunctionIdentifierType;
+ typedef typename opengm::meta::TypeListGenerator<FunctionType,ViewFunctionType>::type FunctionListType;
+ typedef opengm::GraphicalModel<ValueType,opengm::Multiplier, FunctionListType, opengm::DiscreteSpace<IndexType,LabelType> > GmBpType;
+ typedef BeliefPropagationUpdateRules<GmBpType, opengm::Integrator> UpdateRules;
+ typedef MessagePassing<GmBpType, opengm::Integrator, UpdateRules, opengm::MaxDistance> BeliefPropagation;
+
class Parameter{
public:
size_t maxNumSteps_;
- Parameter() :maxNumSteps_(100){;}
+ Parameter() :maxNumSteps_(100)
+ {;}
};
-
+
MaximumLikelihoodLearner(DATASET&, const Parameter & );
- template<class INF>
- void learn(const typename INF::Parameter& weight);
+ // template<class INF>
+ void learn();//const typename INF::Parameter&);
const opengm::learning::Weights<ValueType>& getModelWeights(){return modelWeights_;}
Parameter& getLerningWeights(){return param_;}
@@ -97,12 +108,12 @@ MaximumLikelihoodLearner<DATASET>::MaximumLikelihoodLearner(DATASET& ds, const P
template<class DATASET>
-template<class INF>
-void MaximumLikelihoodLearner<DATASET>::learn(const typename INF::Parameter &weight){
+//template<class INF>
+void MaximumLikelihoodLearner<DATASET>::learn(){//const typename INF::Parameter &infParam){
opengm::learning::Weights<ValueType> modelWeight( dataset_.getNumberOfWeights() );
opengm::learning::Weights<ValueType> bestModelWeight( dataset_.getNumberOfWeights() );
- double bestLoss = 100000000.0;
+ //double bestLoss = 100000000.0;
std::vector<ValueType> point(dataset_.getNumberOfWeights(),0);
std::vector<ValueType> gradient(dataset_.getNumberOfWeights(),0);
std::vector<ValueType> Delta(dataset_.getNumberOfWeights(),0);
@@ -110,11 +121,6 @@ void MaximumLikelihoodLearner<DATASET>::learn(const typename INF::Parameter &wei
point[p] = ValueType((0));
- // test only
- //point[0]=0.5;
- //point[1]=0.7;
- //point[2]=0.9;
-
typename DATASET::LossType lossFunction;
bool search=true;
int count=0;
@@ -127,7 +133,7 @@ void MaximumLikelihoodLearner<DATASET>::learn(const typename INF::Parameter &wei
for(IndexType m=0; m<dataset_.getNumberOfModels(); ++m){ // for each model
const GMType &model = dataset_.getModel(m);
- const std::vector<typename INF::LabelType>& gt = dataset_.getGT(m);
+ const std::vector<LabelType>& gt = dataset_.getGT(m);
for(IndexType v=0; v<model.numberOfVariables();++v)
w[m][v]=(ValueType)gt[v];
@@ -148,38 +154,32 @@ void MaximumLikelihoodLearner<DATASET>::learn(const typename INF::Parameter &wei
modelWeight.setWeight(p, point[p]);
}
- /***********************************************************************************************************/
- // calculate current loss - not needed
- /***********************************************************************************************************/
- opengm::learning::Weights<ValueType>& mp = dataset_.getWeights();
- mp = modelWeight;
- std::vector< std::vector<typename INF::LabelType> > confs( dataset_.getNumberOfModels() );
- double loss = 0;
- for(size_t m=0; m<dataset_.getNumberOfModels(); ++m){
- INF inf( dataset_.getModel(m),weight);
- inf.infer();
- inf.arg(confs[m]);
- const std::vector<typename INF::LabelType>& gt = dataset_.getGT(m);
- loss += lossFunction.loss(dataset_.getModel(m), confs[m].begin(), confs[m].end(), gt.begin(), gt.end());
- }
-
- std::cout << " eta = " << eta << " weights ";//<< std::endl;
- for(IndexType p=0; p<dataset_.getNumberOfWeights(); ++p){
- std::cout << modelWeight[p] << " " ;
- }
-
- optFun=0.0;
+ // /***********************************************************************************************************/
+ // // calculate current loss - not needed
+ // /***********************************************************************************************************/
+ // opengm::learning::Weights<ValueType>& mp = dataset_.getWeights();
+ // mp = modelWeight;
+ // std::vector< std::vector<typename INF::LabelType> > confs( dataset_.getNumberOfModels() );
+ // double loss = 0;
+ // for(size_t m=0; m<dataset_.getNumberOfModels(); ++m){
+ // INF inf( dataset_.getModel(m),infParam);
+ // inf.infer();
+ // inf.arg(confs[m]);
+ // const std::vector<typename INF::LabelType>& gt = dataset_.getGT(m);
+ // loss += lossFunction.loss(dataset_.getModel(m), confs[m].begin(), confs[m].end(), gt.begin(), gt.end());
+ // }
+
+ // std::cout << " eta = " << eta << " weights ";//<< std::endl;
+ // for(IndexType p=0; p<dataset_.getNumberOfWeights(); ++p){
+ // std::cout << modelWeight[p] << " " ;
+ // }
+
+ // optFun=0.0;
/***********************************************************************************************************/
// Loopy Belief Propagation setup
/***********************************************************************************************************/
- typedef typename opengm::ExplicitFunction<ValueType,IndexType,LabelType> FunctionType;
- typedef typename opengm::ViewConvertFunction<GMType,Minimizer,ValueType> ViewFunctionType;
- typedef typename GMType::FunctionIdentifier FunctionIdentifierType;
- typedef typename opengm::meta::TypeListGenerator<FunctionType,ViewFunctionType>::type FunctionListType;
- typedef opengm::GraphicalModel<ValueType,opengm::Multiplier, FunctionListType, opengm::DiscreteSpace<IndexType,LabelType> > GmBpType;
- typedef BeliefPropagationUpdateRules<GmBpType, opengm::Integrator> UpdateRules;
- typedef MessagePassing<GmBpType, opengm::Integrator, UpdateRules, opengm::MaxDistance> BeliefPropagation;
+
const IndexType maxNumberOfIterations = 40;
const double convergenceBound = 1e-7;
@@ -202,7 +202,7 @@ void MaximumLikelihoodLearner<DATASET>::learn(const typename INF::Parameter &wei
// run: Loopy Belief Propagation
/***********************************************************************************************************/
BeliefPropagation bp(bpModel, weight);
- const std::vector<typename INF::LabelType>& gt = dataset_.getGT(m);
+ const std::vector<LabelType>& gt = dataset_.getGT(m);
bp.infer();
typename GMType::IndependentFactorType marg;
@@ -227,7 +227,7 @@ void MaximumLikelihoodLearner<DATASET>::learn(const typename INF::Parameter &wei
for(IndexType m=0; m<dataset_.getNumberOfModels(); ++m){
const GMType &model = dataset_.getModel(m);
- const std::vector<typename INF::LabelType>& gt = dataset_.getGT(m);
+ const std::vector<LabelType>& gt = dataset_.getGT(m);
ValueType f_p;
for(IndexType f=0; f<dataset_.getModel(m).numberOfFactors();++f){
@@ -255,13 +255,14 @@ void MaximumLikelihoodLearner<DATASET>::learn(const typename INF::Parameter &wei
}
}
//std::cout << " loss = " << loss << " optFun = " << optFun << " optFunTmp = " << optFunTmp << std::endl;
- std::cout << " loss = " << loss << " optFun = " << optFun << std::endl;
+ //std::cout << " loss = " << loss << " optFun = " << optFun << std::endl;
+ std::cout << " optFun = " << optFun << std::endl;
if(optFun>=bestOptFun){
bestOptFun=optFun;
bestModelWeight=modelWeight;
bestOptFun=optFun;
- bestLoss=loss;
+ //bestLoss=loss;
}
if (count>=param_.maxNumSteps_){
@@ -289,7 +290,8 @@ void MaximumLikelihoodLearner<DATASET>::learn(const typename INF::Parameter &wei
std::cout << bestModelWeight[p] <<" ";
}
std::cout << " ==> ";
- std::cout << " loss = " << bestLoss << " bestOptFun = " << bestOptFun << " gradient [" << 0 << "] = " << gradient[0] << std::endl;
+ //std::cout << " loss = " << bestLoss << " bestOptFun = " << bestOptFun << " gradient [" << 0 << "] = " << gradient[0] << std::endl;
+ std::cout << " bestOptFun = " << bestOptFun << " gradient [" << 0 << "] = " << gradient[0] << std::endl;
modelWeights_ = bestModelWeight;
};
diff --git a/src/unittest/learning/test_maximum_likelihood_learner.cxx b/src/unittest/learning/test_maximum_likelihood_learner.cxx
index b312846..28a103b 100644
--- a/src/unittest/learning/test_maximum_likelihood_learner.cxx
+++ b/src/unittest/learning/test_maximum_likelihood_learner.cxx
@@ -61,8 +61,9 @@ int main() {
opengm::learning::MaximumLikelihoodLearner<DS1>::Parameter param;
param.maxNumSteps_=3;
opengm::learning::MaximumLikelihoodLearner<DS1> learner(dataset,param);
- INF::Parameter infParam;
- learner.learn<INF>(infParam);
+ //INF::Parameter infParam;
+ //learner.learn<INF>(infParam);
+ learner.learn();
}
/*
--
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