[shark] 56/58: CART/RF: unified const syntax

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Wed Mar 16 10:05:34 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch master
in repository shark.

commit 37e13d2b73e1acb86d52bf9439e55cdf8dccf17e
Author: Jakob Wrigley <wrigleyster at gmail.com>
Date:   Fri Nov 27 12:58:38 2015 +0100

    CART/RF: unified const syntax
---
 include/shark/Algorithms/Trainers/CARTTrainer.h |  2 +-
 include/shark/Algorithms/Trainers/RFTrainer.h   | 20 ++++++++++----------
 include/shark/Models/Trees/CARTClassifier.h     | 24 ++++++++++++------------
 include/shark/Models/Trees/RFClassifier.h       |  2 +-
 src/Algorithms/CARTTrainer.cpp                  |  2 +-
 src/Algorithms/RFTrainer.cpp                    | 18 +++++++++---------
 6 files changed, 34 insertions(+), 34 deletions(-)

diff --git a/include/shark/Algorithms/Trainers/CARTTrainer.h b/include/shark/Algorithms/Trainers/CARTTrainer.h
index 154ff55..4fc61a4 100644
--- a/include/shark/Algorithms/Trainers/CARTTrainer.h
+++ b/include/shark/Algorithms/Trainers/CARTTrainer.h
@@ -141,7 +141,7 @@ protected:
 	///Regression functions
 	SHARK_EXPORT_SYMBOL SplitMatrixType buildTree(AttributeTables const& tables, RegressionDataset const& dataset, std::vector<RealVector> const& labels, std::size_t nodeId, std::size_t trainSize);
 	///Calculates the total sum of squares
-	SHARK_EXPORT_SYMBOL double totalSumOfSquares(std::vector<RealVector> const& labels, std::size_t start, std::size_t length, const RealVector& sumLabel);
+	SHARK_EXPORT_SYMBOL double totalSumOfSquares(std::vector<RealVector> const& labels, std::size_t start, std::size_t length, RealVector const& sumLabel);
 	///Calculates the mean of a vector of labels
 	SHARK_EXPORT_SYMBOL RealVector mean(std::vector<RealVector> const& labels);
 
diff --git a/include/shark/Algorithms/Trainers/RFTrainer.h b/include/shark/Algorithms/Trainers/RFTrainer.h
index e122551..e51aa46 100644
--- a/include/shark/Algorithms/Trainers/RFTrainer.h
+++ b/include/shark/Algorithms/Trainers/RFTrainer.h
@@ -89,10 +89,10 @@ public:
 	{ return "RFTrainer"; }
 
 	/// Train a random forest for classification.
-	SHARK_EXPORT_SYMBOL void train(RFClassifier& model, const ClassificationDataset& dataset);
+	SHARK_EXPORT_SYMBOL void train(RFClassifier& model, ClassificationDataset const& dataset);
 
 	/// Train a random forest for regression.
-	SHARK_EXPORT_SYMBOL void train(RFClassifier& model, const RegressionDataset& dataset);
+	SHARK_EXPORT_SYMBOL void train(RFClassifier& model, RegressionDataset const& dataset);
 
 	/// Set the number of random attributes to investigate at each node.
 	SHARK_EXPORT_SYMBOL void setMTry(std::size_t mtry);
@@ -140,31 +140,31 @@ protected:
 	SHARK_EXPORT_SYMBOL void createAttributeTables(Data<RealVector> const& dataset, AttributeTables& tables);
 
 	/// Create a count matrix as used in the classification case.
-	SHARK_EXPORT_SYMBOL void createCountMatrix(const ClassificationDataset& dataset, boost::unordered_map<std::size_t, std::size_t>& cAbove);
+	SHARK_EXPORT_SYMBOL void createCountMatrix(ClassificationDataset const& dataset, boost::unordered_map<std::size_t, std::size_t>& cAbove);
 
 	// Split attribute tables into left and right parts.
-	SHARK_EXPORT_SYMBOL void splitAttributeTables(const AttributeTables& tables, std::size_t index, std::size_t valIndex, AttributeTables& LAttributeTables, AttributeTables& RAttributeTables);
+	SHARK_EXPORT_SYMBOL void splitAttributeTables(AttributeTables const& tables, std::size_t index, std::size_t valIndex, AttributeTables& LAttributeTables, AttributeTables& RAttributeTables);
 
 	/// Build a decision tree for classification
-	SHARK_EXPORT_SYMBOL CARTClassifier<RealVector>::SplitMatrixType buildTree(AttributeTables& tables, const ClassificationDataset& dataset, boost::unordered_map<std::size_t, std::size_t>& cAbove, std::size_t nodeId);
+	SHARK_EXPORT_SYMBOL CARTClassifier<RealVector>::SplitMatrixType buildTree(AttributeTables& tables, ClassificationDataset const& dataset, boost::unordered_map<std::size_t, std::size_t>& cAbove, std::size_t nodeId);
 
 	/// Builds a decision tree for regression
