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 :

"warning log de zero"


Sujet :

MATLAB

  1. #1
    Candidat au Club
    Inscrit en
    Mai 2011
    Messages
    92
    Détails du profil
    Informations forums :
    Inscription : Mai 2011
    Messages : 92
    Points : 2
    Points
    2
    Par défaut "warning log de zero"
    Bonjour tout le monde,

    j'ai fait ce programme,mais il ne fonctionne pas, aidez-moi svp ; et merci
    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
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    clc
    %Codage des exemples d'apprentissage
    TEMPERATURE=['O1';'N1';'O1';'N1';'O1';'N1';'O1';'O1';'N1';'O1';'N1';'O1';'O1';'N1';'O1';'N1';'O1';'O1';'O1';'O1';'O1';'O1';'O1';'O1';'O1';'O1';'O1';'O1';'O1';'O1';'O1';'O1';'O1';'O1';'O1';'O1';'O1';'O1';'O1';'O1';'O1';'O1';'O1';'N1';'N1';'O1';'N1';'N1';'N1';'O1';'O1';'N1';'N1';'O1';'O1';'O1';'N1';'N1';'N1';'N1';'N1';'N1';'N1';'O1';'O1';'O1';'O1';'O1';'O1';'O1'];
    OXYGENE=['O2';'N2';'O2';'N2';'O2';'N2';'O2';'O2';'N2';'O2';'N2';'O2';'O2';'N2';'O2';'N2';'O2';'N2';'N2';'N2';'N2';'N2';'N2';'N2';'N2';'N2';'O2';'N2';'O2';'O2';'O2';'O2';'O2';'N2';'N2';'N2';'N2';'N2';'O2';'N2';'N2';'N2';'N2';'N2';'N2';'O2';'N2';'N2';'N2';'N2';'N2';'O2';'N2';'O2';'N2';'N2';'N2';'N2';'N2';'N2';'N2';'N2';'N2';'O2';'N2';'O2';'N2';'O2';'O2';'N2'];
    NH4=['N3';'O3';'N3';'O3';'N3';'O3';'N3';'N3';'O3';'N3';'O3';'N3';'N3';'N3';'N3';'N3';'N3';'O3';'N3';'O3';'O3';'O3';'O3';'O3';'N3';'N3';'N3';'O3';'N3';'N3';'N3';'N3';'N3';'O3';'N3';'N3';'N3';'N3';'N3';'N3';'N3';'N3';'N3';'N3';'N3';'N3';'O3';'O3';'O3';'N3';'O3';'N3';'N3';'N3';'N3';'O3';'O3';'O3';'O3';'N3';'N3';'O3';'O3';'N3';'N3';'N3';'N3';'N3';'N3';'N3'];
    NO2=['O4';'O4';'O4';'O4';'O4';'O4';'O4';'N4';'O4';'N4';'O4';'N4';'N4';'N4';'N4';'N4';'N4';'N4';'N4';'N4';'N4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'N4';'N4';'N4';'N4';'N4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4';'O4'];
    NO3=['N5';'O5';'N5';'N5';'N5';'N5';'N5';'N5';'N5';'N5';'N5';'N5';'N5';'N5';'N5';'N5';'N5';'N5';'N5';'N5';'N5';'N5';'N5';'N5';'N5';'N5';'N5';'O5';'N5';'N5';'N5';'N5';'N5';'N5';'N5';'N5';'O5';'O5';'N5';'N5';'N5';'N5';'N5';'O5';'O5';'O5';'O5';'O5';'O5';'O5';'O5';'N5';'N5';'N5';'N5';'N5';'O5';'N5';'O5';'O5';'O5';'O5';'O5';'O5';'O5';'O5';'N5';'O5';'O5';'O5'];
    cod=['N6';'N6';'N6';'N6';'N6';'N6';'N6';'N6';'N6';'O6';'N6';'N6';'N6';'N6';'N6';'N6';'N6';'N6';'N6';'N6';'N6';'N6';'N6';'N6';'N6';'N6';'N6';'N6';'O6';'O6';'O6';'O6';'O6';'O6';'N6';'N6';'O6';'O6';'N6';'N6';'N6';'O6';'O6';'N6';'O6';'O6';'O6';'O6';'N6';'N6';'O6';'O6';'O6';'O6';'O6';'O6';'O6';'O6';'O6';'O6';'O6';'O6';'N6';'O6';'O6';'O6';'O6';'O6';'O6';'O6'];
    COT=['O7';'N7';'O7';'N7';'O7';'N7';'O7';'O7';'O7';'O7';'N7';'N7';'O7';'O7';'O7';'N7';'N7';'O7';'O7';'N7';'O7';'N7';'N7';'N7';'N7';'N7';'N7';'N7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'N7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'O7';'O7'];
    CLASSE=['C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C2';'C2';'C2';'C2';'C2';'C2';'C2';'C2';'C1';'C1';'C1';'C1';'C1';'C1';'C3';'C3';'C2';'C2';'C1';'C1';'C3';'C3';'C3';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C1';'C3';'C3';'C3'];
    disp('*****************  Entropie de la classe *******************')
    NBC1=0; NBC2=0;NBC3=0;
    for i=1:length(CLASSE)
        disp(CLASSE(i));
        if (CLASSE(i)=='C1');
            NBC1=NBC1+1
        else
            if (CLASSE(i)=='C2');
                NBC2=NBC2+1
            else
                NBC3=NBC3+1
            end;
        end;
    end;
    ENTROPIE0=-NBC1/length(CLASSE)*log2(NBC1/length(CLASSE))-NBC2/length(CLASSE)*log2(NBC2/length(CLASSE))-NBC3/length(CLASSE)*log2(NBC3/length(CLASSE))
    %**********calcul des entropies des attributs***********************
    % initialisation des valeurs
    O1C1=0;N1C1=0;O1C2=0;N1C2=0;O1C3=0;N1C3=0;
    O2C1=0;N2C1=0;O2C2=0;N2C2=0;O2C3=0;N2C3=0;
    O3C1=0;N3C1=0;O3C2=0;N3C2=0;O3C3=0;N3C3=0;
    O4C1=0;N4C1=0;O4C2=0;N4C2=0;O4C3=0;N4C3=0;
    O5C1=0;N5C1=0;O5C2=0;N5C2=0;O5C3=0;N5C3=0;
    O6C1=0;N6C1=0;O6C2=0;N6C2=0;O6C3=0;N6C3=0;
    O7C1=0;N7C1=0;O7C2=0;N7C2=0;O7C3=0;N7C3=0;
     
    % CALCUL D"ENTROPIE DE L"ATTRIBUT TEMPERATURE  %
    for i=1:length(CLASSE);
        if (CLASSE(i)=='C1') & (TEMPERATURE(i)=='O1')
            O1C1=O1C1+1;
        else
            if (CLASSE(i)=='C1') & (TEMPERATURE(i)=='N1')
                N1C1=N1C1+1;
            else
                if (CLASSE(i)=='C2') & (TEMPERATURE(i)=='O1')
                    O1C2=O1C2+1;
                else
                    if (CLASSE(i)=='C2') & (TEMPERATURE(i)=='N1')
                        N1C2=N1C2+1;
                    else
                        if (CLASSE(i)=='C3') & (TEMPARATURE(i)=='O1')
                            O1C3=O1C3+1;
                        else
                            N1C3=N1C3+1;
                        end;  end;  end;  end; end;
    end;
    O1=O1C1+O1C2+O1C3;  if O1C1==0 | O1C2==0 | O1C3==0  ENTROPIE_O1=0;   else ENTROPIE_O1=-O1C1/O1*log2(O1C1/O1)-O1C2/O1*log2(O1C2/O1)-O1C3/O1*log2(O1C3/O1);  end;
    disp('ENTROPIE(OUI1) = '); disp(ENTROPIE_O1)
    N1=N1C1+N1C2+N1C3;  if N1C1==0 | N1C2==0 | N1C3==0 ENTROPIE_N1=0;   else  ENTROPIE_N1=-N1C1/N1*log2(N1C1/N1)-N1C2/N1*log2(N1C2/N1)-N1C3/N1*log2(N1C3/N1); end;
    disp('ENTROPIE(NON1) = '); disp(ENTROPIE_N1)
    %************* Gain de l'attribut TEMPERATURE **************%
    GAIN_TEMPERATURE=ENTROPIE0-(O1/length(CLASSE)*ENTROPIE_O1+N1/length(CLASSE)*ENTROPIE_N1)
    %************************************************************
    % CALCUL D"ENTROPIE DE L"ATTRIBUT OXYGENE  %
    for i=1:length(CLASSE);
        if (CLASSE(i)=='C1') & (OXYGENE(i)=='O2')
            O2C1=O2C1+1;
        else
            if (CLASSE(i)=='C1') & (OXYGENE(i)=='N2')
                N2C1=N2C1+1;
            else
                if (CLASSE(i)=='C2') & (OXYGENE(i)=='O2')
                    O1C2=O1C2+1;
                else
                    if (CLASSE(i)=='C2') & (OXYGENE(i)=='N2')
                        N2C2=N2C2+1;
                    else
                        if (CLASSE(i)=='C3') & (OXYGENE(i)=='O2')
                            O2C3=O2C3+1;
                        else
                            N2C3=N2C3+1;
                        end;  end;  end;  end; end;
    end;
    O2=O2C1+O2C2+O2C3;  if O2C1==0 | O2C2==0 | O2C3==0 ENTROPIE_O2=0;   else ENTROPIE_O2=-O2C1/O2*log2(O2C1/O2)-O2C2/O2*log2(O2C2/O2)-O2C3/O2*log2(O2C3/O2);  end;
    disp('ENTROPIE(OUI2) = '); disp(ENTROPIE_O2)
    N2=N2C1+N2C2+N2C3;  if N2C1==0 | N2C2==0 | N2C3==0 ENTROPIE_N2=0;   else  ENTROPIE_N2=-N2C1/N2*log2(N2C1/N2)-N2C2/N2*log2(N2C2/N2)-N2C3/N2*log2(N2C3/N2); end;
    disp('ENTROPIE(NON2) = '); disp(ENTROPIE_N2)
    %************* Gain de l'attribut OXYGENE **************%
    GAIN_OXYGENE=ENTROPIE0-(O2/length(CLASSE)*ENTROPIE_O2+N2/length(CLASSE)*ENTROPIE_N2)
    %******************************************
    % CALCUL D"ENTROPIE DE L"ATTRIBUT NH4  %
    for i=1:length(CLASSE);
        if (CLASSE(i)=='C1') & (NH4(i)=='O3')
            O3C1=O3C1+1;
        else
            if (CLASSE(i)=='C1') & (NH4(i)=='N3')
                N3C1=N3C1+1;
            else
                if (CLASSE(i)=='C2') & (NH4(i)=='O3')
                    O3C2=O3C2+1;
                else
                    if (CLASSE(i)=='C2') & (NH4(i)=='N3')
                        N3C2=N3C2+1;
                    else
                        if (CLASSE(i)=='C3') & (NH4(i)=='O3')
                            O3C3=O3C3+1;
                        else
                            N3C3=N3C3+1;
                        end;  end;  end;  end; end;
    end;
    O3=O3C1+O3C2+O3C3;  if O3C1==0 | O3C2==0 | O3C3==0  ENTROPIE_O3=0;   else ENTROPIE_O3=-O3C1/O3*log2(O3C1/O3)-O3C2/O3*log2(O3C2/O3)-O3C3/O3*log2(O3C3/O3);  end;
    disp('ENTROPIE(OUI3) = '); disp(ENTROPIE_O3)
    N3=N3C1+N3C2+N3C3;  if N3C1==0 | N3C2==0 | N3C3==0 ENTROPIE_N3=0;   else  ENTROPIE_N3=-N3C1/N3*log2(N3C1/N3)-N3C2/N3*log2(N3C2/N3)-N3C3/N3*log2(N3C3/N3); end;
    disp('ENTROPIE(NON3) = '); disp(ENTROPIE_N3)
    %************* Gain de l'attribut NH4 **************%
    GAIN_NH4=ENTROPIE0-(O3/length(CLASSE)*ENTROPIE_O3+N3/length(CLASSE)*ENTROPIE_N3)
    %***********************************************************
    % CALCUL D"ENTROPIE DE L"ATTRIBUT NO2  %
    for i=1:length(CLASSE);
        if (CLASSE(i)=='C1') & (NO2(i)=='O4')
            O4C1=O4C1+1;
        else
            if (CLASSE(i)=='C1') & (NO2(i)=='N4')
                N4C1=N4C1+1;
            else
                if (CLASSE(i)=='C2') & (NO2(i)=='O4')
                    O4C2=O4C2+1;
                else
                    if (CLASSE(i)=='C2') & (NO2(i)=='N4')
                        N4C2=N4C2+1;
                    else
                        if (CLASSE(i)=='C3') & (NO2(i)=='O4')
                            O4C3=O4C3+1;
                        else
                            N4C3=N4C3+1;
                        end;  end;  end;  end; end;
    end;
    O4=O4C1+O4C2+O4C3;  if O4C1==0 | O4C2==0 | O4C3==0 ENTROPIE_O4=0;   else ENTROPIE_O4=-O4C1/O4*log2(O4C1/O4)-O4C2/O4*log2(O4C2/O4)-O4C3/O4*log2(O4C3/O4);  end;
    disp('ENTROPIE(OUI4) = '); disp(ENTROPIE_O4)
    N4=N4C1+N4C2+N4C3;  if N4C1==0 | N4C2==0 | N4C3==0 ENTROPIE_N4=0;   else  ENTROPIE_N4=-N4C1/N4*log2(N4C1/N4)-N4C2/N4*log2(N4C2/N4)-N4C3/N4*log2(N4C3/N4); end;
    disp('ENTROPIE(NON4) = '); disp(ENTROPIE_N4)
    %************* Gain de l'attribut NO2 **************%
    GAIN_NO2=ENTROPIE0-(O4/length(CLASSE)*ENTROPIE_O4+N4/length(CLASSE)*ENTROPIE_N4)
    %************************************************************
    % CALCUL D"ENTROPIE DE L"ATTRIBUT NO3  %
    for i=1:length(CLASSE);
        if (CLASSE(i)=='C1') & (NO3(i)=='O5')
            O5C1=O5C1+1;
        else
            if (CLASSE(i)=='C1') & (NO3(i)=='N5')
                N5C1=N5C1+1;
            else
                if (CLASSE(i)=='C2') & (NO3(i)=='O5')
                    O5C2=O5C2+1;
                else
                    if (CLASSE(i)=='C2') & (NO3(i)=='N5')
                        N5C2=N5C2+1;
                    else
                        if (CLASSE(i)=='C3') & (NO3(i)=='O5')
                            O5C3=O5C3+1;
                        else
                            N5C3=N5C3+1;
                        end;  end;  end;  end; end;
    end;
    O5=O5C1+O5C2+O5C3;  if O5C1==0 | O5C2==0 | O5C3==0 ENTROPIE_O5=0;   else ENTROPIE_O5=-O5C1/O5*log2(O5C1/O5)-O5C2/O5*log2(O5C2/O5)-O5C3/O5*log2(O5C3/O5);  end;
    disp('ENTROPIE(OUI5) = '); disp(ENTROPIE_O5)
    N5=N5C1+N5C2+N5C3;  if N5C1==0 | N5C2==0 | N5C3==0 ENTROPIE_N5=0;   else ENTROPIE_N5=-N5C1/N5*log2(N5C1/N5)-N5C2/N5*log2(N5C2/N5)-N5C3/N5*log2(N5C3/N5); end;
    disp('ENTROPIE(NON5) = '); disp(ENTROPIE_N5)
    %************* Gain de l'attribut NO3 **************%
    GAIN_NO3=ENTROPIE0-(O5/length(CLASSE)*ENTROPIE_O5+N5/length(CLASSE)*ENTROPIE_N5)
    %************************************************************
    % CALCUL D"ENTROPIE DE L"ATTRIBUT COD %
    for i=1:length(CLASSE);
        if (CLASSE(i)=='C1') & (COD(i)=='O6')
            O6C1=O6C1+1;
        else
            if (CLASSE(i)=='C1') & (COD(i)=='N6')
                N6C1=N6C1+1;
            else
                if (CLASSE(i)=='C2') & (COD(i)=='O6')
                    O6C2=O6C2+1;
                else
                    if (CLASSE(i)=='C2') & (COD(i)=='N6')
                        N6C2=N6C2+1;
                    else
                        if (CLASSE(i)=='C3') & (COD(i)=='O6')
                            O6C3=O6C3+1;
                        else
                            N6C3=N6C3+1;
                        end;  end;  end;  end; end;
    end;
    O6=O6C1+O6C2+O6C3;  if O6C1==0 | O6C2==0 | O6C3==0 ENTROPIE_O6=0;   else ENTROPIE_O6=-O6C1/O6*log2(O6C1/O6)-O6C2/O6*log2(O6C2/O6)-O6C3/O6*log2(O6C3/O6); end;
    disp('ENTROPIE(OUI6) = '); disp(ENTROPIE_O6)
    N6=N6C1+N6C2+N6C3;  if N6C1==0 | N6C2==0 | N6C3==0 ENTROPIE_N6=0;   else ENTROPIE_N6=-N6C1/N6*log2(N6C1/N6)-N6C2/N6*log2(N6C2/N6)-N6C3/N6*log2(N6C3/N6); end;
    disp('ENTROPIE(NON6) = '); disp(ENTROPIE_N6)
    %************* Gain de l'attribut COD **************%
    GAIN_COD=ENTROPIE0-(O6/length(CLASSE)*ENTROPIE_O6+N6/length(CLASSE)*ENTROPIE_N6)
    %************************************************************
    % CALCUL D"ENTROPIE DE L"ATTRIBUT COT  %
    for i=1:length(CLASSE);
        if (CLASSE(i)=='C1') & (COT(i)=='O7')
            O7C1=O7C1+1;
        else
            if (CLASSE(i)=='C1') & (COT(i)=='N7')
                N7C1=N7C1+1;
            else
                if (CLASSE(i)=='C2') & (COT(i)=='O7')
                    O7C2=O7C2+1;
                else
                    if (CLASSE(i)=='C2') & (COT(i)=='N7')
                        N7C2=N7C2+1;
                    else
                        if (CLASSE(i)=='C3') & (COT(i)=='O7')
                            O7C3=O7C3+1;
                        else
                            N7C3=N7C3+1;
                        end;  end;  end;  end; end;
    end;
    O7=O7C1+O7C2+O7C3;  if O7C1==0 | O7C2==0 | O7C3==0 ENTROPIE_O7=0;   else ENTROPIE_O7=-O7C1/O7*log2(O7C1/O7)-O7C2/O7*log2(O7C2/O7)-O7C3/O7*log2(O7C3/O7); end;
    disp('ENTROPIE(OUI7) = '); disp(ENTROPIE_O7)
    N7=N7C1+N7C2+N7C3;  if N7C1==0 | N7C2==0 | N7C3==0 ENTROPIE_N7=0;   else ENTROPIE_N7=-N7C1/N7*log2(N7C1/N7)-N7C2/N7*log2(N7C2/N7)-N7C3/N7*log2(N7C3/N7); end;
    disp('ENTROPIE(NON7) = '); disp(ENTROPIE_N7)
    %************* Gain de l'attribut COT **************%
    GAIN_COT=ENTROPIE0-(O7/length(CLASSE)*ENTROPIE_O7+N7/length(CLASSE)*ENTROPIE_N7)
    % /////////////// Choix  du  meilleur attribut /////////////////////  %%%
    attributs={'TEMPERATURE','OXYGENE','NH4','NO2','NO3','COD','COT'}
    Gains=[GAIN_TEMPERATURE; GAIN_OXYGENE; GAIN_NH4; GAIN_NO2;GAIN_NO3;GAIN_COD;GAIN_COT];
    Gain_maximum= max(Gains);
    MaxGain=0;
    for i=1:7  if Gains(i)>=MaxGain;  MaxGain=Gains(i); attr=attributs(i); end; end;
    disp('l"attribut choisit est :'); disp(attributs(i))

  2. #2
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    Pour commencer je t'invite à regarder ce que retourne les CLASSE(i), TEMPERATURE(i), NH4(i), NO2(i)... Tu ne fais que lire un seul caractère.
    Pour information la comparaison de chaines de caractères se fait avec la fonction strcmp.

  3. #3
    Candidat au Club
    Inscrit en
    Mai 2011
    Messages
    92
    Détails du profil
    Informations forums :
    Inscription : Mai 2011
    Messages : 92
    Points : 2
    Points
    2
    Par défaut
    Dans la boucle "for" de la 13 ligne,je comptes le nombre de fois de c1,c2 et de c3 du vecteur CLASSE,par ce que ces nombre je les utilise dans les calculs ;mais la boucle ne fonctionne pas,et je sais pas pour quoi.aidez moi svp et merci

  4. #4
    FLB
    FLB est déconnecté
    Modérateur
    Avatar de FLB
    Homme Profil pro
    Ing. Aérospatiale
    Inscrit en
    Juin 2003
    Messages
    770
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France

    Informations professionnelles :
    Activité : Ing. Aérospatiale
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Juin 2003
    Messages : 770
    Points : 1 185
    Points
    1 185
    Par défaut
    Comme te l'explique Winjerome, CLASSE(1) vaut 'C', CLASSE(2) vaut '1', etc
    Je te conseille de transformer ton code en utilisant des cell la place des tableaux :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    CLASSE={'C1';'C1';   ..etc.. };
    strcmp(CLASSE{1},'C1') %renvoie vrai

  5. #5
    Invité
    Invité(e)
    Par défaut
    Citation Envoyé par karika Voir le message
    et je sais pas pour quoi
    J'ai donné l'explication il me semble
    Citation Envoyé par Winjerome Voir le message
    Pour commencer je t'invite à regarder ce que retourne les CLASSE(i), TEMPERATURE(i), NH4(i), NO2(i)... Tu ne fais que lire un seul caractère.
    Pour information la comparaison de chaines de caractères se fait avec la fonction strcmp.

  6. #6
    Candidat au Club
    Inscrit en
    Mai 2011
    Messages
    92
    Détails du profil
    Informations forums :
    Inscription : Mai 2011
    Messages : 92
    Points : 2
    Points
    2
    Par défaut
    oui, c'est bon ça fonctionné, merci beaucoup, maintenant j'ai fait la suite du programme précédent, mais le calcul des entropie est toujours nul, pourquoi ?

    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
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    disp('-------------------------LEVEL 2---------------------------------')
    %**********calcul des entropies des attributs du deuxième niveau***********************
    % initialisation des valeurs
    O1C1=0;N1C1=0;O1C2=0;N1C2=0;O1C3=0;N1C3=0;
    O2C1=0;N2C1=0;O2C2=0;N2C2=0;O2C3=0;N2C3=0;
    O3C1=0;N3C1=0;O3C2=0;N3C2=0;O3C3=0;N3C3=0;
    O4C1=0;N4C1=0;O4C2=0;N4C2=0;O4C3=0;N4C3=0;
    O5C1=0;N5C1=0;O5C2=0;N5C2=0;O5C3=0;N5C3=0;
    O7C1=0;N7C1=0;O7C2=0;N7C2=0;O7C3=0;N7C3=0;
    % CALCUL D"ENTROPIE DE L"ATTRIBUT TEMPERATURE  %
     
    for i=1:length(CLASSE);
          if (CLASSE(i)=='1') & (TEMPERATURE(i)=='O') & (COD(i)=='O')
           O1C1=O1C1+1
          else 
             if (CLASSE(i)=='2') & (TEMPERATURE(i)=='O') & (COD(i)=='O')
              O1C2=O1C2+1
             else
              if (CLASSE(i)=='3') & (TEMPERATURE(i)=='O') & (COD(i)=='O')
              O1C3=O1C3+1
              else
                  if (CLASSE(i)=='1') & (TEMPERATURE(i)=='N') & (COD(i)=='O')
                  N1C1=N1C1+1
                  else 
                      if (CLASSE(i)=='2') & (TEMPERATURE(i)=='N') & (COD(i)=='O')
                      N1C2=N1C2+1
                      else  if (CLASSE(i)=='3') & (TEMPERATURE(i)=='N') & (COD(i)=='O')
                       N1C3=N1C3+1 
                            end;  
                      end;  
                  end;  
               end; 
             end; 
           end;
    end;
     O1=O1C1+O1C2+O1C3;  if O1C1==0 | O1C2==0 | O1C3==0  ENTROPIE_O1=0;   else ENTROPIE_O1=-O1C1/O1*log2(O1C1/O1)-O1C2/O1*log2(O1C2/O1)-O1C3/O1*log2(O1C3/O1);  end;
     disp('ENTROPIE(OUI1) = '); disp(ENTROPIE_O1)
     N1=N1C1+N1C2+N1C3;  if N1C1==0 | N1C2==0 | N1C3==0 ENTROPIE_N1=0;   else  ENTROPIE_N1=-N1C1/N1*log2(N1C1/N1)-N1C2/N1*log2(N1C2/N1)-N1C3/N1*log2(N1C3/N1); end;
     disp('ENTROPIE(NON1) = '); disp(ENTROPIE_N1) 
        %************* Gain de l'attribut TEMPERATURE **************%
    GAIN_TEMPERATURE=ENTROPIE0-(O1/length(CLASSE)*ENTROPIE_O1+N1/length(CLASSE)*ENTROPIE_N1)
    %************************************************************
    %CALCUL D"ENTROPIE DE L"ATTRIBUT OXYGENE
    for i=1:length(CLASSE);
          if (CLASSE(i)=='1') & (OXYGENE(i)=='O') & (COD(i)=='O')
           O1C1=O1C1+1;
          else 
             if (CLASSE(i)=='2') & (OXYGENE(i)=='O') & (COD(i)=='O')
              O1C2=O1C2+1;
             else
              if (CLASSE(i)=='3') & (OXYGENE(i)=='O') & (COD(i)=='O')
              O1C3=O1C3+1;
              else
                  if (CLASSE(i)=='1') & (OXYGENE(i)=='N') & (COD(i)=='O')
                  N1C1=N1C1+1;
                  else 
                      if (CLASSE(i)=='2') & (OXYGENE(i)=='N') & (COD(i)=='O')
                      N1C2=N1C2+1;
                      else  if (CLASSE(i)=='3') & (OXYGENE(i)=='N') & (COD(i)=='O')
                       N1C3=N1C3+1; 
                            end;  
                      end;  
                  end;  
               end; 
             end; 
           end;
    end;
    O2=O2C1+O2C2+O2C3;  if O2C1==0 | O2C2==0 | O2C3==0 ENTROPIE_O2=0;   else ENTROPIE_O2=-O2C1/O2*log2(O2C1/O2)-O2C2/O2*log2(O2C2/O2)-O2C3/O2*log2(O2C3/O2);  end;
     disp('ENTROPIE(OUI2) = '); disp(ENTROPIE_O2)
     N2=N2C1+N2C2+N2C3;  if N2C1==0 | N2C2==0 | N2C3==0 ENTROPIE_N2=0;   else  ENTROPIE_N2=-N2C1/N2*log2(N2C1/N2)-N2C2/N2*log2(N2C2/N2)-N2C3/N2*log2(N2C3/N2); end;
     disp('ENTROPIE(NON2) = '); disp(ENTROPIE_N2) 
        %************* Gain de l'attribut OXYGENE **************%
    GAIN_OXYGENE=ENTROPIE0-(O2/length(CLASSE)*ENTROPIE_O2+N2/length(CLASSE)*ENTROPIE_N2)
    %****************************************** 
    % CALCUL D"ENTROPIE DE L"ATTRIBUT NH4%
    for i=1:length(CLASSE);
          if (CLASSE(i)=='1') & (NH4(i)=='O') & (COD(i)=='O')
           O1C1=O1C1+1;
          else 
             if (CLASSE(i)=='2') & (NH4(i)=='O') & (COD(i)=='O')
              O1C2=O1C2+1;
             else
              if (CLASSE(i)=='3') & (NH4(i)=='O') & (COD(i)=='O')
              O1C3=O1C3+1;
              else
                  if (CLASSE(i)=='1') & (NH4(i)=='N') & (COD(i)=='O')
                  N1C1=N1C1+1;
                  else 
                      if (CLASSE(i)=='2') & (NH4(i)=='N') & (COD(i)=='O')
                      N1C2=N1C2+1;
                      else  if (CLASSE(i)=='3') & (NH4(i)=='N') & (COD(i)=='O')
                       N1C3=N1C3+1; 
                            end;  
                      end;  
                  end;  
               end; 
             end; 
           end;
    end;
     O3=O3C1+O3C2+O3C3;  if O3C1==0 | O3C2==0 | O3C3==0  ENTROPIE_O3=0;   else ENTROPIE_O3=-O3C1/O3*log2(O3C1/O3)-O3C2/O3*log2(O3C2/O3)-O3C3/O3*log2(O3C3/O3);  end;
     disp('ENTROPIE(OUI3) = '); disp(ENTROPIE_O3)
     N3=N3C1+N3C2+N3C3;  if N3C1==0 | N3C2==0 | N3C3==0 ENTROPIE_N3=0;   else  ENTROPIE_N3=-N3C1/N3*log2(N3C1/N3)-N3C2/N3*log2(N3C2/N3)-N3C3/N3*log2(N3C3/N3); end;
     disp('ENTROPIE(NON3) = '); disp(ENTROPIE_N3) 
        %************* Gain de l'attribut NH4 **************%
    GAIN_NH4=ENTROPIE0-(O3/length(CLASSE)*ENTROPIE_O3+N3/length(CLASSE)*ENTROPIE_N3)
    %***********************************************************
    % CALCUL D"ENTROPIE DE L"ATTRIBUT NO2%
    for i=1:length(CLASSE);
          if (CLASSE(i)=='1') & (NO2(i)=='O') & (COD(i)=='O')
           O1C1=O1C1+1;
          else 
             if (CLASSE(i)=='2') & (NO2(i)=='O') & (COD(i)=='O')
              O1C2=O1C2+1;
             else
              if (CLASSE(i)=='3') & (NO2(i)=='O') & (COD(i)=='O')
              O1C3=O1C3+1;
              else
                  if (CLASSE(i)=='1') & (NO2(i)=='N') & (COD(i)=='O')
                  N1C1=N1C1+1;
                  else 
                      if (CLASSE(i)=='2') & (NO2(i)=='N') & (COD(i)=='O')
                      N1C2=N1C2+1;
                      else  if (CLASSE(i)=='3') & (NO2(i)=='N') & (COD(i)=='O')
                       N1C3=N1C3+1; 
                            end;  
                      end;  
                  end;  
               end; 
             end; 
           end;
    end;
     O4=O4C1+O4C2+O4C3;  if O4C1==0 | O4C2==0 | O4C3==0 ENTROPIE_O4=0;   else ENTROPIE_O4=-O4C1/O4*log2(O4C1/O4)-O4C2/O4*log2(O4C2/O4)-O4C3/O4*log2(O4C3/O4);  end;
     disp('ENTROPIE(OUI4) = '); disp(ENTROPIE_O4)
     N4=N4C1+N4C2+N4C3;  if N4C1==0 | N4C2==0 | N4C3==0 ENTROPIE_N4=0;   else  ENTROPIE_N4=-N4C1/N4*log2(N4C1/N4)-N4C2/N4*log2(N4C2/N4)-N4C3/N4*log2(N4C3/N4); end;
     disp('ENTROPIE(NON4) = '); disp(ENTROPIE_N4) 
        %************* Gain de l'attribut NO2 **************%
    GAIN_NO2=ENTROPIE0-(O4/length(CLASSE)*ENTROPIE_O4+N4/length(CLASSE)*ENTROPIE_N4)
    %***********************************************************
    % CALCUL D"ENTROPIE DE L"ATTRIBUT NO3%
    for i=1:length(CLASSE);
          if (CLASSE(i)=='1') & (NO3(i)=='O') & (COD(i)=='O')
           O1C1=O1C1+1;
          else 
             if (CLASSE(i)=='2') & (NO3(i)=='O') & (COD(i)=='O')
              O1C2=O1C2+1;
             else
              if (CLASSE(i)=='3') & (NO3(i)=='O') & (COD(i)=='O')
              O1C3=O1C3+1;
              else
                  if (CLASSE(i)=='1') & (NO3(i)=='N') & (COD(i)=='O')
                  N1C1=N1C1+1;
                  else 
                      if (CLASSE(i)=='2') & (NO3(i)=='N') & (COD(i)=='O')
                      N1C2=N1C2+1;
                      else  if (CLASSE(i)=='3') & (NO3(i)=='N') & (COD(i)=='O')
                       N1C3=N1C3+1; 
                            end;  
                      end;  
                  end;  
               end; 
             end; 
           end;
    end;
     
    O5=O5C1+O5C2+O5C3;  if O5C1==0 | O5C2==0 | O5C3==0 ENTROPIE_O5=0;   else ENTROPIE_O5=-O5C1/O5*log2(O5C1/O5)-O5C2/O5*log2(O5C2/O5)-O5C3/O5*log2(O5C3/O5);  end;
     disp('ENTROPIE(OUI5) = '); disp(ENTROPIE_O5)
     N5=N5C1+N5C2+N5C3;  if N5C1==0 | N5C2==0 | N5C3==0 ENTROPIE_N5=0;   else ENTROPIE_N5=-N5C1/N5*log2(N5C1/N5)-N5C2/N5*log2(N5C2/N5)-N5C3/N5*log2(N5C3/N5); end;
     disp('ENTROPIE(NON5) = '); disp(ENTROPIE_N5) 
        %************* Gain de l'attribut NO3 **************%
    GAIN_NO3=ENTROPIE0-(O5/length(CLASSE)*ENTROPIE_O5+N5/length(CLASSE)*ENTROPIE_N5)
    %************************************************************
    % CALCUL D"ENTROPIE DE L"ATTRIBUT COT%
    for i=1:length(CLASSE);
          if (CLASSE(i)=='1') & (COT(i)=='O') & (COD(i)=='O')
           O1C1=O1C1+1;
          else 
             if (CLASSE(i)=='2') & (COT(i)=='O') & (COD(i)=='O')
              O1C2=O1C2+1;
             else
              if (CLASSE(i)=='3') & (COT(i)=='O') & (COD(i)=='O')
              O1C3=O1C3+1;
              else
                  if (CLASSE(i)=='1') & (COT(i)=='N') & (COD(i)=='O')
                  N1C1=N1C1+1;
                  else 
                      if (CLASSE(i)=='2') & (COT(i)=='N') & (COD(i)=='O')
                      N1C2=N1C2+1;
                      else  if (CLASSE(i)=='3') & (COT(i)=='N') & (COD(i)=='O')
                       N1C3=N1C3+1; 
                            end;  
                      end;  
                  end;  
               end; 
             end; 
           end;
    end;
    O7=O7C1+O7C2+O7C3;  if O7C1==0 | O7C2==0 | O7C3==0 ENTROPIE_O7=0;   else ENTROPIE_O7=-O7C1/O7*log2(O7C1/O7)-O7C2/O7*log2(O7C2/O7)-O7C3/O7*log2(O7C3/O7); end;
     disp('ENTROPIE(OUI7) = '); disp(ENTROPIE_O7)
     N7=N7C1+N7C2+N7C3;  if N7C1==0 | N7C2==0 | N7C3==0 ENTROPIE_N7=0;   else ENTROPIE_N7=-N7C1/N7*log2(N7C1/N7)-N7C2/N7*log2(N7C2/N7)-N7C3/N7*log2(N7C3/N7); end;
     disp('ENTROPIE(NON7) = '); disp(ENTROPIE_N7) 
        %************* Gain de l'attribut COT **************%
    GAIN_COT=ENTROPIE0-(O7/length(CLASSE)*ENTROPIE_O7+N7/length(CLASSE)*ENTROPIE_N7)
     
    % /////////////// Choix  du  meilleur attribut du second niveau /////////////////////  %%%
    attributs={'TEMPERATURE','OXYGENE','NH4','NO2','NO3','COT'}
    Gains=[GAIN_TEMPERATURE; GAIN_OXYGENE; GAIN_NH4; GAIN_NO2; GAIN_NO3; GAIN_COT];
    Gain_maximum= max(Gains);
    MaxGain=0;
    for i=1:3  if Gains(i)>=MaxGain;  MaxGain=Gains(i); attr1=attributs(i); end; end; 
    disp('le deuxieme attribut choisit est :'); disp(attr1)
    disp('-------------------------LEVEL 3---------------------------------')
    %**********calcul des entropies des attributs du deuxième niveau***********************
    % initialisation des valeurs
    O1C1=0;N1C1=0;O1C2=0;N1C2=0;O1C3=0;N1C3=0;
    O2C1=0;N2C1=0;O2C2=0;N2C2=0;O2C3=0;N2C3=0;
    O4C1=0;N4C1=0;O4C2=0;N4C2=0;O4C3=0;N4C3=0;
    O5C1=0;N5C1=0;O5C2=0;N5C2=0;O5C3=0;N5C3=0;
    O7C1=0;N7C1=0;O7C2=0;N7C2=0;O7C3=0;N7C3=0;
    % CALCUL D"ENTROPIE DE L"ATTRIBUT TEMPERATURE  %
     
    for i=1:length(CLASSE);
          if (CLASSE(i)=='1') & (TEMPERATURE(i)=='O') & (COD(i)=='N')
           O1C1=O1C1+1;
          else 
             if (CLASSE(i)=='2') & (TEMPERATURE(i)=='O') & (COD(i)=='N')
              O1C2=O1C2+1;
             else
              if (CLASSE(i)=='3') & (TEMPERATURE(i)=='O') & (COD(i)=='N')
              O1C3=O1C3+1;
              else
                  if (CLASSE(i)=='1') & (TEMPERATURE(i)=='N') & (COD(i)=='N')
                  N1C1=N1C1+1;
                  else 
                      if (CLASSE(i)=='2') & (TEMPERATURE(i)=='N') & (COD(i)=='N')
                      N1C2=N1C2+1;
                      else  if (CLASSE(i)=='3') & (TEMPERATURE(i)=='N') & (COD(i)=='N')
                       N1C3=N1C3+1; 
                            end;  
                      end;  
                  end;  
               end; 
             end; 
           end;
    end;
     O1=O1C1+O1C2+O1C3;  if O1C1==0 | O1C2==0 | O1C3==0  ENTROPIE_O1=0;   else ENTROPIE_O1=-O1C1/O1*log2(O1C1/O1)-O1C2/O1*log2(O1C2/O1)-O1C3/O1*log2(O1C3/O1);  end;
     disp('ENTROPIE(OUI1) = '); disp(ENTROPIE_O1)
     N1=N1C1+N1C2+N1C3;  if N1C1==0 | N1C2==0 | N1C3==0 ENTROPIE_N1=0;   else  ENTROPIE_N1=-N1C1/N1*log2(N1C1/N1)-N1C2/N1*log2(N1C2/N1)-N1C3/N1*log2(N1C3/N1); end;
     disp('ENTROPIE(NON1) = '); disp(ENTROPIE_N1) 
        %************* Gain de l'attribut TEMPERATURE **************%
    GAIN_TEMPERATURE=ENTROPIE0-(O1/length(CLASSE)*ENTROPIE_O1+N1/length(CLASSE)*ENTROPIE_N1)
    %************************************************************
    %CALCUL D"ENTROPIE DE L"ATTRIBUT OXYGENE
    for i=1:length(CLASSE);
          if (CLASSE(i)=='1') & (OXYGENE(i)=='O') & (COD(i)=='N')
           O1C1=O1C1+1;
          else 
             if (CLASSE(i)=='2') & (OXYGENE(i)=='O') & (COD(i)=='N')
              O1C2=O1C2+1;
             else
              if (CLASSE(i)=='3') & (OXYGENE(i)=='O') & (COD(i)=='N')
              O1C3=O1C3+1;
              else
                  if (CLASSE(i)=='1') & (OXYGENE(i)=='N') & (COD(i)=='N')
                  N1C1=N1C1+1;
                  else 
                      if (CLASSE(i)=='2') & (OXYGENE(i)=='N') & (COD(i)=='N')
                      N1C2=N1C2+1;
                      else  if (CLASSE(i)=='3') & (OXYGENE(i)=='N') & (COD(i)=='N')
                       N1C3=N1C3+1; 
                            end;  
                      end;  
                  end;  
               end; 
             end; 
           end;
    end;
    O2=O2C1+O2C2+O2C3;  if O2C1==0 | O2C2==0 | O2C3==0 ENTROPIE_O2=0;   else ENTROPIE_O2=-O2C1/O2*log2(O2C1/O2)-O2C2/O2*log2(O2C2/O2)-O2C3/O2*log2(O2C3/O2);  end;
     disp('ENTROPIE(OUI2) = '); disp(ENTROPIE_O2)
     N2=N2C1+N2C2+N2C3;  if N2C1==0 | N2C2==0 | N2C3==0 ENTROPIE_N2=0;   else  ENTROPIE_N2=-N2C1/N2*log2(N2C1/N2)-N2C2/N2*log2(N2C2/N2)-N2C3/N2*log2(N2C3/N2); end;
     disp('ENTROPIE(NON2) = '); disp(ENTROPIE_N2) 
        %************* Gain de l'attribut OXYGENE **************%
    GAIN_OXYGENE=ENTROPIE0-(O2/length(CLASSE)*ENTROPIE_O2+N2/length(CLASSE)*ENTROPIE_N2)
    %****************************************** 
    % CALCUL D"ENTROPIE DE L"ATTRIBUT NO2%
    for i=1:length(CLASSE);
          if (CLASSE(i)=='1') & (NO2(i)=='O') & (COD(i)=='N')
           O1C1=O1C1+1;
          else 
             if (CLASSE(i)=='2') & (NO2(i)=='O') & (COD(i)=='N')
              O1C2=O1C2+1;
             else
              if (CLASSE(i)=='3') & (NO2(i)=='O') & (COD(i)=='N')
              O1C3=O1C3+1;
              else
                  if (CLASSE(i)=='1') & (NO2(i)=='N') & (COD(i)=='N')
                  N1C1=N1C1+1;
                  else 
                      if (CLASSE(i)=='2') & (NO2(i)=='N') & (COD(i)=='N')
                      N1C2=N1C2+1;
                      else  if (CLASSE(i)=='3') & (NO2(i)=='N') & (COD(i)=='N')
                       N1C3=N1C3+1; 
                            end;  
                      end;  
                  end;  
               end; 
             end; 
           end;
    end;
     O4=O4C1+O4C2+O4C3;  if O4C1==0 | O4C2==0 | O4C3==0 ENTROPIE_O4=0;   else ENTROPIE_O4=-O4C1/O4*log2(O4C1/O4)-O4C2/O4*log2(O4C2/O4)-O4C3/O4*log2(O4C3/O4);  end;
     disp('ENTROPIE(OUI4) = '); disp(ENTROPIE_O4)
     N4=N4C1+N4C2+N4C3;  if N4C1==0 | N4C2==0 | N4C3==0 ENTROPIE_N4=0;   else  ENTROPIE_N4=-N4C1/N4*log2(N4C1/N4)-N4C2/N4*log2(N4C2/N4)-N4C3/N4*log2(N4C3/N4); end;
     disp('ENTROPIE(NON4) = '); disp(ENTROPIE_N4) 
        %************* Gain de l'attribut NO2 **************%
    GAIN_NO2=ENTROPIE0-(O4/length(CLASSE)*ENTROPIE_O4+N4/length(CLASSE)*ENTROPIE_N4)
    %***********************************************************
    % CALCUL D"ENTROPIE DE L"ATTRIBUT NO3%
    for i=1:length(CLASSE);
          if (CLASSE(i)=='1') & (NO3(i)=='O') & (COD(i)=='N')
           O1C1=O1C1+1;
          else 
             if (CLASSE(i)=='2') & (NO3(i)=='O') & (COD(i)=='N')
              O1C2=O1C2+1;
             else
              if (CLASSE(i)=='3') & (NO3(i)=='O') & (COD(i)=='N')
              O1C3=O1C3+1;
              else
                  if (CLASSE(i)=='1') & (NO3(i)=='N') & (COD(i)=='N')
                  N1C1=N1C1+1;
                  else 
                      if (CLASSE(i)=='2') & (NO3(i)=='N') & (COD(i)=='N')
                      N1C2=N1C2+1;
                      else  if (CLASSE(i)=='3') & (NO3(i)=='N') & (COD(i)=='N')
                       N1C3=N1C3+1; 
                            end;  
                      end;  
                  end;  
               end; 
             end; 
           end;
    end;
     
    O5=O5C1+O5C2+O5C3;  if O5C1==0 | O5C2==0 | O5C3==0 ENTROPIE_O5=0;   else ENTROPIE_O5=-O5C1/O5*log2(O5C1/O5)-O5C2/O5*log2(O5C2/O5)-O5C3/O5*log2(O5C3/O5);  end;
     disp('ENTROPIE(OUI5) = '); disp(ENTROPIE_O5)
     N5=N5C1+N5C2+N5C3;  if N5C1==0 | N5C2==0 | N5C3==0 ENTROPIE_N5=0;   else ENTROPIE_N5=-N5C1/N5*log2(N5C1/N5)-N5C2/N5*log2(N5C2/N5)-N5C3/N5*log2(N5C3/N5); end;
     disp('ENTROPIE(NON5) = '); disp(ENTROPIE_N5) 
        %************* Gain de l'attribut NO3 **************%
    GAIN_NO3=ENTROPIE0-(O5/length(CLASSE)*ENTROPIE_O5+N5/length(CLASSE)*ENTROPIE_N5)
    %************************************************************
    % CALCUL D"ENTROPIE DE L"ATTRIBUT COT%
    for i=1:length(CLASSE);
          if (CLASSE(i)=='1') & (COT(i)=='O') & (COD(i)=='N')
           O1C1=O1C1+1;
          else 
             if (CLASSE(i)=='2') & (COT(i)=='O') & (COD(i)=='N')
              O1C2=O1C2+1;
             else
              if (CLASSE(i)=='3') & (COT(i)=='O') & (COD(i)=='N')
              O1C3=O1C3+1;
              else
                  if (CLASSE(i)=='1') & (COT(i)=='N') & (COD(i)=='N')
                  N1C1=N1C1+1;
                  else 
                      if (CLASSE(i)=='2') & (COT(i)=='N') & (COD(i)=='N')
                      N1C2=N1C2+1;
                      else  if (CLASSE(i)=='3') & (COT(i)=='N') & (COD(i)=='N')
                       N1C3=N1C3+1; 
                            end;  
                      end;  
                  end;  
               end; 
             end; 
           end;
    end;
    O7=O7C1+O7C2+O7C3;  if O7C1==0 | O7C2==0 | O7C3==0 ENTROPIE_O7=0;   else ENTROPIE_O7=-O7C1/O7*log2(O7C1/O7)-O7C2/O7*log2(O7C2/O7)-O7C3/O7*log2(O7C3/O7); end;
     disp('ENTROPIE(OUI7) = '); disp(ENTROPIE_O7)
     N7=N7C1+N7C2+N7C3;  if N7C1==0 | N7C2==0 | N7C3==0 ENTROPIE_N7=0;   else ENTROPIE_N7=-N7C1/N7*log2(N7C1/N7)-N7C2/N7*log2(N7C2/N7)-N7C3/N7*log2(N7C3/N7); end;
     disp('ENTROPIE(NON7) = '); disp(ENTROPIE_N7) 
        %************* Gain de l'attribut COT **************%
    GAIN_COT=ENTROPIE0-(O7/length(CLASSE)*ENTROPIE_O7+N7/length(CLASSE)*ENTROPIE_N7)
     
    % /////////////// Choix  du  meilleur attribut du second niveau /////////////////////  %%%
    attributs={'TEMPERATURE','OXYGENE','NO2','NO3','COT'}
    Gains=[GAIN_TEMPERATURE; GAIN_OXYGENE; GAIN_NO2; GAIN_NO3; GAIN_COT];
    Gain_maximum= max(Gains);
    MaxGain=0;
    for i=1:3  if Gains(i)>=MaxGain;  MaxGain=Gains(i); attr1=attributs(i); end; end; 
    disp('le troisieme attribut choisit est :'); disp(attr1)

  7. #7
    Invité
    Invité(e)
    Par défaut
    On va clarifier un peu les choses. Prends cet exemple :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    CLASSE=['C1';'C1';'C1';'C2';'C2';'C3';'C3';'C3';'C3'];
    for i=1:length(CLASSE)
        fprintf('CLASSE(%d) = ''%c''\n', i , CLASSE(i))
    end
    CLASSE est ici un tableau de taille 9x2 qui est équivalent à :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    CLASSE  = [...
        'C' , '1' ;
        'C' , '1' ;
        'C' , '1' ;
        'C' , '2' ;
        'C' , '2' ;
        'C' , '3' ;
        'C' , '3' ;
        'C' , '3' ;
        'C' , '3' ];
    Donc
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    CLASSE(1) = CLASSE(1,1) = 'C'
    CLASSE(2) = CLASSE(2,1) = 'C'
    ...
    CLASSE(N) = CLASSE(N,1) = 'C' % N = length(CLASSE)
    Tu ne parcours jamais les nombres '1', '2' et '3'.

    Je te conseille de suivre le conseil de FLB et utiliser des tableaux de cellules avec la fonction strcmp.
    Dernière modification par Invité ; 03/01/2013 à 17h57.

Discussions similaires

  1. Warning: Division by zero
    Par nissaexpa dans le forum Langage
    Réponses: 6
    Dernier message: 03/07/2007, 11h24

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