[shark] 49/58: incorporated advise from Tobias at pull request

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Wed Mar 16 10:05:33 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 df0bc82e992a2e69863054985ae1e62dc13d8632
Author: Oswin <oswin.krause at di.ku.dk>
Date:   Sun Feb 28 22:39:33 2016 +0100

    incorporated advise from Tobias at pull request
---
 Test/Algorithms/DirectSearch/MOCMA.cpp             |  4 +--
 Test/Algorithms/DirectSearch/RealCodedNSGAII.cpp   |  1 +
 Test/Algorithms/DirectSearch/SMS-EMOA.cpp          |  1 +
 Test/Algorithms/DirectSearch/SteadyStateMOCMA.cpp  |  1 +
 Test/Algorithms/testFunction.h                     |  1 +
 examples/EA/SOO/CMASimple.tpp                      |  4 +--
 .../Algorithms/DirectSearch/CrossEntropyMethod.h   |  8 +++---
 .../DirectSearch/Indicators/HypervolumeIndicator.h |  1 +
 include/shark/Algorithms/DirectSearch/MOCMA.h      | 29 +++++++++++----------
 .../Algorithms/DirectSearch/RealCodedNSGAII.h      | 27 +++++++++----------
 include/shark/Algorithms/DirectSearch/SMS-EMOA.h   | 27 +++++++++----------
 .../Algorithms/DirectSearch/SteadyStateMOCMA.h     | 30 ++++++++++++----------
 include/shark/Models/Trees/RFClassifier.h          |  5 ++--
 .../ObjectiveFunctions/Loss/EpsilonHingeLoss.h     |  3 ---
 .../Loss/SquaredEpsilonHingeLoss.h                 |  3 +--
 src/Algorithms/DirectSearch/CMA.cpp                |  2 ++
 src/Algorithms/DirectSearch/CMSA.cpp               |  1 +
 src/Algorithms/DirectSearch/CrossEntropyMethod.cpp | 22 +++++++---------
 18 files changed, 85 insertions(+), 85 deletions(-)

