File: gustafson_kessel.html

package info (click to toggle)
octave-fuzzy-logic-toolkit 0.6.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,024 kB
  • sloc: makefile: 147
file content (492 lines) | stat: -rw-r--r-- 19,696 bytes parent folder | download
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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Octave Fuzzy Logic Toolkit: gustafson_kessel</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" integrity="sha512-1ycn6IcaQQ40/MKBW2W4Rhis/DbILU74C1vSrLJxCq57o941Ym01SwNsOMqvEBFlcgUa6xLiPY/NS5R+E6ztJQ==" crossorigin="anonymous" referrerpolicy="no-referrer">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" integrity="sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-U1DAWAznBHeqEIlVSCgzq+c9gqGAJn5c/t99JyeKa9xxaYpSvHU5awsuZVVFIhvj" crossorigin="anonymous"></script>
    <script type="text/javascript" async
      src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML">
    </script>
    <style>
    var {
      font-style: italics;
      font-weight: bold;
    }
    td {
      vertical-align: top;
    }
    </style>
  </head>
  <body>
    <div class="bg-dark">
      <div class="container-xl">
        <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
          <div class="container-fluid">
            <a class="navbar-brand" href=index.html>
              <img src="assets/fuzzy-logic-toolkit.png" alt="fuzzy-logic-toolkit" class="d-inline-block align-top" width="25" height="25">
              Octave Fuzzy Logic Toolkit
            </a>
            <button type="button" class="navbar-toggler" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
              <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
              <ul class="navbar-nav">
                <li class="nav-item">
                  <a class="nav-link" href="index.html#Fuzzy Clustering Functions">
                    <i class="fas fa-list-alt"></i>
                    Fuzzy Clustering Functions
                  </a>
                </li>
                <li class="nav-item">
                  <a class="nav-link" href="https://gnu-octave.github.io/packages/">
                  <img src="assets/octave-logo.svg" alt="GNU Octave logo" class="d-inline-block align-top" width="25" height="25">
                    Octave Packages
                  </a>
                </li>
                <li class="nav-item">
                  <a class="nav-link" href="https://www.octave.org">
                    <i class="fas fa-home"></i>
                    GNU Octave website
                  </a>
                </li>
              </ul>
            </div>
          </div>
        </nav>
      </div>
    </div>
    <div class="container-xl my-4">
      <div class="card rounded">
        <div class="card-header card-header-mod">
          <div class="row d-flex flex-wrap align-items-center">
            <div class="col-sm-3 col-md-5 mb-2 mb-sm-0">
              <h3 class="d-inline-block mr-2">
              Function&nbsp;Reference: <b><code>gustafson_kessel</code></b>
              </h3>
            </div>
          </div>
        </div>
        <div class="card-body">
<dl>
<dt><u>Function File:</u> <var>cluster_centers</var> = <b>gustafson_kessel</b><i> (<var>input_data</var>, <var>num_clusters</var>)</i></dt>
<dt><u>Function File:</u> <var>cluster_centers</var> = <b>gustafson_kessel</b><i> (<var>input_data</var>, <var>num_clusters</var>, <var>cluster_volume</var>)</i></dt>
<dt><u>Function File:</u> <var>cluster_centers</var> = <b>gustafson_kessel</b><i> (<var>input_data</var>, <var>num_clusters</var>, <var>cluster_volume</var>, <var>options</var>)</i></dt>
<dt><u>Function File:</u> <var>cluster_centers</var> = <b>gustafson_kessel</b><i> (<var>input_data</var>, <var>num_clusters</var>, <var>cluster_volume</var>, [<var>m</var>, <var>max_iterations</var>, <var>epsilon</var>, <var>display_intermediate_results</var>])</i></dt>
<dt><u>Function File:</u> [<var>cluster_centers</var>, <var>soft_partition</var>, <var>obj_fcn_history</var>] = <b>gustafson_kessel</b><i> (<var>input_data</var>, <var>num_clusters</var>)</i></dt>
<dt><u>Function File:</u> [<var>cluster_centers</var>, <var>soft_partition</var>, <var>obj_fcn_history</var>] = <b>gustafson_kessel</b><i> (<var>input_data</var>, <var>num_clusters</var>, <var>cluster_volume</var>)</i></dt>
<dt><u>Function File:</u> [<var>cluster_centers</var>, <var>soft_partition</var>, <var>obj_fcn_history</var>] = <b>gustafson_kessel</b><i> (<var>input_data</var>, <var>num_clusters</var>, <var>cluster_volume</var>, <var>options</var>)</i></dt>
<dt><u>Function File:</u> [<var>cluster_centers</var>, <var>soft_partition</var>, <var>obj_fcn_history</var>] = <b>gustafson_kessel</b><i> (<var>input_data</var>, <var>num_clusters</var>, <var>cluster_volume</var>, [<var>m</var>, <var>max_iterations</var>, <var>epsilon</var>, <var>display_intermediate_results</var>])</i></dt>
</dl>