-	SHARK_EXPORT_SYMBOL CARTClassifier<RealVector>::SplitMatrixType buildTree(AttributeTables& tables, const RegressionDataset& dataset, const std::vector<RealVector>& labels, std::size_t nodeId);
+	SHARK_EXPORT_SYMBOL CARTClassifier<RealVector>::SplitMatrixType buildTree(AttributeTables& tables, RegressionDataset const& dataset, std::vector<RealVector> const& labels, std::size_t nodeId);
 
 	/// comparison function for sorting an attributeTable
-	SHARK_EXPORT_SYMBOL static bool tableSort(const RFAttribute& v1, const RFAttribute& v2);
+	SHARK_EXPORT_SYMBOL static bool tableSort(RFAttribute const& v1, RFAttribute const& v2);
 
 	/// Generate a histogram from the count matrix.
 	SHARK_EXPORT_SYMBOL RealVector hist(boost::unordered_map<std::size_t, std::size_t> countMatrix);
 
 	/// Average label over a vector.
-	SHARK_EXPORT_SYMBOL RealVector average(const std::vector<RealVector>& labels);
+	SHARK_EXPORT_SYMBOL RealVector average(std::vector<RealVector> const& labels);
 
 	/// Calculate the Gini impurity of the countMatrix
-	SHARK_EXPORT_SYMBOL double gini(boost::unordered_map<std::size_t, std::size_t>& countMatrix, std::size_t n);
+	SHARK_EXPORT_SYMBOL double gini(boost::unordered_map<std::size_t, std::size_t> & countMatrix, std::size_t n);
 
 	/// Total Sum Of Squares
-	SHARK_EXPORT_SYMBOL double totalSumOfSquares(std::vector<RealVector>& labels, std::size_t from, std::size_t to, const RealVector& sumLabel);
+	SHARK_EXPORT_SYMBOL double totalSumOfSquares(std::vector<RealVector>& labels, std::size_t from, std::size_t to, RealVector const& sumLabel);
 
 	/// Generate random table indices.
 	SHARK_EXPORT_SYMBOL void generateRandomTableIndicies(std::set<std::size_t>& tableIndicies);
diff --git a/include/shark/Models/Trees/CARTClassifier.h b/include/shark/Models/Trees/CARTClassifier.h
index b602fbf..6755781 100644
--- a/include/shark/Models/Trees/CARTClassifier.h
+++ b/include/shark/Models/Trees/CARTClassifier.h
@@ -123,13 +123,13 @@ public:
 	std::string name() const
 	{ return "CARTClassifier"; }
 
