MATLAB Examples

Binary Bat SELECTION DEMO

Contents

Initialize

clc
clear all
warning off all

DEMO 1

row=50;
col=20;
Data=randi([1,50],[row,col]);
disp('Data---->')
disp(Data)
nOfBat=20;
itrationMax=inf;
fun=@meandata;
[Selection , SelectionValue]=batSelection(Data,nOfBat,itrationMax,fun);
MinimizedData=Data(:,Selection);
disp('Selection---->')
disp(Selection)
disp('SelectionValue---->')
disp(SelectionValue)
Data---->
  Columns 1 through 13

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

  Columns 14 through 20

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


Best fitness of 1 iteration is 27.047500
Best fitness of 2 iteration is 27.047500
Best fitness of 3 iteration is 27.366667
Best fitness of 4 iteration is 27.366667
Best fitness of 5 iteration is 27.366667
Best fitness of 6 iteration is 27.366667
Best fitness of 7 iteration is 27.366667
Best fitness of 8 iteration is 27.366667
Best fitness of 9 iteration is 27.366667
Best fitness of 10 iteration is 27.366667
Best fitness of 11 iteration is 27.366667
Best fitness of 12 iteration is 27.587500
Best fitness of 13 iteration is 27.587500
Best fitness of 14 iteration is 27.587500
Best fitness of 15 iteration is 27.587500
Best fitness of 16 iteration is 27.587500
Best fitness of 17 iteration is 27.587500
Best fitness of 18 iteration is 27.587500
Best fitness of 19 iteration is 27.587500
Best fitness of 20 iteration is 27.587500
Best fitness of 21 iteration is 27.587500
Best fitness of 22 iteration is 27.587500
Best fitness of 23 iteration is 27.587500
Best fitness of 24 iteration is 27.587500
Best fitness of 25 iteration is 27.587500
Best fitness of 26 iteration is 27.587500
Best fitness of 27 iteration is 27.587500
Best fitness of 28 iteration is 27.587500
Best fitness of 29 iteration is 27.587500
Best fitness of 30 iteration is 27.587500
Best fitness of 31 iteration is 27.587500
Best fitness of 32 iteration is 27.587500
Best fitness of 33 iteration is 27.587500
Best fitness of 34 iteration is 27.587500
Best fitness of 35 iteration is 27.587500
Best fitness of 36 iteration is 27.587500
Best fitness of 37 iteration is 27.587500
Best fitness of 38 iteration is 27.587500
Best fitness of 39 iteration is 27.587500
Best fitness of 40 iteration is 27.587500
Best fitness of 41 iteration is 27.587500
Best fitness of 42 iteration is 27.587500
Best fitness of 43 iteration is 27.587500
Best fitness of 44 iteration is 27.587500
Best fitness of 45 iteration is 27.587500
Best fitness of 46 iteration is 27.587500
Best fitness of 47 iteration is 27.587500
Best fitness of 48 iteration is 27.587500
Best fitness of 49 iteration is 27.587500
Best fitness of 50 iteration is 27.587500
Best fitness of 51 iteration is 27.587500
Best fitness  overload is 27.587500
Selection---->
     2     6     7     9    14    15    17    19

SelectionValue---->
       27.587

Demo 1 output

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

DEMO 2

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

SelectionValue---->
       15.695

Demo 2 output

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