MATLAB Examples

PSO SELECTION DEMO

Contents

Initialize

clc
clear all
warning off all

DEMO 1

row=50;
col=10;
Data=randi([1,50],[row,col]);
disp('Data---->')
disp(Data)
nOfSelection=3;
population=20;
itrationMax=inf;
fun=@meandata;
[Selection , SelectionValue]=psoSelection(Data,nOfSelection,population,itrationMax,fun);
MinimizedData=Data(:,Selection);
disp('Selection---->')
disp(Selection)
disp('SelectionValue---->')
disp(SelectionValue)
Data---->
    49     9    13    18    29     2    35    14    31    34
    23     4    23    48    29    19    32     5     5    47
     5    24    36     3    23    33     7     6     8    48
    26    28    25    20    41    11    26    32    17    32
    13    48    13    23    17    26     3     5     9    31
     7     9    22    44    30    45    11    16    47    38
     7     6     4    27    10    23    37     3     3    10
    18    11    26    24    35     7    41    34     5    29
    12    21    31     4    36     6    30    43    47    21
    27    11    32    10     5     4     9     8    21    24
    35    33    44    38     2    24    16    16     3     7
     8    29    11    13    49    38    13     5    35    24
    31    32    13    22    15    32    15    12    39    27
     7    41    50    42     3    46    36    12    34    21
    46    25    17     7    37     8    20    47    32    27
    33     7    29     1     8    22    12     1     2    14
     8    42    29    26    40    26    48    31    46    16
    39     8    21    23    44    16    30     8    16    18
    35    20    30     4     8    48    28    10    36    48
    33    34     5    11    38    17    40    46    48    21
    42    18    27    34     8    26    41    26    10    44
    33    32    27     3    20    41    15    28    11     6
     3    22    19     5    11    24    26    29     8    47
    39     8    10    11    48     1    42    50    40    16
     9    14    25    13    21     3    26    12    15    13
    21    36    24     6    33    22     4    15    46    21
    15    48    28     6     4    14    26    44    47    12
    12    50    33    42    50    30     1    15    31    38
    10    30    17     5     8    39    43     6    11    21
    31    18    42     4    49    24    49    23    22    14
    27     4    29    35    35     6    22    35    11    48
    14    49    35     3    39    44    44    25    31    14
     5     9    36     6    22    37    41    36    27    42
    39    26    34     5    48    10    45     1    10     6
    24    36    19     9    21    40    35    31    11    13
    28     1    14     1    25    50    14    27    42     3
    16    33    10     1    28    30    23    33    27    26
    31    46    42    18    49    49    10    15    22    43
    42    30    34    11    25     3    41    26    18     8
    36    48     8    15    18    11    32    37    44    48
    30    43     4    42    17    11     9    47     9    34
    32     6    23    50    29    10    42    36    34    13
     7    18     7    33     6    26    22    17    31     9
    27    28    48    32    14    33    23    21    36    41
     6    28    22    37    18    31    22    13    15    25
    14    46    29    14    21    35    50    30    22    48
     2    21    28    30    11     3    41    17    40    46
    11    39    11    12     1    40    50    14    39    23
     6     3    33    19    19     8    29    38    26    17
     8    24     1    13    31    32    16    33    32    39