-	boost::shared_ptr<State> createState()const{
+	boost::shared_ptr<State> createState() const{
 		return boost::shared_ptr<State>(new EmptyState());
 	}
 
 	using base_type::eval;
 	/// \brief Evaluate the Tree on a batch of patterns
-	void eval(const BatchInputType& patterns, BatchOutputType& outputs)const{
+	void eval(BatchInputType const& patterns, BatchOutputType & outputs) const{
 		std::size_t numPatterns = shark::size(patterns);
 		//evaluate the first pattern alone and create the batch output from that
 		LabelType const& firstResult = evalPattern(row(patterns,0));
@@ -142,11 +142,11 @@ public:
 		}
 	}
 	
-	void eval(const BatchInputType& patterns, BatchOutputType& outputs, State& state)const{
+	void eval(BatchInputType const& patterns, BatchOutputType & outputs, State& state) const{
 		eval(patterns,outputs);
 	}
 	/// \brief Evaluate the Tree on a single pattern
-	void eval(RealVector const & pattern, LabelType& output){
+	void eval(RealVector const& pattern, LabelType& output){
 		output = evalPattern(pattern);		
 	}
 
@@ -162,7 +162,7 @@ public:
 	}
 
 	/// \brief The model does not have any parameters.
-	std::size_t numberOfParameters()const{
+	std::size_t numberOfParameters() const{
 		return 0;
 	}
 
@@ -172,7 +172,7 @@ public:
 	}
 
 	/// \brief The model does not have any parameters.
-	void setParameterVector(const RealVector& param) {
+	void setParameterVector(RealVector const& param) {
 		SHARK_ASSERT(param.size() == 0);
 	}
 
@@ -224,7 +224,7 @@ public:
 	}
 
 	/// Compute oob error, given an oob dataset (Regression)
-	void computeOOBerror(const RegressionDataset& dataOOB){
+	void computeOOBerror(RegressionDataset const& dataOOB){
 		// define loss
 		SquaredLoss<RealVector, RealVector> lossOOB;
 
@@ -246,7 +246,7 @@ public:
 	}
 
 	/// Compute feature importances, given an oob dataset (Classification)
-	void computeFeatureImportances(const ClassificationDataset& dataOOB){
+	void computeFeatureImportances(ClassificationDataset const& dataOOB){
 		m_featureImportances.resize(m_inputDimension);
 
 		// define loss
@@ -281,7 +281,7 @@ public:
 	}
 
 	/// Compute feature importances, given an oob dataset (Regression)
-	void computeFeatureImportances(const RegressionDataset& dataOOB){
+	void computeFeatureImportances(RegressionDataset const& dataOOB){
 		m_featureImportances.resize(m_inputDimension);
 
 		// define loss
@@ -320,7 +320,7 @@ protected:
 	SplitMatrixType m_splitMatrix;
 	
 	/// \brief Finds the index of the node with a certain nodeID in an unoptimized split matrix.
-	std::size_t findNode(std::size_t nodeId)const{
+	std::size_t findNode(std::size_t nodeId) const{
 		std::size_t index = 0;
 		for(; nodeId != m_splitMatrix[index].nodeId; ++index);
 		return index;
@@ -330,7 +330,7 @@ protected:
 	/// The optimization is done by changing the index of the children
 	/// to use indices instead of node ID.
 	/// Furthermore, the node IDs are converted to index numbers.
-	void optimizeSplitMatrix(SplitMatrixType& splitMatrix)const{
+	void optimizeSplitMatrix(SplitMatrixType& splitMatrix) const{
 		for(std::size_t i = 0; i < splitMatrix.size(); i++){
 			splitMatrix[i].leftNodeId = findNode(splitMatrix[i].leftNodeId);
 			splitMatrix[i].rightNodeId = findNode(splitMatrix[i].rightNodeId);
@@ -342,7 +342,7 @@ protected:
 	
 	/// Evaluate the CART tree on a single sample
 	template<class Vector>
-	LabelType const& evalPattern(Vector const& pattern)const{
+	LabelType const& evalPattern(Vector const& pattern) const{
 		std::size_t nodeId = 0;
 		while(m_splitMatrix[nodeId].leftNodeId != 0){
 			if(pattern[m_splitMatrix[nodeId].attributeIndex]<=m_splitMatrix[nodeId].attributeValue){
diff --git a/include/shark/Models/Trees/RFClassifier.h b/include/shark/Models/Trees/RFClassifier.h
index d05803a..b1987af 100644
--- a/include/shark/Models/Trees/RFClassifier.h
+++ b/include/shark/Models/Trees/RFClassifier.h
@@ -52,7 +52,7 @@ typedef std::vector<SplitMatrixType> ForestInfo;
 /// Random Forests. Leo Breiman. Machine Learning, 1(45), pages 5-32. Springer, 2001.<br/>
 ///
 /// \par
-/// It is a ensemble learner that uses multiple decision trees built
+/// It is an ensemble learner that uses multiple decision trees built
 /// using the CART methodology.
 ///
 class RFClassifier : public MeanModel<CARTClassifier<RealVector> >
diff --git a/src/Algorithms/CARTTrainer.cpp b/src/Algorithms/CARTTrainer.cpp
index 33a9160..3ae5379 100644
--- a/src/Algorithms/CARTTrainer.cpp
+++ b/src/Algorithms/CARTTrainer.cpp
@@ -477,7 +477,7 @@ RealVector CARTTrainer::mean(std::vector<RealVector> const& labels){
 /**
  * Returns the Total Sum of Squares
  */
-double CARTTrainer::totalSumOfSquares(std::vector<RealVector> const& labels, std::size_t start, std::size_t length, const RealVector& sumLabel){
+double CARTTrainer::totalSumOfSquares(std::vector<RealVector> const& labels, std::size_t start, std::size_t length, RealVector const& sumLabel){
 	if (length < 1)
 		throw SHARKEXCEPTION("[CARTTrainer::totalSumOfSquares] length < 1");
 	if (start+length > labels.size())
diff --git a/src/Algorithms/RFTrainer.cpp b/src/Algorithms/RFTrainer.cpp
index 2651aef..c3ecdce 100644
--- a/src/Algorithms/RFTrainer.cpp
+++ b/src/Algorithms/RFTrainer.cpp
@@ -84,7 +84,7 @@ void RFTrainer::setDefaults(){
 }
 
 // Regression
-void RFTrainer::train(RFClassifier& model, const RegressionDataset& dataset)
+void RFTrainer::train(RFClassifier& model, RegressionDataset const& dataset)
 {
 	model.clearModels();   // added by TG 23.02.2015
 
@@ -163,7 +163,7 @@ void RFTrainer::train(RFClassifier& model, const RegressionDataset& dataset)
 }
 
 // Classification
-void RFTrainer::train(RFClassifier& model, const ClassificationDataset& dataset)
+void RFTrainer::train(RFClassifier& model, ClassificationDataset const& dataset)
 {
 	model.clearModels();
 
@@ -256,7 +256,7 @@ void RFTrainer::setOOBratio(double ratio){
 
 
 
-CARTClassifier<RealVector>::SplitMatrixType RFTrainer::buildTree(AttributeTables& tables, const ClassificationDataset& dataset, boost::unordered_map<std::size_t, std::size_t>& cAbove, std::size_t nodeId ){
+CARTClassifier<RealVector>::SplitMatrixType RFTrainer::buildTree(AttributeTables& tables, ClassificationDataset const& dataset, boost::unordered_map<std::size_t, std::size_t>& cAbove, std::size_t nodeId ){
 	CARTClassifier<RealVector>::SplitMatrixType lSplitMatrix, rSplitMatrix;
 
 	//Construct split matrix
@@ -376,7 +376,7 @@ RealVector RFTrainer::hist(boost::unordered_map<std::size_t, std::size_t> countM
 	return histogram;
 }
 
-CARTClassifier<RealVector>::SplitMatrixType RFTrainer::buildTree(AttributeTables& tables, const RegressionDataset& dataset, const std::vector<RealVector>& labels, std::size_t nodeId ){
+CARTClassifier<RealVector>::SplitMatrixType RFTrainer::buildTree(AttributeTables& tables, RegressionDataset const& dataset, std::vector<RealVector> const& labels, std::size_t nodeId ){
 
 	//Construct split matrix
 	CARTClassifier<RealVector>::SplitInfo splitInfo;
@@ -506,7 +506,7 @@ CARTClassifier<RealVector>::SplitMatrixType RFTrainer::buildTree(AttributeTables
 /**
  * Returns the average vector of a vector of real vectors
  */
-RealVector RFTrainer::average(const std::vector<RealVector>& labels){
+RealVector RFTrainer::average(std::vector<RealVector> const& labels){
 	RealVector avg(labels[0]);
 	for(std::size_t i = 1; i < labels.size(); i++){
 		avg += labels[i];
@@ -535,7 +535,7 @@ double RFTrainer::totalSumOfSquares(std::vector<RealVector>& labels, std::size_t
  * Returns two attribute tables: LAttrbuteTables and RAttrbuteTables
  * Calculated from splitting tables at (index, valIndex)
  */
-void RFTrainer::splitAttributeTables(const AttributeTables& tables, std::size_t index, std::size_t valIndex, AttributeTables& LAttributeTables, AttributeTables& RAttributeTables){
+void RFTrainer::splitAttributeTables(AttributeTables const& tables, std::size_t index, std::size_t valIndex, AttributeTables& LAttributeTables, AttributeTables& RAttributeTables){
 	AttributeTable table;
 
 	//Build a hash table for fast lookup
@@ -572,7 +572,7 @@ void RFTrainer::generateRandomTableIndicies(set<std::size_t>& tableIndicies){
 ///Calculates the Gini impurity of a node. The impurity is defined as
 ///1-sum_j p(j|t)^2
 ///i.e the 1 minus the sum of the squared probability of observing class j in node t
-double RFTrainer::gini(boost::unordered_map<std::size_t, std::size_t>& countMatrix, std::size_t n){
+double RFTrainer::gini(boost::unordered_map<std::size_t, std::size_t> & countMatrix, std::size_t n){
 	double res = 0;
 	boost::unordered_map<std::size_t, std::size_t>::iterator it;
 	if(n){
@@ -610,13 +610,13 @@ void RFTrainer::createAttributeTables(Data<RealVector> const& dataset, Attribute
 }
 
 
-void RFTrainer::createCountMatrix(const ClassificationDataset& dataset, boost::unordered_map<std::size_t, std::size_t>& cAbove){
+void RFTrainer::createCountMatrix(ClassificationDataset const& dataset, boost::unordered_map<std::size_t, std::size_t>& cAbove){
 	std::size_t elements = dataset.numberOfElements();
 	for(std::size_t i = 0 ; i < elements; i++){
 		cAbove[dataset.element(i).label]++;
 	}
 }
 
-bool RFTrainer::tableSort(const RFAttribute& v1, const RFAttribute& v2) {
+bool RFTrainer::tableSort(RFAttribute const& v1, RFAttribute const& v2) {
 	return v1.value < v2.value;
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/shark.git



More information about the debian-science-commits mailing list