<commit_before>#include "opengm/unittests/test.hxx"
#include "opengm/graphicalmodel/graphicalmodel.hxx"
#include "opengm/operations/adder.hxx"
#include "opengm/learning/struct-max-margin.hxx"
#include "opengm/learning/dataset/testdataset.hxx"
#include "opengm/learning/loss/hammingloss.hxx"
#include "opengm/inference/bruteforce.hxx"

template<class T>
struct LearningTest {

	typedef T                                                                  ValueType;
	typedef OPENGM_TYPELIST_2(
			opengm::ExplicitFunction<T>,
			opengm::functions::learnable::LPotts<T>)                           FunctionTypeList;
	typedef opengm::GraphicalModel<ValueType, opengm::Adder, FunctionTypeList> GraphicalModelType;
	typedef opengm::datasets::TestDataset<GraphicalModelType>                  DatasetType;
	typedef typename DatasetType::ModelParameters                              ModelParameters;
	typedef opengm::learning::HammingLoss                                      LossGeneratorType;
	typedef opengm::Bruteforce<GraphicalModelType,opengm::Minimizer>           InferenceType;

	void testStructMaxMargin() {

		// create a dataset
		DatasetType dataset;

		// create a learning algorithm
		opengm::learning::StructMaxMargin<DatasetType, LossGeneratorType> structMaxMargin(dataset);

		// train
		typename InferenceType::Parameter infParams;
		structMaxMargin.template learn<InferenceType>(infParams);

		// get the result
		const ModelParameters& learntParameters = structMaxMargin.getModelParameters();
	}

	void run() {

		this->testStructMaxMargin();
   }
};

int
main() {
   std::cout << "Learning test...  " << std::endl;
   //{
   //   LearningTest<float >t;
   //   t.run();
   //}
   {
      LearningTest<double >t;
      t.run();
   }
   std::cout << "done.." << std::endl;
   return 0;
}
<commit_msg>add couts<commit_after>#include "opengm/unittests/test.hxx"
#include "opengm/graphicalmodel/graphicalmodel.hxx"
#include "opengm/operations/adder.hxx"
#include "opengm/learning/struct-max-margin.hxx"
#include "opengm/learning/dataset/testdataset.hxx"
#include "opengm/learning/loss/hammingloss.hxx"
#include "opengm/inference/bruteforce.hxx"

template<class T>
struct LearningTest {

	typedef T                                                                  ValueType;
	typedef OPENGM_TYPELIST_2(
			opengm::ExplicitFunction<T>,
			opengm::functions::learnable::LPotts<T>)                           FunctionTypeList;
	typedef opengm::GraphicalModel<ValueType, opengm::Adder, FunctionTypeList> GraphicalModelType;
	typedef opengm::datasets::TestDataset<GraphicalModelType>                  DatasetType;
	typedef typename DatasetType::ModelParameters                              ModelParameters;
	typedef opengm::learning::HammingLoss                                      LossGeneratorType;
	typedef opengm::Bruteforce<GraphicalModelType,opengm::Minimizer>           InferenceType;

	void testStructMaxMargin() {

		// create a dataset
		DatasetType dataset;

		// create a learning algorithm
		opengm::learning::StructMaxMargin<DatasetType, LossGeneratorType> structMaxMargin(dataset);

		// train
		typename InferenceType::Parameter infParams;
		structMaxMargin.template learn<InferenceType>(infParams);

		// get the result
		const ModelParameters& learntParameters = structMaxMargin.getModelParameters(); 
                std::cout << learntParameters.numberOfParameters()<<std::endl;
                for(size_t i=0; i<learntParameters.numberOfParameters();++i)
                   std::cout << learntParameters[i] << " ";
                std::cout << std::endl;
	}

	void run() {

		this->testStructMaxMargin();
   }
};

int
main() {
   std::cout << "Learning test...  " << std::endl;
   //{
   //   LearningTest<float >t;
   //   t.run();
   //}
   {
      LearningTest<double >t;
      t.run();
   }
   std::cout << "done.." << std::endl;
   return 0;
}

{'fraction_non_alphanumeric': 0.11811837684156112, 'fraction_numerical': 0.0012923235978288964, 'mean_word_length': 2.9773895169578624, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5262258', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1160, 'n_words': 192}