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 de fonction objectif (distance de hamming) par métaheuristique


Sujet :

MATLAB

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mars 2013
    Messages
    221
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Enseignement

    Informations forums :
    Inscription : Mars 2013
    Messages : 221
    Points : 31
    Points
    31
    Par défaut optimisation de fonction objectif (distance de hamming) par métaheuristique
    Bonjour tout le monde
    j'essaye d'optimiser dans la mise en correspondance de 2 images
    en fait étant donné les 2 images je cherche d'abord leurs points d’intérêts et je stocke ces points dans deux matrices, puis j'effectue la transformée de census pour chaque matrice et j'aboutie à 2 vecteurs binaires, entre ces 2 vecteurs je veux appliquer la distance de Hamming mais j'aime bien optimiser en minimisant la fonction objectif ( distance de hamming) à l'aide d'une métaheuristique qui est l'algorithme de colonie d'abeilles de miel.
    mon problème est la manipulation des paramètres de cet algorithme. voila ou je suis stagné
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    %/* Problem specific variables*/
    im1=imread('C:\Users\Aymen\Desktop\ABCmatlabcode\MATLABABCv2\image1.jpg');
    im2=imread('C:\Users\Aymen\Desktop\ABCmatlabcode\MATLABABCv2\image2.jpg');
    [C1,C2]=census1(im1,im2);
     
    objfun='distance_hamming'; %cost function to be optimized
    D=10; %/*The number of parameters of the problem to be optimized*/
    ub=ones(1,D)*100; %/*lower bounds of the parameters. */
    lb=ones(1,D)*(-100);%/*upper bound of the parameters.*/
    quand exécute le programme voici les erreurs
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    ??? Input argument "C2" is undefined.
     
    Error in ==> distance_hamming at 10
            out2 = dec2binvec(double(C2(i,j)),8);
     
    Error in ==> mainv21 at 72
    ObjVal=feval(objfun,Foods);
    malgré que dans le workspace j'ai C2 remplie
    y a t'il des suggestions d'aide ? j’espère que j'ai bien expliqué et posé mon problème ainsi que mon travail

  2. #2
    Membre éprouvé
    Inscrit en
    Août 2010
    Messages
    1 124
    Détails du profil
    Informations forums :
    Inscription : Août 2010
    Messages : 1 124
    Points : 1 277
    Points
    1 277
    Par défaut
    Bonjour,

    Vu que ton code n'appelle pas distance_hamming(), il doit en manquer une partie !

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mars 2013
    Messages
    221
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Enseignement

    Informations forums :
    Inscription : Mars 2013
    Messages : 221
    Points : 31
    Points
    31
    Par défaut
    en fait la distance_hamming c'est la fonction objectif que je dois la réduire avec l'algorithme d'abeille de miel artificiel
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    objfun='distance_hamming'; %cost function to be optimized
    meme en ajoutant une ligne de code pour:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    distance_hamming(C1 ,C2 );
    aprés avoir C1 et C2 j'ai la meme erreur .
    en fait voila tout le code qui inclut les paramètres de mon problème ( mise en correspondance entre 2 images et l'algorithme d'abeilles de miel artificiel) :
    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
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    %/* ABC algorithm  */
     
     
    clear all
    close all
    clc
     
    %/* Control Parameters of ABC algorithm*/
    NP=20; %/* The number of colony size (employed bees+onlooker bees)*/
    FoodNumber=NP/2; %/*The number of food sources equals the half of the colony size*/
    limit=100; %/*A food source which could not be improved through "limit" trials is abandoned by its employed bee*/
    maxCycle=25; %/*The number of cycles for foraging {a stopping criteria}*/
     
     
    %/* Problem specific variables*/
    im1=imread('C:\Users\Aymen\Desktop\ABCmatlabcode\MATLABABCv2\image1.jpg');
    im2=imread('C:\Users\Aymen\Desktop\ABCmatlabcode\MATLABABCv2\image4.jpg');
    %[C1,C2]=census1(im1,im2);
    voisinage=3;
    C1 = TransCensus (im1,voisinage);
    C2=TransCensus (im2,voisinage);
    distance_hamming(C1 ,C2 );
    objfun='distance_hamming'; %cost function to be optimized
    D=10; %/*The number of parameters of the problem to be optimized*/
    %ub=3;
    %lb=-3;
    ub=ones(1,D)*100; %/*lower bounds of the parameters. */
    lb=ones(1,D)*(-100);%/*upper bound of the parameters.*/
     
    runtime=1;%/*Algorithm can be run many times in order to see its robustness*/
     
     
     
    %Foods [FoodNumber][D]; /*Foods is the population of food sources. Each row of Foods matrix is a vector holding D parameters to be optimized. The number of rows of Foods matrix equals to the FoodNumber*/
    %ObjVal[FoodNumber];  /*f is a vector holding objective function values associated with food sources */
    %Fitness[FoodNumber]; /*fitness is a vector holding fitness (quality) values associated with food sources*/
    %trial[FoodNumber]; /*trial is a vector holding trial numbers through which solutions can not be improved*/
    %prob[FoodNumber]; /*prob is a vector holding probabilities of food sources (solutions) to be chosen*/
    %solution [D]; /*New solution (neighbour) produced by v_{ij}=x_{ij}+\phi_{ij}*(x_{kj}-x_{ij}) j is a randomly chosen parameter and k is a randomlu chosen solution different from i*/
    %ObjValSol; /*Objective function value of new solution*/
    %FitnessSol; /*Fitness value of new solution*/
    %neighbour, param2change; /*param2change corrresponds to j, neighbour corresponds to k in equation v_{ij}=x_{ij}+\phi_{ij}*(x_{kj}-x_{ij})*/
    %GlobalMin; /*Optimum solution obtained by ABC algorithm*/
    %GlobalParams[D]; /*Parameters of the optimum solution*/
    %GlobalMins[runtime]; /*GlobalMins holds the GlobalMin of each run in multiple runs*/
     
    GlobalMins=zeros(1,runtime);
     
    for r=1:runtime
     
    % /*All food sources are initialized */
    %/*Variables are initialized in the range [lb,ub]. If each parameter has different range, use arrays lb[j], ub[j] instead of lb and ub */
     
    Range = repmat((ub-lb),[FoodNumber 1]);
    Lower = repmat(lb, [FoodNumber 1]);
    Foods = rand(FoodNumber,D) .* Range + Lower;
     
    ObjVal=feval(objfun,Foods);
    Fitness=calculateFitness(ObjVal);
     
    %reset trial counters
    trial=zeros(1,FoodNumber);
     
    %/*The best food source is memorized*/
    BestInd=find(ObjVal==min(ObjVal));
    BestInd=BestInd(end);
    GlobalMin=ObjVal(BestInd);
    GlobalParams=Foods(BestInd,:);
     
    iter=1;
    while ((iter <= maxCycle)),
     
    %%%%%%%%% EMPLOYED BEE PHASE %%%%%%%%%%%%%%%%%%%%%%%%
        for i=1:(FoodNumber)
     
            %/*The parameter to be changed is determined randomly*/
            Param2Change=fix(rand*D)+1;
     
            %/*A randomly chosen solution is used in producing a mutant solution of the solution i*/
            neighbour=fix(rand*(FoodNumber))+1;
     
            %/*Randomly selected solution must be different from the solution i*/        
                while(neighbour==i)
                    neighbour=fix(rand*(FoodNumber))+1;
                end;
     
           sol=Foods(i,:);
           %  /*v_{ij}=x_{ij}+\phi_{ij}*(x_{kj}-x_{ij}) */
           sol(Param2Change)=Foods(i,Param2Change)+(Foods(i,Param2Change)-Foods(neighbour,Param2Change))*(rand-0.5)*2;
     
           %  /*if generated parameter value is out of boundaries, it is shifted onto the boundaries*/
            ind=find(sol<lb);
            sol(ind)=lb(ind);
            ind=find(sol>ub);
            sol(ind)=ub(ind);
     
            %evaluate new solution
            ObjValSol=feval(objfun,sol);
            FitnessSol=calculateFitness(ObjValSol);
     
           % /*a greedy selection is applied between the current solution i and its mutant*/
           if (FitnessSol>Fitness(i)) %/*If the mutant solution is better than the current solution i, replace the solution with the mutant and reset the trial counter of solution i*/
                Foods(i,:)=sol;
                Fitness(i)=FitnessSol;
                ObjVal(i)=ObjValSol;
                trial(i)=0;
            else
                trial(i)=trial(i)+1; %/*if the solution i can not be improved, increase its trial counter*/
           end;
     
     
        end;
     
    %%%%%%%%%%%%%%%%%%%%%%%% CalculateProbabilities %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %/* A food source is chosen with the probability which is proportioal to its quality*/
    %/*Different schemes can be used to calculate the probability values*/
    %/*For example prob(i)=fitness(i)/sum(fitness)*/
    %/*or in a way used in the metot below prob(i)=a*fitness(i)/max(fitness)+b*/
    %/*probability values are calculated by using fitness values and normalized by dividing maximum fitness value*/
     
    prob=(0.9.*Fitness./max(Fitness))+0.1;
     
    %%%%%%%%%%%%%%%%%%%%%%%% ONLOOKER BEE PHASE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     
    i=1;
    t=0;
    while(t<FoodNumber)
        if(rand<prob(i))
            t=t+1;
            %/*The parameter to be changed is determined randomly*/
            Param2Change=fix(rand*D)+1;
     
            %/*A randomly chosen solution is used in producing a mutant solution of the solution i*/
            neighbour=fix(rand*(FoodNumber))+1;
     
            %/*Randomly selected solution must be different from the solution i*/        
                while(neighbour==i)
                    neighbour=fix(rand*(FoodNumber))+1;
                end;
     
           sol=Foods(i,:);
           %  /*v_{ij}=x_{ij}+\phi_{ij}*(x_{kj}-x_{ij}) */
           sol(Param2Change)=Foods(i,Param2Change)+(Foods(i,Param2Change)-Foods(neighbour,Param2Change))*(rand-0.5)*2;
     
           %  /*if generated parameter value is out of boundaries, it is shifted onto the boundaries*/
            ind=find(sol<lb);
            sol(ind)=lb(ind);
            ind=find(sol>ub);
            sol(ind)=ub(ind);
     
            %evaluate new solution
            ObjValSol=feval(objfun,sol);
            FitnessSol=calculateFitness(ObjValSol);
     
           % /*a greedy selection is applied between the current solution i and its mutant*/
           if (FitnessSol>Fitness(i)) %/*If the mutant solution is better than the current solution i, replace the solution with the mutant and reset the trial counter of solution i*/
                Foods(i,:)=sol;
                Fitness(i)=FitnessSol;
                ObjVal(i)=ObjValSol;
                trial(i)=0;
            else
                trial(i)=trial(i)+1; %/*if the solution i can not be improved, increase its trial counter*/
           end;
        end;
     
        i=i+1;
        if (i==(FoodNumber)+1) 
            i=1;
        end;   
    end; 
     
     
    %/*The best food source is memorized*/
             ind=find(ObjVal==min(ObjVal));
             ind=ind(end);
             if (ObjVal(ind)<GlobalMin)
             GlobalMin=ObjVal(ind);
             GlobalParams=Foods(ind,:);
             end;
     
     
    %%%%%%%%%%%% SCOUT BEE PHASE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     
    %/*determine the food sources whose trial counter exceeds the "limit" value. 
    %In Basic ABC, only one scout is allowed to occur in each cycle*/
     
    ind=find(trial==max(trial));
    ind=ind(end);
    if (trial(ind)>limit)
        trial(ind)=0;
        sol=(ub-lb).*rand(1,D)+lb;
        ObjValSol=feval(objfun,sol);
        FitnessSol=calculateFitness(ObjValSol);
        Foods(ind,:)=sol;
        Fitness(ind)=FitnessSol;
        ObjVal(ind)=ObjValSol;
    end;
     
     
     
    fprintf('Ýter=%d ObjVal=%g\n',iter,GlobalMin);
    iter=iter+1;
     
    end % End of ABC
     
    GlobalMins(r)=GlobalMin;
    end; %end of runs
     
    save all
    les fonctions TransCensus, distance_hamming sont définis comme fonctions.
    y a t'il des suggestions de solutions ou bien des paramètres à régler ... ?

  4. #4
    Nouveau membre du Club
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mars 2013
    Messages
    221
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Enseignement

    Informations forums :
    Inscription : Mars 2013
    Messages : 221
    Points : 31
    Points
    31
    Par défaut
    En fait les paramètres de l'algorithme ABC doivent être réglés. Comme j'ai pris la distance de Hamming ma fonction objectif, j'ai introduit en entrée les variables dont dépend distance_hamming que sont C1 et C2. fallait que j'ajoute d'autres paramètres ou rectifier des données ?
    merci d'avance

    l'erreur qui persiste est
    ??? Input argument "C2" is undefined.
    
    Error in ==> distance_hamming at 10
            out2 = dec2binvec(double(C2(i,j)),8);
    
    Error in ==> mainv21 at 77
    ObjVal=feval(objfun,Foods);
    malgré que dans le workspace j'ai la valeur de C2 qui est une matrice

  5. #5
    Invité
    Invité(e)
    Par défaut
    L'avoir dans ton workspace global est une chose, mais l'avoir dans le workspace de ta fonction distance_hamming en est une autre.
    Tu ne l'as pas défini dans ta fonction.

  6. #6
    Nouveau membre du Club
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mars 2013
    Messages
    221
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Enseignement

    Informations forums :
    Inscription : Mars 2013
    Messages : 221
    Points : 31
    Points
    31
    Par défaut
    si mr
    voila
    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
    function ObjVal = distance_hamming(C1 ,C2 )
    [m n]=size(C1);
     
     
    ObjVal = zeros(m,n);
    for i=1:m
        for j=1:n
     
            out1 = dec2binvec(double(C1(i,j)),8);
            out2 = dec2binvec(double(C2(i,j)),8);
     
            Dh=xor(out1,out2);
     
          ObjVal(i,j)=ObjVal(i,j)+sum(Dh);  
     
        end
    end

  7. #7
    Invité
    Invité(e)
    Par défaut
    Sauf que tu l'appelles en ne faisant passer qu'un seul argument Foods :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ObjVal=feval(objfun,Foods);
    C2 n'est donc pas défini.
    ObjVal=feval(objfun,Foods, C2);

  8. #8
    Nouveau membre du Club
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mars 2013
    Messages
    221
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Enseignement

    Informations forums :
    Inscription : Mars 2013
    Messages : 221
    Points : 31
    Points
    31
    Par défaut
    merci
    mais meme en ajoutant C2 comme variable à la fonction objval j'ai cette erreur
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    ??? Error using ==> dec2binvec at 33
    D must be a positive integer.
     
    Error in ==> distance_hamming at 9
            out1 = dec2binvec(double(round(C1(i,j))),8);
     
    Error in ==> mainv21 at 77
    ObjVal=feval(objfun,Foods,C2);

  9. #9
    Invité
    Invité(e)
    Par défaut
    La fonction dec2binvec n'accepte que des entiers positifs.
    D must be a positive integer.
    vu le round, ce n'est pas le côté integer qui pose problème, mais négatif.
    Si ces valeurs négatives sont normales, à toi de voir comment tu souhaites les représenter en binaire.
    Sinon, à toi de contrôler tes valeurs et ton calcul, et d'agir en conséquence..

  10. #10
    Nouveau membre du Club
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mars 2013
    Messages
    221
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Enseignement

    Informations forums :
    Inscription : Mars 2013
    Messages : 221
    Points : 31
    Points
    31
    Par défaut
    j'ai mis les valeurs de C1 et C2 comme positifs, il parait que ça passe pour cette erreur et ça génère une autre erreur :
    ??? Error using ==> eq
    Matrix dimensions must agree.
    
    Error in ==> mainv21 at 84
    BestInd=find(ObjVal==min(ObjVal));
    De quelle matrice il parle ? et c'est quoi l' eq ??

  11. #11
    Invité
    Invité(e)
    Par défaut
    eq = equal : l'opérateur ==.
    Cela concerne cette partie : ObjVal==min(ObjVal).

    Pense à effectuer des recherches sur le forum et dans la FAQ erreurs et avertissements avant de poster chaque erreur que tu rencontres...

  12. #12
    Nouveau membre du Club
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mars 2013
    Messages
    221
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Enseignement

    Informations forums :
    Inscription : Mars 2013
    Messages : 221
    Points : 31
    Points
    31
    Par défaut
    je m'excuse mr Jerome mais l’opérateur d’égalité est juste
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    BestInd=find(ObjVal== min(ObjVal));
    donc pourquoi le programme n'as pas trouvé les indices des valeurs minimales de la matrice objval ?
    en fait objval est une matrice 10*10 d'entiers entre 1 et 7
    prière de m'expliquer s'il vous plait

  13. #13
    Invité
    Invité(e)
    Par défaut
    S'il est juste, peux-tu me dire ce que donne
    tout seul ?
    Et regarde ce que retourne min(ObjVal).

    Sinon tu trouveras ton bonheur dans la FAQ.

  14. #14
    Nouveau membre du Club
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mars 2013
    Messages
    221
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Enseignement

    Informations forums :
    Inscription : Mars 2013
    Messages : 221
    Points : 31
    Points
    31
    Par défaut
    Le problème maintenant est lorsque
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    BestInd=find(ObjVal== min(ObjVal));
    ça genere une erreur et lorsque
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    ObjVal= min(ObjVal);
    min(ObjVal);
    BestInd=find(ObjVal== min(ObjVal));
    ça passe


    donne un vecteur d'objval : [2,2,3,3,2,1,2,3,2,2]
    et donne 1

    donc pourquoi find ne fonctionne pas ??

  15. #15
    Invité
    Invité(e)
    Par défaut
    Parce que ObjVal n'est plus le même à cause de ta ligne : Sinon, tu as cherché dans la FAQ ?

  16. #16
    Nouveau membre du Club
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mars 2013
    Messages
    221
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Enseignement

    Informations forums :
    Inscription : Mars 2013
    Messages : 221
    Points : 31
    Points
    31
    Par défaut
    oui en fait je cherche dans la FAQ avant de postuler mais ça existe pas les réponses que je cherche
    .
    Donc pour le code ça passe quand j'ai ajouté les deux lignes, maintenant il arrive au calcul des probabilités et génère l'erreur suivante
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    ??? Error using ==> rdivide
    Matrix dimensions must agree.
     
    Error in ==> mainv21 at 142
    prob=(0.9.*Fitness./max(Fitness))+0.1;

  17. #17

  18. #18
    Nouveau membre du Club
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mars 2013
    Messages
    221
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Enseignement

    Informations forums :
    Inscription : Mars 2013
    Messages : 221
    Points : 31
    Points
    31
    Par défaut
    je m'excuse mais j'ai bien regardé ces liens et d'autres et même j'ai changé la syntaxe comme j'ai compris de ces liens, toutefois j'ai trouvé des erreurs.
    maintenant comme j'ai ajouté les deux lignes
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    ObjVal= min(ObjVal);
    min(ObjVal);
    j'avance pour affranchir la ligne
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    prob=(0.9.*Fitness./max(Fitness))+0.1;
    et l'erreur c'est
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    ??? Error using ==> rdivide
    Matrix dimensions must agree.
     
    Error in ==> mainv21 at 142
    prob=(0.9.*Fitness./max(Fitness))+0.1;
    même qu'il y on a de division membre par membre( .* et ./ ) ( ce que fait rdivide )

  19. #19
    Invité
    Invité(e)
    Par défaut
    Tu n'as pas compris l'histoire du min.

    Cette ligne min(ObjVal); ne sert strictement à rien, et celle-ci ObjVal= min(ObjVal); modifie ObjVal en vecteur des valeurs minimales selon la première dimension.

    Ce n'est pas tout de recopier bêtement le code de la FAQ, il te faut le comprendre.

    Un exemple :
    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
    >> ObjVal = rand(10)
    
    ObjVal =
    
        0.1622    0.4505    0.1067    0.4314    0.8530    0.4173    0.7803    0.2348    0.5470    0.9294
        0.7943    0.0838    0.9619    0.9106    0.6221    0.0497    0.3897    0.3532    0.2963    0.7757
        0.3112    0.2290    0.0046    0.1818    0.3510    0.9027    0.2417    0.8212    0.7447    0.4868
        0.5285    0.9133    0.7749    0.2638    0.5132    0.9448    0.4039    0.0154    0.1890    0.4359
        0.1656    0.1524    0.8173    0.1455    0.4018    0.4909    0.0965    0.0430    0.6868    0.4468
        0.6020    0.8258    0.8687    0.1361    0.0760    0.4893    0.1320    0.1690    0.1835    0.3063
        0.2630    0.5383    0.0844    0.8693    0.2399    0.3377    0.9421    0.6491    0.3685    0.5085
        0.6541    0.9961    0.3998    0.5797    0.1233    0.9001    0.9561    0.7317    0.6256    0.5108
        0.6892    0.0782    0.2599    0.5499    0.1839    0.3692    0.5752    0.6477    0.7802    0.8176
        0.7482    0.4427    0.8001    0.1450    0.2400    0.1112    0.0598    0.4509    0.0811    0.7948
    
    >> min(ObjVal) % Le résultat est un vecteur !!! (minimum [en rouge] de chaque colonne)
    
    ans =
    
        0.1622    0.0782    0.0046    0.1361    0.0760    0.0497    0.0598    0.0154    0.0811    0.3063
    
    >> min( min(ObjVal) )
    
    ans =
    
        0.0046
    
    >> min( ObjVal(:) ) % <= FAQ !!!
    
    ans =
    
        0.0046
    Aperçu de la documentation :
    Citation Envoyé par doc min
    If A is a matrix, min(A) treats the columns of A as vectors, returning a row vector containing the minimum element from each column.
    Il en est de même pour la fonction max

    Dès que tu as une erreur qui mentionne les dimensions, applique systématiquement la fonction size sur les différentes parties, tu comprendras vite.
    Exemple ici : size(Fitness) et size( max(Fitness) )
    Dernière modification par Invité ; 02/10/2013 à 16h27.

  20. #20
    Nouveau membre du Club
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mars 2013
    Messages
    221
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Enseignement

    Informations forums :
    Inscription : Mars 2013
    Messages : 221
    Points : 31
    Points
    31
    Par défaut
    merci bien Mr
    bon j'ai appliqué vos conseils, ça avance
    maintenant le programme exécute un ensemble d'itérations ( il arrive à 39 itérations) puis il s’arrête et affiche une erreur
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    ???  In an assignment  A(I) = B, the number of elements in B and
     I must be the same.
     
    Error in ==> mainv21 at 221
        Fitness(ind)=FitnessSol;
    malgré que Fitness est une matrice de [10 10] éléments et FitnessSol est un vecteur de [1 10] éléments
    Puisque ça marche pour les premiers itérations pourquoi il s’arrête maintenant ??
    J’espère que j'expilque bien mon problème et merci

Discussions similaires

  1. Fonction objectif pour optimisation de la correspondance visuelle
    Par ERCO503 dans le forum Traitement d'images
    Réponses: 0
    Dernier message: 19/06/2013, 21h38
  2. Optimiser une fonction (trouver le minimum)
    Par Noel Gallagher dans le forum C
    Réponses: 2
    Dernier message: 27/11/2006, 06h46
  3. probleme d'optimisation de fonction
    Par franc82 dans le forum C++
    Réponses: 3
    Dernier message: 31/10/2006, 09h45
  4. Optimisation de fonction
    Par Elendhil dans le forum Assembleur
    Réponses: 2
    Dernier message: 19/06/2006, 15h03
  5. Optimisation de fonction ...
    Par dark_vidor dans le forum Langage
    Réponses: 10
    Dernier message: 02/01/2006, 11h50

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