diff --git a/Test/Algorithms/DirectSearch/MOCMA.cpp b/Test/Algorithms/DirectSearch/MOCMA.cpp
index 664e987..0afcdc8 100644
--- a/Test/Algorithms/DirectSearch/MOCMA.cpp
+++ b/Test/Algorithms/DirectSearch/MOCMA.cpp
@@ -27,6 +27,7 @@ void testObjectiveFunctionMOO(
 ){
 	MOCMA mocma;
 	mocma.mu() = mu;
+	f.init();
 	mocma.init(f);
 	
 	for(std::size_t i = 0; i != iterations; ++i){
@@ -53,9 +54,6 @@ BOOST_AUTO_TEST_CASE( MOCMA_HYPERVOLUME_Functions ) {
 	DTLZ4 dtlz4(5);
 	double dtlz4Volume = 120.178966;
 	testObjectiveFunctionMOO(dtlz4,10,dtlz4Volume,1000,reference);
-	//~ DTLZ7 dtlz7(5); //not sure whether correctly implemented
-	//~ double dtlz7Volume = 115.964708;
-	//~ testObjectiveFunctionMOO(dtlz7,10,dtlz7Volume,10000,reference);
 	ZDT1 zdt1(5);
 	double zdt1Volume = 120.613761;
 	testObjectiveFunctionMOO(zdt1,10,zdt1Volume,1000,reference);
diff --git a/Test/Algorithms/DirectSearch/RealCodedNSGAII.cpp b/Test/Algorithms/DirectSearch/RealCodedNSGAII.cpp
index 1065d84..87790b6 100644
--- a/Test/Algorithms/DirectSearch/RealCodedNSGAII.cpp
+++ b/Test/Algorithms/DirectSearch/RealCodedNSGAII.cpp
@@ -23,6 +23,7 @@ double testObjectiveFunctionMOOHelper(
 ){
 	RealCodedNSGAII realCodedNSGAII;
 	realCodedNSGAII.mu() = mu;
+	f.init();
 	realCodedNSGAII.init(f);
 	
 	for(std::size_t i = 0; i != iterations; ++i){
diff --git a/Test/Algorithms/DirectSearch/SMS-EMOA.cpp b/Test/Algorithms/DirectSearch/SMS-EMOA.cpp
index 5440164..58bf65f 100644
--- a/Test/Algorithms/DirectSearch/SMS-EMOA.cpp
+++ b/Test/Algorithms/DirectSearch/SMS-EMOA.cpp
@@ -23,6 +23,7 @@ double testObjectiveFunctionMOOHelper(
 ){
 	SMSEMOA smsemoa;
 	smsemoa.mu() = mu;
+	f.init();
 	smsemoa.init(f);
 	
 	for(std::size_t i = 0; i != iterations; ++i){
diff --git a/Test/Algorithms/DirectSearch/SteadyStateMOCMA.cpp b/Test/Algorithms/DirectSearch/SteadyStateMOCMA.cpp
index 07ef947..5bce3d7 100644
--- a/Test/Algorithms/DirectSearch/SteadyStateMOCMA.cpp
+++ b/Test/Algorithms/DirectSearch/SteadyStateMOCMA.cpp
@@ -27,6 +27,7 @@ void testObjectiveFunctionMOO(
 ){
 	SteadyStateMOCMA mocma;
 	mocma.mu() = mu;
+	f.init();
 	mocma.init(f);
 	
 	for(std::size_t i = 0; i != iterations; ++i){
diff --git a/Test/Algorithms/testFunction.h b/Test/Algorithms/testFunction.h
index aaa8853..7f5dc0b 100644
--- a/Test/Algorithms/testFunction.h
+++ b/Test/Algorithms/testFunction.h
@@ -32,6 +32,7 @@ BOOST_PARAMETER_FUNCTION(
 	std::vector<double> stats;
 
 	for( size_t trial =0;trial != static_cast<size_t>(trials);++trial ){
+		function.init();
 		optimizer.init(function);
 				
 		double error=0;
diff --git a/examples/EA/SOO/CMASimple.tpp b/examples/EA/SOO/CMASimple.tpp
index cf4e984..8cb1e20 100755
--- a/examples/EA/SOO/CMASimple.tpp
+++ b/examples/EA/SOO/CMASimple.tpp
@@ -52,8 +52,8 @@ int main( int argc, char ** argv ) {
 	// Initialize the optimizer for the objective function instance.
 	//###begin<optimizer>
 	CMA cma;
-	cma.setInitialSigma(0.1);
-	cma.init( sphere, sphere.proposeStartingPoint()); // Explicitely set initial global step size.
+	cma.setInitialSigma(0.1);// Explicitely set initial global step size.
+	cma.init( sphere, sphere.proposeStartingPoint()); 
 	//###end<optimizer>
 
 	// Iterate the optimizer until a solution of sufficient quality is found.
diff --git a/include/shark/Algorithms/DirectSearch/CrossEntropyMethod.h b/include/shark/Algorithms/DirectSearch/CrossEntropyMethod.h
index 5112eca..29ddcd4 100644
--- a/include/shark/Algorithms/DirectSearch/CrossEntropyMethod.h
+++ b/include/shark/Algorithms/DirectSearch/CrossEntropyMethod.h
@@ -181,8 +181,7 @@ namespace shark {
 
 		/** \brief Set all variance values */
 		void setVariance(double variance){
-			for(int i = 0; i < m_variance.size(); i++)
-				m_variance(i) = variance;
+				m_variance = blas::repeat(variance,m_variance.size());
 		}
 
 		/** \brief Access the current population mean. */
@@ -246,14 +245,13 @@ namespace shark {
 
 		RealVector m_variance; ///< Variance for sample parameters.
 
-		StrongNoisePtr m_noise; ///< Noise type to apply in the update of distribution parameters.
-
+		
 		RealVector m_mean; ///< The mean of the population.
 
 		unsigned m_counter; ///< Counter for generations.
 
 		Normal< Rng::rng_type > m_distribution; ///< Normal distribution.
-
+		StrongNoisePtr m_noise; ///< Noise type to apply in the update of distribution parameters.
 	};
 }
 
diff --git a/include/shark/Algorithms/DirectSearch/Indicators/HypervolumeIndicator.h b/include/shark/Algorithms/DirectSearch/Indicators/HypervolumeIndicator.h
index 8c31d8a..9b5c053 100644
--- a/include/shark/Algorithms/DirectSearch/Indicators/HypervolumeIndicator.h
+++ b/include/shark/Algorithms/DirectSearch/Indicators/HypervolumeIndicator.h
@@ -95,6 +95,7 @@ public:
 			copy.erase( copy.begin() + i );
 
 			indicatorValues[i] = ind( extractor, copy,referencePoint);
+			std::cout<<i<<" "<<indicatorValues[i]<<std::endl;
 		}
 
 		std::vector<double>::iterator it = std::max_element( indicatorValues.begin(), indicatorValues.end() );
diff --git a/include/shark/Algorithms/DirectSearch/MOCMA.h b/include/shark/Algorithms/DirectSearch/MOCMA.h
index 135d2c5..579b661 100644
--- a/include/shark/Algorithms/DirectSearch/MOCMA.h
+++ b/include/shark/Algorithms/DirectSearch/MOCMA.h
@@ -133,20 +133,20 @@ public:
 	 * \brief Initializes the algorithm for the supplied objective function.
 	 * 
 	 * \param [in] function The objective function.
-	 * \param [in] startingPoints A set of intiial search points.
+	 * \param [in] initialSearchPoints A set of intiial search points.
 	 */
 	void init( 
 		ObjectiveFunctionType& function, 
-		std::vector<SearchPointType> const& startingPoints
+		std::vector<SearchPointType> const& initialSearchPoints
 	){
 		checkFeatures(function);
-		std::vector<RealVector> values(startingPoints.size());
-		for(std::size_t i = 0; i != startingPoints.size(); ++i){
-			if(!function.isFeasible(startingPoints[i]))
+		std::vector<RealVector> values(initialSearchPoints.size());
+		for(std::size_t i = 0; i != initialSearchPoints.size(); ++i){
+			if(!function.isFeasible(initialSearchPoints[i]))
 				throw SHARKEXCEPTION("[MOCMA::init] starting point(s) not feasible");
-			values[i] = function.eval(startingPoints[i]);
+			values[i] = function.eval(initialSearchPoints[i]);
 		}
-		this->doInit(startingPoints,values,mu(),initialSigma() );
+		this->doInit(initialSearchPoints,values,mu(),initialSigma() );
 	}
 	
 	/**
@@ -165,34 +165,35 @@ protected:
 	typedef CMAIndividual<RealVector> IndividualType;
 
 	void doInit(
-		std::vector<SearchPointType> const& startingPoints,
+		std::vector<SearchPointType> const& initialSearchPoints,
 		std::vector<ResultType> const& functionValues,
 		std::size_t mu,
 		double initialSigma
 	){
+		SIZE_CHECK(initialSearchPoints.size() > 0);
 		m_mu = mu;
 		m_initialSigma = initialSigma;
 		
 		m_best.resize( mu );
 		m_parents.resize( mu );
-		std::size_t noVariables = startingPoints[0].size();
+		std::size_t noVariables = initialSearchPoints[0].size();
 
 		//if the number of supplied points is smaller than mu, fill everything in
 		std::size_t numPoints = 0;
-		if(startingPoints.size()<=mu){
-			numPoints = startingPoints.size();
+		if(initialSearchPoints.size()<=mu){
+			numPoints = initialSearchPoints.size();
 			for(std::size_t i = 0; i != numPoints; ++i){
 				m_parents[i] = IndividualType(noVariables,m_individualSuccessThreshold,m_initialSigma);
-				m_parents[i].searchPoint() = startingPoints[i];
+				m_parents[i].searchPoint() = initialSearchPoints[i];
 				m_parents[i].penalizedFitness() = functionValues[i];
 				m_parents[i].unpenalizedFitness() = functionValues[i];
 			}
 		}
 		//copy points randomly
 		for(std::size_t i = numPoints; i != mu; ++i){
-			std::size_t index = Rng::discrete(0,startingPoints.size()-1);
+			std::size_t index = Rng::discrete(0,initialSearchPoints.size()-1);
 			m_parents[i] = IndividualType(noVariables,m_individualSuccessThreshold,m_initialSigma);
-			m_parents[i].searchPoint() = startingPoints[index];
+			m_parents[i].searchPoint() = initialSearchPoints[index];
 			m_parents[i].penalizedFitness() = functionValues[index];
 			m_parents[i].unpenalizedFitness() = functionValues[index];
 		}
diff --git a/include/shark/Algorithms/DirectSearch/RealCodedNSGAII.h b/include/shark/Algorithms/DirectSearch/RealCodedNSGAII.h
index 71958c3..61d675c 100644
--- a/include/shark/Algorithms/DirectSearch/RealCodedNSGAII.h
+++ b/include/shark/Algorithms/DirectSearch/RealCodedNSGAII.h
@@ -140,18 +140,18 @@ public:
 	 * \brief Initializes the algorithm for the supplied objective function.
 	 * 
 	 * \param [in] function The objective function.
-	 * \param [in] startingPoints A set of intiial search points.
+	 * \param [in] initialSearchPoints A set of intiial search points.
 	 */
 	void init( 
 		ObjectiveFunctionType& function, 
-		std::vector<SearchPointType> const& startingPoints
+		std::vector<SearchPointType> const& initialSearchPoints
 	){
 		checkFeatures(function);
-		std::vector<RealVector> values(startingPoints.size());
-		for(std::size_t i = 0; i != startingPoints.size(); ++i){
-			if(!function.isFeasible(startingPoints[i]))
+		std::vector<RealVector> values(initialSearchPoints.size());
+		for(std::size_t i = 0; i != initialSearchPoints.size(); ++i){
+			if(!function.isFeasible(initialSearchPoints[i]))
 				throw SHARKEXCEPTION("[RealCodedNSGAII::init] starting point(s) not feasible");
-			values[i] = function.eval(startingPoints[i]);
+			values[i] = function.eval(initialSearchPoints[i]);
 		}
 		
 		std::size_t dim = function.numberOfVariables();
@@ -167,7 +167,7 @@ public:
 			throw SHARKEXCEPTION("[RealCodedNSGAII::init] Algorithm does only allow box constraints");
 		}
 		
-		doInit(startingPoints,values,lowerBounds, upperBounds, mu(), nm(), nc(), crossoverProbability());
+		doInit(initialSearchPoints,values,lowerBounds, upperBounds, mu(), nm(), nc(), crossoverProbability());
 	}
 	
 	/**
@@ -186,7 +186,7 @@ protected:
 	typedef shark::Individual<RealVector,RealVector> IndividualType;
 
 	void doInit(
-		std::vector<SearchPointType> const& startingPoints,
+		std::vector<SearchPointType> const& initialSearchPoints,
 		std::vector<ResultType> const& functionValues,
 		RealVector const& lowerBounds,
 		RealVector const& upperBounds,
@@ -195,6 +195,7 @@ protected:
 		double nc,
 		double crossover_prob
 	){
+		SIZE_CHECK(initialSearchPoints.size() > 0);
 		m_mu = mu;
 		m_mutation.m_nm = nm;
 		m_crossover.m_nc = nc;
@@ -203,18 +204,18 @@ protected:
 		m_parents.resize( mu );
 		//if the number of supplied points is smaller than mu, fill everything in
 		std::size_t numPoints = 0;
-		if(startingPoints.size()<=mu){
-			numPoints = startingPoints.size();
+		if(initialSearchPoints.size()<=mu){
+			numPoints = initialSearchPoints.size();
 			for(std::size_t i = 0; i != numPoints; ++i){
-				m_parents[i].searchPoint() = startingPoints[i];
+				m_parents[i].searchPoint() = initialSearchPoints[i];
 				m_parents[i].penalizedFitness() = functionValues[i];
 				m_parents[i].unpenalizedFitness() = functionValues[i];
 			}
 		}
 		//copy points randomly
 		for(std::size_t i = numPoints; i != mu; ++i){
-			std::size_t index = Rng::discrete(0,startingPoints.size()-1);
-			m_parents[i].searchPoint() = startingPoints[index];
+			std::size_t index = Rng::discrete(0,initialSearchPoints.size()-1);
+			m_parents[i].searchPoint() = initialSearchPoints[index];
 			m_parents[i].penalizedFitness() = functionValues[index];
 			m_parents[i].unpenalizedFitness() = functionValues[index];
 		}
diff --git a/include/shark/Algorithms/DirectSearch/SMS-EMOA.h b/include/shark/Algorithms/DirectSearch/SMS-EMOA.h
index c0d3482..b48014d 100644
--- a/include/shark/Algorithms/DirectSearch/SMS-EMOA.h
+++ b/include/shark/Algorithms/DirectSearch/SMS-EMOA.h
@@ -120,18 +120,18 @@ public:
 	 * \brief Initializes the algorithm for the supplied objective function.
 	 * 
 	 * \param [in] function The objective function.
-	 * \param [in] startingPoints A set of intiial search points.
+	 * \param [in] initialSearchPoints A set of intiial search points.
 	 */
 	void init( 
 		ObjectiveFunctionType& function, 
-		std::vector<SearchPointType> const& startingPoints
+		std::vector<SearchPointType> const& initialSearchPoints
 	){
 		checkFeatures(function);
-		std::vector<RealVector> values(startingPoints.size());
-		for(std::size_t i = 0; i != startingPoints.size(); ++i){
-			if(!function.isFeasible(startingPoints[i]))
+		std::vector<RealVector> values(initialSearchPoints.size());
+		for(std::size_t i = 0; i != initialSearchPoints.size(); ++i){
+			if(!function.isFeasible(initialSearchPoints[i]))
 				throw SHARKEXCEPTION("[SMS-EMOA::init] starting point(s) not feasible");
-			values[i] = function.eval(startingPoints[i]);
+			values[i] = function.eval(initialSearchPoints[i]);
 		}
 		
 		std::size_t dim = function.numberOfVariables();
@@ -146,7 +146,7 @@ public:
 		} else{
 			throw SHARKEXCEPTION("[SMS-EMOA::init] Algorithm does only allow box constraints");
 		}
-		doInit(startingPoints,values,lowerBounds, upperBounds,mu(),nm(),nc(),crossoverProbability());
+		doInit(initialSearchPoints,values,lowerBounds, upperBounds,mu(),nm(),nc(),crossoverProbability());
 	}
 
 	/**
@@ -165,7 +165,7 @@ protected:
 	typedef shark::Individual<RealVector,RealVector> IndividualType;
 
 	void doInit(
-		std::vector<SearchPointType> const& startingPoints,
+		std::vector<SearchPointType> const& initialSearchPoints,
 		std::vector<ResultType> const& functionValues,
 		RealVector const& lowerBounds,
 		RealVector const& upperBounds,
@@ -174,6 +174,7 @@ protected:
 		double nc,
 		double crossover_prob
 	){
+		SIZE_CHECK(initialSearchPoints.size() > 0);
 		m_mu = mu;
 		m_mutator.m_nm = nm;
 		m_crossover.m_nc = nc;
@@ -182,18 +183,18 @@ protected:
 		m_parents.resize( mu );
 		//if the number of supplied points is smaller than mu, fill everything in
 		std::size_t numPoints = 0;
-		if(startingPoints.size()<=mu){
-			numPoints = startingPoints.size();
+		if(initialSearchPoints.size()<=mu){
+			numPoints = initialSearchPoints.size();
 			for(std::size_t i = 0; i != numPoints; ++i){
-				m_parents[i].searchPoint() = startingPoints[i];
+				m_parents[i].searchPoint() = initialSearchPoints[i];
 				m_parents[i].penalizedFitness() = functionValues[i];
 				m_parents[i].unpenalizedFitness() = functionValues[i];
 			}
 		}
 		//copy points randomly
 		for(std::size_t i = numPoints; i != mu; ++i){
-			std::size_t index = Rng::discrete(0,startingPoints.size()-1);
-			m_parents[i].searchPoint() = startingPoints[index];
+			std::size_t index = Rng::discrete(0,initialSearchPoints.size()-1);
+			m_parents[i].searchPoint() = initialSearchPoints[index];
 			m_parents[i].penalizedFitness() = functionValues[index];
 			m_parents[i].unpenalizedFitness() = functionValues[index];
 		}
diff --git a/include/shark/Algorithms/DirectSearch/SteadyStateMOCMA.h b/include/shark/Algorithms/DirectSearch/SteadyStateMOCMA.h
index 415c010..5fc5931 100644
--- a/include/shark/Algorithms/DirectSearch/SteadyStateMOCMA.h
+++ b/include/shark/Algorithms/DirectSearch/SteadyStateMOCMA.h
@@ -130,20 +130,20 @@ public:
 	 * \brief Initializes the algorithm for the supplied objective function.
 	 * 
 	 * \param [in] function The objective function.
-	 * \param [in] startingPoints A set of intiial search points.
+	 * \param [in] initialSearchPoints A set of intiial search points.
 	 */
 	void init( 
 		ObjectiveFunctionType& function, 
-		std::vector<SearchPointType> const& startingPoints
+		std::vector<SearchPointType> const& initialSearchPoints
 	){
 		checkFeatures(function);
-		std::vector<RealVector> values(startingPoints.size());
-		for(std::size_t i = 0; i != startingPoints.size(); ++i){
-			if(!function.isFeasible(startingPoints[i]))
+		std::vector<RealVector> values(initialSearchPoints.size());
+		for(std::size_t i = 0; i != initialSearchPoints.size(); ++i){
+			if(!function.isFeasible(initialSearchPoints[i]))
 				throw SHARKEXCEPTION("[SteadyStateMOCMA::init] starting point(s) not feasible");
-			values[i] = function.eval(startingPoints[i]);
+			values[i] = function.eval(initialSearchPoints[i]);
 		}
-		this->doInit(startingPoints,values,mu(),initialSigma() );
+		this->doInit(initialSearchPoints,values,mu(),initialSigma() );
 	}
 	
 	/**
@@ -162,34 +162,36 @@ protected:
 	typedef CMAIndividual<RealVector> IndividualType;
 
 	void doInit(
-		std::vector<SearchPointType> const& startingPoints,
+		std::vector<SearchPointType> const& initialSearchPoints,
 		std::vector<ResultType> const& functionValues,
 		std::size_t mu,
 		double initialSigma
 	){
+		SIZE_CHECK(initialSearchPoints.size() > 0);
+		
 		m_mu = mu;
 		m_initialSigma = initialSigma;
 		
 		m_best.resize( mu );
 		m_parents.resize( mu );
-		std::size_t noVariables = startingPoints[0].size();
+		std::size_t noVariables = initialSearchPoints[0].size();
 
 		//if the number of supplied points is smaller than mu, fill everything in
 		std::size_t numPoints = 0;
-		if(startingPoints.size()<=mu){
-			numPoints = startingPoints.size();
+		if(initialSearchPoints.size()<=mu){
+			numPoints = initialSearchPoints.size();
 			for(std::size_t i = 0; i != numPoints; ++i){
 				m_parents[i] = IndividualType(noVariables,m_individualSuccessThreshold,m_initialSigma);
-				m_parents[i].searchPoint() = startingPoints[i];
+				m_parents[i].searchPoint() = initialSearchPoints[i];
 				m_parents[i].penalizedFitness() = functionValues[i];
 				m_parents[i].unpenalizedFitness() = functionValues[i];
 			}
 		}
 		//copy points randomly
 		for(std::size_t i = numPoints; i != mu; ++i){
-			std::size_t index = Rng::discrete(0,startingPoints.size()-1);
+			std::size_t index = Rng::discrete(0,initialSearchPoints.size()-1);
 			m_parents[i] = IndividualType(noVariables,m_individualSuccessThreshold,m_initialSigma);
-			m_parents[i].searchPoint() = startingPoints[index];
+			m_parents[i].searchPoint() = initialSearchPoints[index];
 			m_parents[i].penalizedFitness() = functionValues[index];
 			m_parents[i].unpenalizedFitness() = functionValues[index];
 		}
diff --git a/include/shark/Models/Trees/RFClassifier.h b/include/shark/Models/Trees/RFClassifier.h
index 0354a49..d05803a 100644
--- a/include/shark/Models/Trees/RFClassifier.h
+++ b/include/shark/Models/Trees/RFClassifier.h
@@ -118,7 +118,7 @@ public:
 
 	ForestInfo getForestInfo() const {
 		ForestInfo finfo(m_models.size());
-		for (int i=0; i<m_models.size(); ++i)
+		for (std::size_t i=0; i<m_models.size(); ++i)
 			finfo[i]=m_models[i].getSplitMatrix();
 		return finfo;
 	}
@@ -132,8 +132,7 @@ public:
 		else if (weights.size() != n_tree)
 			throw SHARKEXCEPTION("Weights must be the same number as trees");
 
-		for (int i=0; i<n_tree; ++i)
-		{
+		for (std::size_t i=0; i<n_tree; ++i){
 			m_models[i]=finfo[i];
 			m_weight.push_back(we[i]);
 			m_weightSum+=we[i];
diff --git a/include/shark/ObjectiveFunctions/Loss/EpsilonHingeLoss.h b/include/shark/ObjectiveFunctions/Loss/EpsilonHingeLoss.h
index cd3d9e5..24a2046 100644
--- a/include/shark/ObjectiveFunctions/Loss/EpsilonHingeLoss.h
+++ b/include/shark/ObjectiveFunctions/Loss/EpsilonHingeLoss.h
@@ -65,9 +65,6 @@ public:
 	double eval(BatchLabelType const& labels, BatchOutputType const& predictions) const{
 		SIZE_CHECK(predictions.size1() == labels.size1());
 		SIZE_CHECK(predictions.size2() == labels.size2());
-		std::size_t numInputs = predictions.size1();
-		std::size_t outputDim = predictions.size2();
-		
 		return sum(max(0.0,abs(labels-predictions)- m_epsilon));
 	}
 
diff --git a/include/shark/ObjectiveFunctions/Loss/SquaredEpsilonHingeLoss.h b/include/shark/ObjectiveFunctions/Loss/SquaredEpsilonHingeLoss.h
index 3635c20..c80d063 100644
--- a/include/shark/ObjectiveFunctions/Loss/SquaredEpsilonHingeLoss.h
+++ b/include/shark/ObjectiveFunctions/Loss/SquaredEpsilonHingeLoss.h
@@ -65,8 +65,7 @@ public:
 	double eval(BatchLabelType const& labels, BatchOutputType const& predictions) const{
 		SIZE_CHECK(predictions.size1() == labels.size1());
 		SIZE_CHECK(predictions.size2() == labels.size2());
-		std::size_t numInputs = predictions.size1();
-		
+
 		return 0.5*sum(max(0.0,sum_columns(sqr(labels-predictions)) - m_sqrEpsilon));
 	}
 
diff --git a/src/Algorithms/DirectSearch/CMA.cpp b/src/Algorithms/DirectSearch/CMA.cpp
index b05985c..c679833 100644
--- a/src/Algorithms/DirectSearch/CMA.cpp
+++ b/src/Algorithms/DirectSearch/CMA.cpp
@@ -215,6 +215,8 @@ void CMA::doInit(
 	std::size_t mu,
 	double initialSigma
 ) {
+	SIZE_CHECK(initialSearchPoints.size() > 0);
+	
 	m_numberOfVariables =initialSearchPoints[0].size();
 	m_lambda = lambda;
 	m_mu = mu;
diff --git a/src/Algorithms/DirectSearch/CMSA.cpp b/src/Algorithms/DirectSearch/CMSA.cpp
index 53fc6d8..558a6dc 100644
--- a/src/Algorithms/DirectSearch/CMSA.cpp
+++ b/src/Algorithms/DirectSearch/CMSA.cpp
@@ -110,6 +110,7 @@ void CMSA::doInit(
 	std::size_t mu,
 	double sima
 ) {
+	SIZE_CHECK(initialSearchPoints.size() > 0);
 	m_numberOfVariables = initialSearchPoints[0].size();
 
 	m_lambda = lambda;
diff --git a/src/Algorithms/DirectSearch/CrossEntropyMethod.cpp b/src/Algorithms/DirectSearch/CrossEntropyMethod.cpp
index 78de3c1..277ad37 100644
--- a/src/Algorithms/DirectSearch/CrossEntropyMethod.cpp
+++ b/src/Algorithms/DirectSearch/CrossEntropyMethod.cpp
@@ -99,13 +99,9 @@ void CrossEntropyMethod::init( ObjectiveFunctionType & function, SearchPointType
 	
 	unsigned int populationSize = CrossEntropyMethod::suggestPopulationSize( );
 	unsigned int selectionSize = CrossEntropyMethod::suggestSelectionSize( populationSize );
-	RealVector initialVariance(p.size());
-
+	
 	// Most papers set the variance to 100 by default.
-	for(int i = 0; i < p.size(); i++)
-	{
-		initialVariance(i) = 100;
-	}
+	RealVector initialVariance(p.size(),100);
 	init( function,
 		p,
 		populationSize,
@@ -129,7 +125,7 @@ void CrossEntropyMethod::init(
 	
 	m_numberOfVariables = function.numberOfVariables();
 	m_populationSize = populationSize;
-	m_selectionSize = static_cast<unsigned int>(::floor(selectionSize));
+	m_selectionSize = selectionSize;
 	m_variance = initialVariance;
 
 	m_mean.resize( m_numberOfVariables );
@@ -149,10 +145,10 @@ void CrossEntropyMethod::updateStrategyParameters( const std::vector<Individual<
 
 	/* Calculate the centroid of the parents */
 	RealVector m(m_numberOfVariables);
-	for (int i = 0; i < m_numberOfVariables; i++)
+	for (std::size_t i = 0; i < m_numberOfVariables; i++)
 	{
 		m(i) = 0;
-		for (int j = 0; j < parents.size(); j++)
+		for (std::size_t j = 0; j < parents.size(); j++)
 		{
 			m(i) += parents[j].searchPoint()(i);
 		}
@@ -167,9 +163,9 @@ void CrossEntropyMethod::updateStrategyParameters( const std::vector<Individual<
 	size_t nParents = parents.size();
 	double normalizationFactor = 1.0 / double(nParents);
 
-	for (int j = 0; j < m_numberOfVariables; j++) {
+	for (std::size_t j = 0; j < m_numberOfVariables; j++) {
 		double innerSum = 0.0;
-		for (int i = 0; i < parents.size(); i++) {
+		for (std::size_t i = 0; i < parents.size(); i++) {
 			double diff = parents[i].searchPoint()(j) - m(j);
 			innerSum += diff * diff;
 		}
@@ -189,9 +185,9 @@ void CrossEntropyMethod::step(ObjectiveFunctionType const& function){
 	std::vector< Individual<RealVector, double> > offspring( m_populationSize );
 
 	PenalizingEvaluator penalizingEvaluator;
-	for( unsigned int i = 0; i < offspring.size(); i++ ) {
+	for( std::size_t i = 0; i < offspring.size(); i++ ) {
 		RealVector sample(m_numberOfVariables);
-		for (int j = 0; j < m_numberOfVariables; j++)
+		for (std::size_t j = 0; j < m_numberOfVariables; j++)
 		{
 			sample(j) = m_distribution(m_mean(j), m_variance(j)); // N (0, 100)
 		}

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