[opengm] 66/386: added lunary to python
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Wed Aug 31 08:35:06 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 ff9f288ac2ce882f15df241ad34331b3d995c251
Author: DerThorsten <thorsten.beier at iwr.uni-heidelberg.de>
Date: Tue Dec 16 14:45:23 2014 +0100
added lunary to python
---
fubar/python_stuff.py | 75 ++++-
include/opengm/functions/learnable/lunary.hxx | 323 +++++++++++++++++++++
include/opengm/functions/learnablefunction.hxx | 4 +
include/opengm/functions/readme.txt | 2 +
include/opengm/python/opengmpython.hxx | 10 +-
.../python/opengm/opengmcore/opengmcore.cpp | 2 +-
.../python/opengm/opengmcore/pyFunctionTypes.cxx | 113 +++++++
src/interfaces/python/opengm/opengmcore/pyGm.cxx | 11 +-
8 files changed, 522 insertions(+), 18 deletions(-)
diff --git a/fubar/python_stuff.py b/fubar/python_stuff.py
index bda65b3..d05ef64 100644
--- a/fubar/python_stuff.py
+++ b/fubar/python_stuff.py
@@ -1,39 +1,92 @@
import opengm
import numpy
+np = numpy
-numLabels = 4
+numLabels = 3
numVar = 6
# make the gm
-space = numpy.ones(numVar)*4
+space = numpy.ones(numVar)*numLabels
gm = opengm.gm(space)
-weightVals = numpy.ones(4)*4.0
+weightVals = numpy.ones(100)*1.0
weights = opengm.Weights(weightVals)
+##################################################################
+# add a unary function
+##################################################################
+features = numpy.ones([numLabels, 2], dtype=opengm.value_type)
+weightIds = numpy.ones([numLabels, 2], dtype=opengm.index_type)
+# set up weight ids for each label
+weightIds[0,:] = [0, 1]
+weightIds[1,:] = [2, 3]
+weightIds[2,:] = [4, 5]
-features = numpy.array([1.0, 5.0]).astype(opengm.value_type)
-weightIds = numpy.array([0,1]).astype(opengm.index_type)
-
-f = opengm.LPottsFunction(weights=weights, numberOfLabels=numLabels,
+print "add f"
+f = opengm.LUnaryFunction(weights=weights, numberOfLabels=numLabels,
weightIds=weightIds, features=features)
+print "add factor"
+fid = gm.addFunction(f)
+gm.addFactor(fid, [0])
+
+print "features",features
+print "unary",np.array(gm[0])
+
+weights[4] = 0.5
+print "unary",np.array(gm[0])
+##################################################################
+# add a unary function
+##################################################################
+features = [
+ numpy.array([1.0, 1.0], dtype=opengm.value_type),
+ numpy.array([1.0, 1.0, 1.0], dtype=opengm.value_type),
+ numpy.array([1.0, 1.0, 1.0, 1.0], dtype=opengm.value_type)
+]
+weightIds = [
+ numpy.array([6, 7], dtype=opengm.index_type),
+ numpy.array([8, 9, 10], dtype=opengm.index_type),
+ numpy.array([11, 12, 13, 14], dtype=opengm.index_type)
+]
+
+
+print "add f"
+f = opengm.LUnaryFunction(weights=weights, numberOfLabels=numLabels,
+ weightIds=weightIds, features=features)
+print "add factor"
fid = gm.addFunction(f)
-gm.addFactor(fid, [0,1])
+gm.addFactor(fid, [0])
+
+print "features",features
+print "unary",np.array(gm[1])
-print numpy.array(gm[0])
-weights[0] = 0.5
-print numpy.array(gm[0])
+print "unary",np.array(gm[1])
+
+
+
+
+
+##################################################################
+# add a potts function
+##################################################################
+features = numpy.array([1.0, 5.0]).astype(opengm.value_type)
+weightIds = numpy.array([6,7]).astype(opengm.index_type)
+f = opengm.LPottsFunction(weights=weights, numberOfLabels=numLabels,
+ weightIds=weightIds, features=features)
+
+# add factor
+fid = gm.addFunction(f)
+gm.addFactor(fid, [0,1])
diff --git a/include/opengm/functions/learnable/lunary.hxx b/include/opengm/functions/learnable/lunary.hxx
new file mode 100644
index 0000000..97674d8
--- /dev/null
+++ b/include/opengm/functions/learnable/lunary.hxx
@@ -0,0 +1,323 @@
+#pragma once
+#ifndef OPENGM_LEARNABLE_UNARY_FUNCTION_HXX
+#define OPENGM_LEARNABLE_UNARY_FUNCTION_HXX
+
+#include <algorithm>
+#include <vector>
+#include <cmath>
+
+#include "opengm/opengm.hxx"
+#include "opengm/functions/function_registration.hxx"
+#include "opengm/functions/function_properties_base.hxx"
+#include "opengm/graphicalmodel/weights.hxx"
+
+namespace opengm {
+namespace functions {
+namespace learnable {
+
+
+
+
+/// Learnable feature function for two variables
+///
+/// f(u,v) = (\sum_i w_i * feat_i) I(u!=v)
+/// - w = parameter vector
+/// - feat = feature vector
+///
+/// derive from this class and implement the function
+/// paramaterGradient(i,x)= A(x)_{i,*}*feat
+///
+/// \ingroup functions
+
+
+template<class V, class I>
+struct FeaturesAndIndices{
+ std::vector<V> features;
+ std::vector<I> indices;
+};
+
+
+
+
+template<class T, class I , class L>
+class LUnary
+ : public opengm::FunctionBase<opengm::functions::learnable::LUnary<T, I, L>, T, I, L>
+{
+public:
+ typedef T ValueType;
+ typedef T V;
+ typedef L LabelType;
+ typedef I IndexType;
+
+
+ LUnary(
+ const opengm::learning::Weights<T>& weights,
+ std::vector<FeaturesAndIndices<T, I> > featuresAndIndicesPerLabel
+ );
+ L shape(const size_t) const;
+ size_t size() const;
+ size_t dimension() const;
+ template<class ITERATOR> T operator()(ITERATOR) const;
+
+ // parameters
+ void setWeights(const opengm::learning::Weights<T>& weights){
+ weights_ = &weights;
+ }
+
+ size_t numberOfWeights()const{
+ return numWeights_;
+ }
+
+ I weightIndex(const size_t weightNumber) const{
+ return weightIds_[weightNumber];
+ }
+
+ template<class ITERATOR>
+ T weightGradient(size_t,ITERATOR) const;
+
+private:
+ bool isMatchingWeight(const LabelType l , const size_t i ){
+
+ }
+protected:
+ const opengm::learning::Weights<T> * weights_;
+ std::vector<size_t> labelOffset_;
+ std::vector<size_t> weightIds_;
+ std::vector<V> features_;
+ size_t numWeights_;
+ friend class opengm::FunctionSerialization<opengm::functions::learnable::LUnary<T, I, L> >;
+
+
+};
+
+
+template <class T, class I, class L>
+inline
+LUnary<T, I, L>::LUnary
+(
+ const opengm::learning::Weights<T> & weights = opengm::learning::Weights<T>(),
+ std::vector<FeaturesAndIndices<V, I> > featuresAndIndicesPerLabel = std::vector<FeaturesAndIndices<V, I> >()
+)
+:
+weights_(&weights),
+labelOffset_(featuresAndIndicesPerLabel.size(),0),
+weightIds_(),
+features_(),
+numWeights_(0){
+
+ // collect how many weights there are at all
+ // for this function
+ size_t offset = 0 ;
+ for(size_t l=0; l<featuresAndIndicesPerLabel.size(); ++l){
+ labelOffset_[l] = offset;
+ const size_t nForThisL = featuresAndIndicesPerLabel[l].features.size();
+ numWeights_ += nForThisL;
+ }
+
+ weightIds_.resize(numWeights_);
+ features_.resize(numWeights_);
+
+ for(size_t l=0; l<featuresAndIndicesPerLabel.size(); ++l){
+ labelOffset_[l] = offset;
+ const size_t nForThisL = featuresAndIndicesPerLabel[l].features.size();
+ for(size_t i=0; i<nForThisL; ++i){
+
+ // as many features as labels
+ OPENGM_CHECK_OP( featuresAndIndicesPerLabel[l].indices.size(), == ,
+ featuresAndIndicesPerLabel[l].features.size() ,
+ "features and weights must be of same length");
+
+ weightIds_[offset + i] = featuresAndIndicesPerLabel[l].indices[i];
+ features_[offset + i] = featuresAndIndicesPerLabel[l].features[i];
+
+ }
+ offset+=nForThisL;
+ }
+}
+
+
+
+template <class T, class I, class L>
+template <class ITERATOR>
+inline T
+LUnary<T, I, L>::weightGradient
+(
+ size_t weightNumber,
+ ITERATOR begin
+) const {
+ OPENGM_CHECK_OP(weightNumber,<,numberOfWeights(),
+ "weightNumber must be smaller than number of weights");
+ const L l = *begin;
+
+ if(l == size()-1){
+ size_t start = labelOffset_[l];
+ if(weightNumber>=start){
+ return features_[weightNumber];
+ }
+ }
+ else{
+ size_t start = labelOffset_[l];
+ size_t end = labelOffset_[l+1];
+ if(weightNumber>= start && weightNumber<end){
+ return features_[weightNumber];
+ }
+ }
+ return V(0);
+
+}
+
+template <class T, class I, class L>
+template <class ITERATOR>
+inline T
+LUnary<T, I, L>::operator()
+(
+ ITERATOR begin
+) const {
+ T val = 0;
+ size_t end = (*begin == size()-1 ? numberOfWeights() : labelOffset_[*begin+1] );
+
+ //std::cout<<"label "<<*begin<<"\n";
+ //std::cout<<"s e "<<labelOffset_[*begin]<<" "<<end<<"\n";
+ for(size_t i=labelOffset_[*begin];i<end;++i){
+ //std::cout<<" i="<<i<<" wi="<<weightIds_[i]<<" w="<< weights_->getWeight(weightIds_[i]) <<" f="<<features_[i]<<"\n";
+ val += weights_->getWeight(weightIds_[i]) * features_[i];
+ }
+ return val;
+}
+
+
+template <class T, class I, class L>
+inline L
+LUnary<T, I, L>::shape
+(
+ const size_t i
+) const {
+ return labelOffset_.size();
+}
+
+template <class T, class I, class L>
+inline size_t
+LUnary<T, I, L>::dimension() const {
+ return 1;
+}
+
+template <class T, class I, class L>
+inline size_t
+LUnary<T, I, L>::size() const {
+ return labelOffset_.size();
+}
+
+} // namespace learnable
+} // namespace functions
+
+
+/// FunctionSerialization
+template<class T, class I, class L>
+class FunctionSerialization<opengm::functions::learnable::LUnary<T, I, L> > {
+public:
+ typedef typename opengm::functions::learnable::LUnary<T, I, L>::ValueType ValueType;
+
+ static size_t indexSequenceSize(const opengm::functions::learnable::LUnary<T, I, L>&);
+ static size_t valueSequenceSize(const opengm::functions::learnable::LUnary<T, I, L>&);
+ template<class INDEX_OUTPUT_ITERATOR, class VALUE_OUTPUT_ITERATOR>
+ static void serialize(const opengm::functions::learnable::LUnary<T, I, L>&, INDEX_OUTPUT_ITERATOR, VALUE_OUTPUT_ITERATOR);
+ template<class INDEX_INPUT_ITERATOR, class VALUE_INPUT_ITERATOR>
+ static void deserialize( INDEX_INPUT_ITERATOR, VALUE_INPUT_ITERATOR, opengm::functions::learnable::LUnary<T, I, L>&);
+};
+
+template<class T, class I, class L>
+struct FunctionRegistration<opengm::functions::learnable::LUnary<T, I, L> > {
+ enum ID {
+ Id = opengm::FUNCTION_TYPE_ID_OFFSET + 100 + 66
+ };
+};
+
+template<class T, class I, class L>
+inline size_t
+FunctionSerialization<opengm::functions::learnable::LUnary<T, I, L> >::indexSequenceSize
+(
+ const opengm::functions::learnable::LUnary<T, I, L> & src
+) {
+ return 2 + src.size() + src.numberOfWeights();
+}
+
+template<class T, class I, class L>
+inline size_t
+FunctionSerialization<opengm::functions::learnable::LUnary<T, I, L> >::valueSequenceSize
+(
+ const opengm::functions::learnable::LUnary<T, I, L> & src
+) {
+ return src.numberOfWeights();
+}
+
+template<class T, class I, class L>
+template<class INDEX_OUTPUT_ITERATOR, class VALUE_OUTPUT_ITERATOR >
+inline void
+FunctionSerialization<opengm::functions::learnable::LUnary<T, I, L> >::serialize
+(
+ const opengm::functions::learnable::LUnary<T, I, L> & src,
+ INDEX_OUTPUT_ITERATOR indexOutIterator,
+ VALUE_OUTPUT_ITERATOR valueOutIterator
+) {
+ *indexOutIterator = src.size();
+ ++indexOutIterator;
+
+ *indexOutIterator = src.numberOfWeights();
+ ++indexOutIterator;
+
+ for(size_t l=0; l<src.size(); ++l){
+ *indexOutIterator = src.labelOffset_[l];
+ ++indexOutIterator;
+ }
+
+ for(size_t i=0; i<src.numberOfWeights(); ++i){
+ *indexOutIterator = src.weightIds_[i];
+ ++indexOutIterator;
+
+ *valueOutIterator = src.features_[i];
+ ++valueOutIterator;
+ }
+
+
+}
+
+template<class T, class I, class L>
+template<class INDEX_INPUT_ITERATOR, class VALUE_INPUT_ITERATOR >
+inline void
+FunctionSerialization<opengm::functions::learnable::LUnary<T, I, L> >::deserialize
+(
+ INDEX_INPUT_ITERATOR indexInIterator,
+ VALUE_INPUT_ITERATOR valueInIterator,
+ opengm::functions::learnable::LUnary<T, I, L> & dst
+) {
+ const size_t numLabels = *indexInIterator;
+ ++indexInIterator;
+
+ dst.numWeights_ = *indexInIterator;
+ ++indexInIterator;
+
+ dst.labelOffset_.resize(numLabels);
+ dst.weightIds_.resize(dst.numWeights_);
+ dst.features_.resize(dst.numWeights_);
+
+ // label offset
+ for(size_t l=0; l<numLabels; ++l){
+ dst.labelOffset_[l] = *indexInIterator;
+ ++indexInIterator;
+ }
+
+ for(size_t i=0; i<dst.numWeights_; ++i){
+ dst.weightIds_[i] = *indexInIterator;
+ ++indexInIterator;
+
+ dst.features_[i] = *valueInIterator;
+ ++valueInIterator;
+ }
+
+
+
+}
+
+} // namespace opengm
+
+#endif // #ifndef OPENGM_LEARNABLE_FUNCTION_HXX
diff --git a/include/opengm/functions/learnablefunction.hxx b/include/opengm/functions/learnablefunction.hxx
index 995e3b7..314fbd9 100644
--- a/include/opengm/functions/learnablefunction.hxx
+++ b/include/opengm/functions/learnablefunction.hxx
@@ -12,6 +12,10 @@
namespace opengm {
+
+
+
+
/// Learnable feature function for two variables
///
/// f(x) = w * A(x) * feat
diff --git a/include/opengm/functions/readme.txt b/include/opengm/functions/readme.txt
index c538627..e1ee309 100644
--- a/include/opengm/functions/readme.txt
+++ b/include/opengm/functions/readme.txt
@@ -59,6 +59,8 @@ opengm::StaticSingleSideFunction 16009
opengm::DynamicSingleSideFunction 16010
opengm::PottsG 16011
+opengm::LPotts 16165
+opengm::LUnary 16166
/////////////////////////////////////////////////////////////
4. Serialization and de-serialization
diff --git a/include/opengm/python/opengmpython.hxx b/include/opengm/python/opengmpython.hxx
index 7418d2d..840b5cc 100644
--- a/include/opengm/python/opengmpython.hxx
+++ b/include/opengm/python/opengmpython.hxx
@@ -19,7 +19,7 @@
#include "opengm/functions/sparsemarray.hxx"
#include "opengm/functions/learnable/lpotts.hxx"
-
+#include "opengm/functions/learnable/lunary.hxx"
#include <opengm/python/opengmpython.hxx>
#include <opengm/python/converter.hxx>
@@ -64,7 +64,7 @@ namespace python{
typedef PythonFunction <ValueType,IndexType,LabelType> PyPythonFunction;
// learning functions
typedef opengm::functions::learnable::LPotts <ValueType,IndexType,LabelType> PyLPottsFunction;
-
+ typedef opengm::functions::learnable::LUnary <ValueType,IndexType,LabelType> PyLUnaryFunction;
typedef typename opengm::meta::TypeListGenerator<
@@ -76,7 +76,8 @@ namespace python{
PyTruncatedSquaredDifferenceFunction,
PySparseFunction,
PyPythonFunction,
- PyLPottsFunction
+ PyLPottsFunction,
+ PyLUnaryFunction
>::type type;
};
@@ -102,7 +103,8 @@ namespace python{
typedef opengm::SparseFunction <GmValueType,GmIndexType,GmLabelType> GmSparseFunction;
typedef opengm::python::PythonFunction <GmValueType,GmIndexType,GmLabelType> GmPythonFunction;
typedef opengm::functions::learnable::LPotts <GmValueType,GmIndexType,GmLabelType> PyLPottsFunction;
-
+ typedef opengm::functions::learnable::LUnary <GmValueType,GmIndexType,GmLabelType> PyLUnaryFunction;
+
typedef std::vector<GmIndexType> IndexVectorType;
typedef std::vector<IndexVectorType> IndexVectorVectorType;
diff --git a/src/interfaces/python/opengm/opengmcore/opengmcore.cpp b/src/interfaces/python/opengm/opengmcore/opengmcore.cpp
index 9cb6235..6397755 100644
--- a/src/interfaces/python/opengm/opengmcore/opengmcore.cpp
+++ b/src/interfaces/python/opengm/opengmcore/opengmcore.cpp
@@ -170,7 +170,7 @@ opengm::learning::Weights<V> * pyWeightsConstructor(
opengm::python::NumpyView<V, 1> values
){
opengm::learning::Weights<V> * f = new opengm::learning::Weights<V> (values.shape(0));
- for(size_t i=0; i<values.shape(i); ++i){
+ for(size_t i=0; i<values.shape(0); ++i){
f->setWeight(i, values(i));
}
return f;
diff --git a/src/interfaces/python/opengm/opengmcore/pyFunctionTypes.cxx b/src/interfaces/python/opengm/opengmcore/pyFunctionTypes.cxx
index f618621..7106784 100644
--- a/src/interfaces/python/opengm/opengmcore/pyFunctionTypes.cxx
+++ b/src/interfaces/python/opengm/opengmcore/pyFunctionTypes.cxx
@@ -190,6 +190,96 @@ namespace pyfunction{
}
+ template<class FUNCTION>
+ FUNCTION * lUnaryConstructor(
+ opengm::python::PyWeights & pyWeights,
+ const opengm::python::GmLabelType numberOfLabels,
+ opengm::python::NumpyView<opengm::python::GmIndexType,2> weightIds,
+ opengm::python::NumpyView<opengm::python::GmValueType,2> features
+ ){
+ FUNCTION * f = NULL;
+ typedef opengm::functions::learnable::FeaturesAndIndices<
+ opengm::python::GmValueType,
+ opengm::python::GmIndexType
+ > FI;
+ typedef std::vector<FI> FI_VEC;
+
+ size_t fPerL = weightIds.shape(1);
+
+ OPENGM_CHECK_OP(weightIds.shape(0), ==, numberOfLabels, "wrong shapes");
+ OPENGM_CHECK_OP(weightIds.shape(0), ==, features.shape(0),"wrong shapes");
+ OPENGM_CHECK_OP(weightIds.shape(1), ==, features.shape(1),"wrong shapes");
+
+ FI_VEC fiVec(numberOfLabels);
+
+ for(size_t l=0; l<numberOfLabels; ++l){
+ fiVec[l].indices.resize(fPerL);
+ fiVec[l].features.resize(fPerL);
+ for(size_t i=0; i<fPerL; ++i){
+ fiVec[l].indices[i] = weightIds(l, i);
+ fiVec[l].features[i] = features(l, i);
+ }
+ }
+ //std::cout<<"done on python side\n";
+ f = new FUNCTION(pyWeights, fiVec);
+ return f;
+ }
+
+ template<class FUNCTION>
+ FUNCTION * lUnaryConstructorList(
+ opengm::python::PyWeights & pyWeights,
+ const opengm::python::GmLabelType numberOfLabels,
+ boost::python::list weightIds,
+ boost::python::list features
+ ){
+
+ typedef opengm::python::NumpyView<opengm::python::GmIndexType,1> IndexArray;
+ typedef opengm::python::NumpyView<opengm::python::GmValueType,1> ValueArray;
+
+
+ OPENGM_CHECK_OP(boost::python::len(weightIds), == ,numberOfLabels ,"length of weightIds must be numberOfLabels");
+ OPENGM_CHECK_OP(boost::python::len(weightIds), == ,boost::python::len(features) ,"weightIds must be as long as features");
+
+
+
+ FUNCTION * f = NULL;
+ typedef opengm::functions::learnable::FeaturesAndIndices<
+ opengm::python::GmValueType,
+ opengm::python::GmIndexType
+ > FI;
+ typedef std::vector<FI> FI_VEC;
+
+ FI_VEC fiVec(numberOfLabels);
+
+ for(size_t l=0; l<numberOfLabels; ++l){
+
+ std::cout<<"extr. l "<<l<<"\n";
+ boost::python::extract<boost::python::numeric::array> eW(weightIds[l]);
+ boost::python::extract<boost::python::numeric::array> eF(features[l]);
+
+ IndexArray wId = eW();
+ ValueArray fs = eF();
+
+ std::cout<<"done\n";
+
+ OPENGM_CHECK_OP(wId.shape(0), ==, fs.shape(0),
+ "for one label the number of features and the number of weights must be the same");
+
+ const size_t fPerL = wId.shape(0);
+ fiVec[l].indices.resize(fPerL);
+ fiVec[l].features.resize(fPerL);
+
+ for(size_t i=0; i<fPerL; ++i){
+ fiVec[l].indices[i] = wId(i);
+ fiVec[l].features[i] = fs(i);
+ }
+ }
+ f = new FUNCTION(pyWeights, fiVec);
+ return f;
+ }
+
+
+
////////////////////////////////////////
// EXPLICIT FUNCTION
////////////////////////////////////////
@@ -357,6 +447,7 @@ void export_functiontypes(){
typedef opengm::SparseFunction <ValueType,IndexType,LabelType> PySparseFunction;
typedef opengm::python::PythonFunction <ValueType,IndexType,LabelType> PyPythonFunction;
typedef opengm::functions::learnable::LPotts <ValueType,IndexType,LabelType> PyLPottsFunction;
+ typedef opengm::functions::learnable::LUnary <ValueType,IndexType,LabelType> PyLUnaryFunction;
// vector exporters
export_function_type_vector<PyExplicitFunction>("ExplicitFunctionVector");
@@ -633,6 +724,28 @@ void export_functiontypes(){
"todo"
);
+ FUNCTION_TYPE_EXPORTER_HELPER(PyLUnaryFunction,"LUnaryFunction")
+ .def("__init__", make_constructor(&pyfunction::lUnaryConstructor<PyLUnaryFunction> ,default_call_policies(),
+ (
+ boost::python::arg("weights"),
+ boost::python::arg("numberOfLabels"),
+ boost::python::arg("weightIds"),
+ boost::python::arg("features")
+ )
+ ),
+ "todo"
+ )
+ .def("__init__", make_constructor(&pyfunction::lUnaryConstructorList<PyLUnaryFunction> ,default_call_policies(),
+ (
+ boost::python::arg("weights"),
+ boost::python::arg("numberOfLabels"),
+ boost::python::arg("weightIds"),
+ boost::python::arg("features")
+ )
+ ),
+ "todo"
+ )
+ ;
}
template void export_functiontypes<opengm::python::GmValueType,opengm::python::GmIndexType>();
diff --git a/src/interfaces/python/opengm/opengmcore/pyGm.cxx b/src/interfaces/python/opengm/opengmcore/pyGm.cxx
index 41d6cb3..e6102cc 100644
--- a/src/interfaces/python/opengm/opengmcore/pyGm.cxx
+++ b/src/interfaces/python/opengm/opengmcore/pyGm.cxx
@@ -684,6 +684,7 @@ namespace pygm {
typedef opengm::SparseFunction <ValueType,IndexType,LabelType> PySparseFunction;
typedef opengm::python::PythonFunction <ValueType,IndexType,LabelType> PyPythonFunction;
typedef opengm::functions::learnable::LPotts <ValueType,IndexType,LabelType> PyLPottsFunction;
+ typedef opengm::functions::learnable::LUnary <ValueType,IndexType,LabelType> PyLUnaryFunction;
if(fname==std::string("explicit")){
return gm. template reserveFunctions<PyExplicitFunction>(size);
@@ -709,6 +710,12 @@ namespace pygm {
else if(fname==std::string("python")){
return gm. template reserveFunctions<PyPythonFunction>(size);
}
+ else if(fname==std::string("lpotts")){
+ return gm. template reserveFunctions<PyLPottsFunction>(size);
+ }
+ else if(fname==std::string("lunary")){
+ return gm. template reserveFunctions<PyLUnaryFunction>(size);
+ }
else{
throw opengm::RuntimeError(fname + std::string(" is an unknown function type name"));
}
@@ -1460,7 +1467,7 @@ void export_gm() {
typedef opengm::SparseFunction <ValueType,IndexType,LabelType> PySparseFunction;
typedef opengm::python::PythonFunction <ValueType,IndexType,LabelType> PyPythonFunction;
typedef opengm::functions::learnable::LPotts <ValueType,IndexType,LabelType> PyLPottsFunction;
-
+ typedef opengm::functions::learnable::LUnary <ValueType,IndexType,LabelType> PyLUnaryFunction;
typedef typename PyGm::FunctionIdentifier PyFid;
typedef typename PyGm::FactorType PyFactor;
@@ -1840,7 +1847,7 @@ void export_gm() {
.def("_addFunctions_vector",&pygm::addFunctionsGenericVectorPy<PyGm,PySparseFunction>,return_value_policy<manage_new_object>(),args("functions"),"todo")
.def("_addFunctions_vector",&pygm::addFunctionsGenericVectorPy<PyGm,PyPythonFunction>,return_value_policy<manage_new_object>(),args("functions"),"todo")
-
+ .def("_addFunction",&pygm::addFunctionGenericPy<PyGm,PyLUnaryFunction>,args("function"))
.def("_addFunction",&pygm::addFunctionGenericPy<PyGm,PyLPottsFunction>,args("function"))
.def("_addFunction",&pygm::addFunctionGenericPy<PyGm,PyPottsFunction>,args("function"))
.def("_addFunction",&pygm::addFunctionGenericPy<PyGm,PyPottsNFunction>,args("function"))
--
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