~ubuntu-branches/ubuntu/utopic/libhac-java/utopic

« back to all changes in this revision

Viewing changes to src/ch/usi/inf/sape/hac/agglomeration/CompleteLinkage.java

  • Committer: Package Import Robot
  • Author(s): Andreas Tille
  • Date: 2014-04-10 20:59:14 UTC
  • Revision ID: package-import@ubuntu.com-20140410205914-jul0jw261jyyy6nn
Tags: upstream-0.20110510
ImportĀ upstreamĀ versionĀ 0.20110510

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is licensed to You under the "Simplified BSD License".
 
3
 * You may not use this software except in compliance with the License. 
 
4
 * You may obtain a copy of the License at
 
5
 *
 
6
 * http://www.opensource.org/licenses/bsd-license.php
 
7
 * 
 
8
 * See the COPYRIGHT file distributed with this work for information
 
9
 * regarding copyright ownership.
 
10
 */
 
11
package ch.usi.inf.sape.hac.agglomeration;
 
12
 
 
13
 
 
14
/**
 
15
 * The "complete", "maximum", "clique", 
 
16
 * "furthest neighbor", or "furthest distance" method is a graph-based approach.
 
17
 * 
 
18
 * The distance between two clusters is calculated as the largest distance 
 
19
 * between two objects in opposite clusters.
 
20
 * This method tends to produce well separated, small, compact spherical clusters.
 
21
 * The cluster space is dilated. 
 
22
 * [The data analysis handbook. By Ildiko E. Frank, Roberto Todeschini]
 
23
 * 
 
24
 * This method tends to produce compact clusters. Outliers are given more weight with this method.
 
25
 * It is generally a good choice if the clusters are far apart in feature space, but not good if the data are noisy.
 
26
 * @see http://www.stanford.edu/~maureenh/quals/html/ml/node75.html
 
27
 *  
 
28
 * The general form of the Lance-Williams matrix-update formula:
 
29
 * d[(i,j),k] = ai*d[i,k] + aj*d[j,k] + b*d[i,j] + g*|d[i,k]-d[j,k]|
 
30
 *
 
31
 * For the "single linkage" method:
 
32
 * ai = 0.5
 
33
 * aj = 0.5
 
34
 * b  = 0
 
35
 * g  = 0.5
 
36
 * 
 
37
 * Thus:
 
38
 * d[(i,j),k] = 0.5*d[i,k] + 0.5*d[j,k] + 0.5*|d[i,k]-d[j,k]|
 
39
 *            = 0.5*d[i,k] + 0.5*d[j,k] + | 0.5*d[i,k] - 0.5*d[j,k] |
 
40
 *            = d[i,j]<d[j,k]  ?  0.5*d[i,k] + 0.5*d[j,k] - 0.5*d[i,k] + 0.5*d[j,k]  :  0.5*d[i,k] + 0.5*d[j,k] + 0.5*d[i,k] - 0.5*d[j,k]
 
41
 *            = d[i,j]<d[j,k]  ?  0.5*d[j,k] + 0.5*d[j,k]  :  0.5*d[i,k] + 0.5*d[i,k]
 
42
 *            = d[i,j]<d[j,k]  ?  d[j,k]  :  d[i,k]
 
43
 *            = max( d[i,k] , d[j,k] )
 
44
 *            
 
45
 * @author Matthias.Hauswirth@usi.ch
 
46
 */
 
47
public final class CompleteLinkage implements AgglomerationMethod {
 
48
 
 
49
    public double computeDissimilarity(final double dik, final double djk, final double dij, final int ci, final int cj, final int ck) {
 
50
        return Math.max(dik, djk);
 
51
    }
 
52
    
 
53
    public String toString() {
 
54
        return "Complete";
 
55
    }
 
56
 
 
57
}