[opengm] 84/386: introduce default LossParameter

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Wed Aug 31 08:35:09 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 359999ded271e6d7601214c70e1076f1c6d27037
Author: mschiegg <martin.schiegg at iwr.uni-heidelberg.de>
Date:   Wed Dec 17 13:26:15 2014 +0100

    introduce default LossParameter
---
 include/opengm/learning/dataset/dataset.hxx        |  1 +
 .../opengm/learning/dataset/editabledataset.hxx    |  4 +--
 src/interfaces/python/opengm/learning/learning.cxx |  1 +
 .../python/opengm/learning/pyDataset.cxx           | 29 ++++++++++++++++++----
 4 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/include/opengm/learning/dataset/dataset.hxx b/include/opengm/learning/dataset/dataset.hxx
index 0add387..3fc724a 100644
--- a/include/opengm/learning/dataset/dataset.hxx
+++ b/include/opengm/learning/dataset/dataset.hxx
@@ -27,6 +27,7 @@ namespace opengm {
          bool                          unlockModel(const size_t i)             { OPENGM_ASSERT(count_[i]>0); --count_[i]; }
          const GM&                     getModel(const size_t i) const          { return gms_[i]; } 
          const GMWITHLOSS&             getModelWithLoss(const size_t i)const   { return gmsWithLoss_[i]; }
+         const LossParameterType&      getLossParameters(const size_t i)const  { return lossParams_[i]; }
          const std::vector<LabelType>& getGT(const size_t i) const             { return gts_[i]; }
          Weights&                      getWeights()                            { return weights_; } 
          size_t                        getNumberOfWeights() const              { return weights_.numberOfWeights(); }
diff --git a/include/opengm/learning/dataset/editabledataset.hxx b/include/opengm/learning/dataset/editabledataset.hxx
index 9df9b3f..560bcbb 100644
--- a/include/opengm/learning/dataset/editabledataset.hxx
+++ b/include/opengm/learning/dataset/editabledataset.hxx
@@ -29,8 +29,8 @@ namespace opengm {
          EditableDataset(size_t numInstances=0) : Dataset<GM, LOSS>(numInstances) {}
          EditableDataset(std::vector<GM>& gms, std::vector<GTVector >& gts, std::vector<LossParameterType>& lossParams);
 
-         void setInstance(const size_t i, GM& gm, GTVector& gt, LossParameterType& p);
-         void pushBackInstance(GM& gm, GTVector& gt, LossParameterType& p);
+         void setInstance(const size_t i, GM& gm, GTVector& gt, LossParameterType& p=LossParameterType());
+         void pushBackInstance(GM& gm, GTVector& gt, LossParameterType& p=LossParameterType());
          void setWeights(Weights& w);
       };
 
diff --git a/src/interfaces/python/opengm/learning/learning.cxx b/src/interfaces/python/opengm/learning/learning.cxx
index 00daf80..32f633a 100644
--- a/src/interfaces/python/opengm/learning/learning.cxx
+++ b/src/interfaces/python/opengm/learning/learning.cxx
@@ -44,4 +44,5 @@ BOOST_PYTHON_MODULE_INIT(_learning) {
     // templated datasets
     opengm::export_dataset<op::GmAdder, ol::HammingLoss >("DatasetWithHammingLoss");
     opengm::export_dataset<op::GmAdder, ol::NoLoss >("DatasetWithNoLoss");
+    opengm::export_dataset<op::GmAdder, ol::GeneralizedHammingLoss >("DatasetWithGeneralizedHammingLoss");
 }
diff --git a/src/interfaces/python/opengm/learning/pyDataset.cxx b/src/interfaces/python/opengm/learning/pyDataset.cxx
index 6a27422..ca7aafd 100644
--- a/src/interfaces/python/opengm/learning/pyDataset.cxx
+++ b/src/interfaces/python/opengm/learning/pyDataset.cxx
@@ -16,25 +16,42 @@ using namespace boost::python;
 namespace opengm{
 
 template<class GM, class LOSS>
-void pySetInstance(opengm::datasets::EditableDataset<GM, LOSS>& ds,
+void pySetInstanceWithLossParam(opengm::datasets::EditableDataset<GM, LOSS>& ds,
                    const size_t i,
                    GM& gm,
                    const opengm::python::NumpyView<typename GM::LabelType,1>& gt,
-                   typename LOSS::Parameter& param) {
+                   typename LOSS::Parameter param) {
     std::vector<typename GM::LabelType> gt_vector(gt.begin(), gt.end());
     ds.setInstance(i, gm, gt_vector, param);
 }
 
 template<class GM, class LOSS>
-void pyPushBackInstance(opengm::datasets::EditableDataset<GM,LOSS>& ds,
+void pySetInstance(opengm::datasets::EditableDataset<GM, LOSS>& ds,
+                   const size_t i,
+                   GM& gm,
+                   const opengm::python::NumpyView<typename GM::LabelType,1>& gt
+                   ) {
+    pySetInstanceWithLossParam(ds, i, gm, gt, typename LOSS::Parameter());
+}
+
+template<class GM, class LOSS>
+void pyPushBackInstanceWithLossParam(opengm::datasets::EditableDataset<GM,LOSS>& ds,
                         GM& gm,
                         const opengm::python::NumpyView<typename GM::LabelType,1>& gt,
-                        typename LOSS::Parameter& param) {
+                        typename LOSS::Parameter param) {
     std::vector<typename GM::LabelType> gt_vector(gt.begin(), gt.end());
     ds.pushBackInstance(gm, gt_vector, param);
 }
 
 template<class GM, class LOSS>
+void pyPushBackInstance(opengm::datasets::EditableDataset<GM,LOSS>& ds,
+                        GM& gm,
+                        const opengm::python::NumpyView<typename GM::LabelType,1>& gt
+                        ) {
+    pyPushBackInstanceWithLossParam(ds, gm, gt, typename LOSS::Parameter());
+}
+
+template<class GM, class LOSS>
 void export_dataset(const std::string& className){
     typedef opengm::datasets::EditableDataset<GM,LOSS > PyDataset;
 
@@ -48,7 +65,9 @@ void export_dataset(const std::string& className){
            .def("getNumberOfWeights", &PyDataset::getNumberOfWeights)
            .def("getNumberOfModels", &PyDataset::getNumberOfModels)
            .def("setInstance", &pySetInstance<GM,LOSS>)
+           .def("setInstanceWithLossParam", &pySetInstanceWithLossParam<GM,LOSS>)
            .def("pushBackInstance", &pyPushBackInstance<GM,LOSS>)
+           .def("pushBackInstanceWithLossParam", &pyPushBackInstanceWithLossParam<GM,LOSS>)
            .def("setWeights", &PyDataset::setWeights)
    ;
 
@@ -57,6 +76,6 @@ void export_dataset(const std::string& className){
 
 template void export_dataset<opengm::python::GmAdder, opengm::learning::HammingLoss> (const std::string& className);
 template void export_dataset<opengm::python::GmAdder, opengm::learning::NoLoss> (const std::string& className);
-//template void export_dataset<opengm::python::GmAdder, opengm::learning::GeneralizedHammingLoss> (const std::string& className);
+template void export_dataset<opengm::python::GmAdder, opengm::learning::GeneralizedHammingLoss> (const std::string& className);
 
 }

-- 
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