IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

MATLAB Discussion :

Optimisation génétique : domaine de définition [Débutant]


Sujet :

MATLAB

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Juillet 2010
    Messages
    6
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Juillet 2010
    Messages : 6
    Points : 2
    Points
    2
    Par défaut Optimisation génétique : domaine de définition
    Bonjour,
    J'ai réalisé un programme dans excel et je cherche maintenant à trouver l'optimum grace à la toolbox d'optimisation génétique de Matlab. C'est à dire que la fonction appellée par la toolbox d'optimisation est simplement une fonction d'échange avec Excel ; Matlab défini les variables, les transmet à excel qui calcule le résultat et le retourne dans Matlab (comme si c'était une fonction normale). Ca marche sans soucis pour des problèmes relativement simples, mais les choses se compliquent ^^!

    J'ai un vecteur contenant toutes les variables, j'utilise la fonction 'ga' (genetique algorithme) et je ne trouve pas le moyen de définir un domaine de définition. Je souhaite que la fonction 'ga' ne travaille qu'avec des entiers compris entre un vecteur lowerbound et un vecteur upperbound pour les variables. J'ai maintenant l'impression d'avoir fait le tour de l'aide et je n'ai pas trouvé d'argument ou d'option permettant d'entrer un domaine de définition.
    Auriez-vous une solution ou une idée?
    Merci!

  2. #2
    Modérateur

    Homme Profil pro
    Ingénieur en calculs scientifiques
    Inscrit en
    Août 2007
    Messages
    4 639
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Ingénieur en calculs scientifiques

    Informations forums :
    Inscription : Août 2007
    Messages : 4 639
    Points : 7 614
    Points
    7 614
    Par défaut
    Bonjour,

    je n'ai peut-être pas bien compris ton problème mais pourtant :
    X = GA(FITNESSFCN,NVARS,A,b,Aeq,beq,lb,ub) defines a set of lower and
    upper bounds on the design variables, X, so that a solution is found in
    the range lb <= X <= ub
    . Use empty matrices for lb and ub if no bounds
    exist. Set lb(i) = -Inf if X(i) is unbounded below; set ub(i) = Inf if
    X(i) is unbounded above. Linear constraints are not satisfied when the
    PopulationType option is set to 'bitString' or 'custom'. See the
    documentation for details.
    Pour une bonne utilisation des balises code c'est ici!
    Petit guide du voyageur MATLABien : Le forum La faq Les tutoriels Les sources


    La nature est un livre écrit en langage mathématique. Galilée.

  3. #3
    Candidat au Club
    Profil pro
    Inscrit en
    Juillet 2010
    Messages
    6
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Juillet 2010
    Messages : 6
    Points : 2
    Points
    2
    Par défaut
    Bonjour Magelan!
    Merci d'avoir pris un peu de temps pour jetter un oeil à mon problème.
    Lorsque j'utilise cette syntaxe ;
    X = GA (FITNESSFCN,NVARS,A,b,Aeq,beq,lb,ub)
    ce qui donne dans mon cas :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    A = ga(@(A)excel(A,serveur), 2,D,E,F,G,lower,upper)
    je reçois le message d'erreur suivant :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    ??? Error using ==> ga
    Too many input arguments.
     
    Error in ==> Test_opti_gene at 55
    A = ga(@(A)excel(A,serveur), 2,D,E,F,G,lower,upper)
    (excel est la fonction de communication entre excel et matlab, elle a besoins de 'serveur' pour établir le lien entre les deux programmes mais ce n'est bien entendu pas une des variables.)

    Je fonctionnais jusqu'à présent avec la syntaxe
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    x = ga(fitnessfun, nvars, options)
    où 'options' est défini à l'aide de 'gaoptimset' ou encore de 'gatool'.
    Je ne parviens pas travailler uniquement avec 'gatool' puisque le lien entre les deux programmes doit être initialiser en début de script avant que la fonction excel ne fonctionne. Je ne vois dans aucun des deux cas la possibilité de définir un 'lb' et un 'ub'? On peut définir un 'PopInitRange' mais il me semble que cela ne concerne que la première génération.
    Pour ce qui est de ne travailler qu'avec des entiers aurais-tu une idée?
    Merci

  4. #4
    Modérateur

    Homme Profil pro
    Ingénieur en calculs scientifiques
    Inscrit en
    Août 2007
    Messages
    4 639
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Ingénieur en calculs scientifiques

    Informations forums :
    Inscription : Août 2007
    Messages : 4 639
    Points : 7 614
    Points
    7 614
    Par défaut
    Que contienne D,E,F,G, lower et upper?
    La ligne suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    [x,fval,exitflag] = ga(@(A)excel(A,serveur),2,[],[],[],[],[],[])
    provoque la même erreur?

    Quelle est ta version de matlab et de la toolbox d'optimisation génétique? (tape ver dans la fenêtre commad window de MATLAB)
    Pour une bonne utilisation des balises code c'est ici!
    Petit guide du voyageur MATLABien : Le forum La faq Les tutoriels Les sources


    La nature est un livre écrit en langage mathématique. Galilée.

  5. #5
    Candidat au Club
    Profil pro
    Inscrit en
    Juillet 2010
    Messages
    6
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Juillet 2010
    Messages : 6
    Points : 2
    Points
    2
    Par défaut
    Lower et upper étaient des vecteurs à deux composantes dans ce cas ci. D E F G étaient des vecteurs vides.
    J'obtiens la même erreur en essayant la ligne de code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    [x,fval,exitflag] = ga(@(A)excel(A,serveur),2,[],[],[],[],[],[])
    Cela pourrait être du à un problème de version du programme?

    La commande ver me donne :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    -------------------------------------------------------------------------------------
    MATLAB Version 7.0.1.24704 (R14) Service Pack 1
    MATLAB License Number: xxxxxx
    Operating System: Microsoft Windows XP Version 5.1 (Build 2600: Service Pack 3)
    Java VM Version: Java 1.4.2_04 with Sun Microsystems Inc. Java HotSpot(TM) Client VM
    -------------------------------------------------------------------------------------
    et pour la toolbox
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Genetic Algorithm Direct Search Toolbox               Version 1.0.2      (R14SP1)

  6. #6
    Modérateur

    Homme Profil pro
    Ingénieur en calculs scientifiques
    Inscrit en
    Août 2007
    Messages
    4 639
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Ingénieur en calculs scientifiques

    Informations forums :
    Inscription : Août 2007
    Messages : 4 639
    Points : 7 614
    Points
    7 614
    Par défaut
    C es possible, ta version n'est pas recente...

    Quant tu regardes dans la doc de ga, cette syntaxe :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    X = GA (FITNESSFCN,NVARS,A,b,Aeq,beq,lb,ub)
    elle apparaît dans la doc?
    Pour une bonne utilisation des balises code c'est ici!
    Petit guide du voyageur MATLABien : Le forum La faq Les tutoriels Les sources


    La nature est un livre écrit en langage mathématique. Galilée.

  7. #7
    Candidat au Club
    Profil pro
    Inscrit en
    Juillet 2010
    Messages
    6
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Juillet 2010
    Messages : 6
    Points : 2
    Points
    2
    Par défaut
    non, j'ai déjà vu cette syntaxe pour d'autres fonctions d'optimisation mais pour ga j'ai :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    x = ga(fitnessfun, nvars, options)
    avec options on peut régler un paquet de chose, mais je ne vois pas les limites pour les variables, ni les définir comme des entiers. Je vais essayer de me procurer une version plus récente, on ne sait jamais...

  8. #8
    Modérateur

    Homme Profil pro
    Ingénieur en calculs scientifiques
    Inscrit en
    Août 2007
    Messages
    4 639
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Ingénieur en calculs scientifiques

    Informations forums :
    Inscription : Août 2007
    Messages : 4 639
    Points : 7 614
    Points
    7 614
    Par défaut
    Ok, en même temps, c'est bien ce que tu avais précise dans ton premier message, mais je ne connaissais pas ta version.

    Peux-tu copier le help de ga que tu as dans ta version?
    Pour une bonne utilisation des balises code c'est ici!
    Petit guide du voyageur MATLABien : Le forum La faq Les tutoriels Les sources


    La nature est un livre écrit en langage mathématique. Galilée.

  9. #9
    Candidat au Club
    Profil pro
    Inscrit en
    Juillet 2010
    Messages
    6
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Juillet 2010
    Messages : 6
    Points : 2
    Points
    2
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    Genetic Algorithm and Direct Search Toolbox   ga 
     
    Find the minimum of a function using the genetic algorithm 
    Syntax
    x = ga(fitnessfun, nvars)
    x = ga(fitnessfun, nvars, options)
    x = ga(problem)
    [x, fval] = ga(...)
    [x, fval, reason] = ga(...)
    [x, fval, reason, output] = ga(...)
    [x, fval, reason, output, population] = ga(...)
    [x, fval, reason, output, population, scores] = ga(...)
     
    Description
     
    ga implements the genetic algorithm at the command line to minimize an objective function. 
    x = ga(fitnessfun, nvars) applies the genetic algorithm to an optimization problem, where fitnessfun is the objective function to minimize and nvars is the length of the solution vector x, the best individual found. 
    x = ga(fitnessfun, nvars, options) applies the genetic algorithm to an optimization problem, using the parameters in the options structure. 
    x = ga(problem) finds the minimum for problem, a structure that has three fields: fitnessfcn -- Fitness function nvars -- Number of independent variables for the fitness function options -- Options structure created with gaoptimset 
    [x, fval] = ga(...) returns fval, the value of the fitness function at x. 
    [x, fval, reason] = ga(...) returns reason, a string containing the reason the algorithm stops. 
    [x, fval, reason, output] = ga(...) returns output, a structure that contains output from each generation and other information about the performance of the algorithm. The output structure contains the following fields: randstate -- The state of rand, the MATLAB random number generator, just before the algorithm started. randnstate -- The state of randn the MATLAB normal random number generator, just before the algorithm started. You can use the values of randstate and randnstate to reproduce the output of ga. See Reproducing Your Results. generations -- The number of generations computed funccount -- The number of evaluations of the fitness function message -- The reason the algorithm terminated. This message is the same as the output argument reason. 
    [x, fval, reason, output, population] = ga(...) returns matrix population, whose rows are the final population. 
    [x, fval, reason, output, population, scores] = ga(...) returns scores, the scores of the final population. 
    Note    For problems that use the population type Double Vector (the default), ga does not accepts functions whose inputs are of type complex. To solve problems involving complex data, write your functions so that they accept real vectors, by separating the real and imaginary parts. 
    Example
    [x fval, reason] = ga(@rastriginsFcn, 10)
    x =
     
      Columns 1 through 7 
     
        0.9977    0.9598    0.0085    0.0097   -0.0274   -0.0173    0.9650
     
      Columns 8 through 10 
     
       -0.0021   -0.0210    0.0065
     
    fval =
     
        3.7456
     
    reason =
     
    generations
     
    Reference
     
    [1]  Goldberg, David E., Genetic Algorithms in Search, Optimzation & Machine Learning, Addison-Wesley, 1989. 
    See Also
     
    gaoptimset, gatool
    gaoptimset permet normalement de tout paramétrer, voici l'aide de gaoptimset : (le tableau n'est pas très lisible ici désolé)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    Genetic Algorithm and Direct Search Toolbox   gaoptimset 
     
    Create a genetic algorithm options structure 
    Syntax
    options = gaoptimset
    gaoptimset
    options = gaoptimset('param1',value1,'param2',value2,...)
    options = gaoptimset(oldopts,'param1',value1,...)
    options = gaoptimset(oldopts,newopts)
     
    Description
     
    options = gaoptimset (with no input arguments) creates a structure called options that contains the options, or parameters, for the genetic algorithm and sets parameters to their default values. 
    gaoptimset with no input or output arguments displays a complete list of parameters with their valid values. 
    options = gaoptimset('param1',value1,'param2',value2,...) creates a structure options and sets the value of 'param1' to value1, 'param2' to value2, and so on. Any unspecified parameters are set to their default values. It is sufficient to type only enough leading characters to define the parameter name uniquely. Case is ignored for parameter names. 
    options = gaoptimset(oldopts,'param1',value1,...) creates a copy of oldopts, modifying the specified parameters with the specified values. 
    options = gaoptimset(oldopts,newopts) combines an existing options structure, oldopts, with a new options structure, newopts. Any parameters in newopts with nonempty values overwrite the corresponding old parameters in oldopts. 
    Options
     
    The following table lists the options you can set with gaoptimset. See Genetic Algorithm Options for a complete description of these options and their values. Values in {} denote the default value. You can also view the optimization parameters and defaults by typing gaoptimset at the command line. 
    Option
    Description
    Values
    CreationFcnHandle to the function that creates the initial population
    {@gacreationuniform} CrossoverFractionThe fraction of the population at the next generation, not including elite children, that is created by the crossover function
    Positive scalar | {0.8} CrossoverFcnHandle to the function that the algorithm uses to create crossover children
    @crossoverheuristic
    {@crossoverscattered}
    @crossoverintermediate
    @crossoversinglepoint
    @crossovertwopoint EliteCountPositive integer specifying how many individuals in the current generation are guaranteed to survive to the next generation
    Positive integer | {2} FitnessLimitScalar. If the fitness function attains the value of FitnessLimit, the algorithm halts. 
    Scalar | {-Inf} FitnessScalingFcnHandle to the function that scales the values of the fitness function
    @fitscalinggoldberg
    {@fitscalingrank}
    @fitscalingprop
    @fitscalingtop GenerationsPositive integer specifying the maximum number of iterations before the algorithm halts
    Positive integer |{100} PopInitRangeMatrix or vector specifying the range of the individuals in the initial population 
    Matrix or vector | [0;1] PopulationTypeString describing the data type of the population
    'bitstring' | 'custom' | {'doubleVector'} HybridFcnHandle to a function that continues the optimization after ga terminates
    Function handle | {[]} InitialPopulationInitial population
    Positive scalar | {[]} InitialScoresInitial scores
    Column vector | {[]} MigrationDirectionDirection of migration
    'both' | {'forward'} MigrationFractionScalar between 0 and 1 specifying the fraction of individuals in each subpopulation that migrates to a different subpopulation
    Scalar | {0.2} MigrationIntervalPositive integer specifying the number of generations that take place between migrations of individuals between subpopulations
    Positive integer | {20} MutationFcnHandle to the function that produces mutation children
    @mutationuniform
    {@mutationgaussian} OutputFcnsArray of handles to functions that ga calls at each iteration.
    Array | {[]} OutputIntervalPositive integer specifying the number of generations between consecutive calls to the output functions
    Positive integer | {1} PlotFcnsArray of handles to functions that plot data computed by the algorithm
    @gaplotbestf @gaplotbestgenome @gaplotdistance @gaplotexpectation @gaplotgeneology @gaplotselection @gaplotrange @gaplotscorediversity @gaplotscores @gaplotstopping | {[]} PlotIntervalPositive integer specifying the number of generations between consecutive calls to the plot functions 
    Positive integer | {1} PopulationSizeSize of the population
    Positive integer | {20} SelectionFcnHandle to the function that selects parents of crossover and mutation children
    @selectiongoldberg
    @selectionrandom
    {@selectionstochunif}
    @selectionroulette
    @selectiontournament StallGenLimitPositive integer. The algorithm stops if there is no improvement in the objective function for StallGenLimit consecutive generations.
    Positive integer | {50} StallTimeLimitPositive scalar. The algorithm stops if there is no improvement in the objective function for StallTimeLimit seconds.
    Positive scalar | {20} TimeLimitPositive scalar. The algorithm stops after running for TimeLimit seconds.
    Positive scalar | {30} VectorizedString specifying whether the computation of the fitness function is vectorized 
    'on' | {'off'}
    Et gatool est une commande qui ouvre un interface qui est sensé simplifier l'implémentation de la fonction. Je pense qu'il ne donne pas accès à des option en plus.

  10. #10
    Modérateur

    Homme Profil pro
    Ingénieur en calculs scientifiques
    Inscrit en
    Août 2007
    Messages
    4 639
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Ingénieur en calculs scientifiques

    Informations forums :
    Inscription : Août 2007
    Messages : 4 639
    Points : 7 614
    Points
    7 614
    Par défaut
    Ta version de toolbox ga n'est même pas affichée dans les release du site mathworks.

    Apparemment, c'est à parti de la verion 2.0 de la toolbox ga que l'on peut introduire des contraintes et des frontières.

    Donc à part mettre à jour MATLAB et la toolbox...
    Pour une bonne utilisation des balises code c'est ici!
    Petit guide du voyageur MATLABien : Le forum La faq Les tutoriels Les sources


    La nature est un livre écrit en langage mathématique. Galilée.

  11. #11
    Candidat au Club
    Profil pro
    Inscrit en
    Juillet 2010
    Messages
    6
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Juillet 2010
    Messages : 6
    Points : 2
    Points
    2
    Par défaut
    Avec la dernière version de MatLab, mon problème s'est avéré beaucoup moins compliqué
    Encore merci pour le coup de main!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Domaine de définition gnuplot
    Par algonum dans le forum Autres langages
    Réponses: 1
    Dernier message: 14/05/2011, 08h38
  2. Domaine de définition d'une variable
    Par Sarra_ dans le forum MATLAB
    Réponses: 4
    Dernier message: 13/12/2009, 11h07
  3. 2 colonnes sur même domaine de définition
    Par merise_lover dans le forum Langage SQL
    Réponses: 7
    Dernier message: 15/05/2008, 13h43
  4. Contrôle du domaine de définition
    Par Mister Nono dans le forum Langage
    Réponses: 1
    Dernier message: 27/03/2008, 14h48
  5. Optimisation sur domaine fini
    Par gorgonite dans le forum Prolog
    Réponses: 1
    Dernier message: 04/10/2006, 23h02

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo