[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[oMetah-devel] ometah ./SConstruct common/geometry.hpp common/...
From: |
Johann |
Subject: |
[oMetah-devel] ometah ./SConstruct common/geometry.hpp common/... |
Date: |
Sat, 26 Mar 2005 04:17:38 -0500 |
CVSROOT: /cvsroot/ometah
Module name: ometah
Branch:
Changes by: Johann <address@hidden> 05/03/26 09:17:38
Modified files:
. : SConstruct
common : geometry.hpp itsSet.hpp logic.hpp matrix.hpp
random.hpp string.hpp
communication : itsCommunicationClient.hpp
itsCommunicationClient_embedded.cpp
itsCommunicationClient_embedded.hpp
interface : ometah.cpp
metaheuristic : itsEstimationOfDistribution.cpp
itsMetaheuristic.cpp itsMetaheuristic.hpp
problem : itsProblem.cpp itsProblem.hpp
Removed files:
common : geometry.cpp itsSet.cpp logic.cpp matrix.cpp
random.cpp string.cpp
Log message:
* templates should be in headers
* corrections on the communication interface
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/SConstruct.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/common/geometry.hpp.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/common/itsSet.hpp.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/common/logic.hpp.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/common/matrix.hpp.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/common/random.hpp.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/common/string.hpp.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/communication/itsCommunicationClient.hpp.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/communication/itsCommunicationClient_embedded.cpp.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/communication/itsCommunicationClient_embedded.hpp.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/interface/ometah.cpp.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/metaheuristic/itsEstimationOfDistribution.cpp.diff?tr1=1.8&tr2=1.9&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/metaheuristic/itsMetaheuristic.cpp.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/metaheuristic/itsMetaheuristic.hpp.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/problem/itsProblem.cpp.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/problem/itsProblem.hpp.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
Patches:
Index: ometah/SConstruct
diff -u ometah/SConstruct:1.5 ometah/SConstruct:1.6
--- ometah/SConstruct:1.5 Wed Mar 16 19:12:50 2005
+++ ometah/SConstruct Sat Mar 26 09:17:38 2005
@@ -2,7 +2,7 @@
-common = ['geometry.cpp','itsPoint.cpp','itsSet.cpp','logic.cpp','matrix.cpp',
\
+common = ['itsPoint.cpp','geometry.cpp','itsSet.cpp','logic.cpp','matrix.cpp',
\
'random.cpp','string.cpp']
common = ['common/'+i for i in common]
Index: ometah/common/geometry.hpp
diff -u ometah/common/geometry.hpp:1.4 ometah/common/geometry.hpp:1.5
--- ometah/common/geometry.hpp:1.4 Fri Mar 11 12:06:07 2005
+++ ometah/common/geometry.hpp Sat Mar 26 09:17:38 2005
@@ -2,7 +2,7 @@
/***************************************************************************
* geometry.hpp
*
- * $Id: geometry.hpp,v 1.4 2005/03/11 12:06:07 nojhan Exp $
+ * $Id: geometry.hpp,v 1.5 2005/03/26 09:17:38 nojhan Exp $
* Author : Johann Dréo <address@hidden>
****************************************************************************/
@@ -29,22 +29,118 @@
//! Translate 2D rectangular coordinates to polar ones
template<class T>
-T rec2pol_2D(T &recVec);
+T rec2pol_2D(T &recVec)
+{
+ typename T::value_type a;
+ T polVec;
+ polVec.reserve(2);
+
+ // special case, both components 0
+ if (recVec[0] == 0.0 && recVec[1] == 0.0) {
+ polVec.push_back(0.0); // angle
+ polVec.push_back(0.0); // radius
+ return polVec;
+ }
+
+ // angle +- pi/2
+ a = atan2(recVec[1],recVec[0]);
+
+ // want it to be 0 to 2 pi
+ if (a < 0.0) {
+ a = a + PI*2;
+ }
+
+ polVec.push_back(a); // angle
+ polVec.push_back(sqrt(recVec[0]*recVec[0] + recVec[1]*recVec[1])); // radius
+
+ return polVec;
+}
//! Translate 2D polar coordinates to rectangular ones
template<class T>
-T pol2rec_2D(T & polVec);
+T pol2rec_2D(T & polVec)
+{
+ T recVec;
+ recVec.reserve(2);
+
+ recVec.push_back( polVec[0]*cos(polVec[1]) ); // x
+ recVec.push_back( polVec[0]*sin(polVec[1]) ); // y
+
+ return recVec;
+}
//! Translate nD polar coordinates to rectangular ones
template<class T>
-T pol2rec(T & polVec);
+T pol2rec(T & polVec)
+{
+ T recVec; recVec.reserve( polVec.size() );
+ T ProjVec; ProjVec.reserve( 2 );
+ typename T::value_type Ri, Ri_1, ai, xi;
+
+ Ri=polVec[0];
+
+ for(unsigned int i=0; i<polVec.size(); i++) {
+
+ Ri_1=Ri;
+ ai=polVec[i];
+
+ T Ra;
+ Ra.push_back(Ri_1);
+ Ra.push_back(ai);
+
+ ProjVec = Pol2Rec_2D(Ra);
+
+ xi=ProjVec[0];
+ Ri=ProjVec[1];
+
+ recVec.push_back(xi);
+ }
+
+ return recVec;
+}
//! Calculate the eucilidan distance between two vectors with n dimensions
template<class T, class U>
-T distanceEuclidian(U & vecA, U & vecB);
+T distanceEuclidian(U & vecA, U & vecB)
+{
+ U squares;
+ squares.reserve( vecA.size() );
+
+ for(unsigned int i=0; i<vecA.size(); i++) {
+ squares.push_back( (vecA[i]-vecB[i])*(vecA[i]-vecB[i]) );
+ }
+
+ return sqrt( sum(squares) );
+}
//! Calculate the gravity center of a matrix with n dimensions
template<class T, class U>
-T gravityCenter(U & points, T & weights);
+T gravityCenter(U & points, T & weights)
+{
+ typename U::value_type Wn = 0;
+ T VG;
+
+ // weight sum
+ unsigned int i;
+ for(i=0; i < points.size(); i++) {
+ Wn = Wn + weights[i];
+ }
+
+ // gravity center
+ unsigned int j;
+
+ // dimensions
+ for(j=0; j < points[0].size(); j++) {
+ typename T::value_type g = 0;
+
+ unsigned int i;
+ for(i=0; i < points.size(); i++) {
+ g = g + (points[i][j] * weights[i] / Wn);
+ }
+ VG.push_back(g);
+ }
+
+ return VG;
+}
#endif
Index: ometah/common/itsSet.hpp
diff -u ometah/common/itsSet.hpp:1.7 ometah/common/itsSet.hpp:1.8
--- ometah/common/itsSet.hpp:1.7 Wed Mar 16 19:09:28 2005
+++ ometah/common/itsSet.hpp Sat Mar 26 09:17:38 2005
@@ -1,5 +1,5 @@
/***************************************************************************
- * $Id: itsSet.hpp,v 1.7 2005/03/16 19:09:28 nojhan Exp $
+ * $Id: itsSet.hpp,v 1.8 2005/03/26 09:17:38 nojhan Exp $
* Author: Walid TFAILI <address@hidden>
****************************************************************************/
@@ -66,19 +66,36 @@
[<string> => <object>]
It use the "name" method to get the key associated to the object.
*/
- void add(T item);
+ void add(T item)
+{
+ // key is based on a const char*, so we take the c_str
+ collection[item->getKey().c_str()] = item;
+};
//! Remove an object
/*!
Remove a T member from the collection hash map, specifying its key
*/
- void remove(string name);
+ void remove(string name)
+{
+ // find the element iterator
+ // erase the element
+ collection.erase(
+ collection.find(name.c_str())
+ );
+};
//! Change the current choice
- void choose(string name);
+ void choose(string name)
+{
+ this->currentItem = name;
+};
//! Return a pointer on the current object
- T item();
+ T item()
+{
+ return collection[currentItem.c_str()];
+};
};
Index: ometah/common/logic.hpp
diff -u ometah/common/logic.hpp:1.2 ometah/common/logic.hpp:1.3
--- ometah/common/logic.hpp:1.2 Fri Mar 11 10:23:36 2005
+++ ometah/common/logic.hpp Sat Mar 26 09:17:38 2005
@@ -2,7 +2,7 @@
/***************************************************************************
* logic.hpp
*
- * $Id: logic.hpp,v 1.2 2005/03/11 10:23:36 nojhan Exp $
+ * $Id: logic.hpp,v 1.3 2005/03/26 09:17:38 nojhan Exp $
* Author : Johann Dréo <address@hidden>
****************************************************************************/
@@ -27,6 +27,13 @@
//! Exclusive or
template<class T>
-bool xOr(T cond1, T cond2);
+bool xOr(T cond1, T cond2)
+{
+ if( cond1>0 && cond2>0 && cond1!=cond2 ) {
+ return true;
+ } else {
+ return false;
+ }
+}
#endif
Index: ometah/common/matrix.hpp
diff -u ometah/common/matrix.hpp:1.5 ometah/common/matrix.hpp:1.6
--- ometah/common/matrix.hpp:1.5 Fri Mar 11 21:28:50 2005
+++ ometah/common/matrix.hpp Sat Mar 26 09:17:38 2005
@@ -1,7 +1,7 @@
/***************************************************************************
* matrix.hpp
*
- * $Id: matrix.hpp,v 1.5 2005/03/11 21:28:50 nojhan Exp $
+ * $Id: matrix.hpp,v 1.6 2005/03/26 09:17:38 nojhan Exp $
* Author : Johann Dréo <address@hidden>
****************************************************************************/
@@ -27,73 +27,376 @@
#include <vector>
using namespace std;
-
//! Test if a vector is comprised in bounds
template<class T>
-bool isInBounds( T aVector, T mins, T maxs );
+bool isInBounds( T aVector, T mins, T maxs)
+{
+ unsigned int i;
+ for(i=0; i<aVector.size(); i++ ){
+ // too low
+ if( aVector[i] < mins[i] ){
+ return false;
+ // too high
+ }else if( aVector[i] > maxs[i] ){
+ return true;
+ }
+ }
+ return true;
+}
+
//! Force a vector to be in bounds
template<class T>
-T forceBounds( T aVector, T mins, T maxs );
+T forceBounds( T aVector, T mins, T maxs)
+{
+ T CastedVector=aVector;
+
+ unsigned int i;
+ for(i=0; i<aVector.size(); i++ ){
+
+ if( aVector[i] < mins[i] ){
+ CastedVector[i]=mins[i];
+
+ }else if( aVector[i] > maxs[i] ){
+ CastedVector[i]=maxs[i];
+ }
+ }
+ return CastedVector;
+}
//! Create a 2D matrix filled with values
-template<class T, class U>
-U matrixFilled( unsigned int dimL, unsigned int dimC, T fillValue );
+/*
+ if we want a vector<vector<double> > :
+ T stand for double
+ V stand for vector<vector<double> >
+*/
+template <class T, class U>
+U matrixFilled( unsigned int dimL, unsigned int dimC, T fillValue )
+{
+ unsigned int i;
+
+ // make the vector<double> possible at this step
+ typename U::value_type vec(dimC, fillValue);
+
+ U mat;
+ for(i=0; i<dimL; i++){
+ mat.push_back(vec);
+ }
+
+ return mat;
+}
+
//! Multipliate two 2D matrix
template<class T>
-T multiply( T matA, T matB );
+T multiply( T matA, T matB)
+{
+
+ T newMat;
+
+ unsigned int Al=matA.size();
+ unsigned int Ac=matA[0].size();
+ unsigned int Bl=matB.size();
+ unsigned int Bc=matB[0].size();
+
+ newMat=filledMatrix( Al,Bc,0.0);
+
+ if(Ac!=Bl) {
+ throw("Error: Can not multiply matrices, sizes does not match");
+ return newMat;
+ }
+
+ for( int i=0; i<Al; i++ ) {
+ for( int j=0; j<Bc; j++ ) {
+ for( int k=0; k<Ac ;k++ ) {
+ newMat[i][j] += matA[i][k]*matB[k][j];
+ }
+ }
+ }
+ return newMat;
+}
//! Multiply each term of a vector by a scalar
template<class T, class U>
-U multiply( U aVector, T aNb );
+U multiply(U aVector, T aNb)
+{
+ U res;
+
+ res.reserve( aVector.size() );
+
+ unsigned int i;
+ for(i=0; i<aVector.size(); i++){
+ double x=aVector[i]*aNb;
+ res.push_back(x);
+ }
+ return res;
+}
+
//! Cholesky factorization
template<class T>
-T cholesky( T A );
+T cholesky( T A)
+{
+
+ // FIXME : vérifier que A est symétrique définie positive
+
+ T B;
+ unsigned int Al=A.size();
+ unsigned int Ac=A[0].size();
+ B = filledMatrix(Al, Ac, 0.0);
+
+ unsigned int i,j,k;
+
+ // first column
+ i=0;
+
+ // diagonal
+ j=0;
+ B[0][0]=sqrt(A[0][0]);
+
+ // end of the column
+ for(j=1;j<Ac;j++) {
+ B[j][0] = A[0][j] / B[0][0];
+ }
+
+ // end of the matrix
+ for(i=1;i<Al;i++){ // each column
+
+ // diagonal
+ double sum=0.0;
+ for(k=0; k<i; k++) {
+ sum += B[i][k]*B[i][k];
+ }
+ B[i][i] = sqrt( A[i][i] - sum );
+
+
+ for(j=i+1;j<Al;j++){ // rows
+
+ // one element
+ sum = 0.0;
+ for(k=0; k<i; k++) {
+ sum += B[j][k]*B[i][k];
+ }
+ B[j][i] = (A[j][i] - sum) / B[i][i];
+
+ }
+ }
+ return B;
+}
//! Transposition of a matrix
template<class T>
-T transpose( T &mat );
+T transpose( T &mat)
+{
+ unsigned int iSize=mat.size();
+ unsigned int jSize=mat[0].size();
+
+ typename T::value_type aVector;
+ T newMat;
+
+ unsigned int i, j;
+
+ for (j=0; j<jSize; j++) {
+ for(i=0; i<iSize; i++) {
+ aVector.push_back(mat[i][j]);
+ }//j
+
+ newMat.push_back(aVector);
+ aVector.clear();
+ }//i
+
+ return newMat;
+}
//! Calculate a variance-covariance matrix from a list of vector
template<class U>
-U varianceCovariance( U pop );
+U varianceCovariance( U pop)
+{
+ // vector of means
+ // => average of columns => transposition before calculations
+ typename U::value_type vecMeanCentered = mean( transpose(pop) );
+
+ // centered population
+ // same size as the initial matrix
+ U popMeanCentered = filledMatrix(pop.size(),pop[0].size(), 0.0);
+
+ // centering
+ // rows
+ for(unsigned int i=0;i<pop.size();i++) {
+ // columns
+ for(unsigned int j=0;j<pop[i].size();j++) {
+ popMeanCentered[i][j] = (pop[i][j] - vecMeanCentered[j]);
+ }
+ }
+
+ // transposition of the centered matrix
+ U popMeanCenteredT;
+ popMeanCenteredT = transpose(popMeanCentered);
+
+
+ // final varaince/covariance matrix
+ U popVar;
+ popVar = multiply( popMeanCenteredT, popMeanCentered );
+
+ // multiplication by n-1 :
+ for(unsigned int i=0;i<popVar.size();i++) {
+ for(unsigned int j=0;j<popVar[i].size();j++) {
+ popVar[i][j]=popVar[i][j]/(pop.size());
+ }
+ }
+
+ return popVar;
+}
//! Calculate the mean vector of a matrix
template<class T, class U>
-T mean( U mat );
+T mean( U mat)
+{
+ T moyDim;
+ moyDim.reserve(mat.size());
+
+ unsigned int i,a;
+ a=mat.size();
+
+ for(i=0;i<a;i++) {
+ moyDim.push_back( mean(mat[i]) );
+ }
+ return moyDim;
+}
//! Calculate the mean of a vector
template<class T, class U>
-T mean( U aVector, int begin=0, int during=0 );
+T mean(U aVector, int begin=0, int during=0)
+{
+ if (during==0) {
+ during = aVector.size() - begin; // if no end : take all
+ }
+
+ T aSum, aMean;
+
+ aSum = Sum(aVector, begin, during); // Sum
+ aMean = aSum / (during - begin); // Mean
+
+ return aMean;
+}
//! Calculate the sum of a vector
template<class T, class U>
-T sum( U aVector, int begin=0, int during=0 );
+T sum(U aVector, int begin=0, int during=0)
+{
+ if (during==0) {
+ during = aVector.size() - begin;
+ }
+
+ T aSum=0;
+
+ for (unsigned int j=begin; j<during; j++) {
+ aSum = aSum + aVector[j]; // sum
+ }//for (j)
+
+ return aSum;
+
+}
//! Calculate the standard deviation of a vector
template<class T, class U>
-T stdev( U aVector, int begin=0, int during=0 );
+T stdev(U aVector, int begin=0, int during=0)
+{
+ if (during==0) {
+ during = aVector.size() - begin;
+ }
+
+ U deviation;
+ T aMean, aDev, aStd;
+
+ aMean = mean(aVector, begin, during); // mean
+
+ for (unsigned int j=begin; j<during; j++) {
+ aDev = aMean - aVector[j];
+ deviation.push_back(aDev*aDev);
+ }//for (j)
+
+ aStd = sqrt( mean(deviation, begin, during) );
+
+ return aStd;
+
+}
//! Find the minimum value of a vector
template<class T>
-typename T::value_type min( T aVector, int begin=0, int during=0 );
+typename T::value_type min(T aVector, int begin=0, int during=0)
+{
+ if (during==0) {
+ during = aVector.size() - begin;
+ }
+
+ typename T::value_type aMin = aVector[begin];
+
+ for (unsigned int i=begin+1; i<during; i++) {
+ if ( aVector[i] < aMin ) {
+ aMin = aVector[i];
+ }
+ }
+
+ return aMin;
+}
//! Find the maximum value of a vector
template<class T>
-typename T::value_type max( T aVector, int begin=0, int during=0 );
+typename T::value_type max(T aVector, int begin=0, int during=0)
+{
+ if (during==0) {
+ during = aVector.size() - begin;
+ }
+
+ typename T::value_type aMax = aVector[begin];
+
+ for (unsigned int i=begin+1; i<during; i++) {
+ if ( aVector[i] > aMax ) {
+ aMax = aVector[i];
+ }
+ }
+
+ return aMax;
+}
//! Substraction of two vectors, terms by terms
template<class T>
-T substraction( T from, T that );
+T substraction(T from, T that)
+{
+ T res;
+
+ res.reserve(from.size());
+
+ for(unsigned int i=0; i<from.size(); i++){
+ res.push_back( from[i]-that[i] );
+ }
+ return res;
+}
//! Addition of two vectors, terms by terms
template<class T>
-T addition( T from, T that );
+T addition(T from, T that)
+{
+ T res;
+
+ res.reserve( from.size() );
+
+ for(unsigned int i=0; i<from.size(); i++){
+ res.push_back( from[i]+that[i] );
+ }
+ return res;
+}
//! Calculate the absolute values of a vector
template<class T>
-T absolute( T aVector );
+T absolute(T aVector)
+{
+ for(unsigned int i=0; i<aVector.size(); i++){
+ aVector[i] = abs(aVector[i]);
+ }
+
+ return aVector;
+}
#endif
Index: ometah/common/random.hpp
diff -u ometah/common/random.hpp:1.2 ometah/common/random.hpp:1.3
--- ometah/common/random.hpp:1.2 Fri Mar 11 12:06:07 2005
+++ ometah/common/random.hpp Sat Mar 26 09:17:38 2005
@@ -1,7 +1,7 @@
/***************************************************************************
* random.hpp
*
- * $Id: random.hpp,v 1.2 2005/03/11 12:06:07 nojhan Exp $
+ * $Id: random.hpp,v 1.3 2005/03/26 09:17:38 nojhan Exp $
* Author : Johann Dréo <address@hidden>
****************************************************************************/
@@ -27,35 +27,156 @@
#define PI 3.141592653589793238462
+
//! Draw a random number between 0 and 1
template<class T>
-T randomO1();
+T randomO1()
+{
+ return (T)rand()/RAND_MAX;
+}
//! Draw a random number in a normal probability density function
template<class T>
-T randomNormal( T mean, T std );
+T randomNormal( T mean, T std )
+{
+ T x1, x2, w, y1;
+ static T y2;
+ static int use_last = 0;
+
+ if (use_last) /* use value from previous call */
+ {
+ y1 = y2;
+ use_last = 0;
+ }
+ else
+ {
+ do {
+ x1 = 2* (T)rand()/RAND_MAX-1; // rand in [0,1]
+ x2 = 2* (T)rand()/RAND_MAX-1;
+ w = x1 * x1 + x2 * x2;
+ } while ( w >= 1.0 );
+
+ w = sqrt( (-2.0 * log( w ) ) / w );
+ y1 = x1 * w;
+ y2 = x2 * w;
+ use_last = 1;
+ }
+ return (T)(mean + y1 * std);
+
+}
+
//! Draw a vector with each scalar drawn in a normal distribution
-template<class T, class U>
-T randomNormal( T & means, U & stds );
+template<class T>
+T randomNormal( T & means, T & stds )
+{
+ T v;
+
+ unsigned int i;
+ for(i=0; i<means.size(); i++) {
+ T x;
+ x = rand_normal(means[i], stds[i]);
+ v.push_back(x);
+ }
+
+ return v;
+}
+
//! Draw a vector in a true multi-normal distribution
template<class T, class U>
-T randomNormalMulti( T means, U varcovar );
+T randomNormalMulti( T means, U varcovar )
+{
+/*
+ - Let $u$ a vector of $n$ number, following a centered/reducted
+ normal distribution;
+ - let $L$ be the matrix resulting from the Cholesky decomposition
+ of $V$;
+ - the vector $y=m+Lu$ follow the multi-normal distribution,
+ with a mean $m$ and a variance-covariance matrix $V$.
+*/
+ T finalPoint;
+
+ // Cholesky decomposition of the variance-covariance matrix
+ U popVarCholesky; // low triangular matrix
+ popVarCholesky = cholesky( varcovar );
+
+ // Vector with terms in a centered/reducted normal distribution
+ T u;
+ T mean(means.size(),0.0);
+ T variance(means.size(),1.0);
+ u = randomNormal( mean,variance );
+
+ // temporary vector for multiplication
+ U tempU;
+ tempU.push_back(u);
+
+ // post multiplication by the u vector
+ U tempCompVar;
+ tempCompVar = multiply( popVarCholesky, transpose(tempU) );
+
+ // transposition
+ T compVar = transpose(tempCompVar)[0];
+
+ // addition to the mean
+ finalPoint = VectorAddition( means, compVar );
+
+ return finalPoint;
+}
+
//! Draw a random vector in a hyper cube
template<class T>
-T randomUniform( T mins, T maxs );
+T randomUniform( T mins, T maxs )
+{
+ T res;
+
+ for(unsigned int i=0; i<mins.size(); i++) {
+ typename T::value_type r;
+ r = (maxs[i]-mins[i])*
+ (typename T::value_type)rand()/RAND_MAX
+ + mins[i];
+ res.push_back(r);
+ }
+
+ return res;
+}
+
//! Draw a random vector in a hyper sphere
template<class T, class U>
-U randomSphere( U & center, T radius );
+U randomSphere(U & center, T radius)
+{
+ //FIXME
+}
+
//! Draw a random vector in a hyper sphere, using a biased method
/*!
- The biased method lead to a pseudo normal distribution, bounded by a sphere
+ The biased method lead to a pseudo-normal distribution, bounded by a sphere
*/
template<class T, class U>
-U randomSphereBiased( U & center, T radius );
+U randomHyperSphereBiased(U & center, T radius)
+{
+ T r;
+ U res;
+
+ r = (radius)*
+ (T)rand()/RAND_MAX;
+
+ res.push_back(r);
+
+ unsigned int i;
+
+ for(i=0; i<center.size(); i++)
+ {
+ r=(2*PI)*(T)rand()/RAND_MAX; // a random angle on 2Pi
+
+ res.push_back(r);
+ }
+
+ return res;
+
+}
#endif
Index: ometah/common/string.hpp
diff -u ometah/common/string.hpp:1.3 ometah/common/string.hpp:1.4
--- ometah/common/string.hpp:1.3 Fri Mar 11 12:06:07 2005
+++ ometah/common/string.hpp Sat Mar 26 09:17:38 2005
@@ -1,6 +1,6 @@
/***************************************************************************
- * $Id: string.hpp,v 1.3 2005/03/11 12:06:07 nojhan Exp $
+ * $Id: string.hpp,v 1.4 2005/03/26 09:17:38 nojhan Exp $
* Author : Johann Dréo <address@hidden>
****************************************************************************/
@@ -30,14 +30,41 @@
//! Print a vector
template<class T,class U>
-void print( T aVector, U aSeparator, ostream * outer );
+void print( T aVector, U aSeparator, ostream * outer )
+{
+ *outer << aVector[0];
+
+ for( unsigned int i=1; i<aVector.size(); i++ ) {
+ *outer << aSeparator << aVector[i];
+ }
+}
//! Make a double vector from a string vector
template<template <class T> class V>
-V<double> stringToDouble(V<string> VString);
+V<double> stringToDouble(V<string> VString)
+{
+
+ double aDouble;
+ V<double> VDouble;
+
+ VDouble.reserve( VString.size() );
+
+ for (unsigned int i=0; i<VString.size(); i++) {
+ aDouble = atof( VString[i].c_str() );
+ VDouble.push_back(aDouble);
+ }
+ return VDouble;
+}
//! Make a double from a string
-double stringToDouble(string aString);
+double stringToDouble(string aString)
+{
+ double aDouble;
+
+ aDouble = atof( aString.c_str() );
+
+ return aDouble;
+}
//! Make a double vector from a string, with shortcut options
/*!
@@ -45,18 +72,67 @@
"1.2,1" => <1.2,1>
"3:1.0" => <1.0,1.0,1.0>
*/
+
template<template <class T> class V>
-V<double> stringToDouble(string aString, string itemSeparator=",", string
multiSeparator=":");
+V<double> stringToDouble(string aString, string itemSeparator=",", string
multiSeparator=":")
+{
+ V<double> res;
+
+ // if find a separator
+ if ( aString.find(multiSeparator) < aString.size() ) {
+ V<double> tempvec = stringToDouble( stringSplit( aString, multiSeparator )
);
+ res.reserve( (int)tempvec[0]);
+
+ for(unsigned int i=0; i<tempvec[0]; i++) {
+ res.push_back(tempvec[1]);
+ }
+ } else {
+ res = stringToDouble( stringSplit( aString, itemSeparator ) );
+ }
+ return res;
+}
//! Make a string vector from a string
/*!
This version modify directly the vector by reference
*/
template<template<class T> class V>
-void stringSplit (string text, string separators, V<string> & words);
+void stringSplit (string text, string separators, V<string> & words)
+{
+ int n = text.length();
+ int start, stop;
+
+ start = text.find_first_not_of(separators);
+ while ((start >= 0) && (start < n)) {
+ stop = text.find_first_of(separators, start);
+
+ if ((stop < 0) || (stop > n)) stop = n;
+
+ words.push_back(text.substr(start, stop - start));
+ start = text.find_first_not_of(separators, stop+1);
+ }
+}
//! Make a string vector from a string
template<template<class T> class V>
-V<string> stringSplit (string text, string separators);
+V<string> stringSplit (string text, string separators)
+{
+ int n = text.length();
+ int start, stop;
+
+ V<string> words;
+
+ start = text.find_first_not_of(separators);
+ while ((start >= 0) && (start < n)) {
+ stop = text.find_first_of(separators, start);
+
+ if ((stop < 0) || (stop > n)) stop = n;
+
+ words.push_back(text.substr(start, stop - start));
+ start = text.find_first_not_of(separators, stop+1);
+ }
+
+ return words;
+}
#endif
Index: ometah/communication/itsCommunicationClient.hpp
diff -u ometah/communication/itsCommunicationClient.hpp:1.5
ometah/communication/itsCommunicationClient.hpp:1.6
--- ometah/communication/itsCommunicationClient.hpp:1.5 Wed Mar 16 19:03:31 2005
+++ ometah/communication/itsCommunicationClient.hpp Sat Mar 26 09:17:38 2005
@@ -1,7 +1,7 @@
/***************************************************************************
* itsCommunicationClientt.hpp
*
- * $Id: itsCommunicationClient.hpp,v 1.5 2005/03/16 19:03:31 nojhan Exp $
+ * $Id: itsCommunicationClient.hpp,v 1.6 2005/03/26 09:17:38 nojhan Exp $
* Author : Johann Dréo <address@hidden>
****************************************************************************/
@@ -24,11 +24,20 @@
#ifndef ITSCOMMUNICATIONCLIENT
#define ITSCOMMUNICATIONCLIENT
+#include <vector>
+#include <string>
+#include <hash_map.h>
#include "../communication/itsCommunication.hpp"
+#include "../communication/itsCommunicationServer.hpp"
class itsCommunicationClient : public itsCommunication
{
+public:
+ //! The problem directly embedded, if necessary
+ itsCommunicationServer* problem;
+public:
+ void initialization(hash_map<string,string> args);
//! Call the problem on a point to get its associated values
itsPoint call(itsPoint point);
Index: ometah/communication/itsCommunicationClient_embedded.cpp
diff -u ometah/communication/itsCommunicationClient_embedded.cpp:1.2
ometah/communication/itsCommunicationClient_embedded.cpp:1.3
--- ometah/communication/itsCommunicationClient_embedded.cpp:1.2 Wed Mar
16 19:03:31 2005
+++ ometah/communication/itsCommunicationClient_embedded.cpp Sat Mar 26
09:17:38 2005
@@ -1,5 +1,5 @@
/***************************************************************************
- * $Id: itsCommunicationClient_embedded.cpp,v 1.2 2005/03/16 19:03:31 nojhan
Exp $
+ * $Id: itsCommunicationClient_embedded.cpp,v 1.3 2005/03/26 09:17:38 nojhan
Exp $
* Copyright : Université Paris 12 Val-de-Marne
* Author : Johann Dréo <address@hidden>
****************************************************************************/
@@ -25,31 +25,33 @@
itsCommunicationClientFactory_embedded::itsCommunicationClientFactory_embedded()
{
setKey("Embedded");
+
+ this->problem = itsCommunicationServer_embedded();
}
itsPoint itsCommunicationClientFactory_embedded::call(itsPoint point)
{
- return this->link->call(point);
+ return this->problem.call(point);
}
vector<double> itsCommunicationClientFactory_embedded::boundsMinima()
{
- return this->link->boundsMinima();
+ return this->problem.boundsMinima();
}
vector<double> itsCommunicationClientFactory_embedded::boundsMaxima()
{
- return this->link->boundsMaxima();
+ return this->problem.boundsMaxima();
}
vector<vector<double> > itsCommunicationClientFactory_embedded::bounds()
{
- return this->link->bounds();
+ return this->problem.bounds();
}
int itsCommunicationClientFactory_embedded::getDimension()
{
- return this->link->getDimension();
+ return this->problem.getDimension();
}
Index: ometah/communication/itsCommunicationClient_embedded.hpp
diff -u ometah/communication/itsCommunicationClient_embedded.hpp:1.2
ometah/communication/itsCommunicationClient_embedded.hpp:1.3
--- ometah/communication/itsCommunicationClient_embedded.hpp:1.2 Wed Mar
16 19:03:31 2005
+++ ometah/communication/itsCommunicationClient_embedded.hpp Sat Mar 26
09:17:38 2005
@@ -1,5 +1,5 @@
/***************************************************************************
- * $Id: itsCommunicationClient_embedded.hpp,v 1.2 2005/03/16 19:03:31 nojhan
Exp $
+ * $Id: itsCommunicationClient_embedded.hpp,v 1.3 2005/03/26 09:17:38 nojhan
Exp $
* Copyright : Université Paris 12 Val-de-Marne
* Author : Johann Dréo <address@hidden>
****************************************************************************/
@@ -31,9 +31,6 @@
class itsCommunicationClient_embedded : public itsCommunicationClient
{
-public:
- //! The problem directly embedded
- itsCommunicationServer_embedded link;
};
Index: ometah/interface/ometah.cpp
diff -u ometah/interface/ometah.cpp:1.5 ometah/interface/ometah.cpp:1.6
--- ometah/interface/ometah.cpp:1.5 Wed Mar 16 19:10:26 2005
+++ ometah/interface/ometah.cpp Sat Mar 26 09:17:38 2005
@@ -1,5 +1,5 @@
/***************************************************************************
- * $Id: ometah.cpp,v 1.5 2005/03/16 19:10:26 nojhan Exp $
+ * $Id: ometah.cpp,v 1.6 2005/03/26 09:17:38 nojhan Exp $
* Copyright : Université Paris 12 Val-de-Marne
* Author : Johann Dréo <address@hidden>
****************************************************************************/
@@ -21,6 +21,11 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+
+
+#include <hash_map.h>
+
+#include "../common/random.hpp"
#include "../common/itsSet.hpp"
#include "../metaheuristic/itsMetaheuristic.hpp"
@@ -116,8 +121,12 @@
// Special case for the embedded protocol : we must link client and server
if( setMetaheuristic.item()->getKey() == "Embedded" ) {
- setCommunicationClient.item()->link = setCommunicationServer.item();
+ setCommunicationClient.item()->problem = setCommunicationServer.item();
}
+
+ // giving parameters
+ hash_map<string,string> parameters;
+ setCommunicationClient.item()->initialization( parameters );
/*
Index: ometah/metaheuristic/itsEstimationOfDistribution.cpp
diff -u ometah/metaheuristic/itsEstimationOfDistribution.cpp:1.8
ometah/metaheuristic/itsEstimationOfDistribution.cpp:1.9
--- ometah/metaheuristic/itsEstimationOfDistribution.cpp:1.8 Sat Mar 12
22:50:35 2005
+++ ometah/metaheuristic/itsEstimationOfDistribution.cpp Sat Mar 26
09:17:38 2005
@@ -1,7 +1,7 @@
/***************************************************************************
* itsMetaheuristic.hpp
*
- * $Id: itsEstimationOfDistribution.cpp,v 1.8 2005/03/12 22:50:35 nojhan Exp $
+ * $Id: itsEstimationOfDistribution.cpp,v 1.9 2005/03/26 09:17:38 nojhan Exp $
* Author : Johann Dréo <address@hidden>
****************************************************************************/
@@ -40,21 +40,21 @@
setKey("CEDA");
setAccronym("CEDA");
setDescription("An estimation of distribution algorithm");
- setCitation("
address@hidden,
- Author = {Bengoetxea, E. and Miqu\'elez, T. and Larra\~naga, P.
- and Lozano, J. A.},
- Editor = {Larranaga, P. and Lozano, J. A.},
- Title = {Estimation of {D}istribution {A}lgorithms, {A} {N}ew
- {T}ool for {E}volutionary {C}omputation},
- Chapter = {Experimental Results in Function Optimization with
- EDAs in Continuous Domain},
- Pages = {181--194},
- Publisher = {Kluwer Academic Publishers},
- Series = {Genetic Algorithms and Evolutionary Computation},
- year = 2002
-}
-");
+ setCitation(
+"@InBoo{{Bengoetxea02,"
+" Author = {Bengoetxea, E. and Miqu\\'elez, T. and Larra\\~naga, P."
+" and Lozano, J. A.},"
+" Editor = {Larranaga, P. and Lozano, J. A.},"
+" Title = {Estimation of {D}istribution {A}lgorithms, {A} {N}ew"
+" {T}ool for {E}volutionary {C}omputation},"
+" Chapter = {Experimental Results in Function Optimization with"
+" EDAs in Continuous Domain},"
+" Pages = {181--194},"
+" Publisher = {Kluwer Academic Publishers},"
+" Series = {Genetic Algorithms and Evolutionary Computation},"
+" year = 2002"
+"}"
+);
setFamily("Estimation of Distribution Algorithm");
Index: ometah/metaheuristic/itsMetaheuristic.cpp
diff -u ometah/metaheuristic/itsMetaheuristic.cpp:1.6
ometah/metaheuristic/itsMetaheuristic.cpp:1.7
--- ometah/metaheuristic/itsMetaheuristic.cpp:1.6 Sat Mar 12 22:50:35 2005
+++ ometah/metaheuristic/itsMetaheuristic.cpp Sat Mar 26 09:17:38 2005
@@ -134,6 +134,13 @@
}
+void itsMetaheuristic::setKey( string key )
+{
+ this->key = key;
+}
+
+
+
string itsMetaheuristic::getName()
{
return this->name;
Index: ometah/metaheuristic/itsMetaheuristic.hpp
diff -u ometah/metaheuristic/itsMetaheuristic.hpp:1.7
ometah/metaheuristic/itsMetaheuristic.hpp:1.8
--- ometah/metaheuristic/itsMetaheuristic.hpp:1.7 Wed Mar 16 19:07:54 2005
+++ ometah/metaheuristic/itsMetaheuristic.hpp Sat Mar 26 09:17:38 2005
@@ -213,6 +213,8 @@
//! Return the key
string getKey();
+ //! Change the key
+ void setKey( string key );
//@}
};
Index: ometah/problem/itsProblem.cpp
diff -u ometah/problem/itsProblem.cpp:1.6 ometah/problem/itsProblem.cpp:1.7
--- ometah/problem/itsProblem.cpp:1.6 Sat Mar 12 22:50:35 2005
+++ ometah/problem/itsProblem.cpp Sat Mar 26 09:17:38 2005
@@ -1,5 +1,5 @@
/***************************************************************************
- * $Id: itsProblem.cpp,v 1.6 2005/03/12 22:50:35 nojhan Exp $
+ * $Id: itsProblem.cpp,v 1.7 2005/03/26 09:17:38 nojhan Exp $
* Copyright 2005 Université Paris 12 Val-de-Marne
* Author : Johann Dréo <address@hidden>
****************************************************************************/
@@ -48,11 +48,6 @@
//setOptima(optim);
}
-string itsProblem::getKey()
-{
- return this->key;
-}
-
string itsProblem::getName()
{
return this->name;
@@ -219,3 +214,14 @@
{
this->formula = formula;
}
+
+string itsProblem::getKey()
+{
+ return this->key;
+}
+
+
+void itsProblem::setKey( string key )
+{
+ this->key = key;
+}
Index: ometah/problem/itsProblem.hpp
diff -u ometah/problem/itsProblem.hpp:1.9 ometah/problem/itsProblem.hpp:1.10
--- ometah/problem/itsProblem.hpp:1.9 Sat Mar 12 22:50:35 2005
+++ ometah/problem/itsProblem.hpp Sat Mar 26 09:17:38 2005
@@ -1,5 +1,5 @@
/***************************************************************************
- * $Id: itsProblem.hpp,v 1.9 2005/03/12 22:50:35 nojhan Exp $
+ * $Id: itsProblem.hpp,v 1.10 2005/03/26 09:17:38 nojhan Exp $
* Copyright 2005 Université Paris 12 Val-de-Marne
* Author : Johann Dréo <address@hidden>
****************************************************************************/
@@ -99,9 +99,6 @@
//! Set the name
void setName(string name);
- //! Return the key
- string getKey();
-
//! Return the description
string getDescription();
//! Change the description
@@ -157,6 +154,11 @@
//! Change all the bounds maxima to the same value
void setBoundsMaximaAll(double max);
+ //! Return the key
+ string getKey();
+ //! Change the key
+ void setKey( string key );
+
//@}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [oMetah-devel] ometah ./SConstruct common/geometry.hpp common/...,
Johann <=