<p> Using the Gustafson-Kessel algorithm, calculate and return the soft partition
 of a set of unlabeled data points.
</p>
<div class="ms-5">
<p> Also, if <var>display_intermediate_results</var> is true, display intermediate 
 results after each iteration. Note that because the initial cluster
 prototypes are randomly selected locations in the ranges determined by the
 input data, the results of this function are nondeterministic.
</p>
<p> The required arguments to gustafson_kessel are:
 </p><ul class="toc">
<li>
 <var>input_data</var>: a matrix of input data points; each row corresponds to one point
 
</li><li>
 <var>num_clusters</var>: the number of clusters to form
 
</li></ul>

<p> The third (optional) argument to gustafson_kessel is a vector of cluster volumes.
 If omitted, a vector of 1&rsquo;s will be used as the default.
</p>
<p> The fourth (optional) argument to gustafson_kessel is a vector consisting of:
 </p><ul class="toc">
<li>
 <var>m</var>: the parameter (exponent) in the objective function; default = 2.0
 
</li><li>
 <var>max_iterations</var>: the maximum number of iterations before stopping; default = 100
 
</li><li>
 <var>epsilon</var>: the stopping criteria; default = 1e-5
 
</li><li>
 <var>display_intermediate_results</var>: if 1, display results after each iteration, and if 0, do not; default = 1
 
</li></ul>

<p> The default values are used if any of the four elements of the vector are missing or
 evaluate to NaN.
</p>
<p> The return values are:
 </p><ul class="toc">
<li>
 <var>cluster_centers</var>: a matrix of the cluster centers; each row corresponds to one point
 
</li><li>
 <var>soft_partition</var>: a constrained soft partition matrix
 
</li><li>
 <var>obj_fcn_history</var>: the values of the objective function after each iteration
 
</li></ul>

<p> Three important matrices used in the calculation are X (the input points
 to be clustered), V (the cluster centers), and Mu (the membership of each
 data point in each cluster). Each row of X and V denotes a single point,
 and Mu(i, j) denotes the membership degree of input point X(j, :) in the
 cluster having center V(i, :).
</p>
<p> X is identical to the required argument <var>input_data</var>; V is identical
 to the output <var>cluster_centers</var>; and Mu is identical to the output
 <var>soft_partition</var>.
</p>
<p> If n denotes the number of input points and k denotes the number of
 clusters to be formed, then X, V, and Mu have the dimensions:
</p>
<pre class="verbatim">                                     1    2   ...  #features
                               1 [[                           ]
    X  =  input_data       =   2  [                           ]
                              ... [                           ]
                               n  [                           ]]

                                     1    2   ...  #features
                               1 [[                           ]
    V  =  cluster_centers  =   2  [                           ]
                              ... [                           ]
                               k  [                           ]]

                                     1    2   ...   n
                               1 [[                    ]
    Mu  =  soft_partition  =   2  [                    ]
                              ... [                    ]
                               k  [                    ]]
 </pre>
<p> <strong>See also: </strong>
  <a href="fcm.html">fcm</a>, 
  <a href="partition_coeff.html">partition_coeff</a>, 
  <a href="partition_entropy.html">partition_entropy</a>, 
  <a href="xie_beni_index.html">xie_beni_index</a>