Iteration 1 gbest value of  fitness= 21.273333
Iteration 2 gbest value of  fitness= 21.273333
Iteration 3 gbest value of  fitness= 21.273333
Iteration 4 gbest value of  fitness= 21.273333
Iteration 5 gbest value of  fitness= 21.273333
Iteration 6 gbest value of  fitness= 21.273333
Iteration 7 gbest value of  fitness= 21.273333
Iteration 8 gbest value of  fitness= 21.273333
Iteration 9 gbest value of  fitness= 21.273333
Iteration 10 gbest value of  fitness= 21.273333
Iteration 11 gbest value of  fitness= 21.273333
Iteration 12 gbest value of  fitness= 21.273333
Iteration 13 gbest value of  fitness= 21.273333
Iteration 14 gbest value of  fitness= 21.273333
Iteration 15 gbest value of  fitness= 21.273333
Iteration 16 gbest value of  fitness= 21.273333
Iteration 17 gbest value of  fitness= 21.273333
Iteration 18 gbest value of  fitness= 21.273333
Iteration 19 gbest value of  fitness= 21.273333
Iteration 20 gbest value of  fitness= 21.273333
Iteration 21 gbest value of  fitness= 21.273333
Iteration 22 gbest value of  fitness= 21.273333
Iteration 23 gbest value of  fitness= 21.273333
Iteration 24 gbest value of  fitness= 21.273333
Iteration 25 gbest value of  fitness= 20.926667
Iteration 26 gbest value of  fitness= 20.926667
Iteration 27 gbest value of  fitness= 20.926667
Iteration 28 gbest value of  fitness= 20.926667
Iteration 29 gbest value of  fitness= 20.926667
Iteration 30 gbest value of  fitness= 20.926667
Iteration 31 gbest value of  fitness= 20.926667
Iteration 32 gbest value of  fitness= 20.926667
Iteration 33 gbest value of  fitness= 20.926667
Iteration 34 gbest value of  fitness= 20.926667
Iteration 35 gbest value of  fitness= 20.926667
Iteration 36 gbest value of  fitness= 20.926667
Iteration 37 gbest value of  fitness= 20.926667
Iteration 38 gbest value of  fitness= 20.926667
Iteration 39 gbest value of  fitness= 20.926667
Iteration 40 gbest value of  fitness= 20.926667
Iteration 41 gbest value of  fitness= 20.926667
Iteration 42 gbest value of  fitness= 20.926667
Iteration 43 gbest value of  fitness= 20.926667
Iteration 44 gbest value of  fitness= 20.926667
Iteration 45 gbest value of  fitness= 20.926667
Iteration 46 gbest value of  fitness= 20.926667
Iteration 47 gbest value of  fitness= 20.926667
Iteration 48 gbest value of  fitness= 20.926667
Iteration 49 gbest value of  fitness= 20.926667
Iteration 50 gbest value of  fitness= 20.926667
Iteration 51 gbest value of  fitness= 20.926667
Iteration 52 gbest value of  fitness= 20.926667
Iteration 53 gbest value of  fitness= 20.926667
Iteration 54 gbest value of  fitness= 20.926667
Iteration 55 gbest value of  fitness= 20.926667
Iteration 56 gbest value of  fitness= 20.926667
Iteration 57 gbest value of  fitness= 20.926667
Iteration 58 gbest value of  fitness= 20.926667
Iteration 59 gbest value of  fitness= 20.926667
Iteration 60 gbest value of  fitness= 20.926667
Iteration 61 gbest value of  fitness= 20.926667
Iteration 62 gbest value of  fitness= 20.926667
Iteration 63 gbest value of  fitness= 20.926667
Iteration 64 gbest value of  fitness= 20.926667
Iteration 65 gbest value of  fitness= 20.926667
Iteration 66 gbest value of  fitness= 20.926667
Iteration 67 gbest value of  fitness= 20.926667
Iteration 68 gbest value of  fitness= 20.926667
Iteration 69 gbest value of  fitness= 20.926667
Iteration 70 gbest value of  fitness= 20.926667
Iteration 71 gbest value of  fitness= 20.926667
Iteration 72 gbest value of  fitness= 20.926667
Iteration 73 gbest value of  fitness= 20.926667
Iteration 74 gbest value of  fitness= 20.926667
Iteration 75 gbest value of  fitness= 20.926667
Iteration 76 gbest value of  fitness= 20.926667
Iteration 77 gbest value of  fitness= 20.926667
Iteration 78 gbest value of  fitness= 20.926667
Iteration 79 gbest value of  fitness= 20.926667
Iteration 80 gbest value of  fitness= 20.926667
Iteration 81 gbest value of  fitness= 20.926667
Iteration 82 gbest value of  fitness= 20.926667
Iteration 83 gbest value of  fitness= 20.926667
Iteration 84 gbest value of  fitness= 20.926667
Iteration 85 gbest value of  fitness= 20.926667
Iteration 86 gbest value of  fitness= 20.926667
Iteration 87 gbest value of  fitness= 20.926667
Iteration 88 gbest value of  fitness= 20.926667
Iteration 89 gbest value of  fitness= 20.926667
Iteration 90 gbest value of  fitness= 20.926667
Iteration 91 gbest value of  fitness= 20.926667
Iteration 92 gbest value of  fitness= 20.926667
Iteration 93 gbest value of  fitness= 20.926667
Iteration 94 gbest value of  fitness= 20.926667
Iteration 95 gbest value of  fitness= 20.926667
Iteration 96 gbest value of  fitness= 20.926667
Iteration 97 gbest value of  fitness= 20.926667
Iteration 98 gbest value of  fitness= 20.926667
Iteration 99 gbest value of  fitness= 20.926667
Iteration 100 gbest value of  fitness= 20.926667
Iteration 101 gbest value of  fitness= 20.926667
Iteration 102 gbest value of  fitness= 20.926667
Iteration 103 gbest value of  fitness= 20.926667
Iteration 104 gbest value of  fitness= 20.926667
Iteration 105 gbest value of  fitness= 20.926667
Iteration 106 gbest value of  fitness= 20.926667
Iteration 107 gbest value of  fitness= 20.926667
Iteration 108 gbest value of  fitness= 20.926667
Iteration 109 gbest value of  fitness= 20.926667
Iteration 110 gbest value of  fitness= 20.926667
Iteration 111 gbest value of  fitness= 20.926667
Iteration 112 gbest value of  fitness= 20.926667
Iteration 113 gbest value of  fitness= 20.926667
Iteration 114 gbest value of  fitness= 20.926667
Iteration 115 gbest value of  fitness= 20.926667
Iteration 116 gbest value of  fitness= 20.926667
Iteration 117 gbest value of  fitness= 20.926667
Iteration 118 gbest value of  fitness= 20.926667
Iteration 119 gbest value of  fitness= 20.926667
Iteration 120 gbest value of  fitness= 20.926667
Iteration 121 gbest value of  fitness= 20.926667
Iteration 122 gbest value of  fitness= 20.926667
Iteration 123 gbest value of  fitness= 20.926667
Iteration 124 gbest value of  fitness= 20.926667
Iteration 125 gbest value of  fitness= 20.926667
Iteration 126 gbest value of  fitness= 20.926667
Iteration 127 gbest value of  fitness= 20.926667
Iteration 128 gbest value of  fitness= 20.926667
Iteration 129 gbest value of  fitness= 20.926667
Iteration 130 gbest value of  fitness= 20.926667
Iteration 131 gbest value of  fitness= 20.926667
Iteration 132 gbest value of  fitness= 20.926667
Iteration 133 gbest value of  fitness= 20.926667
Iteration 134 gbest value of  fitness= 20.926667
Iteration 135 gbest value of  fitness= 20.926667
Iteration 136 gbest value of  fitness= 20.926667
Iteration 137 gbest value of  fitness= 20.926667
Iteration 138 gbest value of  fitness= 20.926667
Iteration 139 gbest value of  fitness= 20.926667
Iteration 140 gbest value of  fitness= 20.926667
Iteration 141 gbest value of  fitness= 20.926667
Iteration 142 gbest value of  fitness= 20.926667
Iteration 143 gbest value of  fitness= 20.926667
Iteration 144 gbest value of  fitness= 20.926667
Iteration 145 gbest value of  fitness= 20.926667
Iteration 146 gbest value of  fitness= 20.926667
Iteration 147 gbest value of  fitness= 20.926667
Iteration 148 gbest value of  fitness= 20.926667
Iteration 149 gbest value of  fitness= 20.926667
Iteration 150 gbest value of  fitness= 20.926667
Iteration 151 gbest value of  fitness= 20.926667
Iteration 152 gbest value of  fitness= 20.926667
Iteration 153 gbest value of  fitness= 20.926667
Iteration 154 gbest value of  fitness= 20.926667
Iteration 155 gbest value of  fitness= 20.926667
Iteration 156 gbest value of  fitness= 20.926667
Iteration 157 gbest value of  fitness= 20.926667
Iteration 158 gbest value of  fitness= 20.926667
Iteration 159 gbest value of  fitness= 20.926667
Iteration 160 gbest value of  fitness= 20.926667
Iteration 161 gbest value of  fitness= 20.926667
Iteration 162 gbest value of  fitness= 20.926667
Iteration 163 gbest value of  fitness= 20.926667
Iteration 164 gbest value of  fitness= 20.926667
Iteration 165 gbest value of  fitness= 20.926667
******Iteration completed******
Selection---->
     8     4     1

