Commit 68df2975 authored by Thomas Feuvrier's avatar Thomas Feuvrier

Lib GALIB: intégration dans l'OTB

- lib
- tests et non-régression
parent 43733705
......@@ -75,7 +75,7 @@ SET(OTB_GLU_INCLUDE_PATH "")
IF(OTB_USE_VISU_GUI)
#-------------------------------
# openGL Library
# OpenGL Library
#-------------------------------
FIND_PACKAGE(OpenGL)
IF(OPENGL_INCLUDE_PATH)
......@@ -84,15 +84,11 @@ IF(OTB_USE_VISU_GUI)
INCLUDE(CheckIncludeFiles)
CHECK_INCLUDE_FILES("GL/glu.h" HAVE_GL_GLU_H)
MESSAGE("HAVE_GL_GLU_H ${HAVE_GL_GLU_H}")
IF ( NOT HAVE_GL_GLU_H )
FIND_PATH(OTB_GLU_INCLUDE_PATH "GL/glu.h" ${OPENGL_INCLUDE_PATH})
MESSAGE("OTB_GLU_INCLUDE_PATH ${OTB_GLU_INCLUDE_PATH}")
IF(NOT OTB_GLU_INCLUDE_PATH)
SET(OTB_GLU_INCLUDE_PATH "")
MESSAGE("Impossible to find GLU files (include lib), detected by FIND_PACKAGE(OpenGL) command.")
MESSAGE("Cannot build OTB Visu module without GLU library.")
MESSAGE(" => You must install GLU (Mesa package, etc.) on your system OR set OTB_USE_VISU to OFF to desactivated OTB Visu module generation !")
MESSAGE("Impossible to find GLU files (include lib), detected by FIND_PACKAGE(OpenGL) command.\nCannot build OTB Visu module without GLU library.\n=> You must install GLU (Mesa package, etc.) on your system OR set OTB_USE_VISU to OFF to desactivated OTB Visu module generation !")
ENDIF(NOT OTB_GLU_INCLUDE_PATH)
ENDIF ( NOT HAVE_GL_GLU_H )
......
......@@ -149,6 +149,181 @@ ADD_TEST(utOssimRadarSatSupport ${UTILITIES_TESTS}
${IMAGEDATA}/RADARSAT2/SCENE01/DAT_01.001
)
# ------- lib Galib ------------------------------
FOREACH(num 1 12 14 16 17 25 27)
ADD_TEST( utTuGalibTest${num} ${CXX_TEST_PATH}/galibTests${num}
galibTests${num}
seed 555 )
ENDFOREACH(num)
FOREACH(num 6 8 19 20)
ADD_TEST( utTvGalibTest${num} ${CXX_TEST_PATH}/galibTests${num}
--compare-ascii ${TOL}
${BASELINE_FILES}/utGalibTest${num}_bog.dat
${TEMP}/utGalibTest${num}_bog.dat
galibTests${num}
score_filename ${TEMP}/utGalibTest${num}_bog.dat
seed 555 )
ENDFOREACH(num)
FOREACH(num 2 4 9 11 15)
ADD_TEST( utTvGalibTest${num} ${CXX_TEST_PATH}/galibTests${num}
--compare-ascii ${TOL}
${BASELINE_FILES}/utGalibTest${num}_bog.dat
${TEMP}/utGalibTest${num}_bog.dat
galibTests${num}
${TEMP}/utGalibTest${num}_bog.dat
seed 555 )
ENDFOREACH(num)
SET(num 13)
ADD_TEST( utTvGalibTest${num} ${CXX_TEST_PATH}/galibTests${num}
--compare-ascii ${TOL}
${BASELINE_FILES}/utGalibTest${num}_bog.dat
${TEMP}/utGalibTest${num}_bog.dat
galibTests${num}
${INPUTDATA}/galib-smiley.txt
score_filename ${TEMP}/utGalibTest${num}_bog.dat
seed 555 )
FOREACH(num 3 18)
ADD_TEST( utTvGalibTest${num} ${CXX_TEST_PATH}/galibTests${num}
--compare-ascii ${TOL}
${BASELINE_FILES}/utGalibTest${num}_bog.dat
${TEMP}/utGalibTest${num}_bog.dat
galibTests${num}
file ${INPUTDATA}/galib-smiley.txt
score_filename ${TEMP}/utGalibTest${num}_bog.dat
seed 555 )
ENDFOREACH(num)
SET(num 5)
ADD_TEST( utTvGalibTest${num} ${CXX_TEST_PATH}/galibTests${num}
--compare-ascii ${TOL}
${BASELINE_FILES}/utGalibTest${num}_bog.dat
${TEMP}/utGalibTest${num}_bog.dat
galibTests${num}
score_filename ${TEMP}/utGalibTest${num}_bog.dat
graph ${INPUTDATA}/galib-smiley.txt
values ${INPUTDATA}/galib-values.txt
seed 555 )
# Test 7 commented becasue impossible to specific he bog.dat file name in the process ;-(
#SET(num 7)
# ADD_TEST( utTvGalibTest${num} ${CXX_TEST_PATH}/galibTests${num}
# --compare-ascii ${TOL}
# ${BASELINE_FILES}/utGalibTest${num}_bog.dat
# ${TEMP}/utGalibTest${num}_bog.dat
# galibTests${num}
# ${TEMP}/utGalibTest${num}_bog.dat
# dfile ${INPUTDATA}/galib-smiley.txt
# pfile ${INPUTDATA}/galib-settings.txt
# seed 555 )
SET(num 10)
ADD_TEST( utTvGalibTest${num} ${CXX_TEST_PATH}/galibTests${num}
--compare-n-ascii ${TOL} 4
${BASELINE_FILES}/utGalibTest${num}_sinusoid.dat
${TEMP}/utGalibTest${num}_sinusoid.dat
${BASELINE_FILES}/utGalibTest${num}_pop.nospec.dat
${TEMP}/utGalibTest${num}_pop.nospec.dat
${BASELINE_FILES}/utGalibTest${num}_pop.genespec.dat
${TEMP}/utGalibTest${num}_pop.genespec.dat
${BASELINE_FILES}/utGalibTest${num}_pop.phenespec.dat
${TEMP}/utGalibTest${num}_pop.phenespec.dat
galibTests${num}
${TEMP}/utGalibTest${num}_sinusoid.dat
${TEMP}/utGalibTest${num}_pop.nospec.dat
${TEMP}/utGalibTest${num}_pop.genespec.dat
${TEMP}/utGalibTest${num}_pop.phenespec.dat
seed 555 )
SET(num 21)
ADD_TEST( utTvGalibTest${num} ${CXX_TEST_PATH}/galibTests${num}
--compare-n-ascii ${TOL} 5
${BASELINE_FILES}/utGalibTest${num}_bog1.dat
${TEMP}/utGalibTest${num}_bog1.dat
${BASELINE_FILES}/utGalibTest${num}_bog2.dat
${TEMP}/utGalibTest${num}_bog2.dat
${BASELINE_FILES}/utGalibTest${num}_bog2a.dat
${TEMP}/utGalibTest${num}_bog2a.dat
${BASELINE_FILES}/utGalibTest${num}_bog3.dat
${TEMP}/utGalibTest${num}_bog3.dat
${BASELINE_FILES}/utGalibTest${num}_bog4.dat
${TEMP}/utGalibTest${num}_bog4.dat
galibTests${num}
${TEMP}/utGalibTest${num}_bog1.dat
${TEMP}/utGalibTest${num}_bog2.dat
${TEMP}/utGalibTest${num}_bog2a.dat
${TEMP}/utGalibTest${num}_bog3.dat
${TEMP}/utGalibTest${num}_bog4.dat
seed 555 )
SET(num 22)
ADD_TEST( utTvGalibTest${num} ${CXX_TEST_PATH}/galibTests${num}
--compare-n-ascii ${TOL} 4
${BASELINE_FILES}/utGalibTest${num}_sinusoid.dat
${TEMP}/utGalibTest${num}_sinusoid.dat
${BASELINE_FILES}/utGalibTest${num}_pop.initial.dat
${TEMP}/utGalibTest${num}_pop.initial.dat
${BASELINE_FILES}/utGalibTest${num}_pop.final.dat
${TEMP}/utGalibTest${num}_pop.final.dat
${BASELINE_FILES}/utGalibTest${num}_blog.dat
${TEMP}/utGalibTest${num}_blog.dat
galibTests${num}
${TEMP}/utGalibTest${num}_sinusoid.dat
${TEMP}/utGalibTest${num}_pop.initial.dat
${TEMP}/utGalibTest${num}_pop.final.dat
score_filename ${TEMP}/utGalibTest${num}_blog.dat
seed 555 )
SET(num 23)
ADD_TEST( utTvGalibTest${num} ${CXX_TEST_PATH}/galibTests${num} galibTests${num}
--compare-n-ascii ${TOL} 4
${BASELINE_FILES}/utGalibTest${num}_popi.dat
${TEMP}/utGalibTest${num}_popi.dat
${BASELINE_FILES}/utGalibTest${num}_popf.dat
${TEMP}/utGalibTest${num}_popf.dat
${BASELINE_FILES}/utGalibTest${num}_sinusoid.dat
${TEMP}/utGalibTest${num}_sinusoid.dat
${BASELINE_FILES}/utGalibTest${num}_blog.dat
${TEMP}/utGalibTest${num}_blog.dat
galibTests${num}
${TEMP}/utGalibTest${num}_popi.dat
${TEMP}/utGalibTest${num}_popf.dat
${TEMP}/utGalibTest${num}_sinusoid.dat
score_filename ${TEMP}/utGalibTest${num}_blog.dat
seed 555 )
SET(num 24)
ADD_TEST( utTvGalibTest${num} ${CXX_TEST_PATH}/galibTests${num} galibTests${num}
--compare-n-ascii ${TOL} 3
${BASELINE_FILES}/utGalibTest${num}_population.dat
${TEMP}/utGalibTest${num}_population.dat
${BASELINE_FILES}/utGalibTest${num}_sinusoid.dat
${TEMP}/utGalibTest${num}_sinusoid.dat
${BASELINE_FILES}/utGalibTest${num}_blog.dat
${TEMP}/utGalibTest${num}_blog.dat
galibTests${num}
${INPUTDATA}/galib-settings.txt
${TEMP}/utGalibTest${num}_population.dat
${TEMP}/utGalibTest${num}_sinusoid.dat
score_filename ${TEMP}/utGalibTest${num}_blog.dat
seed 555 )
SET(num 26)
ADD_TEST( utTvGalibTest${num} ${CXX_TEST_PATH}/galibTests${num}
galibTests${num}
${INPUTDATA}/galib-tsp_rect_20.txt
seed 555 )
# ------- lib OpenJpeg ------------------------------
#ADD_TEST(utOpenJpegEncoder ${UTILITIES_TESTS}
......@@ -184,6 +359,16 @@ IF(UNIX)
TARGET_LINK_LIBRARIES (otbUtilitiesTests m)
ENDIF(UNIX)
# ------- CXX and EXECUTABLES files for GALIB Tests -----------------------------------
FOREACH(loop_var RANGE 1 27 1)
ADD_EXECUTABLE(galibTests${loop_var} galibTests${loop_var}.cxx)
IF(UNIX)
TARGET_LINK_LIBRARIES (galibTests${loop_var} m)
ENDIF(UNIX)
TARGET_LINK_LIBRARIES(galibTests${loop_var} otbgalib OTBIO OTBCommon)
ENDFOREACH(loop_var)
# Original 6S main executable in C
# ADD_EXECUTABLE(otb6SMain 6SMainTest.cxx )
# TARGET_LINK_LIBRARIES(otb6SMain OTBCommon ITKCommon otb6S)
......
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
Some parts of this code are derived from libgalib. See GALIBCopyright.txt
for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
// this file defines the otbMultiScaleTest for the test driver
// and all it expects is that you have a function called RegisterTests
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include <iostream>
#include "otbTestMain.h"
void RegisterTests()
{
REGISTER_TEST(galibTests1);
}
/* ----------------------------------------------------------------------------
ex1.C
mbwall 28jul94
Copyright (c) 1995-1996 Massachusetts Institute of Technology
DESCRIPTION:
Example program for the SimpleGA class and 2DBinaryStringGenome class.
This program tries to fill the 2Dgenome with alternating 1s and 0s.
This example uses the default crossover (single point), default mutator
(uniform random bit flip), and default initializer (uniform random) for the
2D genome.
Notice that one-point crossover is not necessarily the best kind of crossover
to use if you want to generate a 'good' genome with this kind of objective
function. But it does work.
---------------------------------------------------------------------------- */
#include <ga/GASimpleGA.h> // we're going to use the simple GA
#include <ga/GA2DBinStrGenome.h> // and the 2D binary string genome
#include <ga/std_stream.h>
#define cout STD_COUT
float Objective(GAGenome &); // This is the declaration of our obj function.
// The definition comes later in the file.
int
galibTests1(int argc, char *argv[])
{
cout << "Example 1\n\n";
cout << "This program tries to fill a 2DBinaryStringGenome with\n";
cout << "alternating 1s and 0s using a SimpleGA\n\n"; cout.flush();
// See if we've been given a seed to use (for testing purposes). When you
// specify a random seed, the evolution will be exactly the same each time
// you use that seed number.
for(int ii=1; ii<argc; ii++) {
if(strcmp(argv[ii++],"seed") == 0) {
GARandomSeed((unsigned int)atoi(argv[ii]));
}
}
// Declare variables for the GA parameters and set them to some default values.
int width = 10;
int height = 5;
int popsize = 30;
int ngen = 400;
float pmut = 0.001;
float pcross = 0.9;
// Now create the GA and run it. First we create a genome of the type that
// we want to use in the GA. The ga doesn't operate on this genome in the
// optimization - it just uses it to clone a population of genomes.
GA2DBinaryStringGenome genome(width, height, Objective);
// Now that we have the genome, we create the genetic algorithm and set
// its parameters - number of generations, mutation probability, and crossover
// probability. And finally we tell it to evolve itself.
GASimpleGA ga(genome);
ga.populationSize(popsize);
ga.nGenerations(ngen);
ga.pMutation(pmut);
ga.pCrossover(pcross);
ga.evolve();
// Now we print out the best genome that the GA found.
cout << "The GA found:\n" << ga.statistics().bestIndividual() << "\n";
// That's it!
return 0;
}
// This is the objective function. All it does is check for alternating 0s and
// 1s. If the gene is odd and contains a 1, the fitness is incremented by 1.
// If the gene is even and contains a 0, the fitness is incremented by 1. No
// penalties are assigned.
// We have to do the cast because a plain, generic GAGenome doesn't have
// the members that a GA2DBinaryStringGenome has. And it's ok to cast it
// because we know that we will only get GA2DBinaryStringGenomes and
// nothing else.
float
Objective(GAGenome& g) {
GA2DBinaryStringGenome & genome = (GA2DBinaryStringGenome &)g;
float score=0.0;
int count=0;
for(int i=0; i<genome.width(); i++){
for(int j=0; j<genome.height(); j++){
if(genome.gene(i,j) == 0 && count%2 == 0)
score += 1.0;
if(genome.gene(i,j) == 1 && count%2 != 0)
score += 1.0;
count++;
}
}
return score;
}
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
Some parts of this code are derived from libgalib. See GALIBCopyright.txt
for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
// this file defines the otbMultiScaleTest for the test driver
// and all it expects is that you have a function called RegisterTests
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include <iostream>
#include "otbTestMain.h"
void RegisterTests()
{
REGISTER_TEST(galibTests10);
}
/* ----------------------------------------------------------------------------
ex10.C
mbwall 10apr95
Copyright (c) 1995-1996 Massachusetts Institute of Technology
DESCRIPTION:
Sample program that illustrates how to use a distance function to do
speciation. This example does both gene-based and phenotype-based distance
calculations. The differences are quite interesting. Also, the length of the
bit string (i.e. the size of the search space) is also a significant factor in
the performance of the speciation methods.
Notice that Goldberg describes fitness scaling speciation in the context of
a simple genetic algorithm. You can try using it with a steady-state
algorithm, but you'll get bogus results unless you modify the algorithm.
---------------------------------------------------------------------------- */
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <ga/ga.h>
#include <ga/std_stream.h>
#define cout STD_COUT
#define cerr STD_CERR
#define endl STD_ENDL
#define ofstream STD_OFSTREAM
#define USE_RAW_SINE
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define NBITS 8
#ifdef USE_RAW_SINE
#define FUNCTION Function1
#define MIN_VALUE 0
#define MAX_VALUE 5
#else
#define FUNCTION Function2
#define MIN_VALUE -100
#define MAX_VALUE 100
#endif
float Function1(float);
float Function2(float);
float Objective(GAGenome &);
float BitDistance(const GAGenome & a, const GAGenome & b);
float PhenotypeDistance(const GAGenome & a, const GAGenome & b);
int
galibTests10(int argc, char *argv[])
{
cout << "Example 10\n\n";
cout << "This program uses sharing to do speciation. The objective\n";
cout << "function has more than one optimum, so different genomes\n";
cout << "may have equally high scores. Speciation keeps the population\n";
cout << "from clustering at one optimum.\n";
cout << " Both gene-wise and phenotype-wise distance functions are used.\n";
cout << " Populations from all three runs are written to the files \n";
cout << "pop.nospec.dat, pop.genespec.dat and pop.phenespec.dat. The\n";
cout << "function is written to the file sinusoid.dat\n\n";
cout.flush();
// See if we've been given a seed to use (for testing purposes). When you
// specify a random seed, the evolution will be exactly the same each time
// you use that seed number.
int i;
const char * filename = argv[1];//"sinusoid.dat";
const char * popfilename1 = argv[2];//"pop.nospec.dat";
const char * popfilename2 = argv[3];//"pop.genespec.dat";
const char * popfilename3 = argv[4];//"pop.phenespec.dat";
ofstream outfile;
for(int ii=1; ii<argc; ii++) {
if(strcmp(argv[ii],"seed") == 0) {
GARandomSeed((unsigned int)atoi(argv[ii+1]));
}
}
// Create a phenotype for two variables. The number of bits you can use to
// represent any number is limited by the type of computer you are using. In
// this case, we use 16 bits to represent a floating point number whose value
// can range from the minimum to maximum value as defined by the macros.
GABin2DecPhenotype map;
map.add(NBITS, MIN_VALUE, MAX_VALUE);
// Create the template genome using the phenotype map we just made.
GABin2DecGenome genome(map, Objective);
// Now create the GA using the genome and set all of the parameters.
// You'll get different results depending on the type of GA that you use. The
// steady-state GA tends to converge faster (depending on the type of replace-
// ment method you specify).
GASimpleGA ga(genome);
ga.set(gaNpopulationSize, 200);
ga.set(gaNnGenerations, 50);
ga.set(gaNpMutation, 0.001);
ga.set(gaNpCrossover, 0.9);
ga.parameters(argc, argv);
// Do the non-speciated and write to file the best-of-generation.
cout << "running with no speciation (fitness proportionate scaling)...\n";
cout.flush();
GALinearScaling lin;
ga.scaling(lin);
ga.evolve();
genome = ga.statistics().bestIndividual();
cout << "the ga found an optimum at the point "<<genome.phenotype(0)<<endl;
outfile.open(popfilename1, (STD_IOS_OUT | STD_IOS_TRUNC));
if(outfile.fail()){
cerr << "Cannot open " << popfilename1 << " for output.\n";
exit(1);
}
for(i=0; i<ga.population().size(); i++){
outfile<<((GABin2DecGenome&)(ga.population().individual(i))).phenotype(0);
outfile << "\t";
outfile << ga.population().individual(i).score() << "\n";
}
outfile.close();
// Now do speciation using the gene-wise distance function
cout << "running the ga with speciation (sharing using bit-wise)...\n";
cout.flush();
GASharing bitSharing(BitDistance);
ga.scaling(bitSharing);
ga.evolve();
genome = ga.statistics().bestIndividual();
cout << "the ga found an optimum at the point "<<genome.phenotype(0)<<endl;
outfile.open(popfilename2, (STD_IOS_OUT | STD_IOS_TRUNC));
if(outfile.fail()){
cerr << "Cannot open " << popfilename2 << " for output.\n";
exit(1);
}
for(i=0; i<ga.population().size(); i++){
outfile<<((GABin2DecGenome&)(ga.population().individual(i))).phenotype(0);
outfile << "\t";
outfile << ga.population().individual(i).score() << "\n";
}
outfile.close();
// Now do speciation using the phenotype-wise distance function
cout << "running the ga with speciation (sharing using phenotype-wise)...\n";
cout.flush();
GASharing pheneSharing(PhenotypeDistance);
ga.scaling(pheneSharing);
ga.evolve();
genome = ga.statistics().bestIndividual();
cout << "the ga found an optimum at the point "<<genome.phenotype(0)<<endl;
outfile.open(popfilename3, (STD_IOS_OUT | STD_IOS_TRUNC));
if(outfile.fail()){
cerr << "Cannot open " << popfilename3 << " for output.\n";
exit(1);
}
for(i=0; i<ga.population().size(); i++){
outfile<<((GABin2DecGenome&)(ga.population().individual(i))).phenotype(0);
outfile << "\t";
outfile << ga.population().individual(i).score() << "\n";
}
outfile.close();
// Now dump the function to file for comparisons
cout << "dumping the function to file..." << endl;
outfile.open(filename, (STD_IOS_OUT | STD_IOS_TRUNC));
if(outfile.fail()){
cerr << "Cannot open " << filename << " for output.\n";
exit(1);
}
float inc = MAX_VALUE - MIN_VALUE;
inc /= pow(2.0,NBITS);
for(float x=MIN_VALUE; x<=MAX_VALUE; x+=inc){
outfile << x << "\t" << FUNCTION (x) << "\n";
}
outfile << "\n";
outfile.close();
return 0;
}