</p>
</div>
        <div class="container-xl my-4">
          <div class="card rounded">
            <div class="card-header card-header-mod">
              <div class="row d-flex flex-wrap align-items-center">
                <div class="col-sm-3 col-md-5 mb-2 mb-sm-0">
                  <h3 class="d-inline-block mr-2">
                  Example: 1
                  </h3>
                </div>
              </div>
            </div>
            <div class="card-body">
              <div class="container bg-light">
                <div class="row">
                  <table><tbody><tr>
                    <td>&nbsp;</td>
                    <td><pre class="example">

 ## This demo:
 ##    - classifies a small set of unlabeled data points using
 ##      the Gustafson-Kessel algorithm into two fuzzy clusters
 ##    - plots the input points together with the cluster centers
 ##    - evaluates the quality of the resulting clusters using
 ##      three validity measures: the partition coefficient, the
 ##      partition entropy, and the Xie-Beni validity index
 ##
 ## Note: The input_data is taken from Chapter 13, Example 17 in
 ##       Fuzzy Logic: Intelligence, Control and Information, by
 ##       J. Yen and R. Langari, Prentice Hall, 1999, page 381
 ##       (International Edition). 
 
 ## Use gustafson_kessel to classify the input_data.
 input_data = [2 12; 4 9; 7 13; 11 5; 12 7; 14 4];
 number_of_clusters = 2;
 [cluster_centers, soft_partition, obj_fcn_history] = ...
   gustafson_kessel (input_data, number_of_clusters)
 
 ## Plot the data points as small blue x's.
 figure ('NumberTitle', 'off', 'Name', 'Gustafson-Kessel Demo 1');
 for i = 1 : rows (input_data)
   plot (input_data(i, 1), input_data(i, 2), 'LineWidth', 2, ...
         'marker', 'x', 'color', 'b');
   hold on;
 endfor
 
 ## Plot the cluster centers as larger red *'s.
 for i = 1 : number_of_clusters
   plot (cluster_centers(i, 1), cluster_centers(i, 2), ...
         'LineWidth', 4, 'marker', '*', 'color', 'r');
   hold on;
 endfor
 
 ## Make the figure look a little better:
 ##    - scale and label the axes
 ##    - show gridlines
 xlim ([0 15]);
 ylim ([0 15]);
 xlabel ('Feature 1');
 ylabel ('Feature 2');
 grid
 hold
 
 ## Calculate and print the three validity measures.
 printf ("Partition Coefficient: %f\n", ...
         partition_coeff (soft_partition));
 printf ("Partition Entropy (with a = 2): %f\n", ...
         partition_entropy (soft_partition, 2));
 printf ("Xie-Beni Index: %f\n\n", ...
         xie_beni_index (input_data, cluster_centers, ...
         soft_partition));

Iteration count = 1,  Objective fcn = 45.858745
Iteration count = 2,  Objective fcn = 32.524816
Iteration count = 3,  Objective fcn = 26.049556
Iteration count = 4,  Objective fcn = 25.673979
Iteration count = 5,  Objective fcn = 25.652426
Iteration count = 6,  Objective fcn = 25.647293
Iteration count = 7,  Objective fcn = 25.645559
Iteration count = 8,  Objective fcn = 25.644959
Iteration count = 9,  Objective fcn = 25.644752
Iteration count = 10,  Objective fcn = 25.644681
Iteration count = 11,  Objective fcn = 25.644657
Iteration count = 12,  Objective fcn = 25.644648
Iteration count = 13,  Objective fcn = 25.644645
Iteration count = 14,  Objective fcn = 25.644644
Iteration count = 15,  Objective fcn = 25.644644
Iteration count = 16,  Objective fcn = 25.644644
Iteration count = 17,  Objective fcn = 25.644644
Iteration count = 18,  Objective fcn = 25.644644
Iteration count = 19,  Objective fcn = 25.644644
Iteration count = 20,  Objective fcn = 25.644644
Iteration count = 21,  Objective fcn = 25.644644
cluster_centers =

   12.2661    5.3877
    4.2228   11.3276

soft_partition =

   0.065974   0.109473   0.129499   0.976470   0.971912   0.987408
   0.934026   0.890527   0.870501   0.023530   0.028088   0.012592

