[opengm] 241/386: add temperature to mll
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Wed Aug 31 08:37:58 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 de394207c26c881bb66c3f2a55d09cdb4d5b8a93
Author: joergkappes <kappes at math.uni-heidelberg.de>
Date: Thu Jan 15 09:31:37 2015 +0100
add temperature to mll
---
include/opengm/functions/view_convert_function.hxx | 36 ++++++++++++++++++----
.../learning/maximum_likelihood_learning.hxx | 6 ++--
2 files changed, 34 insertions(+), 8 deletions(-)
diff --git a/include/opengm/functions/view_convert_function.hxx b/include/opengm/functions/view_convert_function.hxx
index 26ced72..1cfad00 100644
--- a/include/opengm/functions/view_convert_function.hxx
+++ b/include/opengm/functions/view_convert_function.hxx
@@ -18,7 +18,10 @@ namespace detail_convert_function {
template<class T>
static ProbabilityType convert(const T x)
{ return static_cast<ProbabilityType>(x); }
- };
+ template<class T>
+ static ProbabilityType convert(const T x, const T invT)
+ { return static_cast<ProbabilityType>(x); }
+ };
template<class PROBABILITY>
struct ValueToProbability<Multiplier, Minimizer, PROBABILITY>
@@ -26,7 +29,10 @@ namespace detail_convert_function {
typedef PROBABILITY ProbabilityType;
template<class T>
static ProbabilityType convert(const T x)
- { return static_cast<ProbabilityType>(1) / static_cast<ProbabilityType>(x); }
+ { return static_cast<ProbabilityType>(1) / static_cast<ProbabilityType>(x); } // is this correct ?!?
+ template<class T>
+ static ProbabilityType convert(const T x, const T invT)
+ { return static_cast<ProbabilityType>(1) / static_cast<ProbabilityType>(x); } // is this correct ?!?
};
template<class PROBABILITY>
@@ -36,6 +42,9 @@ namespace detail_convert_function {
template<class T>
static ProbabilityType convert(const T x)
{ return static_cast<ProbabilityType>(std::exp(x)); }
+ template<class T>
+ static ProbabilityType convert(const T x, const T invT)
+ { return static_cast<ProbabilityType>(std::exp(invT * x)); }
};
template<class PROBABILITY>
@@ -44,7 +53,10 @@ namespace detail_convert_function {
typedef PROBABILITY ProbabilityType;
template<class T>
static ProbabilityType convert(const T x)
- { return static_cast<ProbabilityType>(std::exp(-x)); }
+ { return static_cast<ProbabilityType>(std::exp(-x)); }
+ template<class T>
+ static ProbabilityType convert(const T x, const T invT)
+ { return static_cast<ProbabilityType>(std::exp(-invT * x)); }
};
}
/// \endcond
@@ -67,6 +79,7 @@ public:
ViewConvertFunction();
ViewConvertFunction(const FactorType &);
+ ViewConvertFunction(const FactorType &, const ValueType);
template<class Iterator> ValueType operator()(Iterator begin) const;
IndexType shape(const IndexType) const;
IndexType dimension() const;
@@ -74,12 +87,13 @@ public:
private:
FactorType const* factor_;
+ ValueType inverseTemperature_;
};
template<class GM,class ACC,class VALUE_TYPE>
inline
ViewConvertFunction<GM,ACC,VALUE_TYPE>::ViewConvertFunction()
-: factor_(NULL)
+ : factor_(NULL),inverseTemperature_(1)
{}
template<class GM,class ACC,class VALUE_TYPE>
@@ -88,7 +102,17 @@ ViewConvertFunction<GM,ACC,VALUE_TYPE>::ViewConvertFunction
(
const typename ViewConvertFunction<GM,ACC,VALUE_TYPE>::FactorType & factor
)
-: factor_(&factor)
+: factor_(&factor),inverseTemperature_(1)
+{}
+
+template<class GM,class ACC,class VALUE_TYPE>
+inline
+ViewConvertFunction<GM,ACC,VALUE_TYPE>::ViewConvertFunction
+(
+ const typename ViewConvertFunction<GM,ACC,VALUE_TYPE>::FactorType & factor,
+ const VALUE_TYPE invT
+)
+: factor_(&factor),inverseTemperature_(invT)
{}
template<class GM,class ACC,class VALUE_TYPE>
@@ -98,7 +122,7 @@ ViewConvertFunction<GM,ACC,VALUE_TYPE>::operator()
(
Iterator begin
) const {
- return detail_convert_function::ValueToProbability<OperatorType,ACC,ValueType>::convert(factor_->operator()(begin));
+ return detail_convert_function::ValueToProbability<OperatorType,ACC,ValueType>::convert(factor_->operator()(begin),inverseTemperature_);
}
template<class GM,class ACC,class VALUE_TYPE>
diff --git a/include/opengm/learning/maximum_likelihood_learning.hxx b/include/opengm/learning/maximum_likelihood_learning.hxx
index a06733a..9c609aa 100644
--- a/include/opengm/learning/maximum_likelihood_learning.hxx
+++ b/include/opengm/learning/maximum_likelihood_learning.hxx
@@ -27,7 +27,8 @@ namespace opengm {
public:
size_t maxNumSteps_;
double reg_;
- Parameter() : maxNumSteps_(10), reg_(1.0) {;}
+ double temperature_;
+ Parameter() : maxNumSteps_(10), reg_(1.0), temperature_(0.3) {;}
};
class WeightGradientFunctor{
@@ -95,6 +96,7 @@ namespace opengm {
typedef MessagePassing<GmBpType, opengm::Integrator, UpdateRules, opengm::MaxDistance> BeliefPropagation;
bool search = true;
+ double invTemperature = 1.0/param_.temperature_;
//Parameters for inference
const IndexType maxNumberOfIterations = 40;
@@ -125,7 +127,7 @@ namespace opengm {
const typename GMType::FactorType& factor=dataset_.getModel(m)[f];
typedef typename opengm::ViewConvertFunction<GMType,Minimizer,ValueType> ViewFunctionType;
typedef typename GMType::FunctionIdentifier FunctionIdentifierType;
- FunctionIdentifierType fid = bpModel.addFunction(ViewFunctionType(factor));
+ FunctionIdentifierType fid = bpModel.addFunction(ViewFunctionType(factor,invTemperature));
bpModel.addFactor(fid, factor.variableIndicesBegin(), factor.variableIndicesEnd());
}
--
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