SelectionValue---->
       20.927

Demo 1 output

disp('MinimizedData---->')
disp(MinimizedData)
MinimizedData---->
    14    18    49
     5    48    23
     6     3     5
    32    20    26
     5    23    13
    16    44     7
     3    27     7
    34    24    18
    43     4    12
     8    10    27
    16    38    35
     5    13     8
    12    22    31
    12    42     7
    47     7    46
     1     1    33
    31    26     8
     8    23    39
    10     4    35
    46    11    33
    26    34    42
    28     3    33
    29     5     3
    50    11    39
    12    13     9
    15     6    21
    44     6    15
    15    42    12
     6     5    10
    23     4    31
    35    35    27
    25     3    14
    36     6     5
     1     5    39
    31     9    24
    27     1    28
    33     1    16
    15    18    31
    26    11    42
    37    15    36
    47    42    30
    36    50    32
    17    33     7
    21    32    27
    13    37     6
    30    14    14
    17    30     2
    14    12    11
    38    19     6
    33    13     8

DEMO 2

nOfSelection=4;
population=10;
itrationMax=100;
fun=@stddata;
[Selection , SelectionValue]=psoSelection(Data,nOfSelection,population,itrationMax,fun);
MinimizedData=Data(:,Selection);
disp('Selection---->')
disp(Selection)
disp('SelectionValue---->')
disp(SelectionValue)
Iteration 1 gbest value of  fitness= 13.426886
Iteration 2 gbest value of  fitness= 13.426886
Iteration 3 gbest value of  fitness= 13.404519
Iteration 4 gbest value of  fitness= 13.368620
Iteration 5 gbest value of  fitness= 13.368620
Iteration 6 gbest value of  fitness= 13.368620
Iteration 7 gbest value of  fitness= 13.368620
Iteration 8 gbest value of  fitness= 13.368620
Iteration 9 gbest value of  fitness= 13.346253
Iteration 10 gbest value of  fitness= 13.346253
Iteration 11 gbest value of  fitness= 13.346253
Iteration 12 gbest value of  fitness= 13.346253
Iteration 13 gbest value of  fitness= 13.346253
Iteration 14 gbest value of  fitness= 13.346253
Iteration 15 gbest value of  fitness= 13.346253
Iteration 16 gbest value of  fitness= 13.346253
Iteration 17 gbest value of  fitness= 13.346253
Iteration 18 gbest value of  fitness= 13.346253
Iteration 19 gbest value of  fitness= 13.346253
Iteration 20 gbest value of  fitness= 13.346253
Iteration 21 gbest value of  fitness= 13.346253
Iteration 22 gbest value of  fitness= 13.241083
Iteration 23 gbest value of  fitness= 13.241083
Iteration 24 gbest value of  fitness= 13.241083
Iteration 25 gbest value of  fitness= 13.241083
Iteration 26 gbest value of  fitness= 13.241083
Iteration 27 gbest value of  fitness= 13.241083
Iteration 28 gbest value of  fitness= 13.241083
Iteration 29 gbest value of  fitness= 13.241083
Iteration 30 gbest value of  fitness= 13.241083
Iteration 31 gbest value of  fitness= 13.241083
Iteration 32 gbest value of  fitness= 13.241083
Iteration 33 gbest value of  fitness= 13.241083
Iteration 34 gbest value of  fitness= 13.241083
Iteration 35 gbest value of  fitness= 13.241083
Iteration 36 gbest value of  fitness= 13.241083
Iteration 37 gbest value of  fitness= 13.241083
Iteration 38 gbest value of  fitness= 13.241083
Iteration 39 gbest value of  fitness= 13.241083
Iteration 40 gbest value of  fitness= 13.241083
Iteration 41 gbest value of  fitness= 13.241083
Iteration 42 gbest value of  fitness= 13.241083
Iteration 43 gbest value of  fitness= 13.241083
Iteration 44 gbest value of  fitness= 13.241083
Iteration 45 gbest value of  fitness= 13.241083
Iteration 46 gbest value of  fitness= 13.241083
Iteration 47 gbest value of  fitness= 13.241083
Iteration 48 gbest value of  fitness= 13.241083
Iteration 49 gbest value of  fitness= 13.241083
Iteration 50 gbest value of  fitness= 13.241083
Iteration 51 gbest value of  fitness= 13.241083
Iteration 52 gbest value of  fitness= 13.241083
Iteration 53 gbest value of  fitness= 13.241083
Iteration 54 gbest value of  fitness= 13.241083
Iteration 55 gbest value of  fitness= 13.241083
Iteration 56 gbest value of  fitness= 13.241083
Iteration 57 gbest value of  fitness= 13.241083
Iteration 58 gbest value of  fitness= 13.241083
Iteration 59 gbest value of  fitness= 13.241083
Iteration 60 gbest value of  fitness= 13.241083
Iteration 61 gbest value of  fitness= 13.241083
Iteration 62 gbest value of  fitness= 13.241083
Iteration 63 gbest value of  fitness= 13.241083
Iteration 64 gbest value of  fitness= 13.241083
Iteration 65 gbest value of  fitness= 13.241083
Iteration 66 gbest value of  fitness= 13.241083
Iteration 67 gbest value of  fitness= 13.241083
Iteration 68 gbest value of  fitness= 13.241083
Iteration 69 gbest value of  fitness= 13.241083
Iteration 70 gbest value of  fitness= 13.241083
Iteration 71 gbest value of  fitness= 13.241083
Iteration 72 gbest value of  fitness= 13.241083
Iteration 73 gbest value of  fitness= 13.241083
Iteration 74 gbest value of  fitness= 13.241083
Iteration 75 gbest value of  fitness= 13.241083
Iteration 76 gbest value of  fitness= 13.241083
Iteration 77 gbest value of  fitness= 13.241083
Iteration 78 gbest value of  fitness= 13.241083
Iteration 79 gbest value of  fitness= 13.241083
Iteration 80 gbest value of  fitness= 13.241083
Iteration 81 gbest value of  fitness= 13.241083
Iteration 82 gbest value of  fitness= 13.241083
Iteration 83 gbest value of  fitness= 13.241083
Iteration 84 gbest value of  fitness= 13.241083
Iteration 85 gbest value of  fitness= 13.241083
Iteration 86 gbest value of  fitness= 13.241083
Iteration 87 gbest value of  fitness= 13.241083
Iteration 88 gbest value of  fitness= 13.241083
Iteration 89 gbest value of  fitness= 13.241083
Iteration 90 gbest value of  fitness= 13.241083
Iteration 91 gbest value of  fitness= 13.241083
Iteration 92 gbest value of  fitness= 13.241083
Iteration 93 gbest value of  fitness= 13.241083
Iteration 94 gbest value of  fitness= 13.241083
Iteration 95 gbest value of  fitness= 13.241083
Iteration 96 gbest value of  fitness= 13.241083
Iteration 97 gbest value of  fitness= 13.241083
Iteration 98 gbest value of  fitness= 13.241083
Iteration 99 gbest value of  fitness= 13.241083
Iteration 100 gbest value of  fitness= 13.241083
******Iteration completed******
Selection---->
     8     1     7     3

SelectionValue---->
       13.241

Demo 2 output

disp('MinimizedData---->')
disp(MinimizedData)
MinimizedData---->
    14    49    35    13
     5    23    32    23
     6     5     7    36
    32    26    26    25
     5    13     3    13
    16     7    11    22
     3     7    37     4
    34    18    41    26
    43    12    30    31
     8    27     9    32
    16    35    16    44
     5     8    13    11
    12    31    15    13
    12     7    36    50
    47    46    20    17
     1    33    12    29
    31     8    48    29
     8    39    30    21
    10    35    28    30
    46    33    40     5
    26    42    41    27
    28    33    15    27
    29     3    26    19
    50    39    42    10
    12     9    26    25
    15    21     4    24
    44    15    26    28
    15    12     1    33
     6    10    43    17
    23    31    49    42
    35    27    22    29
    25    14    44    35
    36     5    41    36
     1    39    45    34
    31    24    35    19
    27    28    14    14
    33    16    23    10
    15    31    10    42
    26    42    41    34
    37    36    32     8
    47    30     9     4
    36    32    42    23
    17     7    22     7
    21    27    23    48
    13     6    22    22
    30    14    50    29
    17     2    41    28
    14    11    50    11
    38     6    29    33
    33     8    16     1