obj_fcn_history =

 Columns 1 through 10:

   45.859   32.525   26.050   25.674   25.652   25.647   25.646   25.645   25.645   25.645

 Columns 11 through 20:

   25.645   25.645   25.645   25.645   25.645   25.645   25.645   25.645   25.645   25.645

 Column 21:

   25.645

Partition Coefficient: 0.888484
Partition Entropy (with a = 2): 0.308027
Xie-Beni Index: 0.107028

                    </pre></td></tr></tbody>
                  </table>
                  <div class="text-center">
                    <img src="assets/gustafson_kessel_101.png" class="rounded img-thumbnail" alt="plotted figure">
                  </div><p></p>

                </div>
              </div>
            </div>
          </div>
        </div>

        <div class="container-xl my-4">
          <div class="card rounded">
            <div class="card-header card-header-mod">
              <div class="row d-flex flex-wrap align-items-center">
                <div class="col-sm-3 col-md-5 mb-2 mb-sm-0">
                  <h3 class="d-inline-block mr-2">
                  Example: 2
                  </h3>
                </div>
              </div>
            </div>
            <div class="card-body">
              <div class="container bg-light">
                <div class="row">
                  <table><tbody><tr>
                    <td>&nbsp;</td>
                    <td><pre class="example">

 ## This demo:
 ##    - classifies three-dimensional unlabeled data points using
 ##      the Gustafson-Kessel algorithm into three fuzzy clusters
 ##    - plots the input points together with the cluster centers
 ##    - evaluates the quality of the resulting clusters using
 ##      three validity measures: the partition coefficient, the
 ##      partition entropy, and the Xie-Beni validity index
 ##
 ## Note: The input_data was selected to form three areas of
 ##       different shapes.
 
 ## Use gustafson_kessel to classify the input_data.
 input_data = [1 11 5; 1 12 6; 1 13 5; 2 11 7; 2 12 6; 2 13 7;
               3 11 6; 3 12 5; 3 13 7; 1 1 10; 1 3 9; 2 2 11;
               3 1 9; 3 3 10; 3 5 11; 4 4 9; 4 6 8; 5 5 8; 5 7 9;
               6 6 10; 9 10 12; 9 12 13; 9 13 14; 10 9 13; 10 13 12;
               11 10 14; 11 12 13; 12 6 12; 12 7 15; 12 9 15;
               14 6 14; 14 8 13];
 number_of_clusters = 3;
 [cluster_centers, soft_partition, obj_fcn_history] = ...
   gustafson_kessel (input_data, number_of_clusters, [1 1 1], ...
                     [NaN NaN NaN 0])
 
 ## Plot the data points in two dimensions (using features 1 & 2)
 ## as small blue x's.
 figure ('NumberTitle', 'off', 'Name', 'Gustafson-Kessel Demo 2');
 for i = 1 : rows (input_data)
   plot (input_data(i, 1), input_data(i, 2), 'LineWidth', 2, ...
         'marker', 'x', 'color', 'b');
   hold on;
 endfor
 
 ## Plot the cluster centers in two dimensions
 ## (using features 1 & 2) as larger red *'s.
 for i = 1 : number_of_clusters
   plot (cluster_centers(i, 1), cluster_centers(i, 2), ...
         'LineWidth', 4, 'marker', '*', 'color', 'r');
   hold on;
 endfor
 
 ## Make the figure look a little better:
 ##    - scale and label the axes
 ##    - show gridlines
 xlim ([0 15]);
 ylim ([0 15]);
 xlabel ('Feature 1');
 ylabel ('Feature 2');
 grid
  
 ## Plot the data points in two dimensions
 ## (using features 1 & 3) as small blue x's.
 figure ('NumberTitle', 'off', 'Name', 'Gustafson-Kessel Demo 2');
 for i = 1 : rows (input_data)
   plot (input_data(i, 1), input_data(i, 3), 'LineWidth', 2, ...
         'marker', 'x', 'color', 'b');
   hold on;
 endfor
 
 ## Plot the cluster centers in two dimensions
 ## (using features 1 & 3) as larger red *'s.
 for i = 1 : number_of_clusters
   plot (cluster_centers(i, 1), cluster_centers(i, 3), ...
         'LineWidth', 4, 'marker', '*', 'color', 'r');
   hold on;
 endfor
 
 ## Make the figure look a little better:
 ##    - scale and label the axes
 ##    - show gridlines
 xlim ([0 15]);
 ylim ([0 15]);
 xlabel ('Feature 1');
 ylabel ('Feature 3');
 grid
 hold
 
 ## Calculate and print the three validity measures.
 printf ("Partition Coefficient: %f\n", ...
         partition_coeff (soft_partition));
 printf ("Partition Entropy (with a = 2): %f\n", ...
         partition_entropy (soft_partition, 2));
 printf ("Xie-Beni Index: %f\n\n", ...
         xie_beni_index (input_data, cluster_centers, ...
         soft_partition));

cluster_centers =

    3.2679    3.7416    9.5189
   11.1675    9.5123   13.4360
    2.0744   11.9210    6.0810

soft_partition =

 Columns 1 through 7:

   1.9129e-02   9.7022e-03   1.0643e-02   2.4975e-02   8.9273e-05   1.9737e-02   2.1778e-02
   1.1157e-02   7.1681e-03   9.2569e-03   1.3793e-02   6.1636e-05   1.8522e-02   1.0694e-02
   9.6971e-01   9.8313e-01   9.8010e-01   9.6123e-01   9.9985e-01   9.6174e-01   9.6753e-01

 Columns 8 through 14:

   4.1337e-02   2.3680e-02   9.6778e-01   9.1988e-01   9.5714e-01   9.2049e-01   9.9099e-01
   2.5264e-02   2.0998e-02   9.2635e-03   1.8979e-02   1.3117e-02   2.2734e-02   2.4882e-03
   9.3340e-01   9.5532e-01   2.2954e-02   6.1140e-02   2.9744e-02   5.6773e-02   6.5221e-03

 Columns 15 through 21:

   8.8919e-01   9.8157e-01   8.2057e-01   8.7617e-01   8.2343e-01   8.1787e-01   1.3809e-01
   3.1044e-02   4.4868e-03   2.9448e-02   2.6948e-02   3.3445e-02   5.4462e-02   7.2960e-01
   7.9764e-02   1.3944e-02   1.4998e-01   9.6877e-02   1.4313e-01   1.2767e-01   1.3231e-01

 Columns 22 through 28:

   4.4812e-02   5.9662e-02   4.7384e-02   1.0958e-01   8.6143e-03   5.4236e-02   8.1535e-02
   9.0208e-01   8.6338e-01   9.0000e-01   7.8177e-01   9.8041e-01   8.8735e-01   8.1781e-01
   5.3109e-02   7.6958e-02   5.2618e-02   1.0865e-01   1.0973e-02   5.8411e-02   1.0065e-01

 Columns 29 through 32:

   4.1312e-02   3.1916e-02   2.5981e-02   5.2999e-02
   8.9517e-01   9.2117e-01   9.3144e-01   8.7447e-01
   6.3519e-02   4.6918e-02   4.2584e-02   7.2535e-02

obj_fcn_history =

 Columns 1 through 10:

   225.36   174.39   162.04   153.98   148.21   143.92   140.45   137.19   133.86   130.30

 Columns 11 through 20:

   126.69   123.61   121.64   120.69   120.29   120.13   120.07   120.05   120.04   120.03

 Columns 21 through 30:

   120.03   120.03   120.03   120.03   120.03   120.03   120.03   120.03   120.03   120.03

 Columns 31 through 33:

   120.03   120.03   120.03

Partition Coefficient: 0.841843
Partition Entropy (with a = 2): 0.472419
Xie-Beni Index: 0.192632

                    </pre></td></tr></tbody>
                  </table>
                  <div class="text-center">
                    <img src="assets/gustafson_kessel_202.png" class="rounded img-thumbnail" alt="plotted figure">
                  </div><p></p>
                  <div class="text-center">
                    <img src="assets/gustafson_kessel_201.png" class="rounded img-thumbnail" alt="plotted figure">
                  </div><p></p>

                </div>
              </div>
            </div>
          </div>
        </div>


        </div>
      </div>
    </div>

  </body>
</html>